31 lines
953 B
Python
31 lines
953 B
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from mixins.views import ObjectUpdate
|
|
|
|
from core.forms import NotificationSettingsForm
|
|
from core.models import NotificationSettings
|
|
|
|
|
|
# Notifications - we create a new notification settings object if there isn't one
|
|
# Hence, there is only an update view, not a create view.
|
|
class NotificationsUpdate(LoginRequiredMixin, ObjectUpdate):
|
|
model = NotificationSettings
|
|
form_class = NotificationSettingsForm
|
|
|
|
page_title = "Update your notification settings"
|
|
page_subtitle = (
|
|
"At least the topic must be set if you want to receive notifications."
|
|
)
|
|
|
|
submit_url_name = "notifications_update"
|
|
submit_url_args = ["type"]
|
|
|
|
pk_required = False
|
|
|
|
hide_cancel = True
|
|
|
|
def get_object(self, **kwargs):
|
|
notification_settings, _ = NotificationSettings.objects.get_or_create(
|
|
user=self.request.user
|
|
)
|
|
return notification_settings
|