def issue_close(request, id): if not request.user.is_superuser: issue = get_object_or_404(Issue, pk=id, owner=request.user, category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) else: issue = get_object_or_404(Issue, pk=id, category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) if request.method == 'POST': commentForm = CommentForm(request.POST) if commentForm.is_valid(): comment = commentForm.save(commit=False) comment.update_date = datetime.datetime.now() comment.issue = issue comment.owner = request.user comment.save() issue.state = ISSUE_STATE_CLOSED issue.save() Vote.objects.filter(issue=issue).delete() messages.success(request, _('The issue has been closed successfully')) return redirect(reverse('issue_list')) else: commentForm = CommentForm() return render_to_response('comment/edit.html', {'active': 'settings', 'title': _('Close an issue'), 'form': commentForm}, context_instance=RequestContext(request))
def comment_create_or_edit(request, id=None, issue_id=None): if id: title = _('Edit a comment') comment = get_object_or_404(Comment, pk=id, owner=request.user, issue__category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) issue = comment.issue mail_subject = _('A comment has been updated') else: title = _('Send a comment') comment = None issue = get_object_or_404(Issue, pk=issue_id, category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) mail_subject = _('A comment has been added') if request.method == 'POST': form = CommentForm(request.POST, instance=comment) if form.is_valid(): comment = form.save(commit=False) comment.issue = issue comment.update_date = datetime.datetime.now() comment.owner = request.user comment.save() domain = Site.objects.get_current().domain # notify admin mail_message = _('%(issue_subject)s : %(issue_url)s') % {'issue_subject': issue.subject, 'issue_url': 'https://%s%s' % (domain, reverse('issue_detail', kwargs={'id': issue.id}))} mail_admins(mail_subject, mail_message, fail_silently=(not settings.DEBUG)) # notify users who have commented except owner of this comment emails_to_notify = issue.emails_to_notify() emails_to_notify.remove(comment.owner.email) notification_subject = _('A new comment has been added on issue #%(id)d') % {'id': issue.id} notification_message = _("%(user)s wrote:") % {'user': display_name(comment.owner)} notification_message = "%s\n\n%s\n\n%s" % ('https://%s%s' % (domain, reverse('issue_detail', kwargs={'id': issue.id})), notification_message, comment.message) notification_messages = [] for email in emails_to_notify: notification_messages.append((notification_subject, notification_message, settings.DEFAULT_FROM_EMAIL, [email])) send_mass_mail(notification_messages, fail_silently=(not settings.DEBUG)) messages.success(request, _('Your comment has been saved successfully')) return redirect(reverse('issue_detail', kwargs={'id': issue.id})) else: form = CommentForm(instance=comment) return render_to_response('comment/edit.html', {'active': 'settings', 'title': title, 'form': form}, context_instance=RequestContext(request))
def comment_message_create(request, issue_id=None): title = _('Send a comment') if request.user.is_superuser: issue = get_object_or_404(Issue, pk=issue_id, category__in=[ISSUE_CATEGORY_MESSAGE, ISSUE_CATEGORY_SUBSCRIPTION]) else: issue = get_object_or_404(Issue, pk=issue_id, category__in=[ISSUE_CATEGORY_MESSAGE, ISSUE_CATEGORY_SUBSCRIPTION], owner=request.user) if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.issue = issue comment.update_date = datetime.datetime.now() comment.owner = request.user comment.save() site = Site.objects.get_current() if request.user.is_superuser: issue.state = ISSUE_STATE_OPEN issue.save() mail_subject = _('You have received an answer on %(site_name)s') % {'site_name': site.name} mail_message = _("%(message_url)s\n\n%(message)s") % {'message_url': 'https://%s%s' % (site.domain, reverse('message_detail', kwargs={'id': issue.id})), 'message': comment.message} issue.owner.email_user(mail_subject, mail_message) else: mail_subject = _('An answer has been posted') mail_message = _('%(message_subject)s : %(message_url)s') % {'message_subject': issue.subject, 'message_url': 'https://%s%s' % (site.domain, reverse('message_detail', kwargs={'id': issue.id}))} mail_admins(mail_subject, mail_message, fail_silently=(not settings.DEBUG)) messages.success(request, _('Your comment has been saved successfully')) return redirect(reverse('message_detail', kwargs={'id': issue.id})) else: form = CommentForm(instance=comment) return render_to_response('comment/edit.html', {'active': 'settings', 'title': title, 'form': form}, context_instance=RequestContext(request))
def issue_reopen(request, id): if not request.user.is_superuser: issue = get_object_or_404(Issue, pk=id, owner=request.user, category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) else: issue = get_object_or_404(Issue, pk=id, category__in=[ISSUE_CATEGORY_BUG, ISSUE_CATEGORY_FEATURE]) if request.method == 'POST': commentForm = CommentForm(request.POST) if commentForm.is_valid(): comment = commentForm.save(commit=False) comment.update_date = datetime.datetime.now() comment.issue = issue comment.owner = request.user comment.save() issue.state = ISSUE_STATE_OPEN issue.save() domain = Site.objects.get_current().domain mail_subject = _('An issue has been reopened') mail_message = _('%(issue_subject)s : %(issue_url)s') % {'issue_subject': issue.subject, 'issue_url': 'https://%s%s' % (domain, reverse('issue_detail', kwargs={'id': issue.id}))} mail_admins(mail_subject, mail_message, fail_silently=(not settings.DEBUG)) messages.success(request, _('The issue has been reopened successfully')) return redirect(reverse('issue_list')) else: commentForm = CommentForm() return render_to_response('comment/edit.html', {'active': 'settings', 'title': _('Reopen an issue'), 'form': commentForm}, context_instance=RequestContext(request))