Skip to content

Commit

Permalink
blacken codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Datamance committed Jan 17, 2019
1 parent b25e33c commit c6ead64
Show file tree
Hide file tree
Showing 165 changed files with 6,481 additions and 3,748 deletions.
2 changes: 1 addition & 1 deletion accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'accounts.apps.AccountsConfig'
default_app_config = "accounts.apps.AccountsConfig"
24 changes: 17 additions & 7 deletions accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@


class ChildAdmin(GuardedModelAdmin):
list_display = ('id', 'uuid', 'given_name', 'birthday', 'user')
list_filter = ('id', 'uuid',)
list_display = ("id", "uuid", "given_name", "birthday", "user")
list_filter = ("id", "uuid")


class UserAdmin(GuardedModelAdmin):
list_display = ('id', 'uuid', 'nickname', 'given_name', 'family_name', 'is_researcher', 'date_created', 'last_login')
list_filter = ('id', 'uuid',)
exclude = ('is_superuser', 'is_staff')
list_display = (
"id",
"uuid",
"nickname",
"given_name",
"family_name",
"is_researcher",
"date_created",
"last_login",
)
list_filter = ("id", "uuid")
exclude = ("is_superuser", "is_staff")


class OrganizationAdmin(GuardedModelAdmin):
pass


class DemographicDataAdmin(GuardedModelAdmin):
list_display = ('id', 'uuid', 'created_at', 'user')
list_filter = ('id', 'uuid',)
list_display = ("id", "uuid", "created_at", "user")
list_filter = ("id", "uuid")


admin.site.register(User, UserAdmin)
admin.site.register(Organization, OrganizationAdmin)
Expand Down
10 changes: 6 additions & 4 deletions accounts/apps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate

from accounts.signals import (post_migrate_create_organization,
post_migrate_create_social_app,
post_migrate_create_flatpages)
from accounts.signals import (
post_migrate_create_organization,
post_migrate_create_social_app,
post_migrate_create_flatpages,
)


class AccountsConfig(AppConfig):
name = 'accounts'
name = "accounts"

def ready(self):
post_migrate.connect(post_migrate_create_organization, sender=self)
Expand Down
208 changes: 130 additions & 78 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import datetime
from django import forms
from django.contrib.auth.forms import UserCreationForm, PasswordChangeForm, UserChangeForm
from django.contrib.auth.forms import (
UserCreationForm,
PasswordChangeForm,
UserChangeForm,
)
from django.forms.widgets import DateInput
from django.core.exceptions import ValidationError

Expand All @@ -12,36 +16,40 @@
class UserForm(forms.ModelForm):
class Meta:
model = User
exclude = ('password', )
exclude = ("password",)


class UserStudiesForm(forms.Form):
template = 'accounts/researcher_form.html'
user = forms.ModelChoiceField(User.objects.all(), required=True, label='Researcher')
template = "accounts/researcher_form.html"
user = forms.ModelChoiceField(User.objects.all(), required=True, label="Researcher")
studies = forms.ModelMultipleChoiceField(
Study.objects.all(), required=True, label='Assigned Studies')
Study.objects.all(), required=True, label="Assigned Studies"
)

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('instance')
self.user = kwargs.pop("instance")
super(UserStudiesForm, self).__init__(*args, **kwargs)

def is_valid(self):
valid = super(UserStudiesForm, self).is_valid()
if valid and len(self.data['studies']) > 0:
if valid and len(self.data["studies"]) > 0:
return True

def save(self):
permissions = ['studies.can_view_study', 'studies.can_edit_study']
current_permitted_objects = get_objects_for_user(self.cleaned_data['user'], permissions)
permissions = ["studies.can_view_study", "studies.can_edit_study"]
current_permitted_objects = get_objects_for_user(
self.cleaned_data["user"], permissions
)
disallowed_studies = current_permitted_objects.exclude(
id__in=[x.id for x in self.cleaned_data['studies']])
id__in=[x.id for x in self.cleaned_data["studies"]]
)

for perm in permissions:
for study in self.cleaned_data['studies']:
assign_perm(perm, self.cleaned_data['user'], study)
for study in self.cleaned_data["studies"]:
assign_perm(perm, self.cleaned_data["user"], study)
for study in disallowed_studies:
remove_perm(perm, self.cleaned_data['user'], study)
return self.cleaned_data['user']
remove_perm(perm, self.cleaned_data["user"], study)
return self.cleaned_data["user"]


class ParticipantSignupForm(UserCreationForm):
Expand All @@ -57,34 +65,41 @@ def save(self, commit=True):

class Meta:
model = User
fields = ('username', 'nickname')
exclude = ('user_permissions', 'groups', '_identicon', 'organization',
'is_active', 'is_staff', 'is_superuser', 'last_login',
'middle_name', 'last_name')
fields = ("username", "nickname")
exclude = (
"user_permissions",
"groups",
"_identicon",
"organization",
"is_active",
"is_staff",
"is_superuser",
"last_login",
"middle_name",
"last_name",
)


