コード例 #1
0
def notification_update(request, pk):
    notification = get_object_or_404(TopicNotification,
                                     pk=pk,
                                     user=request.user)
    form = NotificationForm(data=request.POST, instance=notification)

    if form.is_valid():
        form.save()
        return redirect(
            request.POST.get('next', notification.topic.get_absolute_url()))
    else:
        messages.error(request, utils.render_form_errors(form))
        return redirect(
            request.POST.get('next', notification.topic.get_absolute_url()))
コード例 #2
0
    def test_notification(self):
        """
        update notification
        """
        category = utils.create_category()
        topic = utils.create_topic(category)
        notification = TopicNotification.objects.create(user=self.user,
                                                        topic=topic,
                                                        is_active=True,
                                                        action=COMMENT)

        form_data = {
            'is_active': True,
        }
        form = NotificationForm(data=form_data, instance=notification)
        self.assertEqual(form.is_valid(), True)
コード例 #3
0
def render_notification_form(user, topic, next=None):
    try:
        notification = TopicNotification.objects.get(user=user, topic=topic)
    except TopicNotification.DoesNotExist:
        notification = None

    initial = {}

    if notification:
        initial['is_active'] = not notification.is_active

    form = NotificationForm(initial=initial)
    return {
        'form': form,
        'topic_id': topic.pk,
        'notification': notification,
        'next': next
    }