How to use the pretalx.common.mixins.views.PermissionRequired function in pretalx

To help you get started, we’ve selected a few pretalx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pretalx / pretalx / src / pretalx / orga / views / organiser.py View on Github external
def _get_team(self):
        if "pk" in self.kwargs:
            return get_object_or_404(
                self.request.organiser.teams.all(), pk=self.kwargs["pk"]
            )

    def get_object(self):
        return self._get_team()

    @context
    @cached_property
    def team(self):
        return self._get_team()


class TeamDetail(PermissionRequired, TeamMixin, CreateOrUpdateView):
    permission_required = "orga.change_teams"
    template_name = "orga/settings/team_detail.html"
    form_class = TeamForm
    model = Team

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs["organiser"] = self.request.organiser
        return kwargs

    def get_object(self):
        if "pk" not in self.kwargs:
            return None
        return super().get_object()

    def get_permission_object(self):
github pretalx / pretalx / src / pretalx / orga / views / speaker.py View on Github external
def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs.pop("read_only", None)
        return kwargs

    def form_valid(self, form):
        if not getattr(form.instance, "event", None):
            form.instance.event = self.request.event
        return super().form_valid(form)

    def get_success_url(self):
        return self.request.event.orga_urls.information


class InformationDelete(PermissionRequired, DetailView):
    model = SpeakerInformation
    permission_required = "orga.change_information"
    template_name = "orga/speaker/information_delete.html"

    def get_queryset(self):
        return self.request.event.information.all()

    def post(self, request, *args, **kwargs):
        information = self.get_object()
        information.delete()
        messages.success(request, _("The information has been deleted."))
        return redirect(request.event.orga_urls.information)
github pretalx / pretalx / src / pretalx / orga / views / event.py View on Github external
logdata.update({k: v for k, v in f.cleaned_data.items()})
        with scope(event=event):
            event.log_action(
                "pretalx.event.create",
                person=self.request.user,
                data=logdata,
                orga=True,
            )

            if steps["copy"] and steps["copy"]["copy_from_event"]:
                event.copy_data_from(steps["copy"]["copy_from_event"])

        return redirect(event.orga_urls.base + "?congratulations")


class EventDelete(PermissionRequired, DeleteView):
    template_name = "orga/event/delete.html"
    permission_required = "person.is_administrator"
    model = Event

    def get_object(self):
        return getattr(self.request, "event", None)

    def delete(self, request, *args, **kwargs):
        event = self.get_object()
        if event:
            event.shred()
        return redirect("/orga/")


def event_list(request):
    query = json.dumps(str(request.GET.get("query", "")))[1:-1]
github pretalx / pretalx / src / pretalx / orga / views / event.py View on Github external
"Your API token has been regenerated. The previous token will not be usable any longer."
                ),
            )
        else:
            messages.error(
                self.request,
                _("Oh :( We had trouble saving your input. See below for details."),
            )
        return redirect(self.get_success_url())


def condition_copy(wizard):
    return EventWizardCopyForm.copy_from_queryset(wizard.request.user).exists()


class EventWizard(PermissionRequired, SensibleBackWizardMixin, SessionWizardView):
    permission_required = "orga.create_events"
    file_storage = FileSystemStorage(location=Path(settings.MEDIA_ROOT) / "new_event")
    form_list = [
        ("initial", EventWizardInitialForm),
        ("basics", EventWizardBasicsForm),
        ("timeline", EventWizardTimelineForm),
        ("display", EventWizardDisplayForm),
        ("copy", EventWizardCopyForm),
    ]
    condition_dict = {"copy": condition_copy}

    def get_template_names(self):
        return f"orga/event/wizard/{self.steps.current}.html"

    @context
    def has_organiser(self):
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
return self.object.feedback.all().order_by("pk")


class ToggleFeatured(SubmissionViewMixin, View):
    permission_required = "orga.change_submissions"

    def get_permission_object(self):
        return self.object or self.request.event

    def post(self, *args, **kwargs):
        self.object.is_featured = not self.object.is_featured
        self.object.save(update_fields=["is_featured"])
        return HttpResponse()


class SubmissionFeed(PermissionRequired, Feed):

    permission_required = "orga.view_submission"
    feed_type = feedgenerator.Atom1Feed

    def get_object(self, request, *args, **kwargs):
        return request.event

    def title(self, obj):
        return _("{name} submission feed").format(name=obj.name)

    def link(self, obj):
        return obj.orga_urls.submissions.full()

    def feed_url(self, obj):
        return obj.orga_urls.submission_feed.full()
github pretalx / pretalx / src / pretalx / orga / views / event.py View on Github external
phase.position = i
            phase.save()
    messages.success(request, _("The order of review phases has been updated."))


