Skip to content

Commit

Permalink
Merge pull request #1408 from gtech-mulearn:dev
Browse files Browse the repository at this point in the history
[STYLE] Styled db files
  • Loading branch information
MZaFaRM authored Oct 23, 2023
2 parents 181edaf + 4fd56f8 commit 11a1dc9
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 614 deletions.
42 changes: 25 additions & 17 deletions api/dashboard/karma_voucher/karma_voucher_serializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from django.db.models import Q
from rest_framework import serializers
from db.task import VoucherLog, TaskList
from db.user import User
Expand Down Expand Up @@ -90,9 +91,10 @@ def create(self, validated_data):
return VoucherLog.objects.create(**validated_data)

def validate_user(self, value):
if not User.objects.filter(id=value).exists():
user = User.objects.filter(Q(muid=value) | Q(email=value)).first()
if not user:
raise serializers.ValidationError("Enter a valid user")
return value
return user.id

def validate_task(self, value):
if not TaskList.objects.filter(id=value).exists():
Expand All @@ -110,33 +112,39 @@ def validate_week(self, value):
return value

class VoucherLogUpdateSerializer(serializers.ModelSerializer):
user = serializers.CharField(required=False)
task = serializers.CharField(required=False)
karma = serializers.IntegerField(required=False)
month = serializers.CharField(required=False)
week = serializers.CharField(required=False)
new_user = serializers.CharField(required=False)
new_task = serializers.CharField(required=False)
new_karma = serializers.IntegerField(required=False)
new_month = serializers.CharField(required=False)
new_week = serializers.CharField(required=False)

class Meta:
model = VoucherLog
fields = [
"user",
"task",
"karma",
"month",
"week",
"new_user",
"new_task",
"new_karma",
"new_month",
"new_week",
]

def update(self, instance, validated_data):
instance.user_id = validated_data.get('user', instance.user)
instance.task_id = validated_data.get('task', instance.task)
instance.karma = validated_data.get('karma', instance.karma)
instance.month = validated_data.get('month', instance.month)
instance.week = validated_data.get('week', instance.week)
instance.user_id = validated_data.get('new_user', instance.user)
instance.task_id = validated_data.get('new_task', instance.task)
instance.karma = validated_data.get('new_karma', instance.karma)
instance.month = validated_data.get('new_month', instance.month)
instance.week = validated_data.get('new_week', instance.week)

instance.updated_by_id = self.context.get('user_id')
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
return instance

def validate_new_user(self, value):
user = User.objects.filter(Q(muid=value) | Q(email=value)).first()
if not user:
raise serializers.ValidationError("Enter a valid user")
return user.id

def destroy(self, obj):
obj.delete()
97 changes: 45 additions & 52 deletions db/hackathon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,76 @@
from db.organization import Organization, District
from db.user import User

# fmt: off

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)
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, default="offline")
website = models.CharField(max_length=200, null=True, blank=True)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
district = models.ForeignKey(District, on_delete=models.CASCADE, blank=True, null=True)
place = models.CharField(max_length=255, blank=True, null=True)
event_logo = models.ImageField(max_length=200, blank=True, null=True, upload_to='hackathon/event_logo')
banner = models.ImageField(max_length=200, blank=True, null=True, upload_to='hackathon/banner')
is_open_to_all = models.BooleanField(blank=True, null=True)
type = models.CharField(max_length=8, default="offline")
website = models.CharField(max_length=200, null=True, blank=True)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
district = models.ForeignKey(District, on_delete=models.CASCADE, blank=True, null=True)
place = models.CharField(max_length=255, blank=True, null=True)
event_logo = models.ImageField(max_length=200, blank=True, null=True, upload_to='hackathon/event_logo')
banner = models.ImageField(max_length=200, blank=True, null=True, upload_to='hackathon/banner')
is_open_to_all = models.BooleanField(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, on_delete=models.CASCADE, db_column='updated_by',
related_name='hackathon_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by',
related_name='hackathon_created_by')
created_at = models.DateTimeField()
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, on_delete=models.CASCADE, db_column='updated_by', related_name='hackathon_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='hackathon_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, on_delete=models.CASCADE)
field_name = models.CharField(max_length=255)
field_type = models.CharField(max_length=50)
is_required = models.BooleanField(default=False)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='hackathon_form_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by',
related_name='hackathon_form_created_by')
created_at = models.DateTimeField()
id = models.CharField(primary_key=True, max_length=36)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
field_name = models.CharField(max_length=255)
field_type = models.CharField(max_length=50)
is_required = models.BooleanField(default=False)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='hackathon_form_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='hackathon_form_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, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='hackathon_organiser_link_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by',
related_name='hackathon_organiser_link_created_by')
created_at = models.DateTimeField()
id = models.CharField(primary_key=True, max_length=36)
organiser = models.ForeignKey(User, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='hackathon_organiser_link_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='hackathon_organiser_link_created_by')
created_at = models.DateTimeField()

class Meta:
managed = False
db_table = 'hackathon_organiser_link'


class HackathonUserSubmission(models.Model):
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='hackathon_submission_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by',
related_name='hackathon_submission_created_by')
created_at = models.DateTimeField()
data = models.JSONField(max_length=2000, blank=True, null=True)
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='hackathon_submission_updated_by')
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='hackathon_submission_created_by')
created_at = models.DateTimeField()
data = models.JSONField(max_length=2000, blank=True, null=True)

