Skip to content

Commit ebeeea5

Browse files
authored
Issue 311 (#312)
Implement #311 Allow to chose which social network sharing button to show.
1 parent 441a7b3 commit ebeeea5

13 files changed

+1282
-91
lines changed

pytition/petition/forms.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ class SocialNetworkForm(forms.Form):
130130
twitter_image = forms.FileField(max_length=500, required=False)
131131
org_twitter_handle = forms.CharField(max_length=20, required=False)
132132
remove_twitter_image = forms.BooleanField(required=False, initial=False)
133-
has_share_buttons = forms.BooleanField(required=False)
133+
has_email_share_button = forms.BooleanField(required=False)
134+
has_facebook_share_button = forms.BooleanField(required=False)
135+
has_tumblr_share_button = forms.BooleanField(required=False)
136+
has_linkedin_share_button = forms.BooleanField(required=False)
137+
has_twitter_share_button = forms.BooleanField(required=False)
138+
has_mastodon_share_button = forms.BooleanField(required=False)
139+
has_whatsapp_share_button = forms.BooleanField(required=False)
140+
134141

135142

136143
class NewsletterForm(forms.Form):
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Generated by Django 4.2.7 on 2023-12-03 10:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('petition', '0019_petition_show_publication_date'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='petition',
15+
name='has_email_share_button',
16+
field=models.BooleanField(default=False),
17+
),
18+
migrations.AddField(
19+
model_name='petition',
20+
name='has_facebook_share_button',
21+
field=models.BooleanField(default=False),
22+
),
23+
migrations.AddField(
24+
model_name='petition',
25+
name='has_linkedin_share_button',
26+
field=models.BooleanField(default=False),
27+
),
28+
migrations.AddField(
29+
model_name='petition',
30+
name='has_mastodon_share_button',
31+
field=models.BooleanField(default=False),
32+
),
33+
migrations.AddField(
34+
model_name='petition',
35+
name='has_tumblr_share_button',
36+
field=models.BooleanField(default=False),
37+
),
38+
migrations.AddField(
39+
model_name='petition',
40+
name='has_twitter_share_button',
41+
field=models.BooleanField(default=False),
42+
),
43+
migrations.AddField(
44+
model_name='petition',
45+
name='has_whatsapp_share_button',
46+
field=models.BooleanField(default=False),
47+
),
48+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 4.2.7 on 2023-12-03 16:26
2+
3+
from django.db import migrations
4+
5+
def set_new_petition_share_fields(apps, schema_editor):
6+
Petition = apps.get_model("petition", "Petition")
7+
for petition in Petition.objects.all():
8+
if petition.has_share_buttons:
9+
petition.has_email_share_button = True
10+
petition.has_facebook_share_button = True
11+
petition.has_tumblr_share_button = True
12+
petition.has_linkedin_share_button = True
13+
petition.has_twitter_share_button = True
14+
petition.has_mastodon_share_button = True
15+
petition.has_whatsapp_share_button = True
16+
petition.save()
17+
18+
19+
class Migration(migrations.Migration):
20+
21+
dependencies = [
22+
('petition', '0020_petition_has_email_share_button_and_more'),
23+
]
24+
25+
operations = [
26+
migrations.RunPython(set_new_petition_share_fields)
27+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 4.2.7 on 2023-12-06 06:28
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('petition', '0021_auto_20231203_1026'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='petition',
15+
name='has_share_buttons',
16+
),
17+
]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Generated by Django 4.2.7 on 2023-12-08 11:51
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('petition', '0022_remove_petition_has_share_buttons'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='petitiontemplate',
15+
name='has_email_share_button',
16+
field=models.BooleanField(default=False),
17+
),
18+
migrations.AddField(
19+
model_name='petitiontemplate',
20+
name='has_facebook_share_button',
21+
field=models.BooleanField(default=False),
22+
),
23+
migrations.AddField(
24+
model_name='petitiontemplate',
25+
name='has_linkedin_share_button',
26+
field=models.BooleanField(default=False),
27+
),
28+
migrations.AddField(
29+
model_name='petitiontemplate',
30+
name='has_mastodon_share_button',
31+
field=models.BooleanField(default=False),
32+
),
33+
migrations.AddField(
34+
model_name='petitiontemplate',
35+
name='has_tumblr_share_button',
36+
field=models.BooleanField(default=False),
37+
),
38+
migrations.AddField(
39+
model_name='petitiontemplate',
40+
name='has_twitter_share_button',
41+
field=models.BooleanField(default=False),
42+
),
43+
migrations.AddField(
44+
model_name='petitiontemplate',
45+
name='has_whatsapp_share_button',
46+
field=models.BooleanField(default=False),
47+
),
48+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 4.2.7 on 2023-12-08 12:21
2+
3+
from django.db import migrations
4+
5+
6+
def set_new_petition_template_share_fields(apps, schema_editor):
7+
PetitionTemplate = apps.get_model('petition', 'PetitionTemplate')
8+
for pt in PetitionTemplate.objects.all():
9+
if pt.has_share_buttons:
10+
pt.has_email_share_button = True
11+
pt.has_facebook_share_button = True
12+
pt.has_tumblr_share_button = True
13+
pt.has_linkedin_share_button = True
14+
pt.has_twitter_share_button = True
15+
pt.has_mastodon_share_button = True
16+
pt.has_whatsapp_share_button = True
17+
pt.save()
18+
19+
class Migration(migrations.Migration):
20+
21+
dependencies = [
22+
('petition', '0023_petitiontemplate_has_email_share_button_and_more'),
23+
]
24+
25+
operations = [
26+
migrations.RunPython(set_new_petition_template_share_fields)
27+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.7 on 2023-12-09 06:02
2+
3+
import colorfield.fields
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('petition', '0024_auto_20231208_0621'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='petitiontemplate',
16+
name='has_share_buttons',
17+
),
18+
]

pytition/petition/models.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ class Petition(models.Model):
215215
creation_date = models.DateTimeField(blank=True)
216216
last_modification_date = models.DateTimeField(blank=True)
217217
moderated = models.BooleanField(default=False)
218-
has_share_buttons = models.BooleanField(default=True)
218+
has_email_share_button = models.BooleanField(default=False)
219+
has_facebook_share_button = models.BooleanField(default=False)
220+
has_tumblr_share_button = models.BooleanField(default=False)
221+
has_linkedin_share_button = models.BooleanField(default=False)
222+
has_twitter_share_button = models.BooleanField(default=False)
223+
has_mastodon_share_button = models.BooleanField(default=False)
224+
has_whatsapp_share_button = models.BooleanField(default=False)
219225
publication_date = models.DateTimeField(blank=True, null=True)
220226
show_publication_date = models.BooleanField(default=False)
221227

@@ -437,6 +443,11 @@ def moderate(self, do_moderate=True):
437443
self.moderated = do_moderate
438444
self.save()
439445

446+
@property
447+
def has_any_share_button(self):
448+
return (self.has_email_share_button or self.has_facebook_share_button or self.has_tumblr_share_button or self.has_linkedin_share_button
449+
or self.has_twitter_share_button or self.has_mastodon_share_button or self.has_whatsapp_share_button)
450+
440451
# --------------------------------- Signature ---------------------------------
441452
class Signature(models.Model):
442453
first_name = models.CharField(max_length=50, verbose_name=gettext_lazy("First name"))
@@ -540,7 +551,13 @@ class PetitionTemplate(models.Model):
540551
sign_form_footer = models.TextField(blank=True)
541552
confirmation_email_reply = models.EmailField(max_length=100, blank=True)
542553
use_custom_email_settings = models.BooleanField(default=False)
543-
has_share_buttons = models.BooleanField(default=True)
554+
has_email_share_button = models.BooleanField(default=False)
555+
has_facebook_share_button = models.BooleanField(default=False)
556+
has_tumblr_share_button = models.BooleanField(default=False)
557+
has_linkedin_share_button = models.BooleanField(default=False)
558+
has_twitter_share_button = models.BooleanField(default=False)
559+
has_mastodon_share_button = models.BooleanField(default=False)
560+
has_whatsapp_share_button = models.BooleanField(default=False)
544561
paper_signatures_enabled = models.BooleanField(default=False)
545562

546563
def __str__(self):

pytition/petition/templates/petition/edit_petition.html

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,76 @@
9090
{% if petition.org_twitter_handle %}value="{{ petition.org_twitter_handle }}"{% endif %}>
9191
</div>
9292
</div>
93-
<div class="form-group row">
94-
<label for="id_has_share_buttons" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable share buttons?" %}</label>
95-
<div class="col-sm-12 col-md-9 col-lg-10">
96-
<div class="custom-control custom-switch">
97-
<input type="checkbox" name="has_share_buttons" class="is-valid custom-control-input" id="id_has_share_buttons"
98-
{% if petition.has_share_buttons %} checked {% endif %}>
99-
<label class="custom-control-label" for="id_has_share_buttons">{% trans "Enable share buttons?" %}</label>
100-
</div>
101-
</div>
102-
</div>
93+
<div class="form-group row">
94+
<label for="id_has_email_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable email share button?" %}</label>
95+
<div class="col-sm-12 col-md-9 col-lg-10">
96+
<div class="custom-control custom-switch">
97+
<input type="checkbox" name="has_email_share_button" class="is-valid custom-control-input" id="id_has_email_share_button"
98+
{% if petition.has_email_share_button %} checked {% endif %}>
99+
<label class="custom-control-label" for="id_has_email_share_button">{% trans "Enable email share button?" %}</label>
100+
</div>
101+
</div>
102+
</div>
103+
<div class="form-group row">
104+
<label for="id_has_facebook_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable Facebook share button?" %}</label>
105+
<div class="col-sm-12 col-md-9 col-lg-10">
106+
<div class="custom-control custom-switch">
107+
<input type="checkbox" name="has_facebook_share_button" class="is-valid custom-control-input" id="id_has_facebook_share_button"
108+
{% if petition.has_facebook_share_button %} checked {% endif %}>
109+
<label class="custom-control-label" for="id_has_facebook_share_button">{% trans "Enable Facebook share button?" %}</label>
110+
</div>
111+
</div>
112+
</div>
113+
<div class="form-group row">
114+
<label for="id_has_tumblr_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable Tumblr share button?" %}</label>
115+
<div class="col-sm-12 col-md-9 col-lg-10">
116+
<div class="custom-control custom-switch">
117+
<input type="checkbox" name="has_tumblr_share_button" class="is-valid custom-control-input" id="id_has_tumblr_share_button"
118+
{% if petition.has_tumblr_share_button %} checked {% endif %}>
119+
<label class="custom-control-label" for="id_has_tumblr_share_button">{% trans "Enable Tumblr share button?" %}</label>
120+
</div>
121+
</div>
122+
</div>
123+
<div class="form-group row">
124+
<label for="id_has_linkedin_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable LinkedIn share button?" %}</label>
125+
<div class="col-sm-12 col-md-9 col-lg-10">
126+
<div class="custom-control custom-switch">
127+
<input type="checkbox" name="has_linkedin_share_button" class="is-valid custom-control-input" id="id_has_linkedin_share_button"
128+
{% if petition.has_linkedin_share_button %} checked {% endif %}>
129+
<label class="custom-control-label" for="id_has_linkedin_share_button">{% trans "Enable LinkedIn share button?" %}</label>
130+
</div>
131+
</div>
132+
</div>
133+
<div class="form-group row">
134+
<label for="id_has_twitter_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable Twitter share button?" %}</label>
135+
<div class="col-sm-12 col-md-9 col-lg-10">
136+
<div class="custom-control custom-switch">
137+
<input type="checkbox" name="has_twitter_share_button" class="is-valid custom-control-input" id="id_has_twitter_share_button"
138+
{% if petition.has_twitter_share_button %} checked {% endif %}>
139+
<label class="custom-control-label" for="id_has_twitter_share_button">{% trans "Enable Twitter share button?" %}</label>
140+
</div>
141+
</div>
142+
</div>
143+
<div class="form-group row">
144+
<label for="id_has_mastodon_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable Mastodon share button?" %}</label>
145+
<div class="col-sm-12 col-md-9 col-lg-10">
146+
<div class="custom-control custom-switch">
147+
<input type="checkbox" name="has_mastodon_share_button" class="is-valid custom-control-input" id="id_has_mastodon_share_button"
148+
{% if petition.has_mastodon_share_button %} checked {% endif %}>
149+
<label class="custom-control-label" for="id_has_mastodon_share_button">{% trans "Enable Mastodon share button?" %}</label>
150+
</div>
151+
</div>
152+
</div>
153+
<div class="form-group row">
154+
<label for="id_has_whatsapp_share_button" class="col-sm-12 col-md-3 col-lg-2 col-form-label">{% trans "Enable Whatsapp share button?" %}</label>
155+
<div class="col-sm-12 col-md-9 col-lg-10">
156+
<div class="custom-control custom-switch">
157+
<input type="checkbox" name="has_whatsapp_share_button" class="is-valid custom-control-input" id="id_has_whatsapp_share_button"
158+
{% if petition.has_whatsapp_share_button %} checked {% endif %}>
159+
<label class="custom-control-label" for="id_has_whatsapp_share_button">{% trans "Enable Whatsapp share button?" %}</label>
160+
</div>
161+
</div>
162+
</div>
103163
<div class="form-group row">
104164
<div class="input-group">
105165
<input type="checkbox" name="remove_twitter_image" id="remove_twitter_image" hidden>

0 commit comments

Comments
 (0)