Example #1
0
    def get_text(self, request, **kwargs):
        data = ScheduleData(
            event=self.request.event,
            schedule=self.schedule,
            with_accepted=self.answer_type == "html"
            and self.schedule == self.request.event.wip_schedule,
            with_breaks=True,
        ).data
        response_start = textwrap.dedent(f"""
        \033[1m{request.event.name}\033[0m

        Get different formats:
           curl {request.event.urls.schedule.full()}\?format=table (default)
           curl {request.event.urls.schedule.full()}\?format=list

        """)
        output_format = request.GET.get("format", "table")
        if output_format not in ["list", "table"]:
            output_format = "table"
        if output_format == "list":
            result = self._get_text_list(data)
        else:
            result = self._get_text_table(data)
        return HttpResponse(response_start + result,
                            content_type="text/plain; charset=utf-8")
Example #2
0
    def get_context_data(self, *args, **kwargs):
        from pretalx.schedule.exporters import ScheduleData
        ctx = super().get_context_data(*args, **kwargs)
        ctx['exporters'] = list(
            exporter(self.request.event) for _, exporter in
            register_data_exporters.send(self.request.event))
        tz = pytz.timezone(self.request.event.timezone)
        if 'schedule' not in ctx:
            return ctx

        ctx['data'] = ScheduleData(event=self.request.event,
                                   schedule=ctx['schedule']).data
        for date in ctx['data']:
            if date.get('first_start') and date.get('last_end'):
                start = date.get('first_start').astimezone(tz).replace(
                    second=0, minute=0)
                end = date.get('last_end').astimezone(tz)
                date['height'] = int((end - start).total_seconds() / 60 * 2)
                date['hours'] = []
                d = start
                while d < end:
                    date['hours'].append(d.strftime('%H:%M'))
                    d += timedelta(hours=1)
                for room in date['rooms']:
                    for talk in room.get('talks', []):
                        talk.top = int((talk.start.astimezone(tz) -
                                        start).total_seconds() / 60 * 2)
                        talk.height = int(talk.duration * 2)
                        talk.is_active = talk.start <= now() <= talk.end
        return ctx
Example #3
0
    def get_context_data(self, **kwargs):
        result = super().get_context_data(**kwargs)
        if "schedule" not in result:
            return result

        data = ScheduleData(
            event=self.request.event,
            schedule=self.schedule,
            with_accepted=self.answer_type == "html"
            and self.schedule == self.request.event.wip_schedule,
            with_breaks=True,
        ).data
        method = getattr(
            self, f"get_schedule_data_{self.request.event.settings.schedule_display}"
        )
        result.update(**method(data))
        result["day_count"] = len(result["data"])
        if result["day_count"]:
            today = now().date()
            result["initial_day"] = (
                today
                if result["data"][0]["start"].date()
                <= today
                <= result["data"][-1]["start"].date()
                else result["data"][0]["start"]
            )
        return result
Example #4
0
    def get_schedule_data(self):
        from pretalx.schedule.exporters import ScheduleData

        timezone = pytz.timezone(self.request.event.timezone)
        data = ScheduleData(
            event=self.request.event,
            schedule=self.schedule,
            with_accepted=self.answer_type == 'html'
            and self.schedule == self.request.event.wip_schedule).data
        max_rooms = 0
        for date in data:
            if date.get('first_start') and date.get('last_end'):
                start = (date.get('first_start').astimezone(timezone).replace(
                    second=0, minute=0))
                end = date.get('last_end').astimezone(timezone)
                height_seconds = (end - start).total_seconds()
                date['display_start'] = start
                date['height'] = int(height_seconds / 60 * 2)
                date['hours'] = []
                step = start
                while step < end:
                    date['hours'].append(step.strftime('%H:%M'))
                    step += timedelta(hours=1)
                max_rooms = max(max_rooms, len(date['rooms']))
                for room in date['rooms']:
                    for talk in room.get('talks', []):
                        talk.top = int((talk.start.astimezone(timezone) -
                                        start).total_seconds() / 60 * 2)
                        talk.height = int(talk.duration * 2)
                        talk.is_active = talk.start <= now() <= talk.real_end
        return data, max_rooms
Example #5
0
    def get_schedule_data(self):
        from pretalx.schedule.exporters import ScheduleData

        timezone = pytz.timezone(self.request.event.timezone)
        data = ScheduleData(
            event=self.request.event,
            schedule=self.schedule,
            with_accepted=self.answer_type == "html"
            and self.schedule == self.request.event.wip_schedule,
            with_breaks=True,
        ).data
        max_rooms = 0
        for date in data:
            if date.get("first_start") and date.get("last_end"):
                start = (date.get("first_start").astimezone(timezone).replace(
                    second=0, minute=0))
                end = date.get("last_end").astimezone(timezone)
                height_seconds = (end - start).total_seconds()
                date["display_start"] = start
                date["height"] = int(height_seconds / 60 * 2)
                date["hours"] = []
                step = start
                while step < end:
                    date["hours"].append(step.strftime("%H:%M"))
                    step += dt.timedelta(hours=1)
                max_rooms = max(max_rooms, len(date["rooms"]))
                for room in date["rooms"]:
                    for talk in room.get("talks", []):
                        talk.top = int((talk.start.astimezone(timezone) -
                                        start).total_seconds() / 60 * 2)
                        talk.height = int(talk.duration * 2)
                        talk.is_active = talk.start <= now() <= talk.real_end
        return list(data), max_rooms
