Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show publication date on petition page #299

Merged
merged 7 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytition/petition/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class PetitionCreationStep3(forms.Form):

class ContentFormGeneric(forms.Form):
### Content of a Petition ###
publication_date = forms.DateField(required=False)
fallen marked this conversation as resolved.
Show resolved Hide resolved
show_publication_date = SwitchField(required=False, label=_("Show publication date"))
text = forms.CharField(widget=TinyMCE)
target = forms.IntegerField(required=False)
side_text = forms.CharField(widget=TinyMCE, required=False)
Expand Down
18 changes: 18 additions & 0 deletions pytition/petition/migrations/0018_petition_publication_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.28 on 2022-12-09 11:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('petition', '0017_petitiontemplate_paper_signatures_enabled'),
]

operations = [
migrations.AddField(
model_name='petition',
name='publication_date',
field=models.DateTimeField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.28 on 2022-12-16 05:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('petition', '0018_petition_publication_date'),
]

operations = [
migrations.AddField(
model_name='petition',
name='show_publication_date',
field=models.BooleanField(default=False),
),
]
4 changes: 4 additions & 0 deletions pytition/petition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class Petition(models.Model):
last_modification_date = models.DateTimeField(blank=True)
moderated = models.BooleanField(default=False)
has_share_buttons = models.BooleanField(default=True)
publication_date = models.DateTimeField(blank=True, null=True)
show_publication_date = models.BooleanField(default=False)

@property
def is_moderated(self):
Expand Down Expand Up @@ -316,10 +318,12 @@ def confirm_signature(self, conf_hash):

def publish(self):
self.published = True
self.publication_date = timezone.now()
self.save()

def unpublish(self):
self.published = False
self.publication_date = None
self.save()

@property
Expand Down
5 changes: 5 additions & 0 deletions pytition/petition/templates/petition/petition_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ <h2 class="text-danger">{% trans "This petition is moderated. You only see it be
</div>
</div>
<div class="presentation">
{% if petition.publication_date and petition.show_publication_date %}
<div class="font-weight-light font-italic">
{% trans "Published on: "%} {{ petition.publication_date|date:"SHORT_DATE_FORMAT" }}
</div>
{% endif %}
{{ petition.text|html_sanitize|safe }}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions pytition/petition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ def edit_petition(request, petition_id):
submitted_ctx['content_form_submitted'] = True
content_form = ContentFormPetition(request.POST)
if content_form.is_valid():
petition.publication_date = content_form.cleaned_data['publication_date']
petition.show_publication_date = content_form.cleaned_data['show_publication_date']
petition.title = content_form.cleaned_data['title']
petition.target = content_form.cleaned_data['target']
petition.paper_signatures = content_form.cleaned_data['paper_signatures']
Expand Down