Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project creation overhaul and minor fix #721

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions zubhub_backend/zubhub/creators/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ class CustomRegisterSerializer(RegisterSerializer):
bio = serializers.CharField(allow_blank=True, default="", max_length=255)
subscribe = serializers.BooleanField(default=False)

def validate_username(self, username):
# Check if the value is a valid email
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if re.match(pattern, username):
# If it's a valid email, raise an error
raise serializers.ValidationError(_("Username cannot be an email."))

return username

def validate_email(self, email):
if (len(email) == 0 and len(self.initial_data.get("phone", "")) == 0):
raise serializers.ValidationError(
Expand Down
4 changes: 1 addition & 3 deletions zubhub_backend/zubhub/creators/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
name="add_comment"),
path('delete/', DeleteCreatorAPIView.as_view(), name='delete_creator'),
path('locations/', LocationListAPIView.as_view(), name='location_list'),
path('<str:username>/projects/',
UserProjectsAPIView.as_view(),
name="user_projects"),
path('<str:username>/projects/',UserProjectsAPIView.as_view(),name="user_projects"),
path('<str:username>/drafts/',
UserDraftsAPIView.as_view(),
name="user_drafts"),
Expand Down
5 changes: 5 additions & 0 deletions zubhub_backend/zubhub/creators/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,24 @@ class UserProjectsAPIView(ListAPIView):
def get_queryset(self):
username = self.kwargs.get("username")
limit = self.request.GET.get("limit")
project_to_omit = self.request.GET.get('project_to_omit')
creator = Creator.objects.get(username=username)

if limit:
if hasattr(creator, "creatorgroup"):
return creator.creatorgroup.get_projects(limit=limit)
else:
all = creator.projects.exclude(publish__type=PublishingRule.DRAFT)
if(project_to_omit):
all = all.exclude(id=project_to_omit)
return get_published_projects_for_user(self.request.user, all)[:int(limit)]
else:
if hasattr(creator, "creatorgroup"):
return creator.creatorgroup.get_projects()
else:
all = creator.projects.exclude(publish__type=PublishingRule.DRAFT)
if(project_to_omit):
all = all.exclude(id=project_to_omit)
return get_published_projects_for_user(self.request.user, all)

class UserDraftsAPIView(ListAPIView):
Expand Down
Loading