def create_feedback(self): d = Feedback() d.discussion = self.admin d.title = "Visit the moon" d.full_clean() d.save() return d
def discussion_add_feedback(discussion, user, feedbabk_type = None, content = None, voice_recording = None): if feedbabk_type == None: return None, 'No feedback type' if feedbabk_type != Feedback.ADVICE and feedbabk_type != Feedback.COOPERATION and feedbabk_type != Feedback.INTUITION and feedbabk_type != Feedback.ENCOURAGE: return None,( 'Wrong feedback type ' + str(feedbabk_type)) if False == discussion.can_user_access_discussion(user): return None, "user cannot access discussion" # if not discussion.is_active(): # return None, "discussion is not active" if user == discussion.owner: return None, "discussion owner cannot post a feedback" if Feedback.objects.filter( discussion = discussion, feedbabk_type = feedbabk_type, content = content, user = user).count() != 0: return None, "feedback already exists" feedback = Feedback(discussion=discussion, user=user, feedbabk_type=feedbabk_type, content=content, voice_recording = voice_recording) feedback.full_clean() feedback.save() discussion.save() #verify that the entire discussion is considered updated success, error_string = start_discussion_following( discussion, user) if success == False: return None, error_string t = Template(""" {{feedbabk.user.get_full_name|default:feedbabk.user.username}} פירסם/ה {{feedbabk.get_feedbabk_type_name}}:\n "{{feedbabk.content}} "\n """) trunkated_subject_and_detailes = t.render(Context({"feedbabk": feedback})) discussion_email_updates(discussion, trunkated_subject_and_detailes, user, trunkated_subject_and_detailes) user_posted_a_feedback_in_another_other_user_s_discussion(user, feedback.get_absolute_url()) return feedback, None