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

Add pre-commit (black, flake8) #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Migrate code style to Black
# https://github.com/ome/omero-signup/pull/14
02d69a02c902b64a40663dd4b030f0469dbca2e4
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
args: [--target-version=py36]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args: [
# default black line length is 88
--max-line-length=88,
# Conflicts with black: E203 whitespace before ':'
--extend-ignore=E203,
]
2 changes: 1 addition & 1 deletion omero_signup/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'omero_signup.apps.WebSignupAppConfig'
default_app_config = "omero_signup.apps.WebSignupAppConfig"
27 changes: 14 additions & 13 deletions omero_signup/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,39 @@
def _string_not_white_space(value):
value = value.strip()
if not value:
raise forms.ValidationError('Field must not be empty')
raise forms.ValidationError("Field must not be empty")
wordchars = [c for c in value if c.isalpha()]
if not wordchars:
raise forms.ValidationError(
'At least one alphabetical character required')
raise forms.ValidationError("At least one alphabetical character required")
return value


#################################################################
# Non-model Form


class SignupForm(forms.Form):

firstname = forms.CharField(
max_length=50, widget=forms.TextInput(attrs={
'size': 22, 'autofocus': 'autofocus'}))
max_length=50,
widget=forms.TextInput(attrs={"size": 22, "autofocus": "autofocus"}),
)

lastname = forms.CharField(
max_length=50, widget=forms.TextInput(attrs={'size': 22}))
max_length=50, widget=forms.TextInput(attrs={"size": 22})
)

institution = forms.CharField(
max_length=100, widget=forms.TextInput(attrs={'size': 22}))
max_length=100, widget=forms.TextInput(attrs={"size": 22})
)

email = forms.EmailField(
max_length=100, widget=forms.TextInput(attrs={
'size': 22}))
email = forms.EmailField(max_length=100, widget=forms.TextInput(attrs={"size": 22}))

def clean_firstname(self):
return _string_not_white_space(self.cleaned_data['firstname'])
return _string_not_white_space(self.cleaned_data["firstname"])

def clean_lastname(self):
return _string_not_white_space(self.cleaned_data['lastname'])
return _string_not_white_space(self.cleaned_data["lastname"])

def clean_institution(self):
return _string_not_white_space(self.cleaned_data['institution'])
return _string_not_white_space(self.cleaned_data["institution"])
70 changes: 45 additions & 25 deletions omero_signup/signup_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,57 @@
def str_not_empty(o):
s = str(o)
if not o or not s:
raise ValueError('Invalid empty value')
raise ValueError("Invalid empty value")
return s


# load settings
SIGNUP_SETTINGS_MAPPING = {
'omero.web.signup.admin.user':
['SIGNUP_ADMIN_USERNAME', '', str_not_empty, None],
'omero.web.signup.admin.password':
['SIGNUP_ADMIN_PASSWORD', '', str_not_empty, None],
'omero.web.signup.group.name':
['SIGNUP_GROUP_NAME', '', str_not_empty, None],
'omero.web.signup.group.templatetime':
['SIGNUP_GROUP_NAME_TEMPLATETIME', "false", parse_boolean, None],
'omero.web.signup.group.perms':
['SIGNUP_GROUP_PERMS', 'rw----', str_not_empty, None],
'omero.web.signup.email.enabled':
['SIGNUP_EMAIL_ENABLED', "false", parse_boolean, None],
'omero.web.signup.email.subject':
['SIGNUP_EMAIL_SUBJECT', 'Your OMERO server login details',
str_not_empty, None],
'omero.web.signup.email.body':
['SIGNUP_EMAIL_BODY', (
'Your login details for OMERO server are:\n\n'
'username: {username}\n'
'password: {password}\n'
), str_not_empty, None],
'omero.web.signup.helpmessage':
['SIGNUP_HELP_MESSAGE', '', str, None],
"omero.web.signup.admin.user": ["SIGNUP_ADMIN_USERNAME", "", str_not_empty, None],
"omero.web.signup.admin.password": [
"SIGNUP_ADMIN_PASSWORD",
"",
str_not_empty,
None,
],
"omero.web.signup.group.name": ["SIGNUP_GROUP_NAME", "", str_not_empty, None],
"omero.web.signup.group.templatetime": [
"SIGNUP_GROUP_NAME_TEMPLATETIME",
"false",
parse_boolean,
None,
],
"omero.web.signup.group.perms": [
"SIGNUP_GROUP_PERMS",
"rw----",
str_not_empty,
None,
],
"omero.web.signup.email.enabled": [
"SIGNUP_EMAIL_ENABLED",
"false",
parse_boolean,
None,
],
"omero.web.signup.email.subject": [
"SIGNUP_EMAIL_SUBJECT",
"Your OMERO server login details",
str_not_empty,
None,
],
"omero.web.signup.email.body": [
"SIGNUP_EMAIL_BODY",
(
"Your login details for OMERO server are:\n\n"
"username: {username}\n"
"password: {password}\n"
),
str_not_empty,
None,
],
"omero.web.signup.helpmessage": ["SIGNUP_HELP_MESSAGE", "", str, None],
}


process_custom_settings(sys.modules[__name__], 'SIGNUP_SETTINGS_MAPPING')
process_custom_settings(sys.modules[__name__], "SIGNUP_SETTINGS_MAPPING")
report_settings(sys.modules[__name__])
3 changes: 1 addition & 2 deletions omero_signup/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


urlpatterns = [

# index 'home page' of the websignup app
url(r'^$', views.WebSignupView.as_view(), name="signup_index"),
url(r"^$", views.WebSignupView.as_view(), name="signup_index"),
]
Loading