Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -92,6 +92,8 @@ class PetitionCreationStep3(forms.Form):

class ContentFormGeneric(forms.Form):
### Content of a Petition ###
publication_date = forms.DateField(required=False)
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/0017_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', '0016_signature_uses_phone_number_field'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now there is a migration 0017 (https://github.com/pytition/Pytition/blob/master/pytition/petition/migrations/0017_petitiontemplate_paper_signatures_enabled.py)
Could you "rebase" your PR so that your migrations depend on this one please?

]

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration should now depend on 0018 and be renamed as 0019


from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('petition', '0017_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 @@ -314,10 +316,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 @@ -330,6 +330,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">
Published on: {{ petition.publication_date|date:"M d, Y" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this date format is specific to english speaking countries and others but do not work for France for instance.
I would say petition.publication_date|date:"SHORT_DATE_FORMAT" would be better, don't you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use text that can be translated via i18n :

{% trans "Published on: "%}

</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 @@ -1226,6 +1226,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