def add_opinion(request, discussion, user, title, slug, speech_act): parent_story = request.POST.get('parent_story', None) parent_class = request.POST.get('parent_class', None) if parent_story is None: return HttpResponse("Did not get parent story.") if parent_class is None: return HttpResponse("Did not get parent type.") opinion = Opinion() opinion.discussion = discussion opinion.created_by = user opinion.title = title opinion.slug = slug opinion.speech_act = speech_act opinion.parent_story = { '1': Story.objects.get, '2': Opinion.objects.get, '3': StoryRelation.objects.get }[parent_class](pk=parent_story) try: try: opinion.full_clean() except ValidationError, e: message = DEFAULT_FORM_ERROR_MSG if e.message_dict[NON_FIELD_ERRORS] and re.search(UNIQUENESS_ERROR_PATTERN, e.message_dict[NON_FIELD_ERRORS][0]): message = _('Oops! An opinion with this title was already created inside this discussion.') resp = HttpResponse(message) resp.status_code = 500 return resp opinion.save() resp = HttpResponse("%s" % discussion.last_related_update) create_notification_task.delay("There is a new opinion in %s discussion: %s" % (discussion.slug, title), opinion, request.user)
def add_story(request, discussion, user, title, slug, speech_act): # x = request.POST.get('x', None) y = request.POST.get('y', None) group_profile = GroupProfile.objects.filter(group=discussion.group)[0] if discussion.is_private and not group_profile.is_user_in_group(request.user): return HttpResponse("The discussion is private. You're not allowed to create story.") try: story = Story() story.discussion = discussion story.created_by = user story.title = title story.slug = slug story.speech_act = speech_act # if x: # story.x = x if y: story.y = y try: story.full_clean() except ValidationError, e: message = DEFAULT_FORM_ERROR_MSG if e.message_dict[NON_FIELD_ERRORS] and re.search(UNIQUENESS_ERROR_PATTERN, e.message_dict[NON_FIELD_ERRORS][0]): message = _('Oops! A story with this title was already created inside this discussion.') resp = HttpResponse(message) resp.status_code = 500 return resp story.save() resp = HttpResponse("%s" % discussion.last_related_update) create_notification_task.delay("There is a new story in %s discussion: %s" % (discussion.slug, title), story, request.user)