diff --git a/migrations/versions/b1a6e7630185_.py b/migrations/versions/b1a6e7630185_.py
new file mode 100644
index 0000000..2c136f8
--- /dev/null
+++ b/migrations/versions/b1a6e7630185_.py
@@ -0,0 +1,33 @@
+"""empty message
+
+Revision ID: b1a6e7630185
+Revises: 35a6577b6af8
+Create Date: 2021-01-25 11:38:36.483434
+
+"""
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+from project import dbtypes
+
+
+# revision identifiers, used by Alembic.
+revision = "b1a6e7630185"
+down_revision = "35a6577b6af8"
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column(
+ "adminunit",
+ sa.Column("incoming_reference_requests_allowed", sa.Boolean(), nullable=True),
+ )
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column("adminunit", "incoming_reference_requests_allowed")
+ # ### end Alembic commands ###
diff --git a/project/access.py b/project/access.py
index 9baa8f1..6835864 100644
--- a/project/access.py
+++ b/project/access.py
@@ -4,6 +4,7 @@ from flask_security.utils import FsPermNeed
from flask_principal import Permission
from project.models import AdminUnitMember, AdminUnit
from project.services.admin_unit import get_member_for_admin_unit_by_user_id
+from sqlalchemy import and_
def has_current_user_permission(permission):
@@ -101,7 +102,12 @@ def can_request_event_reference(event):
def get_admin_units_for_event_reference_request(event):
- return AdminUnit.query.filter(AdminUnit.id != event.admin_unit_id).all()
+ return AdminUnit.query.filter(
+ and_(
+ AdminUnit.id != event.admin_unit_id,
+ AdminUnit.incoming_reference_requests_allowed,
+ )
+ ).all()
def admin_units_the_current_user_is_member_of():
diff --git a/project/forms/admin.py b/project/forms/admin.py
index 931ec2d..bef93ad 100644
--- a/project/forms/admin.py
+++ b/project/forms/admin.py
@@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
from flask_babelex import lazy_gettext
-from wtforms import TextAreaField, SubmitField
+from wtforms import TextAreaField, SubmitField, BooleanField
from wtforms.validators import Optional
from project.forms.widgets import MultiCheckboxField
@@ -17,3 +17,14 @@ class AdminSettingsForm(FlaskForm):
class UpdateUserForm(FlaskForm):
roles = MultiCheckboxField(lazy_gettext("Roles"))
submit = SubmitField(lazy_gettext("Update user"))
+
+
+class UpdateAdminUnitForm(FlaskForm):
+ incoming_reference_requests_allowed = BooleanField(
+ lazy_gettext("Incoming reference requests allowed"),
+ description=lazy_gettext(
+ "If set, other admin units can ask this admin unit to reference their event."
+ ),
+ validators=[Optional()],
+ )
+ submit = SubmitField(lazy_gettext("Update admin unit"))
diff --git a/project/models.py b/project/models.py
index 9a5660d..e6692f9 100644
--- a/project/models.py
+++ b/project/models.py
@@ -210,6 +210,7 @@ class AdminUnit(db.Model, TrackableMixin):
widget_background_color = Column(ColorType)
widget_primary_color = Column(ColorType)
widget_link_color = Column(ColorType)
+ incoming_reference_requests_allowed = Column(Boolean())
@listens_for(AdminUnit, "before_insert")
diff --git a/project/templates/admin/admin_units.html b/project/templates/admin/admin_units.html
index 41436fe..04a7370 100644
--- a/project/templates/admin/admin_units.html
+++ b/project/templates/admin/admin_units.html
@@ -1,4 +1,5 @@
{% extends "layout.html" %}
+{% from "_macros.html" import render_pagination %}
{% block title %}
{{ _('Admin Units') }}
{% endblock %}
@@ -16,16 +17,20 @@
| {{ _('Name') }} |
+ |
{% for admin_unit in admin_units %}
| {{ admin_unit.name }} |
+ {{ _('Edit') }} |
{% endfor %}
+{{ render_pagination(pagination) }}
+
{% endblock %}
\ No newline at end of file
diff --git a/project/templates/admin/update_admin_unit.html b/project/templates/admin/update_admin_unit.html
new file mode 100644
index 0000000..07b8730
--- /dev/null
+++ b/project/templates/admin/update_admin_unit.html
@@ -0,0 +1,25 @@
+{% extends "layout.html" %}
+{% from "_macros.html" import render_field_with_errors, render_field %}
+{% block title %}
+{{ _('Update admin unit') }}
+{% endblock %}
+{% block content %}
+
+{{ _('Update admin unit') }}
+
+
+
+{% endblock %}
diff --git a/project/translations/de/LC_MESSAGES/messages.mo b/project/translations/de/LC_MESSAGES/messages.mo
index 77be93a..ee99997 100644
Binary files a/project/translations/de/LC_MESSAGES/messages.mo and b/project/translations/de/LC_MESSAGES/messages.mo differ
diff --git a/project/translations/de/LC_MESSAGES/messages.po b/project/translations/de/LC_MESSAGES/messages.po
index 298f193..dfe7864 100644
--- a/project/translations/de/LC_MESSAGES/messages.po
+++ b/project/translations/de/LC_MESSAGES/messages.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2021-01-25 10:17+0100\n"
+"POT-Creation-Date: 2021-01-25 11:56+0100\n"
"PO-Revision-Date: 2020-06-07 18:51+0200\n"
"Last-Translator: FULL NAME \n"
"Language: de\n"
@@ -158,6 +158,21 @@ msgstr "Rollen"
msgid "Update user"
msgstr "Nutzer aktualisieren"
+#: project/forms/admin.py:24
+msgid "Incoming reference requests allowed"
+msgstr "Eingehende Empfehlungsanfragen erlauben"
+
+#: project/forms/admin.py:25
+msgid ""
+"If set, other admin units can ask this admin unit to reference their "
+"event."
+msgstr "Wenn gesetzt, können andere Organisationen diese Organisation bitten, deren Veranstaltungen zu empfehlen."
+
+#: project/forms/admin.py:30 project/templates/admin/update_admin_unit.html:4
+#: project/templates/admin/update_admin_unit.html:8
+msgid "Update admin unit"
+msgstr "Organisation aktualisieren"
+
#: project/forms/admin_unit.py:17 project/forms/event.py:32
#: project/forms/event_place.py:17 project/forms/organizer.py:16
msgid "Street"
@@ -194,7 +209,7 @@ msgstr "Längengrad"
#: project/forms/event_suggestion.py:25 project/forms/organizer.py:29
#: project/forms/organizer.py:56 project/forms/reference.py:39
#: project/forms/reference_request.py:21 project/templates/_macros.html:115
-#: project/templates/admin/admin_units.html:18
+#: project/templates/admin/admin_units.html:19
#: project/templates/event_place/list.html:19 project/templates/profile.html:19
#: project/templates/profile.html:39
msgid "Name"
@@ -1099,7 +1114,7 @@ msgid "Profile"
msgstr "Profil"
#: project/templates/admin/admin.html:3 project/templates/admin/admin.html:9
-#: project/templates/admin/admin_units.html:9
+#: project/templates/admin/admin_units.html:10
#: project/templates/admin/users.html:10 project/templates/layout.html:130
msgid "Admin"
msgstr "Administration"
@@ -1182,8 +1197,8 @@ msgid "Invitations"
msgstr "Einladungen"
#: project/templates/admin/admin.html:19
-#: project/templates/admin/admin_units.html:3
-#: project/templates/admin/admin_units.html:10
+#: project/templates/admin/admin_units.html:4
+#: project/templates/admin/admin_units.html:11
#: project/templates/manage/admin_units.html:3
#: project/templates/manage/admin_units.html:16
#: project/templates/profile.html:34
@@ -1195,6 +1210,7 @@ msgstr "Organisationen"
msgid "Users"
msgstr "Benutzer"
+#: project/templates/admin/admin_units.html:27
#: project/templates/admin/users.html:27
#: project/templates/manage/events.html:27
#: project/templates/manage/members.html:35
@@ -1485,11 +1501,16 @@ msgstr "Optionale Details"
msgid "Preview"
msgstr "Vorschau"
-#: project/views/admin.py:41 project/views/manage.py:247
+#: project/views/admin.py:45
+#, fuzzy
+msgid "Admin unit successfully updated"
+msgstr "Organisation erfolgreich aktualisiert"
+
+#: project/views/admin.py:68 project/views/manage.py:247
msgid "Settings successfully updated"
msgstr "Einstellungen erfolgreich aktualisiert"
-#: project/views/admin.py:76
+#: project/views/admin.py:103
msgid "User successfully updated"
msgstr "Nutzer erfolgreich aktualisiert"
@@ -1638,14 +1659,16 @@ msgstr "Empfehlungsanfrage erfolgreich aktualisiert"
msgid ""
"An entry with the entered values already exists. Duplicate entries are "
"not allowed."
-msgstr "Ein Eintrag mit den eingegebenen Werten existiert bereits. Doppelte Einträge sind nicht erlaubt."
+msgstr ""
+"Ein Eintrag mit den eingegebenen Werten existiert bereits. Doppelte "
+"Einträge sind nicht erlaubt."
-#: project/views/utils.py:61
+#: project/views/utils.py:63
#, python-format
msgid "Error in the %s field - %s"
msgstr "Fehler im Feld %s: %s"
-#: project/views/utils.py:69
+#: project/views/utils.py:71
msgid "Show"
msgstr "Anzeigen"
diff --git a/project/views/admin.py b/project/views/admin.py
index ff787b0..76f2ed3 100644
--- a/project/views/admin.py
+++ b/project/views/admin.py
@@ -3,7 +3,7 @@ from project.models import AdminUnit, User, Role
from flask import render_template, flash, url_for, redirect
from flask_babelex import gettext
from flask_security import roles_required
-from project.forms.admin import AdminSettingsForm, UpdateUserForm
+from project.forms.admin import AdminSettingsForm, UpdateUserForm, UpdateAdminUnitForm
from project.services.admin import upsert_settings
from project.services.user import set_roles_for_user
from project.views.utils import (
@@ -24,7 +24,37 @@ def admin():
@app.route("/admin/admin_units")
@roles_required("admin")
def admin_admin_units():
- return render_template("admin/admin_units.html", admin_units=AdminUnit.query.all())
+ admin_units = AdminUnit.query.order_by(func.lower(AdminUnit.name)).paginate()
+ return render_template(
+ "admin/admin_units.html",
+ admin_units=admin_units.items,
+ pagination=get_pagination_urls(admin_units),
+ )
+
+
+@app.route("/admin/admin_unit//update", methods=("GET", "POST"))
+@roles_required("admin")
+def admin_admin_unit_update(id):
+ admin_unit = AdminUnit.query.get_or_404(id)
+
+ form = UpdateAdminUnitForm(obj=admin_unit)
+
+ if form.validate_on_submit():
+ form.populate_obj(admin_unit)
+
+ try:
+ db.session.commit()
+ flash(gettext("Admin unit successfully updated"), "success")
+ return redirect(url_for("admin_admin_units"))
+ except SQLAlchemyError as e:
+ db.session.rollback()
+ flash(handleSqlError(e), "danger")
+ else:
+ flash_errors(form)
+
+ return render_template(
+ "admin/update_admin_unit.html", admin_unit=admin_unit, form=form
+ )
@app.route("/admin/settings", methods=("GET", "POST"))
diff --git a/tests/seeder.py b/tests/seeder.py
index 1702bc9..080b73b 100644
--- a/tests/seeder.py
+++ b/tests/seeder.py
@@ -50,6 +50,7 @@ class Seeder(object):
admin_unit = AdminUnit()
admin_unit.name = name
admin_unit.short_name = name.lower().replace(" ", "")
+ admin_unit.incoming_reference_requests_allowed = True
insert_admin_unit_for_user(admin_unit, user)
self._db.session.commit()
admin_unit_id = admin_unit.id