class ParticipantUpdateForm(forms.ModelForm):
nickname = forms.CharField(required=True, max_length=255)

def __init__(self, *args, **kwargs):
if 'user' in kwargs:
kwargs.pop('user')
if "user" in kwargs:
kwargs.pop("user")
super().__init__(*args, **kwargs)
instance = getattr(self, 'instance', None)
self.fields['username'].widget.attrs.pop("autofocus", None)
instance = getattr(self, "instance", None)
self.fields["username"].widget.attrs.pop("autofocus", None)

class Meta:
model = User
fields = ('username', 'nickname')
labels = {
'username': 'Email address'
}
fields = ("username", "nickname")
labels = {"username": "Email address"}


class ParticipantPasswordForm(PasswordChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['old_password'].widget.attrs.pop("autofocus", None)
self.fields["old_password"].widget.attrs.pop("autofocus", None)

class Meta:
model = User
Expand All @@ -93,102 +108,139 @@ class Meta:
class EmailPreferencesForm(forms.ModelForm):
class Meta:
model = User
fields = ('email_next_session', 'email_new_studies', 'email_study_updates', 'email_response_questions')
fields = (
"email_next_session",
"email_new_studies",
"email_study_updates",
"email_response_questions",
)
labels = {
'email_next_session': "It's time for another session of a study we are currently participating in",
'email_new_studies': "A new study is available for one of my children",
'email_study_updates': "There's an update about a study we participated in (for example, results are published)",
'email_response_questions': "A researcher has questions about my individual responses (for example, if I report a technical problem during the study)"
"email_next_session": "It's time for another session of a study we are currently participating in",
"email_new_studies": "A new study is available for one of my children",
"email_study_updates": "There's an update about a study we participated in (for example, results are published)",
"email_response_questions": "A researcher has questions about my individual responses (for example, if I report a technical problem during the study)",
}


class DemographicDataForm(forms.ModelForm):
race_identification = forms.MultipleChoiceField(
choices = DemographicData.RACE_CHOICES,
choices=DemographicData.RACE_CHOICES,
widget=forms.CheckboxSelectMultiple(),
label="What category(ies) does your family identify as?",
required=False
required=False,
)

class Meta:
model = DemographicData
exclude = ('created_at', 'previous', 'user', 'extra', 'uuid' )
fields = ('country', 'state', 'density', 'languages_spoken_at_home', 'number_of_children', 'child_birthdays', 'number_of_guardians',
'number_of_guardians_explanation', 'race_identification', 'age', 'gender', 'education_level', 'spouse_education_level', 'annual_income',
'number_of_books', 'lookit_referrer', 'additional_comments')
exclude = ("created_at", "previous", "user", "extra", "uuid")
fields = (
"country",
"state",
"density",
"languages_spoken_at_home",
"number_of_children",
"child_birthdays",
"number_of_guardians",
"number_of_guardians_explanation",
"race_identification",
"age",
"gender",
"education_level",
"spouse_education_level",
"annual_income",
"number_of_books",
"lookit_referrer",
"additional_comments",
)

help_texts = {
'child_birthdays': 'Enter as a comma-separated list: YYYY-MM-DD, YYYY-MM-DD, ...'
"child_birthdays": "Enter as a comma-separated list: YYYY-MM-DD, YYYY-MM-DD, ..."
}

labels = {
'country': 'What country do you live in?',
'state': 'What state do you live in?',
'density': 'How would you describe the area where you live?',
'languages_spoken_at_home': 'What language(s) does your family speak at home?',
'number_of_children': 'How many children do you have?',
'child_birthdays': 'For each child, please enter his or her birthdate:',
'number_of_guardians': 'How many parents/guardians do your children live with?',
'race_identification': 'What category(ies) does your family identify as?',
'age': "What is your age?",
'gender': "What is your gender?",
'education_level': "What is the highest level of education you've completed?",
'spouse_education_level': 'What is the highest level of education your spouse has completed?',
'annual_income': 'What is your approximate family yearly income (in US dollars)?',
'number_of_books': "About how many children's books are there in your home?",
'additional_comments': "Anything else you'd like us to know?",
'lookit_referrer': 'How did you hear about Lookit?',
'number_of_guardians_explanation': 'If the answer varies due to shared custody arrangements or travel, please enter the number of parents/guardians your children are usually living with or explain.',
"country": "What country do you live in?",
"state": "What state do you live in?",
"density": "How would you describe the area where you live?",
"languages_spoken_at_home": "What language(s) does your family speak at home?",
"number_of_children": "How many children do you have?",
"child_birthdays": "For each child, please enter his or her birthdate:",
"number_of_guardians": "How many parents/guardians do your children live with?",
"race_identification": "What category(ies) does your family identify as?",
"age": "What is your age?",
"gender": "What is your gender?",
"education_level": "What is the highest level of education you've completed?",
"spouse_education_level": "What is the highest level of education your spouse has completed?",
"annual_income": "What is your approximate family yearly income (in US dollars)?",
"number_of_books": "About how many children's books are there in your home?",
"additional_comments": "Anything else you'd like us to know?",
"lookit_referrer": "How did you hear about Lookit?",
"number_of_guardians_explanation": "If the answer varies due to shared custody arrangements or travel, please enter the number of parents/guardians your children are usually living with or explain.",
}

widgets = {
'languages_spoken_at_home': forms.Textarea(attrs={'rows': 1}),
'additional_comments': forms.Textarea(attrs={'rows':2}),
'number_of_guardians_explanation': forms.Textarea(attrs={'rows':2}),
'lookit_referrer': forms.Textarea(attrs={'rows':2})
"languages_spoken_at_home": forms.Textarea(attrs={"rows": 1}),
"additional_comments": forms.Textarea(attrs={"rows": 2}),
"number_of_guardians_explanation": forms.Textarea(attrs={"rows": 2}),
"lookit_referrer": forms.Textarea(attrs={"rows": 2}),
}


class ChildForm(forms.ModelForm):
birthday = forms.DateField(widget=forms.DateInput(attrs={'class': 'datepicker'}), help_text="This lets us figure out exactly how old your child is when they participate in a study. We never publish children\'s birthdates or information that would allow a reader to calculate the birthdate.")
birthday = forms.DateField(
widget=forms.DateInput(attrs={"class": "datepicker"}),
help_text="This lets us figure out exactly how old your child is when they participate in a study. We never publish children's birthdates or information that would allow a reader to calculate the birthdate.",
)

def clean_birthday(self):
date = self.cleaned_data['birthday']
date = self.cleaned_data["birthday"]
if date > datetime.date.today():
raise ValidationError("Birthdays cannot be in the future.")
raise ValidationError("Birthdays cannot be in the future.")
return date

class Meta:
model = Child
fields = ('given_name', 'birthday', 'gender', 'age_at_birth', 'additional_information')
fields = (
"given_name",
"birthday",
"gender",
"age_at_birth",
"additional_information",
)

labels = {
'given_name': 'First Name',
'birthday': "Birthday",
'age_at_birth': 'Gestational Age at Birth',
'additional_information': "Any additional information you'd like us to know"
"given_name": "First Name",
"birthday": "Birthday",
"age_at_birth": "Gestational Age at Birth",
"additional_information": "Any additional information you'd like us to know",
}

help_texts = {
'given_name': 'This lets you select the correct child to participate in a particular study. A nickname or initials are fine! We may include your child\'s name in email to you (for instance, "There\'s a new study available for Molly!") but will never publish names or use them in our research.',
'additional_information': "for instance, diagnosed developmental disorders or vision or hearing problems"
"given_name": "This lets you select the correct child to participate in a particular study. A nickname or initials are fine! We may include your child's name in email to you (for instance, \"There's a new study available for Molly!\") but will never publish names or use them in our research.",
"additional_information": "for instance, diagnosed developmental disorders or vision or hearing problems",
}


class ChildUpdateForm(forms.ModelForm):
birthday = forms.DateField(disabled=True, help_text='YYYY-MM-DD')
birthday = forms.DateField(disabled=True, help_text="YYYY-MM-DD")

class Meta:
model = Child
fields = ('given_name', 'birthday', 'gender', 'age_at_birth', 'additional_information')
fields = (
"given_name",
"birthday",
"gender",
"age_at_birth",
"additional_information",
)

labels = {
'given_name': 'First Name',
'birthday': "Birthday",
'age_at_birth': 'Gestational Age at Birth',
'additional_information': "Any additional information you'd like us to know"
"given_name": "First Name",
"birthday": "Birthday",
"age_at_birth": "Gestational Age at Birth",
"additional_information": "Any additional information you'd like us to know",
}

help_texts = {
'given_name': 'This lets you select the correct child to participate in a particular study. A nickname or initials are fine! We may include your child\'s name in email to you (for instance, "There\'s a new study available for Molly!") but will never publish names or use them in our research.',
'additional_information': "for instance, diagnosed developmental disorders or vision or hearing problems",
"given_name": "This lets you select the correct child to participate in a particular study. A nickname or initials are fine! We may include your child's name in email to you (for instance, \"There's a new study available for Molly!\") but will never publish names or use them in our research.",
"additional_information": "for instance, diagnosed developmental disorders or vision or hearing problems",
}
Loading

0 comments on commit c6ead64

Please sign in to comment.