def phase_move_up(request, event, pk):
    phase_move(request, pk, up=True)
    return redirect(request.event.orga_urls.review_settings)


def phase_move_down(request, event, pk):
    phase_move(request, pk, up=False)
    return redirect(request.event.orga_urls.review_settings)


class PhaseDelete(PermissionRequired, View):
    permission_required = "orga.change_settings"

    def get_object(self):
        return get_object_or_404(
            ReviewPhase, event=self.request.event, pk=self.kwargs.get("pk")
        )

    def dispatch(self, request, *args, **kwargs):
        super().dispatch(request, *args, **kwargs)
        phase = self.get_object()
        phase.delete()
        return redirect(self.request.event.orga_urls.review_settings)


class PhaseActivate(PermissionRequired, View):
    permission_required = "orga.change_settings"
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
def items(self, obj):
        return obj.submissions.order_by("-pk")

    def item_title(self, item):
        return _("New {event} submission: {title}").format(
            event=item.event.name, title=item.title
        )

    def item_link(self, item):
        return item.orga_urls.base.full()

    def item_pubdate(self, item):
        return item.created


class SubmissionStats(PermissionRequired, TemplateView):
    template_name = "orga/submission/stats.html"
    permission_required = "orga.view_submissions"

    def get_permission_object(self):
        return self.request.event

    @context
    def submission_timeline_data(self):
        data = Counter(
            timestamp.astimezone(self.request.event.tz).date()
            for timestamp in ActivityLog.objects.filter(
                event=self.request.event, action_type="pretalx.submission.create"
            ).values_list("timestamp", flat=True)
        )
        dates = data.keys()
        if len(dates) > 1:
github pretalx / pretalx / src / pretalx / orga / views / organiser.py View on Github external
def get_permission_object(self):
        return self.request.organiser

    @context
    def team(self):
        return get_object_or_404(
            self.request.organiser.teams.all(), pk=self.object.team.pk
        )

    def post(self, request, *args, **kwargs):
        self.get_object().delete()
        messages.success(request, _("The team invitation was retracted."))
        return redirect(self.request.organiser.orga_urls.base)


class TeamResetPassword(PermissionRequired, TemplateView):
    model = Team
    template_name = "orga/settings/team_reset_password.html"
    permission_required = "orga.change_teams"

    def get_permission_object(self):
        return self.request.organiser

    @context
    @cached_property
    def team(self):
        return get_object_or_404(
            self.request.organiser.teams.all(), pk=self.kwargs["pk"]
        )

    @context
    @cached_property
github pretalx / pretalx / src / pretalx / orga / views / cfp.py View on Github external
self.instance = form.instance
        result = super().form_valid(form)
        if form.cleaned_data.get("variant") in ("choices", "multiple_choice"):
            formset = self.save_formset(self.instance)
            if not formset:
                return self.get(self.request, *self.args, **self.kwargs)
        if form.has_changed():
            action = "pretalx.question." + (
                "update" if "pk" in self.kwargs else "create"
            )
            form.instance.log_action(action, person=self.request.user, orga=True)
        messages.success(self.request, "The question has been saved.")
        return result


class CfPQuestionDelete(PermissionRequired, DetailView):
    permission_required = "orga.remove_question"
    template_name = "orga/cfp/question_delete.html"

    def get_object(self) -> Question:
        return get_object_or_404(
            Question.all_objects, event=self.request.event, pk=self.kwargs.get("pk")
        )

    def post(self, request, *args, **kwargs):
        question = self.get_object()

        try:
            with transaction.atomic():
                question.options.all().delete()
                question.logged_actions().delete()
                question.delete()
github pretalx / pretalx / src / pretalx / orga / views / cfp.py View on Github external
"pretalx.cfp.update", person=self.request.user, orga=True
            )
        self.sform.save()
        return result


class CfPQuestionList(EventPermissionRequired, TemplateView):
    template_name = "orga/cfp/question_view.html"
    permission_required = "orga.view_question"

    @context
    def questions(self):
        return Question.all_objects.filter(event=self.request.event)


class CfPQuestionDetail(PermissionRequired, ActionFromUrl, CreateOrUpdateView):
    model = Question
    form_class = QuestionForm
    permission_required = "orga.edit_question"
    write_permission_required = "orga.edit_question"

    def get_template_names(self):
        action = self.request.path.lstrip("/").rpartition("/")[2]
        if action in ("edit", "new"):
            return "orga/cfp/question_form.html"
        return "orga/cfp/question_detail.html"

    def get_permission_object(self):
        return self.object or self.request.event

    def get_object(self) -> Question:
        return Question.all_objects.filter(