from django.contrib.messages.views import SuccessMessageMixin
from django.utils.translation import gettext_lazy as _
from django.views import generic

from adhocracy4.dashboard import mixins as a4dashboard_mixins
from meinberlin.apps.dashboard import forms
from meinberlin.apps.organisations.models import Organisation


class DashboardOrganisationUpdateView(
    a4dashboard_mixins.DashboardBaseMixin, SuccessMessageMixin, generic.UpdateView
):

    model = Organisation
    form_class = forms.OrganisationForm
    slug_url_kwarg = "organisation_slug"
    template_name = "meinberlin_organisations/organisation_form.html"
    success_message = _("Organisation successfully updated.")
    permission_required = "meinberlin_organisations.change_organisation"
    menu_item = "organisation"

    def get_permission_object(self):
        return self.organisation
