8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Lerennais remarques

This commit is contained in:
Gabriel Detraz 2020-04-23 03:21:11 +02:00
parent 2f018cf11b
commit bd9a227cae
5 changed files with 13 additions and 9 deletions

View file

@ -96,8 +96,8 @@ def edit_options_template_function(request, section, forms, models):
return redirect(reverse("preferences:display-options"))
options_instance, _created = model.objects.get_or_create()
can, msg, permissions = options_instance.can_edit(request.user)
if not can:
_is_allowed_to_edit, msg, permissions = options_instance.can_edit(request.user)
if not _is_allowed_to_edit:
messages.error(request, acl_error_message(msg, permissions))
return redirect(reverse("index"))
options = form_instance(

View file

@ -42,13 +42,14 @@ class NewTicketForm(FormRevMixin, ModelForm):
fields = ["title", "description", "email"]
def __init__(self, *args, **kwargs):
request = kwargs.pop("request")
request = kwargs.pop("request", None)
super(NewTicketForm, self).__init__(*args, **kwargs)
if request.user.is_authenticated:
self.fields.pop('email')
self.instance.user = request.user
self.fields['description'].help_text = render_to_string('tickets/help_text.html')
self.instance.language = getattr(request, "LANGUAGE_CODE", "en")
self.instance.request = request
class EditTicketForm(FormRevMixin, ModelForm):
@ -71,7 +72,9 @@ class CommentTicketForm(FormRevMixin, ModelForm):
fields = ["comment"]
def __init__(self, *args, **kwargs):
request = kwargs.pop("request", None)
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
super(CommentTicketForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields["comment"].label = _("comment")
self.instance.request = request

View file

@ -34,6 +34,7 @@ from django.utils.functional import cached_property
from reversion.models import Version
from re2o.mixins import AclMixin
from re2o.mail_utils import send_mail_object
from django.core.mail import EmailMessage
from preferences.models import GeneralOption
@ -69,6 +70,7 @@ class Ticket(AclMixin, models.Model):
language = models.CharField(
max_length=16, help_text=_("Language of the ticket."), default="en"
)
request = None
class Meta:
permissions = (("view_ticket", _("Can view a ticket object")),)
@ -113,7 +115,7 @@ class Ticket(AclMixin, models.Model):
[to_addr],
reply_to=[self.get_mail],
)
mail_to_send.send(fail_silently=False)
send_mail_object(mail_to_send, self.request)
def can_view(self, user_request, *_args, **_kwargs):
@ -165,6 +167,7 @@ class CommentTicket(AclMixin, models.Model):
on_delete=models.CASCADE,
related_name="ticket_comment",
)
request = None
class Meta:
permissions = (("view_commentticket", _("Can view a ticket object")),)
@ -221,6 +224,7 @@ class CommentTicket(AclMixin, models.Model):
return "Comment " + str(self.comment_id) + " on " + str(self.parent_ticket)
def publish_mail(self):
"""Send mail to user and admin after new comment"""
site_url = GeneralOption.get_cached_value("main_site_url")
to_addr = TicketOption.get_cached_value("publish_address")
context = {"comment": self, "site_url": site_url}
@ -236,7 +240,7 @@ class CommentTicket(AclMixin, models.Model):
GeneralOption.get_cached_value("email_from"),
[to_addr, self.parent_ticket.get_mail],
)
mail_to_send.send(fail_silently=False)
send_mail_object(mail_to_send, self.request)
@receiver(post_save, sender=Ticket)

View file

@ -28,11 +28,8 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.views.decorators.cache import cache_page
from django.utils.translation import ugettext as _
from django.urls import reverse
from django.forms import modelformset_factory
from re2o.views import form
from re2o.base import re2o_paginator

View file

@ -121,7 +121,7 @@ def edit_ticket(request, ticket, ticketid):
@can_view(Ticket)
def add_comment(request, ticket, ticketid):
""" Add a comment to a ticket"""
commentticket = CommentTicketForm(request.POST or None)
commentticket = CommentTicketForm(request.POST or None, request=request)
if commentticket.is_valid():
commentticket = commentticket.save(commit=False)
commentticket.parent_ticket = ticket