diff --git a/nablapps/mailfeed/admin.py b/nablapps/mailfeed/admin.py index 9955b3a7..9f80c588 100644 --- a/nablapps/mailfeed/admin.py +++ b/nablapps/mailfeed/admin.py @@ -9,12 +9,6 @@ class Meta: verbose_name = "Subscription" verbose_name_plural = "Subscriptions" - def short_description(self, com): - return (com.story[:23] + "...") if len(com.story) > 25 else com.story - - def full_user_name(self, com): - return com.user.get_full_name() - list_display = ("mailfeed", "email", "uuid", "created") list_select_related = [ "mailfeed", diff --git a/nablapps/mailfeed/forms.py b/nablapps/mailfeed/forms.py index cec2050c..347bdac9 100644 --- a/nablapps/mailfeed/forms.py +++ b/nablapps/mailfeed/forms.py @@ -2,6 +2,8 @@ class MailFeedForm(forms.Form): + """Form for creation of a new mailfeed""" + name_field = forms.CharField(required=True) def get_name(self) -> str: @@ -29,6 +31,8 @@ def get_result(self) -> bool: class EmailForm(forms.Form): + """Form for creating an email""" + subject_field = forms.CharField(max_length=80) content_field = forms.CharField(required=True, widget=forms.Textarea) diff --git a/nablapps/mailfeed/views.py b/nablapps/mailfeed/views.py index 7ec1f165..c53016aa 100644 --- a/nablapps/mailfeed/views.py +++ b/nablapps/mailfeed/views.py @@ -11,6 +11,8 @@ class MailFeedListView(PermissionRequiredMixin, ListView): + """An overview of all mailfeeeds""" + permission_required = "Mailfeed.generate_mailfeeds" model = Mailfeed template_name = "mailfeed/mailfeed_list.html" @@ -22,6 +24,8 @@ def get_context_data(self, **kwargs): class CreateMailFeedView(PermissionRequiredMixin, View): + """Create a new mailfeed""" + permission_required = "Mailfeed.generate_mailfeeds" def get(self, request): @@ -40,6 +44,8 @@ def post(self, request): class SubscribeView(View): + """Subscribe to a mailfeed by submitting an email adress""" + def get(self, request, mailfeed_id: int): subscribe_form = SubscribeForm() context = {"subscribe_form": subscribe_form} @@ -70,6 +76,8 @@ def post(self, request, mailfeed_id: int): class UnsubscribeView(View): + """Unsubscribe from a mailfeed""" + def get(self, request, mailfeed_id: int, uuid: str): unsubscribe_form = UnsubscribeForm() context = {"unsubscribe_form": unsubscribe_form} @@ -82,10 +90,11 @@ def get(self, request, mailfeed_id: int, uuid: str): def post(self, request, mailfeed_id: int, uuid: str): mailfeed = Mailfeed.objects.get(pk=mailfeed_id) - subscription = Subscription.objects.filter(mailfeed=mailfeed, uuid=uuid).first() - print(subscription) + subscription = Subscription.objects.filter( + mailfeed=mailfeed, uuid=uuid + ).first() # Should only be one instance - if subscription == None: + if subscription is None: return render( request, "mailfeed/msg.html", @@ -115,6 +124,8 @@ def post(self, request, mailfeed_id: int, uuid: str): class MailFeedDetailView(PermissionRequiredMixin, DetailView): + """Create and send emails to a mailfeed""" + permission_required = "Mailfeed.generate_mailfeeds" def get(self, request, mailfeed_id: int): @@ -130,6 +141,7 @@ def post(self, request: HttpRequest, mailfeed_id: int): email_form = EmailForm(request.POST) mailfeed = Mailfeed.objects.get(pk=mailfeed_id) email_list = mailfeed.get_email_list() + if not email_form.is_valid(): return HttpResponse("Oops! Noe gikk galt.") @@ -144,7 +156,6 @@ def post(self, request: HttpRequest, mailfeed_id: int): content += ( f"\n\nHvis du vil slutte å abonnere på disse mailene trykk her:\n" ) - print(request.build_absolute_uri("unsubscribe-mailfeed")) unsubscribe_url = "https://nabla.no" + reverse( "unsubscribe-mailfeed", kwargs={"mailfeed_id": mailfeed_id, "uuid": subscription.uuid},