diff --git a/api/common/common_views.py b/api/common/common_views.py index 03e4d17f..808b8f4d 100644 --- a/api/common/common_views.py +++ b/api/common/common_views.py @@ -1,3 +1,6 @@ +import json + +import requests from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q from django.db.models.functions import Coalesce from rest_framework.views import APIView @@ -158,3 +161,35 @@ def get(self, request): 'learning_circle_count': learning_circles_count } return CustomResponse(response=data).get_success_response() + + +class GTASANDSHOREAPI(APIView): + def get(self, request): + + response = requests.get('https://devfolio.vez.social/rank') + if response.status_code == 200: + # Save JSON response to a local file + with open('response.json', 'w') as json_file: + json.dump(response.json(), json_file) + + with open('response.json', 'r') as file: + data = json.load(file) + else: + with open('response.json', 'r') as file: + data = json.load(file) + + # Create a dictionary to store the grouped data + grouped_colleges = {} + + for college, count in data.items(): + # Clean the college name by removing spaces and converting to lowercase + cleaned_college = college.replace(" ", "").lower() + + # Check if the cleaned name already exists in the grouped_colleges dictionary + if cleaned_college in grouped_colleges: + # If it exists, add the count to the existing entry + grouped_colleges[cleaned_college] += int(count) + else: + # If it doesn't exist, create a new entry + grouped_colleges[cleaned_college] = int(count) + return CustomResponse(response=grouped_colleges).get_success_response() diff --git a/api/common/urls.py b/api/common/urls.py index 0a695775..808741fd 100644 --- a/api/common/urls.py +++ b/api/common/urls.py @@ -8,4 +8,5 @@ path('college-wise-lc-report/', common_views.CollegeWiseLcReport.as_view()), path('download/lc-report/', common_views.LcReportDownloadAPI.as_view()), path('global-count/', common_views.GlobalCountAPI.as_view()), + path('gta-sandshore/',common_views.GTASANDSHOREAPI.as_view()) ] diff --git a/api/dashboard/affiliation/affiliation_views.py b/api/dashboard/affiliation/affiliation_views.py new file mode 100644 index 00000000..bd7147e3 --- /dev/null +++ b/api/dashboard/affiliation/affiliation_views.py @@ -0,0 +1,77 @@ +from rest_framework.views import APIView +from utils.permission import CustomizePermission,role_required,JWTUtils +from utils.types import RoleType +from .serializers import AffiliationReadSerializer, AffiliationCreateUpdateSerializer +from db.organization import OrgAffiliation +from utils.response import CustomResponse +from utils.utils import CommonUtils + +class AffiliationView(APIView): + authentication_classes = [CustomizePermission] + + + def get(self,request): + all_affiliations = OrgAffiliation.objects.all() + pager_ = CommonUtils.get_paginated_queryset(all_affiliations,request,['title'],sort_fields={'created':'created_at','updated':'updated_at','title':'title'}) + serial_ = AffiliationReadSerializer(pager_.get('queryset'),many=True) + # serial_.is_valid() + return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination")) + + @role_required([RoleType.ADMIN.value]) + def post(self,request): + user_id = JWTUtils.fetch_user_id(request) + + serial_ = AffiliationCreateUpdateSerializer(data=request.data,context={'user_id':user_id}) + + if serial_.is_valid(): + serial_.save() + + return CustomResponse( + general_message=f"{request.data.get('title')} added successfully" + ).get_success_response() + + return CustomResponse( + general_message=serial_.errors + ).get_failure_response() + + @role_required([RoleType.ADMIN.value]) + def put(self,request,affiliation_id): + user_id = JWTUtils.fetch_user_id(request) + affiliation = OrgAffiliation.objects.filter(id=affiliation_id).first() + + if affiliation is None: + return CustomResponse( + general_message="Invalid affiliation" + ).get_failure_response() + + serializer = AffiliationCreateUpdateSerializer( + affiliation, + data=request.data, + context={ + "user_id": user_id + } + ) + if serializer.is_valid(): + serializer.save() + + return CustomResponse( + general_message=f"{affiliation.title} Edited Successfully" + ).get_success_response() + + return CustomResponse( + message=serializer.errors + ).get_failure_response() + + @role_required([RoleType.ADMIN.value]) + def delete(self,request,affiliation_id): + user_id = JWTUtils.fetch_user_id(request) + affiliation = OrgAffiliation.objects.filter(id=affiliation_id).first() + + if affiliation is None: + return CustomResponse( + general_message="Invalid affiliation" + ).get_failure_response() + affiliation.delete() + return CustomResponse( + general_message=f"{affiliation.title} Deleted Successfully" + ).get_success_response() \ No newline at end of file diff --git a/api/dashboard/affiliation/serializers.py b/api/dashboard/affiliation/serializers.py new file mode 100644 index 00000000..793e30d0 --- /dev/null +++ b/api/dashboard/affiliation/serializers.py @@ -0,0 +1,37 @@ +from rest_framework import serializers +from db.organization import OrgAffiliation +import uuid + +class AffiliationReadSerializer(serializers.ModelSerializer): + + title = serializers.ReadOnlyField() + affiliation_id = serializers.ReadOnlyField(source='id') + + class Meta: + model = OrgAffiliation + fields = [ + "title", + "affiliation_id" + ] + +class AffiliationCreateUpdateSerializer(serializers.ModelSerializer): + class Meta: + model = OrgAffiliation + fields = [ + "title" + ] + + def create(self, validated_data): + user_id = self.context.get('user_id') + validated_data['created_by_id'] = user_id + validated_data['updated_by_id'] = user_id + validated_data['id'] = uuid.uuid4() + return OrgAffiliation.objects.create(**validated_data) + + def update(self, instance, validated_data): + user_id = self.context.get('user_id') + instance.title = validated_data.get('title', instance.title) + instance.updated_by_id = user_id + + instance.save() + return instance \ No newline at end of file diff --git a/api/dashboard/affiliation/urls.py b/api/dashboard/affiliation/urls.py new file mode 100644 index 00000000..7cfb05ee --- /dev/null +++ b/api/dashboard/affiliation/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import affiliation_views + +urlpatterns = [ + path('',affiliation_views.AffiliationView.as_view()), + path('create/',affiliation_views.AffiliationView.as_view()), + path('edit//',affiliation_views.AffiliationView.as_view()), + path('delete//',affiliation_views.AffiliationView.as_view()) +] diff --git a/api/dashboard/channels/channel_views.py b/api/dashboard/channels/channel_views.py new file mode 100644 index 00000000..d35183d7 --- /dev/null +++ b/api/dashboard/channels/channel_views.py @@ -0,0 +1,76 @@ +from rest_framework.views import APIView +from utils.permission import CustomizePermission,role_required,JWTUtils +from utils.types import RoleType +from .serializers import ChannelReadSerializer,ChannelCreateUpdateSerializer +from db.task import Channel +from utils.response import CustomResponse +from utils.utils import CommonUtils + +class ChannelView(APIView): + authentication_classes = [CustomizePermission] + + def get(self,request): + all_channels = Channel.objects.all() + pager_ = CommonUtils.get_paginated_queryset(all_channels,request,['name','discord_id','id'],sort_fields={'created':'created_at','updated':'updated_at','name':'name'}) + serial_ = ChannelReadSerializer(pager_.get("queryset"),many=True) + # serial_.is_valid() + return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination")) + + @role_required([RoleType.ADMIN.value]) + def post(self,request): + user_id = JWTUtils.fetch_user_id(request) + + serial_ = ChannelCreateUpdateSerializer(data=request.data,context={'user_id':user_id}) + + if serial_.is_valid(): + serial_.save() + + return CustomResponse( + general_message=f"{request.data.get('name')} added successfully" + ).get_success_response() + + return CustomResponse( + general_message=serial_.errors + ).get_failure_response() + + @role_required([RoleType.ADMIN.value]) + def put(self,request,channel_id): + user_id = JWTUtils.fetch_user_id(request) + channel = Channel.objects.filter(id=channel_id).first() + + if channel is None: + return CustomResponse( + general_message="Invalid channel" + ).get_failure_response() + + serializer = ChannelCreateUpdateSerializer( + channel, + data=request.data, + context={ + "user_id": user_id + } + ) + if serializer.is_valid(): + serializer.save() + + return CustomResponse( + general_message=f"{channel.name} Edited Successfully" + ).get_success_response() + + return CustomResponse( + message=serializer.errors + ).get_failure_response() + + @role_required([RoleType.ADMIN.value]) + def delete(self,request,channel_id): + user_id = JWTUtils.fetch_user_id(request) + channel = Channel.objects.filter(id=channel_id).first() + + if channel is None: + return CustomResponse( + general_message="Invalid channel" + ).get_failure_response() + channel.delete() + return CustomResponse( + general_message=f"{channel.name} Deleted Successfully" + ).get_success_response() \ No newline at end of file diff --git a/api/dashboard/channels/serializers.py b/api/dashboard/channels/serializers.py new file mode 100644 index 00000000..25ee6f59 --- /dev/null +++ b/api/dashboard/channels/serializers.py @@ -0,0 +1,48 @@ +from rest_framework import serializers +from db.task import Channel +from django.utils import timezone +from utils.utils import DateTimeUtils +import uuid +class ChannelReadSerializer(serializers.ModelSerializer): + + name = serializers.ReadOnlyField() + discord_id = serializers.ReadOnlyField() + channel_id = serializers.ReadOnlyField(source='id') + updated_at = serializers.ReadOnlyField() + created_at = serializers.ReadOnlyField() + + class Meta: + model = Channel + fields = [ + "name", + "channel_id", + "discord_id", + "created_at", + "updated_at" + ] + +class ChannelCreateUpdateSerializer(serializers.ModelSerializer): + class Meta: + model = Channel + fields = [ + "name", + "discord_id" + ] + + def create(self, validated_data): + user_id = self.context.get('user_id') + validated_data['id'] = uuid.uuid4() + validated_data['created_by_id'] = user_id + validated_data['updated_by_id'] = user_id + validated_data['created_at'] = DateTimeUtils.get_current_utc_time() + validated_data['updated_at'] = DateTimeUtils.get_current_utc_time() + return Channel.objects.create(**validated_data) + + def update(self, instance, validated_data): + user_id = self.context.get('user_id') + instance.name = validated_data.get('name', instance.name) + instance.discord_id = validated_data.get('discord_id', instance.name) + instance.updated_by_id = user_id + instance.updated_at = DateTimeUtils.get_current_utc_time() + instance.save() + return instance \ No newline at end of file diff --git a/api/dashboard/channels/urls.py b/api/dashboard/channels/urls.py new file mode 100644 index 00000000..c466b0ab --- /dev/null +++ b/api/dashboard/channels/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import channel_views + +urlpatterns = [ + path('',channel_views.ChannelView.as_view()), + path('create/',channel_views.ChannelView.as_view()), + path('edit//',channel_views.ChannelView.as_view()), + path('delete//',channel_views.ChannelView.as_view()) +] diff --git a/api/dashboard/ig/dash_ig_serializer.py b/api/dashboard/ig/dash_ig_serializer.py index b79298e7..f84edfd4 100644 --- a/api/dashboard/ig/dash_ig_serializer.py +++ b/api/dashboard/ig/dash_ig_serializer.py @@ -41,4 +41,4 @@ class Meta: "icon", "created_by", "updated_by" - ] \ No newline at end of file + ] diff --git a/api/dashboard/ig/dash_ig_view.py b/api/dashboard/ig/dash_ig_view.py index 12f34b34..2eae90e9 100644 --- a/api/dashboard/ig/dash_ig_view.py +++ b/api/dashboard/ig/dash_ig_view.py @@ -35,9 +35,9 @@ def get(self, request): { "name": "name", "updated_on": "updated_at", - "updated_by": "updated_by", + "updated_by": "updated_by__first_name", "created_on": "created_at", - "created_by": "created_by", + "created_by": "created_by__first_name", }, ) @@ -52,7 +52,9 @@ def get(self, request): @role_required([RoleType.ADMIN.value]) def post(self, request): user_id = JWTUtils.fetch_user_id(request) + request_data = request.data + request_data["created_by"] = request_data["updated_by"] = user_id serializer = InterestGroupCreateUpdateSerializer( @@ -78,6 +80,7 @@ def post(self, request): def put(self, request, pk): user_id = JWTUtils.fetch_user_id(request) ig = InterestGroup.objects.get(id=pk) + ig_old_name = ig.name request_data = request.data diff --git a/api/dashboard/organisation/serializers.py b/api/dashboard/organisation/serializers.py index 42878868..17015a05 100644 --- a/api/dashboard/organisation/serializers.py +++ b/api/dashboard/organisation/serializers.py @@ -1,21 +1,41 @@ import uuid -from django.db.models import Sum, Count +from django.db.models import Count +from rest_framework import serializers +from db.organization import Organization, District, Zone, State, OrgAffiliation, Department from utils.permission import JWTUtils from utils.types import OrganizationType -from utils.utils import DateTimeUtils -from rest_framework import serializers -from db.organization import ( - Organization, - District, - Zone, - State, - OrgAffiliation, - Department, -) +class InstitutionSerializer(serializers.ModelSerializer): + affiliation = serializers.ReadOnlyField(source="affiliation.title") + district = serializers.ReadOnlyField(source="district.name") + zone = serializers.ReadOnlyField(source="district.zone.name") + state = serializers.ReadOnlyField(source="district.zone.state.name") + country = serializers.ReadOnlyField(source="district.zone.state.country.name") + user_count = serializers.SerializerMethodField() + + class Meta: + model = Organization + fields = [ + "id", + "title", + "code", + "affiliation", + "district", + "zone", + "state", + "country", + "user_count" + ] + + def get_user_count(self, obj): + return obj.user_organization_link_org.annotate( + user_count=Count( + 'user' + ) + ).count() class InstitutionSerializer(serializers.ModelSerializer): @@ -75,6 +95,8 @@ class Meta: class InstitutionCreateUpdateSerializer(serializers.ModelSerializer): + district = serializers.CharField(required=False) + class Meta: model = Organization fields = ["title", "code", "org_type", "affiliation", "district"] @@ -105,6 +127,14 @@ def validate_org_type(self, organization): raise serializers.ValidationError("Invalid organization affiliation") return organization + def validate_district(self, value): + district = District.objects.filter(id=value).first() + + if district is None: + raise serializers.ValidationError("Invalid district") + + return district + def validate_affiliation(self, affiliation_id): if self.initial_data.get("org_type") != OrganizationType.COLLEGE.value: return None @@ -112,8 +142,8 @@ def validate_affiliation(self, affiliation_id): class AffiliationSerializer(serializers.ModelSerializer): - label = serializers.ReadOnlyField(source="title") - value = serializers.ReadOnlyField(source="id") + label = serializers.ReadOnlyField(source='title') + value = serializers.ReadOnlyField(source='id') class Meta: model = OrgAffiliation @@ -141,8 +171,15 @@ def update(self, instance, validated_data): return instance def validate_title(self, title): - if OrgAffiliation.objects.filter(title=title).first(): - raise serializers.ValidationError("Affiliation already exist") + org_affiliation = OrgAffiliation.objects.filter( + title=title + ).first() + + if org_affiliation: + raise serializers.ValidationError( + "Affiliation already exist" + ) + return title diff --git a/api/dashboard/urls.py b/api/dashboard/urls.py index a2151839..3c46702a 100644 --- a/api/dashboard/urls.py +++ b/api/dashboard/urls.py @@ -18,4 +18,6 @@ path('organisation/', include('api.dashboard.organisation.urls')), path('dynamic-management/', include('api.dashboard.dynamic_management.urls')), path('error-log/', include('api.dashboard.error_log.urls')), + path('affiliation/',include('api.dashboard.affiliation.urls')), + path('channels/',include('api.dashboard.channels.urls')) ] diff --git a/db/user.py b/db/user.py index f72005e1..d74732db 100644 --- a/db/user.py +++ b/db/user.py @@ -2,24 +2,25 @@ from django.db import models + # fmt: off class User(models.Model): - id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) - discord_id = models.CharField(unique=True, max_length=36, blank=True, null=True) - muid = models.CharField(unique=True, max_length=100) - first_name = models.CharField(max_length=75) - last_name = models.CharField(max_length=75, blank=True, null=True) - email = models.EmailField(unique=True, max_length=200) - password = models.CharField(max_length=200, blank=True, null=True) - mobile = models.CharField(unique=True, max_length=15) - gender = models.CharField(max_length=10, blank=True, null=True, choices=[("Male", "Male"),("Female", "Female")]) - dob = models.DateField(blank=True, null=True) - admin = models.BooleanField(default=False) - active = models.BooleanField(default=True) + id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) + discord_id = models.CharField(unique=True, max_length=36, blank=True, null=True) + muid = models.CharField(unique=True, max_length=100) + first_name = models.CharField(max_length=75) + last_name = models.CharField(max_length=75, blank=True, null=True) + email = models.EmailField(unique=True, max_length=200) + password = models.CharField(max_length=200, blank=True, null=True) + mobile = models.CharField(unique=True, max_length=15) + gender = models.CharField(max_length=10, blank=True, null=True, choices=[("Male", "Male"), ("Female", "Female")]) + dob = models.DateField(blank=True, null=True) + admin = models.BooleanField(default=False) + active = models.BooleanField(default=True) exist_in_guild = models.BooleanField(default=False) - profile_pic = models.CharField(max_length=200, blank=True, null=True) - created_at = models.DateTimeField(auto_now_add=True) + profile_pic = models.CharField(max_length=200, blank=True, null=True) + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -34,14 +35,16 @@ def fullname(self): class UserReferralLink(models.Model): - id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) - user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_user') - referral = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_referral') - is_coin = models.BooleanField(default=False) - updated_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_updated_by', db_column='updated_by') - updated_at = models.DateTimeField(auto_now=True) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_created_by', db_column='created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_user') + referral = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_referral') + is_coin = models.BooleanField(default=False) + updated_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_updated_by', + db_column='updated_by') + updated_at = models.DateTimeField(auto_now=True) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_referral_link_created_by', + db_column='created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -49,13 +52,15 @@ class Meta: class Role(models.Model): - id = models.CharField(primary_key=True, max_length=36) - title = models.CharField(max_length=75) - description = models.CharField(max_length=300, blank=True, null=True) - updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='role_updated_by') - updated_at = models.DateTimeField(auto_now=True) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='role_created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + description = models.CharField(max_length=300, blank=True, null=True) + updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', + related_name='role_updated_by') + updated_at = models.DateTimeField(auto_now=True) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', + related_name='role_created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -63,12 +68,13 @@ class Meta: class UserRoleLink(models.Model): - id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) - user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_role_link_user') - role = models.ForeignKey(Role, on_delete=models.CASCADE) - verified = models.BooleanField(default=False) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='user_role_link_created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_role_link_user') + role = models.ForeignKey(Role, on_delete=models.CASCADE) + verified = models.BooleanField(default=False) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', + related_name='user_role_link_created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -76,20 +82,22 @@ class Meta: class Socials(models.Model): - id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) - user = models.ForeignKey(User, on_delete=models.CASCADE) - github = models.CharField(max_length=60, blank=True, null=True) - facebook = models.CharField(max_length=60, blank=True, null=True) - instagram = models.CharField(max_length=60, blank=True, null=True) - linkedin = models.CharField(max_length=60, blank=True, null=True) - dribble = models.CharField(max_length=60, blank=True, null=True) - behance = models.CharField(max_length=60, blank=True, null=True) - stackoverflow = models.CharField(max_length=60, blank=True, null=True) - medium = models.CharField(max_length=60, blank=True, null=True) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='socials_created_by') - updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='socials_updated_by') - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(blank=True, null=True, auto_now=True) + id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) + user = models.ForeignKey(User, on_delete=models.CASCADE) + github = models.CharField(max_length=60, blank=True, null=True) + facebook = models.CharField(max_length=60, blank=True, null=True) + instagram = models.CharField(max_length=60, blank=True, null=True) + linkedin = models.CharField(max_length=60, blank=True, null=True) + dribble = models.CharField(max_length=60, blank=True, null=True) + behance = models.CharField(max_length=60, blank=True, null=True) + stackoverflow = models.CharField(max_length=60, blank=True, null=True) + medium = models.CharField(max_length=60, blank=True, null=True) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', + related_name='socials_created_by') + updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', + related_name='socials_updated_by') + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(blank=True, null=True, auto_now=True) class Meta: managed = False @@ -97,10 +105,10 @@ class Meta: class ForgotPassword(models.Model): - id = models.CharField(primary_key=True, max_length=36) - user = models.ForeignKey(User, on_delete=models.CASCADE) - expiry = models.DateTimeField() - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, on_delete=models.CASCADE) + expiry = models.DateTimeField() + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -108,13 +116,15 @@ class Meta: class UserSettings(models.Model): - id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) - user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="user_settings_user") - is_public = models.BooleanField(default=False) - updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='user_settings_updated_by') - updated_at = models.DateTimeField(auto_now=True) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='user_settings_created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4) + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="user_settings_user") + is_public = models.BooleanField(default=False) + updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', + related_name='user_settings_updated_by') + updated_at = models.DateTimeField(auto_now=True) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', + related_name='user_settings_created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -122,13 +132,15 @@ class Meta: class DynamicRole(models.Model): - id = models.CharField(primary_key=True, max_length=36) - type = models.CharField(max_length=50) - role = models.ForeignKey(Role, on_delete=models.CASCADE, db_column='role', related_name='dynamic_role_role') - updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='dynamic_role_updated_by') - updated_at = models.DateTimeField(auto_now=True) - created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='dynamic_role_created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + role = models.ForeignKey(Role, on_delete=models.CASCADE, db_column='role', related_name='dynamic_role_role') + updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', + related_name='dynamic_role_updated_by') + updated_at = models.DateTimeField(auto_now=True) + created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', + related_name='dynamic_role_created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False @@ -136,13 +148,15 @@ class Meta: class DynamicUser(models.Model): - id = models.CharField(primary_key=True, max_length=36) - type = models.CharField(max_length=50) - user = models.ForeignKey('User', on_delete=models.CASCADE, related_name='dynamic_user_user') - updated_by = models.ForeignKey('User', on_delete=models.CASCADE, db_column='updated_by', related_name='dynamic_user_updated_by') - updated_at = models.DateTimeField(auto_now=True) - created_by = models.ForeignKey('User', on_delete=models.CASCADE, db_column='created_by', related_name='dynamic_user_created_by') - created_at = models.DateTimeField(auto_now_add=True) + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + user = models.ForeignKey('User', on_delete=models.CASCADE, related_name='dynamic_user_user') + updated_by = models.ForeignKey('User', on_delete=models.CASCADE, db_column='updated_by', + related_name='dynamic_user_updated_by') + updated_at = models.DateTimeField(auto_now=True) + created_by = models.ForeignKey('User', on_delete=models.CASCADE, db_column='created_by', + related_name='dynamic_user_created_by') + created_at = models.DateTimeField(auto_now_add=True) class Meta: managed = False diff --git a/hello.py b/hello.py new file mode 100644 index 00000000..9cae60e1 --- /dev/null +++ b/hello.py @@ -0,0 +1,719 @@ +# This is an auto-generated Django model module. +# You'll have to do the following manually to clean this up: +# * Rearrange models' order +# * Make sure each model has one field with primary_key=True +# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior +# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table +# Feel free to rename the models, but don't rename db_table values or field names. +from django.db import models + + +class Channel(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(unique=True, max_length=75) + discord_id = models.CharField(max_length=36) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'channel' + + +class College(models.Model): + id = models.CharField(primary_key=True, max_length=36) + level = models.IntegerField() + org = models.ForeignKey('Organization', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'college' + + +class Country(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'country' + + +class Department(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'department' + + +class Device(models.Model): + id = models.CharField(primary_key=True, max_length=36) + browser = models.CharField(max_length=36) + os = models.CharField(max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + last_log_in = models.DateTimeField() + + class Meta: + managed = False + db_table = 'device' + + +class District(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + zone = models.ForeignKey('Zone', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'district' + + +class DynamicRole(models.Model): + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + role = models.ForeignKey('Role', models.DO_NOTHING, db_column='role') + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'dynamic_role' + + +class DynamicUser(models.Model): + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + user = models.ForeignKey('User', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'dynamic_user' + + +class ForgotPassword(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + expiry = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'forgot_password' + + +class Hackathon(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + tagline = models.CharField(max_length=150, blank=True, null=True) + description = models.CharField(max_length=5000, blank=True, null=True) + participant_count = models.IntegerField(blank=True, null=True) + type = models.CharField(max_length=8, blank=True, null=True) + website = models.CharField(max_length=200, blank=True, null=True) + org = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True) + district = models.ForeignKey(District, models.DO_NOTHING, blank=True, null=True) + place = models.CharField(max_length=255, blank=True, null=True) + event_logo = models.CharField(max_length=200, blank=True, null=True) + banner = models.CharField(max_length=200, blank=True, null=True) + is_open_to_all = models.IntegerField(blank=True, null=True) + application_start = models.DateTimeField(blank=True, null=True) + application_ends = models.DateTimeField(blank=True, null=True) + event_start = models.DateTimeField(blank=True, null=True) + event_end = models.DateTimeField(blank=True, null=True) + status = models.CharField(max_length=20, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon' + + +class HackathonForm(models.Model): + id = models.CharField(primary_key=True, max_length=36) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + field_name = models.CharField(max_length=255) + field_type = models.CharField(max_length=50) + is_required = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_form' + + +class HackathonOrganiserLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + organiser = models.ForeignKey('User', models.DO_NOTHING) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_organiser_link' + + +class HackathonSubmission(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField('User', models.DO_NOTHING) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + data = models.CharField(max_length=2000) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_submission' + + +class Integration(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=255) + token = models.CharField(max_length=400) + created_at = models.DateTimeField() + updated_at = models.DateTimeField() + auth_token = models.CharField(max_length=255, blank=True, null=True) + base_url = models.CharField(max_length=255, blank=True, null=True) + + class Meta: + managed = False + db_table = 'integration' + + +class IntegrationAuthorization(models.Model): + id = models.CharField(primary_key=True, max_length=36) + integration = models.ForeignKey(Integration, models.DO_NOTHING) + user = models.OneToOneField('User', models.DO_NOTHING) + integration_value = models.CharField(unique=True, max_length=255) + additional_field = models.CharField(max_length=255, blank=True, null=True) + verified = models.IntegerField() + updated_at = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'integration_authorization' + unique_together = (('integration', 'user', 'integration_value'),) + + +class InterestGroup(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + code = models.CharField(unique=True, max_length=5, blank=True, null=True) + icon = models.CharField(max_length=10, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'interest_group' + + +class IntroTaskLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + progress = models.IntegerField() + channel_id = models.CharField(max_length=36, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'intro_task_log' + + +class KarmaActivityLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + karma = models.IntegerField() + task = models.ForeignKey('TaskList', models.DO_NOTHING) + task_message_id = models.CharField(max_length=36) + lobby_message_id = models.CharField(max_length=36, blank=True, null=True) + dm_message_id = models.CharField(max_length=36, blank=True, null=True) + peer_approved = models.IntegerField(blank=True, null=True) + peer_approved_by = models.CharField(max_length=36, blank=True, null=True) + appraiser_approved = models.IntegerField(blank=True, null=True) + appraiser_approved_by = models.CharField(max_length=36, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'karma_activity_log' + + +class LearningCircle(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=255) + circle_code = models.CharField(unique=True, max_length=15, blank=True, null=True) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING) + org = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True) + meet_place = models.CharField(max_length=255, blank=True, null=True) + meet_time = models.DateTimeField(blank=True, null=True) + day = models.CharField(max_length=20, blank=True, null=True) + note = models.CharField(max_length=500, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'learning_circle' + + +class Level(models.Model): + id = models.CharField(primary_key=True, max_length=36) + level_order = models.IntegerField() + name = models.CharField(unique=True, max_length=36) + karma = models.IntegerField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'level' + + +class MucoinActivityLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + coin = models.FloatField() + status = models.CharField(max_length=36) + task = models.ForeignKey('TaskList', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by', blank=True, null=True) + updated_at = models.DateTimeField(blank=True, null=True) + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by', blank=True, null=True) + created_at = models.DateTimeField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'mucoin_activity_log' + + +class MucoinInviteLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + email = models.CharField(max_length=200) + invite_code = models.CharField(max_length=36) + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'mucoin_invite_log' + + +class Notification(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + title = models.CharField(max_length=50) + description = models.CharField(max_length=200) + button = models.CharField(max_length=10, blank=True, null=True) + url = models.CharField(max_length=100, blank=True, null=True) + created_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + + class Meta: + managed = False + db_table = 'notification' + + +class OrgAffiliation(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'org_affiliation' + + +class OrgDiscordLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + discord_id = models.CharField(unique=True, max_length=36) + org = models.OneToOneField('Organization', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'org_discord_link' + + +class Organization(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + code = models.CharField(unique=True, max_length=12) + org_type = models.CharField(max_length=25) + affiliation = models.ForeignKey(OrgAffiliation, models.DO_NOTHING, blank=True, null=True) + district = models.ForeignKey(District, models.DO_NOTHING, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'organization' + + +class OtpVerification(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + otp = models.IntegerField() + expiry = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'otp_verification' + + +class Role(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + description = models.CharField(max_length=300, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'role' + + +class Socials(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + github = models.CharField(max_length=60, blank=True, null=True) + facebook = models.CharField(max_length=60, blank=True, null=True) + instagram = models.CharField(max_length=60, blank=True, null=True) + linkedin = models.CharField(max_length=60, blank=True, null=True) + dribble = models.CharField(max_length=60, blank=True, null=True) + behance = models.CharField(max_length=60, blank=True, null=True) + stackoverflow = models.CharField(max_length=60, blank=True, null=True) + medium = models.CharField(max_length=60, blank=True, null=True) + updated_by = models.CharField(max_length=36) + updated_at = models.DateTimeField(blank=True, null=True) + created_by = models.CharField(max_length=36, blank=True, null=True) + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'socials' + + +class State(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + country = models.ForeignKey(Country, models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'state' + + +class SystemSetting(models.Model): + key = models.CharField(primary_key=True, max_length=100) + value = models.CharField(max_length=100) + updated_at = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'system_setting' + + +class TaskList(models.Model): + id = models.CharField(primary_key=True, max_length=36) + hashtag = models.CharField(max_length=75) + discord_link = models.CharField(max_length=200, blank=True, null=True) + title = models.CharField(max_length=75) + description = models.CharField(max_length=200, blank=True, null=True) + karma = models.IntegerField(blank=True, null=True) + channel = models.ForeignKey(Channel, models.DO_NOTHING, blank=True, null=True) + type = models.ForeignKey('TaskType', models.DO_NOTHING) + org = models.ForeignKey(Organization, models.DO_NOTHING, blank=True, null=True) + level = models.ForeignKey(Level, models.DO_NOTHING, blank=True, null=True) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING, blank=True, null=True) + active = models.IntegerField() + variable_karma = models.IntegerField() + usage_count = models.IntegerField(blank=True, null=True) + event = models.CharField(max_length=50, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'task_list' + + +class TaskType(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'task_type' + + +class UrlShortener(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + short_url = models.CharField(unique=True, max_length=100) + long_url = models.CharField(max_length=500) + count = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'url_shortener' + + +class UrlShortenerTracker(models.Model): + id = models.CharField(primary_key=True, max_length=36) + url_shortener = models.ForeignKey(UrlShortener, models.DO_NOTHING, blank=True, null=True) + ip_address = models.CharField(max_length=45, blank=True, null=True) + browser = models.CharField(max_length=255, blank=True, null=True) + operating_system = models.CharField(max_length=255, blank=True, null=True) + version = models.CharField(max_length=255, blank=True, null=True) + device_type = models.CharField(max_length=255, blank=True, null=True) + city = models.CharField(max_length=36, blank=True, null=True) + region = models.CharField(max_length=36, blank=True, null=True) + country = models.CharField(max_length=36, blank=True, null=True) + location = models.CharField(max_length=36, blank=True, null=True) + referrer = models.CharField(max_length=36, blank=True, null=True) + + class Meta: + managed = False + db_table = 'url_shortener_tracker' + + +class User(models.Model): + id = models.CharField(primary_key=True, max_length=36) + discord_id = models.CharField(unique=True, max_length=36, blank=True, null=True) + muid = models.CharField(unique=True, max_length=100) + first_name = models.CharField(max_length=75) + last_name = models.CharField(max_length=75, blank=True, null=True) + email = models.CharField(unique=True, max_length=200) + password = models.CharField(max_length=200, blank=True, null=True) + mobile = models.CharField(max_length=15) + gender = models.CharField(max_length=10, blank=True, null=True) + dob = models.DateField(blank=True, null=True) + admin = models.IntegerField() + active = models.IntegerField() + exist_in_guild = models.IntegerField() + created_at = models.DateTimeField() + profile_pic = models.CharField(max_length=200, blank=True, null=True) + + class Meta: + managed = False + db_table = 'user' + + +class UserCircleLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + circle = models.ForeignKey(LearningCircle, models.DO_NOTHING) + lead = models.IntegerField(blank=True, null=True) + accepted = models.IntegerField(blank=True, null=True) + accepted_at = models.DateTimeField(blank=True, null=True) + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_circle_link' + + +class UserIgLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING) + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_ig_link' + + +class UserLvlLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField(User, models.DO_NOTHING) + level = models.ForeignKey(Level, models.DO_NOTHING) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_lvl_link' + + +class UserOrganizationLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + org = models.ForeignKey(Organization, models.DO_NOTHING) + department = models.ForeignKey(Department, models.DO_NOTHING, blank=True, null=True) + graduation_year = models.CharField(max_length=10, blank=True, null=True) + verified = models.IntegerField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_organization_link' + + +class UserReferralLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + referral = models.ForeignKey(User, models.DO_NOTHING) + is_coin = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_referral_link' + + +class UserRoleLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + role = models.ForeignKey(Role, models.DO_NOTHING) + verified = models.IntegerField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_role_link' + + +class UserSettings(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + is_public = models.IntegerField() + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_settings' + + +class VoucherLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + code = models.CharField(max_length=15) + user = models.ForeignKey(User, models.DO_NOTHING) + task = models.ForeignKey(TaskList, models.DO_NOTHING) + karma = models.IntegerField() + week = models.CharField(max_length=2) + month = models.CharField(max_length=10) + claimed = models.IntegerField() + updated_by = models.CharField(max_length=36) + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'voucher_log' + + +class Wallet(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField(User, models.DO_NOTHING) + karma = models.BigIntegerField() + coin = models.IntegerField() + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'wallet' + + +class Zone(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + state = models.ForeignKey(State, models.DO_NOTHING) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'zone' diff --git a/utils/utils.py b/utils/utils.py index 37f20725..49e2a209 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -2,29 +2,29 @@ import datetime import gzip import io +from datetime import timedelta import decouple import openpyxl import pytz import requests from decouple import config +from django.core.mail import EmailMessage from django.core.mail import send_mail from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.db.models import Q from django.db.models.query import QuerySet from django.http import HttpResponse from django.template.loader import render_to_string -from django.core.mail import EmailMessage -from datetime import timedelta class CommonUtils: @staticmethod def get_paginated_queryset( queryset: QuerySet, request, search_fields, sort_fields: dict = None - ) -> QuerySet: + ) -> QuerySet: if sort_fields is None: - sort_fields = { } + sort_fields = {} page = int(request.query_params.get("pageIndex", 1)) per_page = int(request.query_params.get("perPage", 10)) @@ -34,7 +34,7 @@ def get_paginated_queryset( if search_query: query = Q() for field in search_fields: - query |= Q(**{ f"{field}__icontains": search_query }) + query |= Q(**{f"{field}__icontains": search_query}) queryset = queryset.filter(query) @@ -64,8 +64,8 @@ def get_paginated_queryset( "nextPage": queryset.next_page_number() if queryset.has_next() else None, - }, - } + }, + } @staticmethod def generate_csv(queryset: QuerySet, csv_name: str) -> HttpResponse: @@ -79,7 +79,7 @@ def generate_csv(queryset: QuerySet, csv_name: str) -> HttpResponse: compressed_response = HttpResponse( gzip.compress(response.content), content_type="text/csv", - ) + ) compressed_response[ "Content-Disposition" ] = f'attachment; filename="{csv_name}.csv"' @@ -124,7 +124,7 @@ def get_start_and_end_of_previous_month(): start_date = today.replace(day=1) end_date = start_date.replace( day=1, month=start_date.month % 12 + 1 - ) - timedelta(days=1) + ) - timedelta(days=1) return start_date, end_date @@ -153,7 +153,7 @@ def general_updates(category, action, *values) -> str: for value in values: content = f"{content}<|=|>{value}" url = config("DISCORD_WEBHOOK_LINK") - data = { "content": content } + data = {"content": content} requests.post(url, json=data) @@ -166,7 +166,7 @@ def read_excel_file(self, file_obj): for row in sheet.iter_rows(values_only=True): row_dict = { header.value: cell_value for header, cell_value in zip(sheet[1], row) - } + } rows.append(row_dict) workbook.close() @@ -194,8 +194,8 @@ def send_template_mail( status = None email_content = render_to_string( - f"mails/{'/'.join(map(str, address))}", { "user": context, "base_url": base_url } - ) + f"mails/{'/'.join(map(str, address))}", {"user": context, "base_url": base_url} + ) if not (mail := getattr(context, "email", None)): mail = context["email"] @@ -207,7 +207,7 @@ def send_template_mail( recipient_list=[mail], html_message=email_content, fail_silently=False, - ) + ) else: email = EmailMessage( @@ -215,9 +215,9 @@ def send_template_mail( body=email_content, from_email=from_mail, to=[context["email"]], - ) + ) email.attach(attachment) email.content_subtype = "html" status = email.send() - return status \ No newline at end of file + return status