Ajout de la possibilité d'ajouter des messages quand on soumet un événement
See #209
This commit is contained in:
parent
c3d10f01db
commit
4b55830419
@ -314,7 +314,7 @@ def weekly_imports(self):
|
||||
run_recurrent_imports_from_list([imp.pk for imp in imports])
|
||||
|
||||
@app.task(base=ChromiumTask, bind=True)
|
||||
def import_events_from_url(self, url, cat, tags, force=False, user_id=None):
|
||||
def import_events_from_url(self, url, cat, tags, force=False, user_id=None, email=None, comments=None):
|
||||
from .db_importer import DBImporterEvents
|
||||
from agenda_culturel.models import RecurrentImport, BatchImportation
|
||||
from agenda_culturel.models import Event, Category
|
||||
@ -348,7 +348,13 @@ def import_events_from_url(self, url, cat, tags, force=False, user_id=None):
|
||||
# set default values
|
||||
values = {}
|
||||
if cat is not None:
|
||||
values = {"category": cat, "tags": tags}
|
||||
values["category"] = cat
|
||||
if tags is not None:
|
||||
values["tags"] = tags
|
||||
if email is not None:
|
||||
values["email"] = email
|
||||
if comments is not None:
|
||||
values["comments"] = comments
|
||||
|
||||
# get event
|
||||
events = u2e.process(
|
||||
@ -377,14 +383,14 @@ def import_events_from_url(self, url, cat, tags, force=False, user_id=None):
|
||||
|
||||
|
||||
@app.task(base=ChromiumTask, bind=True)
|
||||
def import_events_from_urls(self, urls_cat_tags, user_id=None):
|
||||
def import_events_from_urls(self, urls_cat_tags, user_id=None, email=None, comments=None):
|
||||
for ucat in urls_cat_tags:
|
||||
if ucat is not None:
|
||||
url = ucat[0]
|
||||
cat = ucat[1]
|
||||
tags = ucat[2]
|
||||
|
||||
import_events_from_url.delay(url, cat, tags, user_id=user_id)
|
||||
import_events_from_url.delay(url, cat, tags, user_id=user_id, email=email, comments=comments)
|
||||
|
||||
|
||||
app.conf.beat_schedule = {
|
||||
|
@ -13,7 +13,10 @@ from django.forms import (
|
||||
BooleanField,
|
||||
HiddenInput,
|
||||
ModelChoiceField,
|
||||
EmailField
|
||||
)
|
||||
from django.forms import formset_factory
|
||||
|
||||
from django_better_admin_arrayfield.forms.widgets import DynamicArrayWidget
|
||||
|
||||
from .utils import PlaceGuesser
|
||||
@ -125,7 +128,42 @@ class TagRenameForm(Form):
|
||||
def is_force(self):
|
||||
return "force" in self.fields and self.cleaned_data["force"] == True
|
||||
|
||||
class URLSubmissionForm(Form):
|
||||
|
||||
class SimpleContactForm(GroupFormMixin, Form):
|
||||
email = EmailField(
|
||||
label=_("Your email"),
|
||||
help_text=_("Your email address"),
|
||||
max_length=254,
|
||||
required=False
|
||||
)
|
||||
|
||||
comments = CharField(
|
||||
label=_("Comments"),
|
||||
help_text=_("Your message for the moderation team (comments, clarifications, requests...)"),
|
||||
widget=Textarea,
|
||||
max_length=2048,
|
||||
required=False
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
is_authenticated = "is_authenticated" in kwargs and kwargs["is_authenticated"]
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if not is_authenticated:
|
||||
self.add_group('communication',
|
||||
_('Receive notification of publication or leave a message for moderation'),
|
||||
maskable=True,
|
||||
default_masked=True)
|
||||
self.fields["email"].group_id = 'communication'
|
||||
self.fields["comments"].group_id = 'communication'
|
||||
else:
|
||||
del self.fields["email"]
|
||||
del self.fields["comments"]
|
||||
|
||||
|
||||
|
||||
|
||||
class URLSubmissionForm(GroupFormMixin, Form):
|
||||
required_css_class = 'required'
|
||||
|
||||
url = URLField(max_length=512)
|
||||
@ -143,11 +181,20 @@ class URLSubmissionForm(Form):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
is_authenticated = kwargs.pop("is_authenticated", False)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["tags"].choices = Tag.get_tag_groups(all=True)
|
||||
|
||||
self.add_group('event', _('Event'))
|
||||
self.fields["url"].group_id = 'event'
|
||||
self.fields["category"].group_id = 'event'
|
||||
self.fields["tags"].group_id = 'event'
|
||||
|
||||
|
||||
class URLSubmissionFormWithContact(SimpleContactForm, URLSubmissionForm):
|
||||
pass
|
||||
|
||||
URLSubmissionFormSet = formset_factory(URLSubmissionForm, extra=9, min_num=1)
|
||||
|
||||
class DynamicArrayWidgetURLs(DynamicArrayWidget):
|
||||
template_name = "agenda_culturel/widgets/widget-urls.html"
|
||||
@ -282,6 +329,8 @@ class EventForm(GroupFormMixin, ModelForm):
|
||||
self.fields['local_image'].group_id = 'illustration'
|
||||
self.fields['image_alt'].group_id = 'illustration'
|
||||
|
||||
self.add_group('urls', _('URLs'))
|
||||
self.fields["reference_urls"].group_id = 'urls'
|
||||
|
||||
if is_authenticated:
|
||||
self.add_group('meta-admin', _('Meta information'))
|
||||
@ -338,6 +387,9 @@ class EventForm(GroupFormMixin, ModelForm):
|
||||
self.cleaned_data['local_image'] = File(name=basename, file=open(old, "rb"))
|
||||
|
||||
|
||||
class EventFormWithContact(SimpleContactForm, EventForm):
|
||||
pass
|
||||
|
||||
class MultipleChoiceFieldAcceptAll(MultipleChoiceField):
|
||||
def validate(self, value):
|
||||
pass
|
||||
|
@ -200,6 +200,8 @@ class Extractor(ABC):
|
||||
"published": published,
|
||||
"image": image,
|
||||
"image_alt": image_alt,
|
||||
"email": self.default_value_if_exists(default_values, "email"),
|
||||
"comments": self.default_value_if_exists(default_values, "comments"),
|
||||
}
|
||||
# TODO: pourquoi url_human et non reference_url
|
||||
if url_human is not None:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1182,6 +1182,12 @@ class Event(models.Model):
|
||||
key = make_template_fragment_key("event_body", [is_auth, self])
|
||||
cache.delete(key)
|
||||
|
||||
# save message if required
|
||||
if self.has_message():
|
||||
msg = self.get_message()
|
||||
msg.related_event = self
|
||||
msg.save()
|
||||
|
||||
# then if its a clone, update the representative
|
||||
if clone:
|
||||
self.other_versions.representative = self
|
||||
@ -1198,6 +1204,8 @@ class Event(models.Model):
|
||||
def from_structure(event_structure, import_source=None):
|
||||
# organisers is a manytomany relation thus cannot be initialised before creation of the event
|
||||
organisers = event_structure.pop('organisers', None)
|
||||
email = event_structure.pop('email', None)
|
||||
comments = event_structure.pop('comments', None)
|
||||
|
||||
if "category" in event_structure and event_structure["category"] is not None:
|
||||
try:
|
||||
@ -1276,6 +1284,8 @@ class Event(models.Model):
|
||||
|
||||
result = Event(**event_structure)
|
||||
result.add_pending_organisers(organisers)
|
||||
if email or comments:
|
||||
result.set_message(Message(subject=_('during import process'), email=email, message=comments))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -1564,8 +1564,11 @@ label.required::after {
|
||||
}
|
||||
}
|
||||
|
||||
.maskable_group .body_group.closed {
|
||||
display: none;
|
||||
.maskable_group {
|
||||
margin: 0.5em 0;
|
||||
.body_group.closed {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.form-place {
|
||||
|
@ -21,7 +21,7 @@
|
||||
<form method="post" action="">
|
||||
{% csrf_token %}
|
||||
{{ form.media }}
|
||||
{{ form.as_p }}
|
||||
{{ form }}
|
||||
<input type="submit" value="Lancer l'import" id="import-button">
|
||||
</form>
|
||||
<p>Si tu as plein d'événements à ajouter, tu peux les <a href="{% url 'add_event_urls' %}" >ajouter par lots</a>.</p>
|
||||
|
@ -28,6 +28,12 @@
|
||||
|
||||
{{ formset.management_form }}
|
||||
{% csrf_token %}
|
||||
{% if contactform %}
|
||||
<article>
|
||||
{{ contactform }}
|
||||
</article>
|
||||
{% endif %}
|
||||
|
||||
{% for form in formset %}
|
||||
<article>
|
||||
<header>
|
||||
|
@ -47,7 +47,10 @@
|
||||
<div class="entree">
|
||||
<div><span class="ts">{{ step.timestamp }}</span></div>
|
||||
<div>
|
||||
<header><strong>Message</strong>{% if step.data.related_event and event != step.data.related_event %} sur <a href="{{ step.data.related_event.get_absolute_url }}">une autre</a> version{% endif %} : <a href="{{ step.data.get_absolute_url }}">{{ step.data.subject|truncatechars:20 }}</a> {% if step.data.user %} par <em>{{ step.data.user }}</em>{% else %} par {{ step.data.name }}{% if step.data.email %} (<a href="mailto: {{ step.data.email }}">{{ step.data.email }}</a>){% endif %}{% endif %}</header>
|
||||
<header><strong>Message</strong>{% if step.data.related_event and event != step.data.related_event %} sur
|
||||
<a href="{{ step.data.related_event.get_absolute_url }}">une autre</a> version{% endif %} :
|
||||
<a href="{{ step.data.get_absolute_url }}">{{ step.data.subject|truncatechars:20 }}</a>
|
||||
{% if step.data.user %} par <em>{{ step.data.user }}</em>{% else %} par {% if step.data.name %}{{ step.data.name }}{% if step.data.email %} (<a href="mailto: {{ step.data.email }}">{{ step.data.email }}</a>){% endif %}{% else %} <a href="mailto: {{ step.data.email }}">{{ step.data.email }}</a>{% endif %}{% endif %}</header>
|
||||
<div class="texte">{{ step.data.message|safe }}</div>
|
||||
{% if step.data.comments %}
|
||||
<div><strong>Commentaire :</strong> {{ step.data.comments }}</div>
|
||||
|
@ -25,11 +25,9 @@ from django.urls import reverse
|
||||
from collections import Counter
|
||||
import emoji
|
||||
|
||||
from django.forms import formset_factory
|
||||
|
||||
from .forms import (
|
||||
URLSubmissionForm,
|
||||
EventForm,
|
||||
EventFormWithContact,
|
||||
BatchImportationForm,
|
||||
FixDuplicates,
|
||||
SelectEventInList,
|
||||
@ -45,6 +43,9 @@ from .forms import (
|
||||
TagRenameForm,
|
||||
MessageForm,
|
||||
MessageEventForm,
|
||||
URLSubmissionFormWithContact,
|
||||
URLSubmissionFormSet,
|
||||
SimpleContactForm,
|
||||
)
|
||||
|
||||
from .filters import (
|
||||
@ -496,7 +497,6 @@ class EventDetailView(UserPassesTestMixin, DetailView, ModelFormMixin):
|
||||
|
||||
def get_object(self):
|
||||
o = super().get_object()
|
||||
logger.warning(">>>> details")
|
||||
o.download_missing_image()
|
||||
y = self.kwargs["year"]
|
||||
m = self.kwargs["month"]
|
||||
@ -558,7 +558,7 @@ def import_event_proxy(request):
|
||||
|
||||
class EventCreateView(SuccessMessageMixin, CreateView):
|
||||
model = Event
|
||||
form_class = EventForm
|
||||
form_class = EventFormWithContact
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
@ -585,6 +585,10 @@ class EventCreateView(SuccessMessageMixin, CreateView):
|
||||
|
||||
if form.cleaned_data['cloning']:
|
||||
form.instance.set_in_moderation_process()
|
||||
|
||||
if form.cleaned_data["email"] or form.cleaned_data["comments"]:
|
||||
form.instance.set_message(
|
||||
Message(subject=_('during the creation process'), message=form.cleaned_data["comments"], email=form.cleaned_data["email"]))
|
||||
|
||||
form.instance.import_sources = None
|
||||
form.instance.set_processing_user(self.request.user)
|
||||
@ -658,11 +662,14 @@ class URLEventEvaluation:
|
||||
|
||||
|
||||
def import_from_urls(request):
|
||||
URLSubmissionFormSet = formset_factory(URLSubmissionForm, extra=9, min_num=1)
|
||||
|
||||
|
||||
if request.method == "POST":
|
||||
formset = URLSubmissionFormSet(request.POST, request.FILES)
|
||||
if formset.is_valid():
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
contactform = SimpleContactForm(request.POST)
|
||||
if formset.is_valid() and (request.user.is_authenticated or contactform.is_valid()):
|
||||
# evaluate all the forms
|
||||
ucat = [URLEventEvaluation(form, request.user.is_authenticated) for form in formset.forms]
|
||||
|
||||
@ -689,20 +696,32 @@ def import_from_urls(request):
|
||||
request,
|
||||
_('Integrating {} url(s) into our import process.').format(len(ucat))
|
||||
)
|
||||
import_events_from_urls.delay(ucat, user_id=request.user.pk if request.user else None)
|
||||
email = None
|
||||
comments = None
|
||||
if not request.user.is_authenticated:
|
||||
email = contactform.cleaned_data["email"]
|
||||
comments = contactform.cleaned_data["comments"]
|
||||
import_events_from_urls.delay(ucat,
|
||||
user_id=request.user.pk if request.user else None,
|
||||
email=email, comments=comments)
|
||||
return HttpResponseRedirect(reverse("thank_you"))
|
||||
else:
|
||||
return HttpResponseRedirect(reverse("home"))
|
||||
|
||||
else:
|
||||
formset = URLSubmissionFormSet()
|
||||
if not request.user.is_authenticated:
|
||||
contactform = SimpleContactForm()
|
||||
|
||||
return render(request, "agenda_culturel/import_set.html", context={"formset": formset})
|
||||
context = {"formset": formset}
|
||||
if not request.user.is_authenticated:
|
||||
context["contactform"] = contactform
|
||||
return render(request, "agenda_culturel/import_set.html", context=context)
|
||||
|
||||
|
||||
def import_from_url(request):
|
||||
|
||||
form = URLSubmissionForm()
|
||||
form = URLSubmissionFormWithContact(is_authenticated=request.user.is_authenticated)
|
||||
|
||||
initial = {
|
||||
"start_day": date.today() + timedelta(days=1),
|
||||
@ -714,7 +733,7 @@ def import_from_url(request):
|
||||
|
||||
# if the form has been sent
|
||||
if request.method == "POST":
|
||||
form = URLSubmissionForm(request.POST)
|
||||
form = URLSubmissionFormWithContact(request.POST, is_authenticated=request.user.is_authenticated)
|
||||
|
||||
# if the form is valid
|
||||
if form.is_valid():
|
||||
@ -739,7 +758,7 @@ def import_from_url(request):
|
||||
request,
|
||||
_('Integrating {} into our import process.').format(uc.url)
|
||||
)
|
||||
import_events_from_url.delay(uc.url, uc.cat, uc.tags, user_id=request.user.pk if request.user else None)
|
||||
import_events_from_url.delay(uc.url, uc.cat, uc.tags, user_id=request.user.pk if request.user else None, email=form.cleaned_data.get("email"), comments=form.cleaned_data.get("comments"))
|
||||
return HttpResponseRedirect(reverse("thank_you"))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user