Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tncrdk committed Jan 12, 2024
1 parent d41df0e commit 84ad988
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 0 additions & 6 deletions nablapps/mailfeed/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions nablapps/mailfeed/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 15 additions & 4 deletions nablapps/mailfeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand All @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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.")

Expand All @@ -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},
Expand Down

0 comments on commit 84ad988

Please sign in to comment.