diff --git a/aleksis/apps/paweljong/forms.py b/aleksis/apps/paweljong/forms.py index 0f2bfce6964c036a564e00825425a186bddaa760..2777d222ee4fa485b0327c834ce5ee5bdeeb4a1b 100644 --- a/aleksis/apps/paweljong/forms.py +++ b/aleksis/apps/paweljong/forms.py @@ -491,21 +491,6 @@ class RegistrationStatesForm(forms.ModelForm): exclude = [] -class PersonGroupFormGroup(forms.Form): - - layout = Layout("group") - - group = forms.ModelChoiceField( - label=_("Group"), - queryset=Group.objects.all(), - required=True, - widget=ModelSelect2Widget( - search_fields=["name__icontains"], - attrs={"data-minimum-input-length": 0, "class": "browser-default"}, - ), - ) - - class PersonGroupFormPerson(forms.Form): layout = Layout("username") diff --git a/aleksis/apps/paweljong/tables.py b/aleksis/apps/paweljong/tables.py index 00056416cf72d4f446e5070ea501526d2e3424ce..afd35341ca6b16ad89e8a3e33ab862e467b87832 100644 --- a/aleksis/apps/paweljong/tables.py +++ b/aleksis/apps/paweljong/tables.py @@ -126,3 +126,20 @@ class RegistrationStatesTable(tables.Table): def render_name(self, value, record): context = dict(state=record) return render_to_string("paweljong/registration_state/chip.html", context) + + +class ChildGroupsTable(tables.Table): + """Table to list groups.""" + + class Meta: + attrs = {"class": "highlight"} + + name = tables.LinkColumn("group_by_id", args=[A("id")]) + short_name = tables.LinkColumn("group_by_id", args=[A("id")]) + + add_persons = tables.LinkColumn( + "add_persons_to_group", + args=[A("id")], + verbose_name=_("Add persons"), + text=_("Add persons"), + ) diff --git a/aleksis/apps/paweljong/templates/paweljong/event/persons_group.html b/aleksis/apps/paweljong/templates/paweljong/event/persons_group.html new file mode 100644 index 0000000000000000000000000000000000000000..5819aa8382735771d5962359afed1bf94d7841c6 --- /dev/null +++ b/aleksis/apps/paweljong/templates/paweljong/event/persons_group.html @@ -0,0 +1,20 @@ +{% extends "core/base.html" %} +{% load material_form i18n any_js %} + +{% block page_title %}{% blocktrans %}Add person to group{% endblocktrans %}{% endblock %} +{% block browser_title %}{% blocktrans %}Add person to group{% endblocktrans %}{% endblock %} + +{% block extra_head %} + {{ form.media.css }} +{% endblock %} + +{% block content %} + + <form method="post"> + {% csrf_token %} + {% form form=form %}{% form %} + {% include "core/partials/save_button.html" %} + </form> + {{ form.media.js }} + +{% endblock %} diff --git a/aleksis/apps/paweljong/templates/paweljong/person_group_wizard.html b/aleksis/apps/paweljong/templates/paweljong/person_group_wizard.html deleted file mode 100644 index 08d4672291186dd3b9f9e4e2de09c9f0e18cfa09..0000000000000000000000000000000000000000 --- a/aleksis/apps/paweljong/templates/paweljong/person_group_wizard.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "core/base.html" %} -{% load material_form i18n %} - -{% block browser_title %}{% trans "Add person to group" %}{% endblock %} -{% block page_title %}{% trans "Add person to group" %}{% endblock %} - -{% block content %} - - <form method="post"> - {% csrf_token %} - {{ wizard.form.media }} - {{ wizard.management_form }} - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {% form form=form %}{% endform %} - {% endfor %} - {% else %} - {% form form=wizard.form %}{% endform %} - {% endif %} - - {% if wizard.steps.prev %} - <button type="submit" value="{{ wizard.steps.first }}" class="btn waves-effect waves-light color-primary" name="wizard_goto_step"> - <i class="material-icons left">first_page</i> - {% trans "first step" %} - </button> - <button type="submit" value="{{ wizard.steps.prev }}" class="btn waves-effect waves-light color-secondary" name="wizard_goto_step"> - <i class="material-icons left">arrow_back_ios</i> - {% trans "previous step" %} - </button> - {% endif %} - {% trans "Next" as caption %} - {% include "core/partials/save_button.html" with caption=caption icon="navigate_next" %} - </form> - -{% endblock %} diff --git a/aleksis/apps/paweljong/urls.py b/aleksis/apps/paweljong/urls.py index 0fa603da28ae3ce2a6cd046788f5abdb55b6ae87..339c71deef0705be3ffe767c2881ee2ac7361f38 100644 --- a/aleksis/apps/paweljong/urls.py +++ b/aleksis/apps/paweljong/urls.py @@ -4,8 +4,6 @@ from aleksis.apps.postbuero.forms import MailAddForm from . import views from .forms import ( - PersonGroupFormGroup, - PersonGroupFormPerson, RegisterEventAccount, RegisterEventAdditional, RegisterEventConsent, @@ -37,11 +35,6 @@ account_conditions = { "email": views.is_email_needed, } -add_persons_to_group_forms = [ - ("group", PersonGroupFormGroup), - ("person", PersonGroupFormPerson), -] - urlpatterns = [ path("event/<slug:slug>/edit", views.EditEventView.as_view(), name="edit_event_by_slug"), path( @@ -50,8 +43,8 @@ urlpatterns = [ name="register_event_by_slug", ), path( - "group_persons/add", - views.PersonGroupWizardView.as_view(add_persons_to_group_forms), + "group_persons/<int:pk>/add", + views.PersonGroupView.as_view(), name="add_persons_to_group", ), path("event/<slug:slug>", views.EventFullView.as_view(), name="event_by_name"), diff --git a/aleksis/apps/paweljong/views.py b/aleksis/apps/paweljong/views.py index fb9f3e19899b8879daa9dd52432511219bfdfd8d..b032c06c67748284361aa0aa89567027df7f6dd3 100644 --- a/aleksis/apps/paweljong/views.py +++ b/aleksis/apps/paweljong/views.py @@ -24,8 +24,8 @@ from templated_email import send_templated_mail from aleksis.apps.postbuero.models import MailAddress from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView -from aleksis.core.tables import AdditionalFieldsTable, GroupsTable -from aleksis.core.models import Activity, Person, Group +from aleksis.core.models import Activity, Group, Person +from aleksis.core.tables import AdditionalFieldsTable from aleksis.core.util import messages from aleksis.core.util.core_helpers import get_site_preferences, objectgetter_optional @@ -37,11 +37,13 @@ from .forms import ( EditTermForm, EditVoucherForm, GenerateListForm, + PersonGroupFormPerson, RegistrationNotificationForm, RegistrationStatesForm, ) from .models import Event, EventRegistration, InfoMailing, RegistrationState, Terms, Voucher from .tables import ( + ChildGroupsTable, EventRegistrationsTable, InfoMailingsTable, ManageEventsTable, @@ -903,7 +905,7 @@ class EventDetailView(PermissionRequiredMixin, DetailView): # Child groups table child_groups = self.object.linked_group.child_groups.all() - child_groups_table = GroupsTable(child_groups) + child_groups_table = ChildGroupsTable(child_groups) RequestConfig(self.request).configure(child_groups_table) context["child_groups_table"] = child_groups_table @@ -916,34 +918,24 @@ class EventDetailView(PermissionRequiredMixin, DetailView): return context -class PersonGroupWizardView(SessionWizardView): - template_name = "paweljong/person_group_wizard.html" - file_storage = settings.DEFAULT_FILE_STORAGE - - def get_form_initial(self, step): +class PersonGroupView(PermissionRequiredMixin, FormView): - initial = self.initial_dict.get(step, {}) + template_name = "paweljong/event/persons_group.html" + permission_required = "paweljong.add_persons_to_group_rule" + form_class = PersonGroupFormPerson - if step == "group": - if self.request.session["person_group_group"]: - group = Group.objects.get(id=self.request.session["person_group_group"]) - initial.update( - { - "group": group, - } - ) - - return self.initial_dict.get(step, initial) + def form_valid(self, form): - def done(self, form_list, **kwargs): + group = Group.objects.get(id=self.kwargs["pk"]) - cleaned_data_group = self.get_cleaned_data_for_step("group") - cleaned_data_person = self.get_cleaned_data_for_step("person") + try: + person = Person.objects.get(user__username=form.cleaned_data["username"]) + group.members.add(person) + messages.success(self.request, _(f"Person {person} added successfully!")) + except Person.DoesNotExist: + messages.error(self.request, _("Person does not exist!")) - # Add person to group - group = cleaned_data_group["group"] - self.request.session["person_group_group"] = group.id - person = Person.objects.get(user__username=cleaned_data_person["username"]) - group.members.add(person) + return super().form_valid(self) - return redirect("add_persons_to_group") + def get_success_url(self): + return reverse("add_persons_to_group", kwargs={"pk": self.kwargs["pk"]})