Beispiel #1
0
def set_up_notification_settings(sender, instance, created, **kwargs):
    if created:
        # Create a settings profile for notifications for the new user
        # Connecting the signal to `Profile` ensures this is only created
        # for "actual" users (interns and staff)
        profile = instance

        settings = NYTSettings(user=profile.user)
        settings.save()
Beispiel #2
0
 def __init__(self, article, request, *args, **kwargs):
     self.article = article
     self.user = request.user
     initial = kwargs.pop("initial", None)
     self.notification_type = NotificationType.objects.get_or_create(
         key=ARTICLE_EDIT,
         content_type=ContentType.objects.get_for_model(article))[0]
     self.edit_notifications = models.ArticleSubscription.objects.filter(
         article=article,
         subscription__notification_type=self.notification_type,
         subscription__settings__user=self.user,
     )
     self.default_settings = Settings.get_default_setting(request.user)
     if self.edit_notifications:
         self.default_settings = self.edit_notifications[
             0].subscription.settings
     if not initial:
         initial = {
             "edit":
             bool(self.edit_notifications),
             "edit_email":
             bool(
                 self.edit_notifications.filter(
                     subscription__send_emails=True)),
             "settings":
             self.default_settings,
         }
     kwargs["initial"] = initial
     super().__init__(*args, **kwargs)
     self.fields["settings"].queryset = Settings.objects.filter(
         user=request.user, )
Beispiel #3
0
    def __init__(self, article, request, *args, **kwargs):

        self.article = article
        self.user = request.user
        initial = kwargs.pop('initial', None)
        self.notification_type = NotificationType.objects.get_or_create(
            key=ARTICLE_EDIT,
            content_type=ContentType.objects.get_for_model(article)
        )[0]
        self.edit_notifications = models.ArticleSubscription.objects.filter(
            article=article,
            subscription__notification_type=self.notification_type,
            subscription__settings__user=self.user,
        )
        self.default_settings = Settings.get_default_setting(request.user)
        if self.edit_notifications:
            self.default_settings = self.edit_notifications[
                0].subscription.settings
        if not initial:
            initial = {
                'edit': bool(
                    self.edit_notifications),
                'edit_email': bool(
                    self.edit_notifications.filter(
                        subscription__send_emails=True)),
                'settings': self.default_settings,
            }
        kwargs['initial'] = initial
        super().__init__(*args, **kwargs)
        self.fields['settings'].queryset = Settings.objects.filter(
            user=request.user,
        )
Beispiel #4
0
def subscribeu(request):
    if not request.user.is_authenticated():
        return HttpResponse("not authoride")

    from django_nyt.models import Settings
    settings = Settings.get_default_setting(request.user)
    subscribe(settings, "test")

    return HttpResponse("Ok")
Beispiel #5
0
 def get_context_data(self, **kwargs):
     c = TemplateView.get_context_data(self, **kwargs)
     user_model = get_user_model()
     c['users'] = user_model.objects.all()
     if self.request.user.is_authenticated():
         c['notifications'] = Notification.objects.filter(
             user=self.request.user).order_by('-created')
         c['settings_form'] = SettingsForm(
             instance=Settings.get_default_setting(self.request.user))
         c['testmodel_form'] = forms.TestModelForm()
     return c
Beispiel #6
0
def create_users(apps, schema_editor):
    from django.contrib.auth import get_user_model
    user_model = get_user_model()

    for username, email in FIXTURES:
        user = user_model.objects.create(
            username=username,
            email=email,
            is_active=True,
        )
        from django_nyt.models import Settings
        settings = Settings.get_default_setting(user)
        subscribe(settings, NOTIFICATION_TEST_KEY)
def create_users(apps, schema_editor):
    from django.contrib.auth import get_user_model
    user_model = get_user_model()

    for username, email in FIXTURES:
        user = user_model.objects.create(
            username=username,
            email=email,
            is_active=True,
        )
        from django_nyt.models import Settings
        settings = Settings.get_default_setting(user)
        subscribe(settings, NOTIFICATION_TEST_KEY)
Beispiel #8
0
 def get_context_data(self, **kwargs):
     c = TemplateView.get_context_data(self, **kwargs)
     user_model = get_user_model()
     c['users'] = user_model.objects.all()
     if self.request.user.is_authenticated():
         c['notifications'] = Notification.objects.filter(
             user=self.request.user
         ).order_by(
             '-created'
         )
         c['settings_form'] = SettingsForm(
             instance=Settings.get_default_setting(self.request.user)
         )
         c['testmodel_form'] = forms.TestModelForm()
     return c