Example #6
0
    def get_context_data(self, **kwargs):
        from pretalx.schedule.exporters import ScheduleData

        context = super().get_context_data(**kwargs)
        context['exporters'] = list(
            exporter(self.request.event) for _, exporter in
            register_data_exporters.send(self.request.event))
        timezone = pytz.timezone(self.request.event.timezone)
        if 'schedule' not in context:
            return context

        context['data'] = ScheduleData(event=self.request.event,
                                       schedule=context['schedule']).data
        context['search'] = self.request.GET.get('q', '').lower()
        max_rooms = 0
        for date in context['data']:
            if date.get('first_start') and date.get('last_end'):
                start = (date.get('first_start').astimezone(timezone).replace(
                    second=0, minute=0))
                end = date.get('last_end').astimezone(timezone)
                date['height'] = int((end - start).total_seconds() / 60 * 2)
                date['hours'] = []
                step = start
                while step < end:
                    date['hours'].append(step.strftime('%H:%M'))
                    step += timedelta(hours=1)
                max_rooms = max(max_rooms, len(date['rooms']))
                for room in date['rooms']:
                    for talk in room.get('talks', []):
                        talk.top = int((talk.start.astimezone(timezone) -
                                        start).total_seconds() / 60 * 2)
                        talk.height = int(talk.duration * 2)
                        talk.is_active = talk.start <= now() <= talk.real_end
        context['max_rooms'] = max_rooms
        return context
Example #7
0
 def get(self, request, *args, **kwargs):
     locale = request.GET.get("locale", "en")
     with language(locale):
         data = ScheduleData(
             event=self.request.event,
             schedule=self.schedule,
             with_accepted=self.answer_type == "html"
             and self.schedule == self.request.event.wip_schedule,
             with_breaks=True,
         ).data
         schedule = self.get_schedule_data_proportional(data)["data"]
         for day in schedule:
             for room in day["rooms"]:
                 room["name"] = str(room["name"])
                 room["talks"] = [{
                     "title":
                     talk.submission.title
                     if talk.submission else str(talk.description),
                     "code":
                     talk.submission.code if talk.submission else None,
                     "display_speaker_names":
                     talk.submission.display_speaker_names
                     if talk.submission else None,
                     "speakers": [{
                         "name": speaker.name,
                         "code": speaker.code
                     } for speaker in talk.submission.speakers.all()]
                     if talk.submission else None,
                     "height":
                     talk.height,
                     "top":
                     talk.top,
                     "start":
                     talk.start,
                     "end":
                     talk.end,
                     "do_not_record":
                     talk.submission.do_not_record
                     if talk.submission else None,
                     "track":
                     getattr(talk.submission.track, "name", "")
                     if talk.submission else None,
                 } for talk in room["talks"]]
         response = JsonResponse(
             {
                 "schedule": schedule,
                 "event": {
                     "url":
                     request.event.urls.schedule.full(),
                     "tracks": [{
                         "name": track.name,
                         "color": track.color
                     } for track in request.event.tracks.all()],
                 },
             },
             encoder=I18nJSONEncoder,
         )
         response["Access-Control-Allow-Origin"] = "*"
         return response
Example #8
0
 def get_schedule_data(self):
     data = ScheduleData(
         event=self.request.event,
         schedule=self.schedule,
         with_accepted=self.schedule and not self.schedule.version,
         with_breaks=True,
     ).data
     for date in data:
         rooms = date.pop("rooms")
         talks = [talk for room in rooms for talk in room.get("talks", [])]
         talks.sort(key=lambda x: (x.start, x.submission.title
                                   if x.submission else ""))
         date["talks"] = talks
     return {"data": list(data)}
Example #9
0
def test_schedule_data_empty_methods():
    assert ScheduleData(None).metadata == []
    assert ScheduleData(None).data == []
Example #10
0
def test_schedule_data_out_of_order_slots(event, slot, other_slot):
    with scope(event=event):
        slot.start, other_slot.start = other_slot.start, slot.start
        slot.save()
        other_slot.save()
        assert ScheduleData(event=event, schedule=slot.schedule).data
Example #11
0
def test_schedule_data_out_of_bounds_slot(event, slot, other_slot):
    with scope(event=event):
        slot.start -= dt.timedelta(days=1)
        slot.end -= dt.timedelta(days=1)
        slot.save()
        assert ScheduleData(event=event, schedule=slot.schedule).data
Example #12
0
def test_schedule_data_really_early_slot(event, slot, other_slot):
    with scope(event=event):
        slot.start += dt.timedelta(days=1)
        slot.end += dt.timedelta(days=1)
        slot.save()
        assert ScheduleData(event=event, schedule=slot.schedule).data