def v_document_create(): document_id = -1 lang_api = LangApi() languages = lang_api.list() return render_template('admin/document/create.html', languages=languages, document={'id': document_id})
def v_register(): if current_user.is_authenticated: # Force logout logout_user() form = RegistrationForm() a_user = UserApi() a_role = RoleApi() a_lang = LangApi() a_o_type = OrganisationTypeApi() a_org = OrganisationApi() form.language.choices = [(l.id, l.lang) for l in a_lang.list()] form.organisation_type.choices = [(t.id, t.type) for t in a_o_type.list()] if request.method == 'POST' and form.validate_on_submit(): user_data = { 'email': form.email.data, 'password': form.password.data, 'username': form.email.data, 'lang_id': form.language.data } try: public_role = a_role.get_by_role('public') except DatabaseItemDoesNotExist: flash(_('An unexpected error occurred.')) return redirect(url_for('admin.v_register')) user_data['roles'] = [public_role.id] if form.organisation_name: # Add to organisation & create organisation_data = { 'name': form.organisation_name.data, 'size': form.organisation_size.data, 'type_id': form.organisation_type.data } try: new_organisation = a_org.create(organisation_data) except Exception as e: flash(_('An unexpected error occurred.')) logger.exception(str(e)) return redirect(url_for('admin.v_register')) user_data['organisation_id'] = new_organisation.id try: new_user = a_user.create(user_data) except DatabaseItemAlreadyExists: flash(_('This e-mail address is already in use.')) except RequiredAttributeMissing as e: flash( _('A required form element was not submitted: {0}').format(e)) except Exception as e: # Remove this after debugging # flash('An unexpected error occurred: {0}'.format(e)) flash(_('An unexpected error occurred.')) logger.exception(str(e)) return redirect(url_for('admin.v_register')) else: flash( _('You have been successfully registered. Please log in using your username and password.' )) return redirect(url_for('admin.v_login')) return render_template('admin/user/register.html', form=form)
def v_document_edit(document_id): document_api = DocumentApi() try: existing_document = document_api.read(document_id) except DatabaseItemDoesNotExist as e: flash(_('No document with id {0}').format(document_id)) return redirect(url_for('admin.v_document_list')) except Exception as e: flash(_('An unexpected error occurred: {0}').format(e)) # flash('An unexpected error occurred.') return redirect(url_for('admin.v_document_list')) lang_api = LangApi() languages = lang_api.list() return render_template('admin/document/create.html', languages=languages, document=existing_document)