mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
Org with admin unit
This commit is contained in:
parent
5361f40855
commit
18c6d653bb
20
app.py
20
app.py
@ -363,6 +363,12 @@ def upsert_event(event_name, host, location_name, start, description, link = Non
|
||||
|
||||
return result
|
||||
|
||||
def get_admin_units_for_organizations():
|
||||
if has_current_user_permission('event:create'):
|
||||
return AdminUnit.query.all()
|
||||
|
||||
return admin_units_the_current_user_is_member_of()
|
||||
|
||||
def get_event_hosts():
|
||||
# User permission, e.g. user is global admin
|
||||
if has_current_user_permission('event:create'):
|
||||
@ -482,6 +488,14 @@ def admin_units_with_current_user_member_permission(permission):
|
||||
|
||||
return result
|
||||
|
||||
def admin_units_the_current_user_is_member_of():
|
||||
result = list()
|
||||
admin_unit_members = AdminUnitMember.query.filter_by(user_id=current_user.id).all()
|
||||
for admin_unit_member in admin_unit_members:
|
||||
result.append(admin_unit_member.adminunit)
|
||||
|
||||
return result
|
||||
|
||||
def organizations_with_current_user_org_member_permission(permission):
|
||||
result = list()
|
||||
org_members = OrgMember.query.filter_by(user_id=current_user.id).all()
|
||||
@ -992,13 +1006,19 @@ def organization_create():
|
||||
abort(401)
|
||||
|
||||
form = CreateOrganizationForm()
|
||||
form.admin_unit_id.choices = sorted([(admin_unit.id, admin_unit.name) for admin_unit in get_admin_units_for_organizations()], key=lambda admin_unit: admin_unit[1])
|
||||
|
||||
if form.validate_on_submit():
|
||||
organization = Organization()
|
||||
organization.location = Location()
|
||||
update_organization_with_form(organization, form)
|
||||
|
||||
admin_unit = AdminUnit.query.get_or_404(form.admin_unit_id.data)
|
||||
add_organization_to_admin_unit(organization, admin_unit)
|
||||
|
||||
try:
|
||||
db.session.add(organization)
|
||||
upsert_org_or_admin_unit_for_organization(organization)
|
||||
db.session.commit()
|
||||
flash(gettext('Organization successfully created'), 'success')
|
||||
return redirect(url_for('organization', organization_id=organization.id))
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from flask_babelex import lazy_gettext
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField, FileAllowed
|
||||
from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField
|
||||
from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField, SelectField
|
||||
from wtforms.validators import DataRequired, Optional
|
||||
import decimal
|
||||
|
||||
@ -13,14 +13,16 @@ class OrganizationLocationForm(FlaskForm):
|
||||
latitude = DecimalField(lazy_gettext('Latitude'), places=16, validators=[Optional()])
|
||||
longitude = DecimalField(lazy_gettext('Longitude'), places=16, validators=[Optional()])
|
||||
|
||||
class CreateOrganizationForm(FlaskForm):
|
||||
submit = SubmitField(lazy_gettext("Create organization"))
|
||||
|
||||
class BaseOrganizationForm(FlaskForm):
|
||||
name = StringField(lazy_gettext('Name'), validators=[DataRequired()])
|
||||
url = StringField(lazy_gettext('Link URL'), validators=[Optional()])
|
||||
logo_file = FileField(lazy_gettext('Logo'), validators=[FileAllowed(['jpg', 'jpeg', 'png'], lazy_gettext('Images only!'))])
|
||||
legal_name = TextAreaField(lazy_gettext('Legal name'), validators=[Optional()])
|
||||
location = FormField(OrganizationLocationForm)
|
||||
|
||||
class UpdateOrganizationForm(CreateOrganizationForm):
|
||||
class CreateOrganizationForm(BaseOrganizationForm):
|
||||
submit = SubmitField(lazy_gettext("Create organization"))
|
||||
admin_unit_id = SelectField(lazy_gettext('Admin unit'), validators=[DataRequired()], coerce=int)
|
||||
|
||||
class UpdateOrganizationForm(BaseOrganizationForm):
|
||||
submit = SubmitField(lazy_gettext("Update organization"))
|
||||
@ -49,6 +49,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
{{ _('Admin unit') }}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ render_field_with_errors(form.admin_unit_id, class="autocomplete w-100") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ render_field(form.submit) }}
|
||||
</form>
|
||||
|
||||
|
||||
Binary file not shown.
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PROJECT VERSION\n"
|
||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
||||
"POT-Creation-Date: 2020-07-04 21:11+0200\n"
|
||||
"POT-Creation-Date: 2020-07-05 17:27+0200\n"
|
||||
"PO-Revision-Date: 2020-06-07 18:51+0200\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language: de\n"
|
||||
@ -94,27 +94,27 @@ msgstr "Sport"
|
||||
msgid "Event_Other"
|
||||
msgstr "Sonstiges"
|
||||
|
||||
#: app.py:1003
|
||||
#: app.py:1023
|
||||
msgid "Organization successfully created"
|
||||
msgstr "Organisation erfolgreich erstellt"
|
||||
|
||||
#: app.py:1023
|
||||
#: app.py:1043
|
||||
msgid "Organization successfully updated"
|
||||
msgstr "Organisation erfolgreich aktualisiert"
|
||||
|
||||
#: app.py:1078
|
||||
#: app.py:1098
|
||||
msgid "Place successfully updated"
|
||||
msgstr "Ort erfolgreich aktualisiert"
|
||||
|
||||
#: app.py:1101
|
||||
#: app.py:1121
|
||||
msgid "Place successfully created"
|
||||
msgstr "Ort erfolgreich erstellt"
|
||||
|
||||
#: app.py:1193
|
||||
#: app.py:1213
|
||||
msgid "Event successfully created"
|
||||
msgstr "Veranstaltung erfolgreich erstellt"
|
||||
|
||||
#: app.py:1225
|
||||
#: app.py:1245
|
||||
msgid "Event suggestion successfully created"
|
||||
msgstr "Veranstaltungsvorschlag erfolgreich erstellt"
|
||||
|
||||
@ -350,6 +350,10 @@ msgstr "Organisation hinzufügen"
|
||||
msgid "Organization"
|
||||
msgstr "Organisation"
|
||||
|
||||
#: templates/organization/create.html:54
|
||||
msgid "Admin unit"
|
||||
msgstr "Verwaltungseinheit"
|
||||
|
||||
#: templates/organization/read.html:12 templates/organization/update.html:10
|
||||
msgid "Update organization"
|
||||
msgstr "Organisation aktualisieren"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user