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

added draft lastschriftmandat #179

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
115 changes: 67 additions & 48 deletions member_database/admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask_admin.form import fields
from wtforms.fields import PasswordField

from .models import db, Person, TUStatus
from .models import db, Person, TUStatus, SepaMandate
from .events import Event, EventRegistration
from .authentication import User, Role, AccessLevel, handle_needs_login, ACCESS_LEVELS

Expand All @@ -19,11 +19,11 @@ def _value(self):
elif self.data:
return json.dumps(self.data, ensure_ascii=False, indent=2)
else:
return ''
return ""


class IndexView(AdminIndexView):
@expose('/')
@expose("/")
def index(self):
if not current_user.is_authenticated:
return handle_needs_login()
Expand All @@ -37,13 +37,12 @@ class AuthorizedView(ModelView):
details_modal = True

def __init_subclass__(cls):
'''Add a subclasses access level to the set of access levels'''
"""Add a subclasses access level to the set of access levels"""
ACCESS_LEVELS.add(cls.access_level)

def is_accessible(self):
return (
current_user.is_authenticated
and current_user.has_access(self.access_level)
return current_user.is_authenticated and current_user.has_access(
self.access_level
)

def inaccessible_callback(self, name, **kwargs):
Expand All @@ -56,47 +55,53 @@ def inaccessible_callback(self, name, **kwargs):


class EventView(AuthorizedView):
access_level = 'event_admin'
column_list = ['name', 'notify_email', 'max_participants', 'force_tu_mail',
'registration_open']
column_filters = ['name', 'max_participants', 'force_tu_mail',
'registration_open', 'notify_email']
form_excluded_columns = ['registrations']
column_editable_list = ['name', 'registration_open']
column_descriptions = {
'description': 'HTML is allowed in this field.'
}
access_level = "event_admin"
column_list = [
"name",
"notify_email",
"max_participants",
"force_tu_mail",
"registration_open",
]
column_filters = [
"name",
"max_participants",
"force_tu_mail",
"registration_open",
"notify_email",
]
form_excluded_columns = ["registrations"]
column_editable_list = ["name", "registration_open"]
column_descriptions = {"description": "HTML is allowed in this field."}
form_widget_args = {
'description': {
'rows': 10,
'style': 'width: 100%; font-family: monospace;',
"description": {
"rows": 10,
"style": "width: 100%; font-family: monospace;",
},
"registration_schema": {
"rows": 16,
"style": "width: 100%; font-family: monospace;",
},
'registration_schema': {
'rows': 16,
'style': 'width: 100%; font-family: monospace;',
}
}
form_overrides = {
'registration_schema': PrettyJSONField
}
form_overrides = {"registration_schema": PrettyJSONField}


class RoleView(AuthorizedView):
column_display_pk = True
column_list = ['id', 'access_levels', 'users']
form_columns = ['id', 'access_levels', 'users']
access_level = 'role_admin'
column_list = ["id", "access_levels", "users"]
form_columns = ["id", "access_levels", "users"]
access_level = "role_admin"


class AccessLevelView(AuthorizedView):
column_display_pk = True
column_list = ['id', 'roles']
form_columns = ['id', 'roles']
access_level = 'access_level_admin'
column_list = ["id", "roles"]
form_columns = ["id", "roles"]
access_level = "access_level_admin"


class EventRegistrationView(AuthorizedView):
access_level = 'event_registration_admin'
access_level = "event_registration_admin"
column_filters = [
Event.id,
Event.name,
Expand All @@ -105,43 +110,56 @@ class EventRegistrationView(AuthorizedView):
]

form_columns = [
'id', 'event', 'person', 'status', 'data', 'timestamp',
"id",
"event",
"person",
"status",
"data",
"timestamp",
]



class PersonView(AuthorizedView):
access_level = 'person_admin'
access_level = "person_admin"
column_list = [
'name', 'email', 'user', 'event_registrations',
'membership_status', 'joining_date',
"name",
"email",
"user",
"event_registrations",
"membership_status",
"joining_date",
]
column_filters = ['name', 'email', Person.membership_status_id]
column_filters = ["name", "email", Person.membership_status_id]


class TUStatusView(AuthorizedView):
access_level = 'person_admin'
access_level = "person_admin"


class UserView(AuthorizedView):
access_level = 'user_admin'
column_list = ['username', 'person', 'roles']
column_filters = ['username', Person.email]
form_excluded_columns = ['password_hash']
access_level = "user_admin"
column_list = ["username", "person", "roles"]
column_filters = ["username", Person.email]
form_excluded_columns = ["password_hash"]
form_extra_fields = {
'new_password': PasswordField('New Password'),
"new_password": PasswordField("New Password"),
}

def on_model_change(self, form, user, is_created):
if form.new_password.data is not None:
user.set_password(form.new_password.data)


class SepaView(AuthorizedView):
access_level = "user_admin"
column_list = ["id", "person", "creation_date"]


def create_admin_views():
admin = Admin(
index_view=IndexView(),
template_mode='bootstrap4',
base_template="admin_master.html"
template_mode="bootstrap4",
base_template="admin_master.html",
)
admin.add_view(EventView(Event, db.session))
admin.add_view(EventRegistrationView(EventRegistration, db.session))
Expand All @@ -150,4 +168,5 @@ def create_admin_views():
admin.add_view(RoleView(Role, db.session))
admin.add_view(AccessLevelView(AccessLevel, db.session))
admin.add_view(TUStatusView(TUStatus, db.session))
admin.add_view(SepaView(SepaMandate, db.session))
return admin
Loading