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

Newsletter Updates #206

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Newsletter Updates #206

wants to merge 3 commits into from

Conversation

yukitya-1811
Copy link
Contributor

Description

Features being implemented -

  1. Admins and Core members can now create events and announcements that shall be displayed on the What's New page
  2. They can also mark these as archived so that they are not displayed any longer
  3. They can also link the announcements/events to certain pages on the corpus website or external websites
  4. Extra change - allow admins to change and modify the profile_pic attribute of Users

Type of Change

What types of changes does your code introduce?
Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Comment on lines +12 to +14
'start_date': forms.DateInput(attrs={'type': 'date', 'class': 'border p-2 w-full'}),
'end_date': forms.DateInput(attrs={'type': 'date', 'class': 'border p-2 w-full'}),
'timing': forms.TimeInput(attrs={'type': 'time', 'class': 'border p-2 w-full'}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These classes are not handled by the base form?

timing = models.TimeField(null=True, blank=True)
link = models.URLField(null=True, blank=True)
archived = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have created at, also add updated at

Comment on lines +7 to +11
path("manage_announcements/", views.manage_announcements, name="newsletter_manage_announcements"),
path("new_announcement/", views.new_announcement, name="newsletter_new_announcement"),
path("edit_announcement/<int:pk>", views.edit_announcement, name="newsletter_edit_announcement"),
path("toggle_announcement/<int:pk>", views.toggle_announcement, name="newsletter_toggle_announcement"),
path("delete_announcement/<int:pk>", views.delete_announcement, name="newsletter_delete_announcement")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use resource API style

/announcements/new, /announcements/manage, /announcement/edit, etc.

{% load static %}

{% block title %}
Newsletter | New

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New for update announcement?

Also use consistent naming so that devs are not confused in the future xD Use Edit announcement everywhere (similar to the file name)

Comment on lines +67 to +73
def toggle_announcement(request, pk):
announcement = get_object_or_404(Announcement, pk=pk)
announcement.archived = not announcement.archived
announcement.save()
string = "archived" if announcement.archived else "unarchived"
messages.success(request, f"Announcement {string} successfully")
return redirect('newsletter_manage_announcements')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be like this. Use the edit announcement view itself because

  1. We already have a view that updates the model.
  2. Any APIs that can update the DB should always be POST/PATCH requests. GET requests should never be able to update the DB.

Comment on lines +77 to +81
def delete_announcement(request, pk):
announcement = get_object_or_404(Announcement, pk=pk)
announcement.delete()
messages.success(request, "Announcement deleted successfully")
return redirect('newsletter_manage_announcements')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few opinions on this, can discuss further - I don't think we should delete data. Let it be there, on deletion, just archive it but not actually delete it.

Again, cannot be a GET request, has to be a POST/PATCH/DELETE request.

@@ -12,7 +12,7 @@ class CorpusUserAdmin(UserAdmin):
(None, {"fields": ("email", "password")}),
(
"Personal Info",
{"fields": ("first_name", "last_name", "phone_no", "gender")},
{"fields": ("first_name", "last_name", "phone_no", "gender", "profile_pic")},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally shouldn't be part of this diff since it is something separate and not pertaining to the diff.....

But I'll allow it once xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants