Conditions | 8 |
Total Lines | 110 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | """ |
||
87 | @blueprint.route('/', methods=['POST']) |
||
88 | def create(): |
||
89 | """Create a user.""" |
||
90 | _abort_if_user_account_creation_disabled() |
||
91 | |||
92 | terms_document_id = terms_document_service.find_document_id_for_brand( |
||
93 | g.brand_id |
||
94 | ) |
||
95 | |||
96 | privacy_policy_consent_subject_id = ( |
||
97 | _find_privacy_policy_consent_subject_id() |
||
98 | ) |
||
99 | |||
100 | newsletter_list_id = _find_newsletter_list_for_brand() |
||
101 | |||
102 | real_name_required = _is_real_name_required() |
||
103 | terms_consent_required = terms_document_id is not None |
||
104 | privacy_policy_consent_required = ( |
||
105 | privacy_policy_consent_subject_id is not None |
||
106 | ) |
||
107 | newsletter_offered = newsletter_list_id is not None |
||
108 | |||
109 | form = UserCreateForm(request.form) |
||
110 | |||
111 | _adjust_create_form( |
||
112 | form, |
||
113 | real_name_required, |
||
114 | terms_consent_required, |
||
115 | privacy_policy_consent_required, |
||
116 | newsletter_offered, |
||
117 | ) |
||
118 | |||
119 | if not form.validate(): |
||
120 | return create_form(form) |
||
121 | |||
122 | screen_name = form.screen_name.data.strip() |
||
123 | email_address = form.email_address.data.strip().lower() |
||
124 | password = form.password.data |
||
125 | |||
126 | now_utc = datetime.utcnow() |
||
127 | |||
128 | if user_service.is_screen_name_already_assigned(screen_name): |
||
129 | flash_error( |
||
130 | 'Dieser Benutzername ist bereits einem Benutzerkonto zugeordnet.' |
||
131 | ) |
||
132 | return create_form(form) |
||
133 | |||
134 | if user_service.is_email_address_already_assigned(email_address): |
||
135 | flash_error( |
||
136 | 'Diese E-Mail-Adresse ist bereits einem Benutzerkonto zugeordnet.' |
||
137 | ) |
||
138 | return create_form(form) |
||
139 | |||
140 | if real_name_required: |
||
141 | first_names = form.first_names.data.strip() |
||
142 | last_name = form.last_name.data.strip() |
||
143 | else: |
||
144 | first_names = None |
||
145 | last_name = None |
||
146 | |||
147 | terms_consent = None |
||
148 | if terms_consent_required: |
||
149 | terms_version_id = form.terms_version_id.data |
||
150 | consent_to_terms = form.consent_to_terms.data |
||
151 | |||
152 | terms_version = terms_version_service.find_version(terms_version_id) |
||
153 | if terms_version.document_id != terms_document_id: |
||
154 | abort(400, 'Die AGB-Version gehört nicht zu dieser Veranstaltung.') |
||
155 | |||
156 | terms_consent = _assemble_privacy_policy_consent( |
||
157 | terms_version.consent_subject_id, now_utc |
||
158 | ) |
||
159 | |||
160 | privacy_policy_consent = _get_privacy_policy_consent( |
||
161 | privacy_policy_consent_required, |
||
162 | privacy_policy_consent_subject_id, |
||
163 | now_utc, |
||
164 | ) |
||
165 | |||
166 | newsletter_subscription = _get_newsletter_subscription( |
||
167 | newsletter_offered, form, newsletter_list_id, now_utc |
||
168 | ) |
||
169 | |||
170 | try: |
||
171 | user, event = user_creation_service.create_user( |
||
172 | screen_name, |
||
173 | email_address, |
||
174 | password, |
||
175 | first_names, |
||
176 | last_name, |
||
177 | g.site_id, |
||
178 | terms_consent=terms_consent, |
||
179 | privacy_policy_consent=privacy_policy_consent, |
||
180 | newsletter_subscription=newsletter_subscription, |
||
181 | ) |
||
182 | except user_creation_service.UserCreationFailed: |
||
183 | flash_error( |
||
184 | f'Das Benutzerkonto für "{screen_name}" konnte nicht angelegt werden.' |
||
185 | ) |
||
186 | return create_form(form) |
||
187 | |||
188 | flash_success( |
||
189 | f'Das Benutzerkonto für "{user.screen_name}" wurde angelegt. ' |
||
190 | 'Bevor du dich damit anmelden kannst, muss zunächst der Link in ' |
||
191 | 'der an die angegebene Adresse verschickten E-Mail besucht werden.' |
||
192 | ) |
||
193 | |||
194 | signals.account_created.send(None, event=event) |
||
195 | |||
196 | return redirect_to('authentication.login_form') |
||
197 | |||
331 |