-
Notifications
You must be signed in to change notification settings - Fork 0
Add "terms of service" checkbox #35
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,15 @@ class UserProfileForm(forms.ModelForm): | |
|
|
||
| class Meta: | ||
| model = accounts_models.UserProfile | ||
| fields = ('first_name', 'last_name', 'email', 'language') | ||
| fields = ('first_name', 'last_name', 'email', 'language', 'accepted_terms') | ||
| help_texts = { | ||
| 'email': _( | ||
| "Will be used for communication. If you want not to get any emails, leave this field empty." | ||
| ), | ||
| 'accepted_terms': _( | ||
| "[Terms of serivce](http://pylab.lt/terms/). Basically, you accept that all your " | ||
| "creation and work done for Python workshops will belong to Python workshops." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to refer to Wikipedia TOS and additionally tosdr.org badge could be added. Also, intellectual property can't be given to anyone and no content should belong to Python workshops, TOS should tell, that you agree that all created content will be released to public under a CC licence. And for code, terms off LICENSE file in each repository applies. Anyway this is tricky part. |
||
| ), | ||
| } | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
|
|
@@ -26,6 +30,9 @@ def __init__(self, *args, **kwargs): | |
| self.fields['email'].initial = self.instance.user.email | ||
| self.fields['first_name'].initial = self.instance.user.first_name | ||
| self.fields['last_name'].initial = self.instance.user.last_name | ||
| self.fields['accepted_terms'].required = True | ||
| if self.instance.accepted_terms: | ||
| self.fields.pop('accepted_terms') | ||
|
|
||
| def save(self, *args, **kwargs): | ||
| super(UserProfileForm, self).save(*args, **kwargs) | ||
|
|
@@ -41,6 +48,10 @@ class SignupForm(forms.ModelForm): | |
| ) + tuple(settings.LANGUAGES) | ||
|
|
||
| language = forms.ChoiceField(label=_('Language'), required=False, choices=LANGUAGE_CHOICES) | ||
| accepted_terms = forms.BooleanField(label=_('Accept terms of service'), required=True, help_text=_( | ||
| "[Terms of serivce](http://pylab.lt/terms/). Basically, you accept that all your " | ||
| "creation and work done for Python workshops will belong to Python workshops." | ||
| )) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using this in two form, maybe a mixin should be created? |
||
|
|
||
| class Meta: | ||
| model = auth_models.User | ||
|
|
@@ -58,4 +69,5 @@ def signup(self, request, user): # pylint: disable=unused-argument | |
| user.email = self.cleaned_data['email'] | ||
| user.save() | ||
| user.profile.language = self.cleaned_data['language'] | ||
| user.profile.accepted_terms = self.cleaned_data['accepted_terms'] | ||
| user.profile.save() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.db import models, migrations | ||
| from django.conf import settings | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('accounts', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='userprofile', | ||
| name='accepted_terms', | ||
| field=models.BooleanField(default=False, verbose_name='Accept terms of service'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='userprofile', | ||
| name='language', | ||
| field=models.CharField(choices=[('lt', 'Lithuanian'), ('en', 'English')], default='', max_length=7, blank=True, verbose_name='Language'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='userprofile', | ||
| name='user', | ||
| field=models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,4 +27,6 @@ | |
| } | ||
| } | ||
|
|
||
|
|
||
| #id_accepted_terms { | ||
| width: 10%; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
| class SettingsTests(django_webtest.WebTest): | ||
| def setUp(self): | ||
| super().setUp() | ||
| auth_models.User.objects.create_user('u1') | ||
| u1 = auth_models.User.objects.create_user('u1') | ||
| u1.profile.accepted_terms = True | ||
| u1.profile.save() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, you could use factory boy. Factory for user is already defined in |
||
|
|
||
| def test_user_settings(self): | ||
| resp = self.app.get('/accounts/settings/', user='u1') | ||
|
|
@@ -47,3 +49,17 @@ def test_user_profile_locale_middleware(self): | |
| resp = self.app.get('/accounts/settings/', user='u1') | ||
| # Website interface is displayed in lithuanian | ||
| self.assertTrue(b'Saugoti' in resp.content) | ||
|
|
||
| def test_requirement_to_accept_terms_of_service(self): | ||
| auth_models.User.objects.create_user('u2_not_accepted_terms_yet') | ||
| resp = self.app.get('/accounts/settings/', user='u2_not_accepted_terms_yet') | ||
| resp.form['language'] = 'en' | ||
| resp = resp.form.submit() | ||
| # Don't allow to save unless user accepts terms of service | ||
| self.assertEqual(resp.status_int, 200) | ||
| self.assertTrue(b'has-error' in resp.content) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A css or xpath query to a particular field would be much better. Now any field can have
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| resp.form['language'] = 'en' | ||
| resp.form['accepted_terms'].checked = True | ||
| resp = resp.form.submit() | ||
| # Allow to save settings changes because user accepted terms of service | ||
| self.assertEqual(resp.status_int, 302) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
[Terms of serivce](http://pylab.lt/terms/){:target=_blank}to force link to TOS open in new tab instead of replacing current page, possibly loosing filled form values.