class Meta:
managed = False
Expand Down
40 changes: 15 additions & 25 deletions db/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,31 @@
from django.db import models

from db.user import User

# fmt: off

class Integration(models.Model):
id = models.CharField(primary_key=True, default=uuid.uuid4, max_length=36)
name = models.CharField(max_length=255, null=False)
token = models.CharField(max_length=400, null=False)
auth_token = models.CharField(max_length=255, null=False)
base_url = models.CharField(max_length=255, null=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
id = models.CharField(primary_key=True, default=uuid.uuid4, max_length=36)
name = models.CharField(max_length=255, null=False)
token = models.CharField(max_length=400, null=False)
auth_token = models.CharField(max_length=255, null=False)
base_url = models.CharField(max_length=255, null=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
db_table = "integration"


#
class IntegrationAuthorization(models.Model):
id = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4)
integration = models.ForeignKey(
Integration,
on_delete=models.CASCADE,
null=False,
related_name="integration_authorization_integration",
)
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name="integration_authorization_user",
null=False,
)
id = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4)
integration = models.ForeignKey(Integration,on_delete=models.CASCADE,null=False,related_name="integration_authorization_integration",)
user = models.ForeignKey(User,on_delete=models.CASCADE,related_name="integration_authorization_user",null=False,)
integration_value = models.CharField(max_length=255, unique=True, null=False)
additional_field = models.CharField(max_length=255)
verified = models.BooleanField(default=False, null=False)
updated_at = models.DateTimeField(null=False, auto_now=True)
created_at = models.DateTimeField(null=False, auto_now_add=True)
additional_field = models.CharField(max_length=255)
verified = models.BooleanField(default=False, null=False)
updated_at = models.DateTimeField(null=False, auto_now=True)
created_at = models.DateTimeField(null=False, auto_now_add=True)

class Meta:
constraints = [
Expand Down
36 changes: 17 additions & 19 deletions db/learning_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

from db.task import InterestGroup, Organization
from db.user import User

# fmt: off

class LearningCircle(models.Model):
id = models.CharField(primary_key=True, max_length=36)
name = models.CharField(max_length=255, unique=True)
circle_code = models.CharField(unique=True, max_length=36)
ig = models.ForeignKey(InterestGroup, on_delete=models.CASCADE, blank=True, null=True)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
id = models.CharField(primary_key=True, max_length=36)
name = models.CharField(max_length=255, unique=True)
circle_code= models.CharField(unique=True, max_length=36)
ig = models.ForeignKey(InterestGroup, on_delete=models.CASCADE, blank=True, null=True)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
meet_place = models.CharField(max_length=255, blank=True, null=True)
meet_time = models.CharField(max_length=10, 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, on_delete=models.CASCADE, db_column="updated_by",
related_name="learning_circle_updated_by")
meet_time = models.CharField(max_length=10, 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, on_delete=models.CASCADE, db_column="updated_by",related_name="learning_circle_updated_by")
updated_at = models.DateTimeField()
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="created_by",
related_name="learning_circle_created_by")
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="created_by",related_name="learning_circle_created_by")
created_at = models.DateTimeField()

class Meta:
Expand All @@ -27,13 +25,13 @@ class Meta:


class UserCircleLink(models.Model):
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE)
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE)
lead = models.BooleanField(default=False)
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE)
circle = models.ForeignKey(LearningCircle, on_delete=models.CASCADE)
lead = models.BooleanField(default=False)
is_invited = models.BooleanField(default=False)
accepted = models.BooleanField()
accepted_at = models.DateTimeField(blank=True, null=True)
accepted = models.BooleanField()
accepted_at= models.DateTimeField(blank=True, null=True)
created_at = models.DateTimeField()

class Meta:
Expand Down
23 changes: 8 additions & 15 deletions db/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
from django.db import models

from db.user import User

# fmt: off

class Notification(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="notifications"
)
title = models.CharField(max_length=50, blank=False)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="notifications")
title = models.CharField(max_length=50, blank=False)
description = models.CharField(max_length=200, blank=False)
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,
on_delete=models.CASCADE,
db_column="created_by",
related_name="created_notifications",
)
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, on_delete=models.CASCADE, db_column="created_by", related_name="created_notifications")

class Meta:
managed = False
Expand Down
Loading

0 comments on commit 11a1dc9

Please sign in to comment.