def notification_create(request, topic_id): topic = get_object_or_404(Topic.objects.for_access(request.user), pk=topic_id) form = NotificationCreationForm(user=request.user, topic=topic, data=request.POST) if form.is_valid(): form.save() return redirect(request.POST.get('next', topic.get_absolute_url())) else: messages.error(request, utils.render_form_errors(form)) return redirect(request.POST.get('next', topic.get_absolute_url()))
def notification_create(request, topic_id): topic = get_object_or_404(Topic.objects.for_access(request.user), pk=topic_id) form = NotificationCreationForm(user=request.user, topic=topic, data=request.POST) if form.is_valid(): form.save() return redirect(request.POST.get('next', topic.get_absolute_url())) else: messages.error(request, utils.render_form_errors(form)) return redirect(request.POST.get('next', topic.get_absolute_url()))
def test_notification_creation(self): """ create notification """ category = utils.create_category() topic = utils.create_topic(category) form_data = { 'is_active': True, } form = NotificationCreationForm(data=form_data) form.user = self.user form.topic = topic self.assertEqual(form.is_valid(), True) TopicNotification.objects.create(user=self.user, topic=topic, is_active=True, action=COMMENT) form = NotificationCreationForm(data=form_data) form.user = self.user form.topic = topic self.assertEqual(form.is_valid(), False)
def test_notification_creation(self): """ create notification """ category = utils.create_category() topic = utils.create_topic(category) form_data = {'is_active': True, } form = NotificationCreationForm(data=form_data) form.user = self.user form.topic = topic self.assertEqual(form.is_valid(), True) TopicNotification.objects.create(user=self.user, topic=topic, is_active=True, action=COMMENT) form = NotificationCreationForm(data=form_data) form.user = self.user form.topic = topic self.assertEqual(form.is_valid(), False)