mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add preview button to news
This commit is contained in:
@ -9,8 +9,6 @@
|
||||
{% block content %}
|
||||
<p><a href="{{ url('com:news_list') }}">{% trans %}Back to news{% endtrans %}</a></p>
|
||||
<h3>{% trans %}News{% endtrans %}</h3>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
|
||||
{% endif %}
|
||||
<section class="news_event">
|
||||
<h4>{{ news.title }}</h4>
|
||||
<p class="date">
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block title %}
|
||||
{% if object %}
|
||||
@ -9,6 +10,30 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if 'preview' in request.POST.keys() %}
|
||||
<section class="news_event">
|
||||
<h4> <a href="#">{{ form.instance.title }}</a></h4>
|
||||
<p class="date">
|
||||
<span>{{ form.instance.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
|
||||
<span>{{ form.instance.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
|
||||
</p>
|
||||
<p><a href="#">{{ form.instance.club or "Club" }}</a></p>
|
||||
<p>{{ form.instance.summary|markdown }}</p>
|
||||
</section>
|
||||
<hr>
|
||||
<section class="news_event">
|
||||
<h4>{{ form.instance.title }}</h4>
|
||||
<p class="date">
|
||||
<span>{{ form.instance.dates.first().start_date|localtime|date(DATETIME_FORMAT) }}
|
||||
{{ form.instance.dates.first().start_date|localtime|time(DATETIME_FORMAT) }}</span> -
|
||||
<span>{{ form.instance.dates.first().end_date|localtime|date(DATETIME_FORMAT) }}
|
||||
{{ form.instance.dates.first().end_date|localtime|time(DATETIME_FORMAT) }}</span>
|
||||
</p>
|
||||
<p><a href="#">{{ form.instance.club or "Club" }}</a></p>
|
||||
<p>{{ form.instance.summary|markdown }}</p>
|
||||
<p>{% trans %}Author: {% endtrans %} {{ user_profile_link(form.instance.author) }}</p>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if object %}
|
||||
<h2>{% trans %}Edit news{% endtrans %}</h2>
|
||||
{% else %}
|
||||
@ -20,10 +45,10 @@
|
||||
{{ form.author }}
|
||||
<p>{{ form.type.errors }}<label for="{{ form.type.name }}">{{ form.type.label }}</label>
|
||||
<ul>
|
||||
<li>Notice: Information, election result - no date</li>
|
||||
<li>Evenement: punctual event, associated with one date</li>
|
||||
<li>Weekly: recurrent event, associated with many dates (specify the first one, and a deadline)</li>
|
||||
<li>Call: long time event, associated with a long date (election appliance, ...)</li>
|
||||
<li>{% trans %}Notice: Information, election result - no date{% endtrans %}</li>
|
||||
<li>{% trans %}Event: punctual event, associated with one date{% endtrans %}</li>
|
||||
<li>{% trans %}Weekly: recurrent event, associated with many dates (specify the first one, and a deadline){% endtrans %}</li>
|
||||
<li>{% trans %}Call: long time event, associated with a long date (election appliance, ...){% endtrans %}</li>
|
||||
</ul>
|
||||
{{ form.type }}</p>
|
||||
<p class="date">{{ form.start_date.errors }}<label for="{{ form.start_date.name }}">{{ form.start_date.label }}</label> {{ form.start_date }}</p>
|
||||
@ -37,6 +62,7 @@
|
||||
<p>{{ form.automoderation.errors }}<label for="{{ form.automoderation.name }}">{{ form.automoderation.label }}</label>
|
||||
{{ form.automoderation }}</p>
|
||||
{% endif %}
|
||||
<p><input type="submit" name="preview" value="{% trans %}Preview{% endtrans %}" /></p>
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
15
com/views.py
15
com/views.py
@ -125,6 +125,13 @@ class NewsEditView(CanEditMixin, UpdateView):
|
||||
except: pass
|
||||
return init
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.get_form()
|
||||
if form.is_valid() and not 'preview' in request.POST.keys():
|
||||
return self.form_valid(form)
|
||||
else:
|
||||
return self.form_invalid(form)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save()
|
||||
if form.cleaned_data['automoderation'] and self.request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
|
||||
@ -148,6 +155,14 @@ class NewsCreateView(CanCreateMixin, CreateView):
|
||||
except: pass
|
||||
return init
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.get_form()
|
||||
if form.is_valid() and not 'preview' in request.POST.keys():
|
||||
return self.form_valid(form)
|
||||
else:
|
||||
self.object = form.instance
|
||||
return self.form_invalid(form)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save()
|
||||
print(form.cleaned_data)
|
||||
|
Reference in New Issue
Block a user