How to use the pretalx.common.mixins.views.EventPermissionRequired 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 / cfp.py View on Github external
def get_object(self) -> Question:
        return Question.all_objects.filter(
            event=self.request.event, pk=self.kwargs.get("pk")
        ).first()

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

        question.active = not question.active
        question.save(update_fields=["active"])
        return redirect(question.urls.base)


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

    @context
    @cached_property
    def filter_form(self):
        data = self.request.GET if self.request.method == "GET" else self.request.POST
        return SpeakerFilterForm(data)

    @staticmethod
    def get_missing_answers(*, questions, person, submissions):
        missing = []
        submissions = submissions.filter(speakers__in=[person])
        for question in questions:
            if question.target == QuestionTarget.SUBMISSION:
                for submission in submissions:
github pretalx / pretalx / src / pretalx / orga / views / review.py View on Github external
if next_submission:
                messages.success(self.request, phrases.orga.another_review)
                return next_submission.orga_urls.reviews
            messages.success(
                self.request, _("Nice, you have no submissions left to review!")
            )
            return self.request.event.orga_urls.reviews
        return self.submission.orga_urls.reviews


class ReviewSubmissionDelete(EventPermissionRequired, TemplateView):
    template_name = "orga/review/submission_delete.html"
    permission_required = "orga.remove_review"


class RegenerateDecisionMails(EventPermissionRequired, TemplateView):
    template_name = "orga/review/regenerate_decision_mails.html"
    permission_required = "orga.change_submissions"

    def get_queryset(self):
        return self.request.event.submissions.filter(
            state__in=[SubmissionStates.ACCEPTED, SubmissionStates.REJECTED],
            speakers__isnull=False,
        )

    @context
    @cached_property
    def count(self):
        return self.get_queryset().count()

    def post(self, request, **kwargs):
        for submission in self.get_queryset():
github pretalx / pretalx / src / pretalx / orga / views / schedule.py View on Github external
if schedule:
            schedule.unfreeze(user=request.user)
            messages.success(
                self.request,
                _(
                    "Reset successful – start editing the schedule from your selected version!"
                ),
            )
        else:
            messages.error(
                self.request, _("Error retrieving the schedule version to reset to.")
            )
        return redirect(self.request.event.orga_urls.schedule)


class ScheduleToggleView(EventPermissionRequired, View):
    permission_required = "orga.edit_schedule"

    def dispatch(self, request, event):
        super().dispatch(request, event)
        self.request.event.settings.set(
            "show_schedule", not self.request.event.settings.show_schedule
        )
        return redirect(self.request.event.orga_urls.schedule)


class ScheduleResendMailsView(EventPermissionRequired, View):
    permission_required = "orga.edit_schedule"

    def dispatch(self, request, event):
        super().dispatch(request, event)
        if self.request.event.current_schedule:
github pretalx / pretalx / src / pretalx / orga / views / cfp.py View on Github external
}
        for person in people:
            missing = self.get_missing_answers(
                questions=mandatory_questions, person=person, submissions=submissions
            )
            if missing:
                data["questions"] = "\n".join(
                    f"- {question.question}" for question in missing
                )
                request.event.question_template.to_mail(
                    person, event=request.event, context=data
                )
        return redirect(request.event.orga_urls.outbox)


class SubmissionTypeList(EventPermissionRequired, ListView):
    template_name = "orga/cfp/submission_type_view.html"
    context_object_name = "types"
    permission_required = "orga.view_submission_type"

    def get_queryset(self):
        return self.request.event.submission_types.all().annotate(
            submission_count=models.Count("submissions")
        )


class SubmissionTypeDetail(PermissionRequired, ActionFromUrl, CreateOrUpdateView):
    model = SubmissionType
    form_class = SubmissionTypeForm
    template_name = "orga/cfp/submission_type_form.html"
    permission_required = "orga.edit_submission_type"
    write_permission_required = "orga.edit_submission_type"
github pretalx / pretalx / src / pretalx / orga / views / cards.py View on Github external
if self.submission.abstract:
            self.render_paragraph(
                Paragraph(
                    ellipsize(self.submission.abstract, 140), style=self.styles["Meta"]
                )
            )

        if self.submission.notes:
            self.render_paragraph(
                Paragraph(
                    ellipsize(self.submission.notes, 140), style=self.styles["Meta"]
                )
            )


class SubmissionCards(EventPermissionRequired, View):
    permission_required = "orga.view_submission_cards"

    def get_queryset(self):
        return (
            self.request.event.submissions.select_related("submission_type")
            .prefetch_related("speakers")
            .filter(
                state__in=[
                    SubmissionStates.ACCEPTED,
                    SubmissionStates.CONFIRMED,
                    SubmissionStates.SUBMITTED,
                ]
            )
        )

    def get(self, request, *args, **kwargs):
