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 display_author(self): return display_name(self.author)