Skip to content

Commit

Permalink
Added form_link, registration_time attributes, solo event api, and ch…
Browse files Browse the repository at this point in the history
…eck for is_registration_on (#12)

* Added form_link, timestamp of team registration, check for is_registration_on

* Added solo event view
  • Loading branch information
rohithpeddi7 authored Feb 2, 2024
1 parent a2f96e7 commit 4ed6508
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
21 changes: 12 additions & 9 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ class Event(models.Model):
min_members = models.PositiveIntegerField(default=1)
max_members = models.PositiveIntegerField(default=1)
is_registration_on = models.BooleanField(default=True)
form_link = models.CharField(max_length=1000, null=True, blank=True)
slug = models.SlugField(max_length=50, default="default")

def create_team(self, profile, t_name):

team = Team.objects.create(event=self, creator=profile, name=t_name)

team.access_code = hashids_team.encode(team.id)
if self.max_members == 1:
team.is_active = True
team.save()
member = Membership.objects.create(team=team, profile=profile)
return team
if self.is_registration_on == False:
raise ValidationError("Registrations are not live for this event")
else:
team = Team.objects.create(event=self, creator=profile, name=t_name)
team.access_code = hashids_team.encode(team.id)
if self.max_members == 1:
team.is_active = True
team.save()
member = Membership.objects.create(team=team, profile=profile)
return team

def __str__(self):
return self.name
Expand Down Expand Up @@ -149,6 +151,7 @@ def __str__(self):
class Team(models.Model):
name = models.CharField(max_length=100)
event = models.ForeignKey(Event, on_delete=models.CASCADE)
registration_time = models.DateTimeField(auto_now_add=True)
members = models.ManyToManyField(
Profile, through="Membership", related_name="team_members"
)
Expand Down
1 change: 1 addition & 0 deletions website/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Meta:
"is_registration_on",
"min_members",
"max_members",
"form_link",
"team",
]

Expand Down
1 change: 1 addition & 0 deletions website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

urlpatterns = [
path("events/", EventListView.as_view(), name="event-list"),
path("events/<int:pk>/", EventDetailView.as_view(), name="event-detail"),
path("profile/", ProfileView.as_view()),
path("profile/fcm-token/update/", FCMTokenView.as_view()),
path("teams/create/", TeamCreationView.as_view()),
Expand Down
12 changes: 12 additions & 0 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ class EventListView(generics.ListAPIView):
queryset = Event.objects.all()


class EventDetailView(generics.RetrieveAPIView):
permission_classes = [permissions.IsAuthenticated]
authentication_classes = [
authentication.TokenAuthentication,
authentication.SessionAuthentication,
]
serializer_class = EventSerializer
lookup_field = "pk"
queryset = Event.objects.all()



class ProfileView(generics.RetrieveUpdateAPIView):
permission_classes = [permissions.IsAuthenticated]
authentication_classes = [
Expand Down

0 comments on commit 4ed6508

Please sign in to comment.