github pretalx / pretalx / src / pretalx / orga / views / review.py View on Github external
from django.views.generic import ListView, TemplateView
from django_context_decorator import context

from pretalx.common.mixins.views import (
    EventPermissionRequired,
    Filterable,
    PermissionRequired,
)
from pretalx.common.phrases import phrases
from pretalx.common.views import CreateOrUpdateView
from pretalx.orga.forms import ReviewForm
from pretalx.submission.forms import QuestionsForm, SubmissionFilterForm
from pretalx.submission.models import Review, Submission, SubmissionStates


class ReviewDashboard(EventPermissionRequired, Filterable, ListView):
    template_name = "orga/review/dashboard.html"
    paginate_by = None
    context_object_name = "submissions"
    permission_required = "orga.view_review_dashboard"
    default_filters = (
        "code__icontains",
        "speakers__name__icontains",
        "title__icontains",
    )
    filter_fields = ("submission_type", "state", "track")

    def get_filter_form(self):
        return SubmissionFilterForm(
            data=self.request.GET,
            event=self.request.event,
            usable_states=[
github pretalx / pretalx / src / pretalx / orga / views / speaker.py View on Github external
if form.has_changed():
            self.get_object().event_profile(self.request.event).log_action(
                "pretalx.user.profile.update", person=self.request.user, orga=True
            )
        if form.has_changed() or self.questions_form.has_changed():
            self.request.event.cache.set("rebuild_schedule_export", True, None)
        messages.success(self.request, "The speaker profile has been updated.")
        return result

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs.update({"event": self.request.event, "user": self.object})
        return kwargs


class SpeakerPasswordReset(EventPermissionRequired, DetailView):
    permission_required = "orga.change_speaker"
    template_name = "orga/speaker/reset_password.html"
    model = User
    context_object_name = "speaker"

    @context
    def profile(self):
        return self.get_object().event_profile(self.request.event)

    @transaction.atomic()
    def post(self, request, *args, **kwargs):
        user = self.get_object()
        try:
            user.reset_password(
                event=getattr(self.request, "event", None), user=self.request.user
            )
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
state__in=[SubmissionStates.ACCEPTED, SubmissionStates.CONFIRMED]
                )
            )
            return json.dumps(
                sorted(
                    list(
                        {"label": label, "value": value}
                        for label, value in counter.items()
                    ),
                    key=itemgetter("label"),
                )
            )
        return ""


class AllFeedbacksList(EventPermissionRequired, ListView):
    model = Feedback
    context_object_name = "feedback"
    template_name = "orga/submission/feedbacks_list.html"

    permission_required = "submission.view_feedback"
    paginate_by = 25

    def get_queryset(self):
        qs = (
            Feedback.objects.order_by("-pk")
            .select_related("talk")
            .filter(talk__event=self.request.event)
        )
        return qs
github pretalx / pretalx / src / pretalx / orga / views / cfp.py View on Github external
try:
            track.delete()
            request.event.log_action(
                "pretalx.track.delete", person=self.request.user, orga=True
            )
            messages.success(request, _("The track has been deleted."))
        except ProtectedError:  # TODO: show which/how many submissions are concerned
            messages.error(
                request,
                _("This track is in use in a submission and cannot be deleted."),
            )
        return redirect(self.request.event.cfp.urls.tracks)


class AccessCodeList(EventPermissionRequired, ListView):
    template_name = "orga/cfp/access_code_view.html"
    context_object_name = "access_codes"
    permission_required = "orga.view_access_codes"

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


class AccessCodeDetail(PermissionRequired, CreateOrUpdateView):
    model = SubmitterAccessCode
    form_class = SubmitterAccessCodeForm
    template_name = "orga/cfp/access_code_form.html"
    permission_required = "orga.view_access_code"
    write_permission_required = "orga.edit_access_code"

    def get_success_url(self) -> str:
github pretalx / pretalx / src / pretalx / orga / views / schedule.py View on Github external
return result


class ScheduleExportView(EventPermissionRequired, TemplateView):
    template_name = "orga/schedule/export.html"
    permission_required = "orga.view_schedule"

    @context
    def exporters(self):
        return list(
            exporter(self.request.event)
            for _, exporter in register_data_exporters.send(self.request.event)
        )


class ScheduleExportTriggerView(EventPermissionRequired, View):
    permission_required = "orga.view_schedule"

    def post(self, request, event):
        if settings.HAS_CELERY:
            export_schedule_html.apply_async(kwargs={"event_id": self.request.event.id})
            messages.success(
                self.request,
                _("A new export is being generated and will be available soon."),
            )
        else:
            self.request.event.cache.set("rebuild_schedule_export", True, None)
            messages.success(
                self.request,
                _(
                    "A new export will be generated on the next scheduled opportunity – please contact your administrator for details."
                ),