def _add_comment(request, score): """ Handle new comment adding from POST data. Process autoscore bricks in comment. """ comment_form = score.comment_form(request.POST) if not comment_form.is_valid(): # Comment is empty or request was forged. return message = comment_form.cleaned_data['comment'] # BUG 2174 Replace with regular space to fix urlization. message = re.sub(' ', ' ', message) # Replace all autoscore bricks with normal text. soup = BeautifulSoup(message) for input_node in soup.findAll('input'): input_node.replaceWith(input_node['value']) message = ''.join(map(unicode, soup.body.contents)) comment = CommentExmo.objects.create( object_pk=score.pk, content_type=ContentType.objects.get_for_model(Score), user=request.user, comment=clean_message(message), posted_by_expert=request.user.is_expert, site_id=1) if request.user.is_expert: # Expert comment. Close existing org representatives comments for this score. org_comments = CommentExmo.objects.filter( object_pk=score.pk, status=CommentExmo.OPEN, user__userprofile__organization__isnull=False) org_comments.update(status=CommentExmo.ANSWERED, answered_date=datetime.now()) else: # Org representative comment, update org status to "Active" org = score.task.organization if org.inv_status == 'RGS' and org in request.user.profile.organization.all( ): org.inv_status = 'ACT' org.save() mail_comment(request, comment)
def clarification_answer(request, clarification_pk): if request.method != 'POST': return HttpResponseNotAllowed(['POST']) clarification = get_object_or_404(Clarification, pk=clarification_pk) if not request.user.has_perm('exmo2010.answer_clarification', clarification.score): raise PermissionDenied form = clarification.answer_form(request.POST) if form.is_valid(): clarification.add_answer(request.user, clean_message(form.cleaned_data['answer'])) mail_clarification(request, clarification) redirect = reverse('exmo2010:score', args=[clarification.score.pk]) + '#clarifications' return HttpResponseRedirect(redirect)
def clarification_create(request, score_pk): if request.method != 'POST': return HttpResponseNotAllowed(['POST']) score = get_object_or_404(Score, pk=score_pk) if not request.user.has_perm('exmo2010.add_clarification', score): raise PermissionDenied form = Clarification.form(request.POST) if form.is_valid(): clarification = score.add_clarification(request.user, clean_message(form.cleaned_data['comment'])) mail_clarification(request, clarification) redirect = reverse('exmo2010:score', args=[score.pk]) + '#clarifications' return HttpResponseRedirect(redirect)
def clarification_create(request, score_pk): if request.method != 'POST': return HttpResponseNotAllowed(['POST']) score = get_object_or_404(Score, pk=score_pk) if not request.user.has_perm('exmo2010.add_clarification', score): raise PermissionDenied form = Clarification.form(request.POST) if form.is_valid(): clarification = score.add_clarification( request.user, clean_message(form.cleaned_data['comment'])) mail_clarification(request, clarification) redirect = reverse('exmo2010:score', args=[score.pk]) + '#clarifications' return HttpResponseRedirect(redirect)
def _add_comment(request, score): """ Handle new comment adding from POST data. Process autoscore bricks in comment. """ comment_form = score.comment_form(request.POST) if not comment_form.is_valid(): # Comment is empty or request was forged. return message = comment_form.cleaned_data['comment'] # BUG 2174 Replace with regular space to fix urlization. message = re.sub(' ', ' ', message) # Replace all autoscore bricks with normal text. soup = BeautifulSoup(message) for input_node in soup.findAll('input'): input_node.replaceWith(input_node['value']) message = ''.join(map(unicode, soup.body.contents)) comment = CommentExmo.objects.create( object_pk=score.pk, content_type=ContentType.objects.get_for_model(Score), user=request.user, comment=clean_message(message), posted_by_expert=request.user.is_expert, site_id=1) if request.user.is_expert: # Expert comment. Close existing org representatives comments for this score. org_comments = CommentExmo.objects.filter( object_pk=score.pk, status=CommentExmo.OPEN, user__userprofile__organization__isnull=False) org_comments.update(status=CommentExmo.ANSWERED, answered_date=datetime.now()) else: # Org representative comment, update org status to "Active" org = score.task.organization if org.inv_status == 'RGS' and org in request.user.profile.organization.all(): org.inv_status = 'ACT' org.save() mail_comment(request, comment)
def clarification_answer(request, clarification_pk): if request.method != 'POST': return HttpResponseNotAllowed(['POST']) clarification = get_object_or_404(Clarification, pk=clarification_pk) if not request.user.has_perm('exmo2010.answer_clarification', clarification.score): raise PermissionDenied form = clarification.answer_form(request.POST) if form.is_valid(): clarification.add_answer(request.user, clean_message(form.cleaned_data['answer'])) mail_clarification(request, clarification) redirect = reverse('exmo2010:score', args=[clarification.score.pk ]) + '#clarifications' return HttpResponseRedirect(redirect)
def get_comment_create_data(self): data = super(CustomCommentForm, self).get_comment_create_data() data['comment'] = clean_message(data['comment']) return data
def forwards(self, orm): "Write your forwards methods here." # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..." for comment in orm.CommentExmo.objects.all(): comment.comment = clean_message(comment.comment) comment.save()
def clean_comment(self): return clean_message(self.cleaned_data['comment'])
def add_answer(self, user, answer): self.answer = clean_message(answer) self.close_user = user self.close_date = datetime.datetime.now() self.save() return self
def add_claim(self, creator, comment): claim = Claim(score=self, creator=creator, comment=clean_message(comment)) claim.addressee = claim.score.task.user claim.full_clean() claim.save() return claim
def add_clarification(self, creator, comment): clarification = Clarification(score=self, creator=creator, comment=clean_message(comment)) clarification.save() return clarification