How to use the pretalx.submission.models.Submission 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 / common / management / commands / create_test_event.py View on Github external
def build_submission(self, speaker, submission_type, submission_time):
        with self.freeze_time(submission_time):
            submission = Submission.objects.create(
                event=self.event,
                title=self.fake.catch_phrase(),
                submission_type=submission_type,
                track=random.choice(self.event.tracks.all()),
                abstract=self.fake.bs().capitalize() + "!",
                description=self.fake.text(),
                content_locale="en",
                do_not_record=random.choice([False] * 10 + [True]),
            )
            submission.log_action("pretalx.submission.create", person=speaker)
        submission.speakers.add(speaker)
        return submission
github djangocon / 2019.djangocon.eu / dceu2019 / src / dceu2019 / apps / pretalx_utils / management / commands / pretalx_submissions2csv.py View on Github external
def handle(self, *args, **options):

        field_names = [f.name for f in models.Submission._meta.fields]
        writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
        writer.writerow(
            ["speakers", "score"] +
            field_names
        )
        for instance in models.Submission.objects.all():
            values = []
            speakers = ", ".join([person.get_display_name() for person in instance.speakers.all()])
            score = instance.average_score
            values.append(speakers)
            values.append(score)
            for f in field_names:
                value = getattr(instance, f)
                if not isinstance(value, (int, float)):
                    values.append(str(value).encode('utf-8'))
                else:
                    values.append(value)
            writer.writerow(values)
github pretalx / pretalx / src / pretalx / person / models / user.py View on Github external
def shred(self):
        """Actually remove the user account."""
        from pretalx.submission.models import Submission

        with scopes_disabled():
            if (
                Submission.all_objects.filter(speakers__in=[self]).count()
                or self.teams.count()
                or self.answers.count()
            ):
                raise Exception(
                    f"Cannot delete user <{self.email}> because they have submissions, answers, or teams. Please deactivate this user instead."
                )
            self.logged_actions().delete()
            self.own_actions().update(person=None)
            self.delete()
github pretalx / pretalx / src / pretalx / api / serializers / question.py View on Github external
class Meta:
        model = AnswerOption
        fields = ("id", "answer")


class QuestionSerializer(ModelSerializer):
    options = AnswerOptionSerializer(many=True)

    class Meta:
        model = Question
        fields = ("id", "question", "required", "target", "options")


class AnswerSerializer(ModelSerializer):
    question = QuestionSerializer(Question.objects.none(), read_only=True)
    submission = SlugRelatedField(queryset=Submission.objects.none(), slug_field="code")
    person = SlugRelatedField(queryset=User.objects.none(), slug_field="code")
    options = AnswerOptionSerializer(many=True)

    class Meta:
        model = Answer
        fields = (
            "id",
            "question",
            "answer",
            "answer_file",
            "submission",
            "person",
            "options",
        )
github djangocon / 2019.djangocon.eu / dceu2019 / src / dceu2019 / apps / pretalx_utils / management / commands / pretalx_submissions2csv.py View on Github external
def handle(self, *args, **options):

        field_names = [f.name for f in models.Submission._meta.fields]
        writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
        writer.writerow(
            ["speakers", "score"] +
            field_names
        )
        for instance in models.Submission.objects.all():
            values = []
            speakers = ", ".join([person.get_display_name() for person in instance.speakers.all()])
            score = instance.average_score
            values.append(speakers)
            values.append(score)
            for f in field_names:
                value = getattr(instance, f)
                if not isinstance(value, (int, float)):
                    values.append(str(value).encode('utf-8'))
                else:
github pretalx / pretalx / src / pretalx / agenda / views / talk.py View on Github external
)
        qs = self.filter_queryset(qs)
        all_talks = list(self.request.event.talks.all().prefetch_related("speakers"))
        for profile in qs:
            profile.talks = [
                talk for talk in all_talks if profile.user in talk.speakers.all()
            ]
        return qs

    @context
    def search(self):
        return self.request.GET.get("q")


class TalkView(PermissionRequired, TemplateView):
    model = Submission
    slug_field = "code"
    template_name = "agenda/talk.html"
    permission_required = "agenda.view_slot"

    def get_object(self, queryset=None):
        talk = (
            self.request.event.talks.prefetch_related("slots", "answers", "resources")
            .filter(code__iexact=self.kwargs["slug"],)
            .first()
        )
        if talk:
            return talk
        if getattr(self.request, "is_orga", False):
            talk = (
                self.request.event.submissions.filter(code__iexact=self.kwargs["slug"],)
                .prefetch_related("speakers", "slots", "answers", "resources")
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
def submission_type_data(self):
        counter = Counter(
            str(submission.submission_type)
            for submission in Submission.all_objects.filter(event=self.request.event)
        )
        return json.dumps(
            sorted(
                list(
                    {"label": label, "value": value} for label, value in counter.items()
                ),
                key=itemgetter("label"),
            )
github pretalx / pretalx / src / pretalx / common / models / log.py View on Github external
def get_orga_url(self) -> str:
        """Returns an organiser backend URL to the object in question (if
        any)."""
        if isinstance(self.content_object, Submission):
            return self.content_object.orga_urls.base
        if isinstance(self.content_object, Question):
            return self.content_object.urls.base
        if isinstance(self.content_object, AnswerOption):
            return self.content_object.question.urls.base
        if isinstance(self.content_object, Answer):
            if self.content_object.submission:
                return self.content_object.submission.orga_urls.base
            return self.content_object.question.urls.base
        if isinstance(self.content_object, CfP):
            return self.content_object.urls.text
        if isinstance(self.content_object, (MailTemplate, QueuedMail)):
            return self.content_object.urls.base
        return ""
github pretalx / pretalx / src / pretalx / common / models / log.py View on Github external
def get_public_url(self) -> str:
        """Returns a public URL to the object in question (if any)."""
        if isinstance(self.content_object, Submission):
            return self.content_object.urls.public
        if isinstance(self.content_object, CfP):
            return self.content_object.urls.public
        return ""
github pretalx / pretalx / src / pretalx / api / views / submission.py View on Github external
from rest_framework import viewsets

from pretalx.api.serializers.submission import (
    ScheduleListSerializer,
    ScheduleSerializer,
    SubmissionOrgaSerializer,
    SubmissionSerializer,
)
from pretalx.schedule.models import Schedule
from pretalx.submission.models import Submission


class SubmissionViewSet(viewsets.ReadOnlyModelViewSet):
    serializer_class = SubmissionSerializer
    queryset = Submission.objects.none()
    lookup_field = "code__iexact"
    filterset_fields = ("state", "content_locale", "submission_type")
    search_fields = ("title", "speakers__name")

    def get_queryset(self):
        if self.request._request.path.endswith(
            "/talks/"
        ) or not self.request.user.has_perm(
            "orga.view_submissions", self.request.event
        ):
            if (
                not self.request.user.has_perm(
                    "agenda.view_schedule", self.request.event
                )
                or not self.request.event.current_schedule
            ):