Beispiel #1
0
def multiexport(self, organizer: Organizer, user: User, fileid: str, provider: str, form_data: Dict[str, Any]) -> None:
    def set_progress(val):
        if not self.request.called_directly:
            self.update_state(
                state='PROGRESS',
                meta={'value': val}
            )

    file = CachedFile.objects.get(id=fileid)
    with language(user.locale), override(user.timezone):
        allowed_events = user.get_events_with_permission('can_view_orders')

        events = allowed_events.filter(pk__in=form_data.get('events'))
        responses = register_multievent_data_exporters.send(organizer)

        for receiver, response in responses:
            if not response:
                continue
            ex = response(events, set_progress)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.')
                    )
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename), ContentFile(data))
                file.save()
    return file.pk
Beispiel #2
0
def badges_create_pdf(event: Event, fileid: int, positions: List[int]) -> int:
    file = CachedFile.objects.get(id=fileid)

    pdfcontent = render_pdf(event, OrderPosition.objects.filter(id__in=positions))
    file.file.save(cachedfile_name(file, file.filename), ContentFile(pdfcontent.read()))
    file.save()
    return file.pk
Beispiel #3
0
def badges_create_pdf(fileid: int, event: int, orders: List[int]) -> int:
    file = CachedFile.objects.get(id=fileid)
    event = Event.objects.get(id=event)

    pdfcontent = render_pdf(event, OrderPosition.objects.filter(order_id__in=orders))
    file.file.save(cachedfile_name(file, file.filename), ContentFile(pdfcontent.read()))
    file.save()
    return file.pk
Beispiel #4
0
def export(event, fileid, provider, form_data):
    event = Event.objects.current.get(identity=event)
    file = CachedFile.objects.get(id=fileid)
    responses = register_data_exporters.send(event)
    for receiver, response in responses:
        ex = response(event)
        if ex.identifier == provider:
            file.filename, file.type, data = ex.render(form_data)
            file.file.save(cachedfile_name(file, file.filename), ContentFile(data))
            file.save()
Beispiel #5
0
def export(event: str, fileid: str, provider: str, form_data: Dict[str, Any]) -> None:
    event = Event.objects.get(id=event)
    file = CachedFile.objects.get(id=fileid)
    with language(event.settings.locale):
        responses = register_data_exporters.send(event)
        for receiver, response in responses:
            ex = response(event)
            if ex.identifier == provider:
                file.filename, file.type, data = ex.render(form_data)
                file.file.save(cachedfile_name(file, file.filename), ContentFile(data))
                file.save()
Beispiel #6
0
def export(event: str, fileid: str, provider: str, form_data: Dict[str, Any]) -> None:
    event = Event.objects.get(id=event)
    file = CachedFile.objects.get(id=fileid)
    with language(event.settings.locale):
        responses = register_data_exporters.send(event)
        for receiver, response in responses:
            ex = response(event)
            if ex.identifier == provider:
                file.filename, file.type, data = ex.render(form_data)
                file.file.save(cachedfile_name(file, file.filename), ContentFile(data))
                file.save()
Beispiel #7
0
def export(event, fileid, provider, form_data):
    event = Event.objects.current.get(identity=event)
    file = CachedFile.objects.get(id=fileid)
    responses = register_data_exporters.send(event)
    for receiver, response in responses:
        ex = response(event)
        if ex.identifier == provider:
            file.filename, file.type, data = ex.render(form_data)
            file.file.save(cachedfile_name(file, file.filename),
                           ContentFile(data))
            file.save()
Beispiel #8
0
def multiexport(self, organizer: Organizer, user: User, device: int,
                token: int, fileid: str, provider: str,
                form_data: Dict[str, Any]) -> None:
    if device:
        device = Device.objects.get(pk=device)
    if token:
        device = TeamAPIToken.objects.get(pk=token)
    allowed_events = (device or token
                      or user).get_events_with_permission('can_view_orders')

    def set_progress(val):
        if not self.request.called_directly:
            self.update_state(state='PROGRESS', meta={'value': val})

    file = CachedFile.objects.get(id=fileid)
    if user:
        locale = user.locale
        timezone = user.timezone
        region = None  # todo: add to user?
    else:
        e = allowed_events.first()
        if e:
            locale = e.settings.locale
            timezone = e.settings.timezone
            region = e.settings.region
        else:
            locale = settings.LANGUAGE_CODE
            timezone = settings.TIME_ZONE
            region = None
    with language(locale, region), override(timezone):
        if isinstance(form_data['events'][0], str):
            events = allowed_events.filter(slug__in=form_data.get('events'),
                                           organizer=organizer)
        else:
            events = allowed_events.filter(pk__in=form_data.get('events'))
        responses = register_multievent_data_exporters.send(organizer)

        for receiver, response in responses:
            if not response:
                continue
            ex = response(events, set_progress)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.'))
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename),
                               ContentFile(data))
                file.save()
    return file.pk
Beispiel #9
0
def export(event: Event, shredders: List[str], session_key=None) -> None:
    known_shredders = event.get_data_shredders()

    with NamedTemporaryFile() as rawfile:
        with ZipFile(rawfile, 'w') as zipfile:
            ccode = get_random_string(6)
            zipfile.writestr(
                'CONFIRM_CODE.txt',
                ccode,
            )
            zipfile.writestr(
                'index.json',
                json.dumps(
                    {
                        'instance': settings.SITE_URL,
                        'organizer': event.organizer.slug,
                        'event': event.slug,
                        'time': now().isoformat(),
                        'shredders': shredders,
                        'confirm_code': ccode
                    },
                    indent=4))
            for s in shredders:
                shredder = known_shredders.get(s)
                if not shredder:
                    continue

                it = shredder.generate_files()
                if not it:
                    continue
                for fname, ftype, content in it:
                    zipfile.writestr(fname, content)

        rawfile.seek(0)

        cf = CachedFile()
        cf.date = now()
        cf.filename = event.slug + '.zip'
        cf.type = 'application/zip'
        cf.session_key = session_key
        cf.web_download = True
        cf.expires = now() + timedelta(hours=1)
        cf.save()
        cf.file.save(cachedfile_name(cf, cf.filename), rawfile)

    return cf.pk
Beispiel #10
0
def export(event: Event, fileid: str, provider: str,
           form_data: Dict[str, Any]) -> None:
    file = CachedFile.objects.get(id=fileid)
    with language(event.settings.locale), override(event.settings.timezone):
        responses = register_data_exporters.send(event)
        for receiver, response in responses:
            ex = response(event)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        ugettext('Your export did not contain any data.'))
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename),
                               ContentFile(data))
                file.save()
    return file.pk
Beispiel #11
0
def generate(order, provider):
    order = Order.objects.current.select_related('event').get(identity=order)
    ct = CachedTicket.objects.get_or_create(order=order, provider=provider)[0]
    if not ct.cachedfile:
        cf = CachedFile()
        cf.date = now()
        cf.expires = order.event.date_from + timedelta(days=30)
        cf.save()
        ct.cachedfile = cf
        ct.save()

    responses = register_ticket_outputs.send(order.event)
    for receiver, response in responses:
        prov = response(order.event)
        if prov.identifier == provider:
            ct.cachedfile.filename, ct.cachedfile.type, data = prov.generate(order)
            ct.cachedfile.file.save(cachedfile_name(ct.cachedfile, ct.cachedfile.filename), ContentFile(data))
            ct.cachedfile.save()
Beispiel #12
0
def generate(order: str, provider: str):
    order = Order.objects.select_related('event').get(id=order)
    ct = CachedTicket.objects.get_or_create(order=order, provider=provider)[0]
    if not ct.cachedfile:
        cf = CachedFile()
        cf.date = now()
        cf.expires = order.event.date_from + timedelta(days=30)
        cf.save()
        ct.cachedfile = cf
        ct.save()

    responses = register_ticket_outputs.send(order.event)
    for receiver, response in responses:
        prov = response(order.event)
        if prov.identifier == provider:
            ct.cachedfile.filename, ct.cachedfile.type, data = prov.generate(order)
            ct.cachedfile.file.save(cachedfile_name(ct.cachedfile, ct.cachedfile.filename), ContentFile(data))
            ct.cachedfile.save()
Beispiel #13
0
def export(event: str, shredders: List[str]) -> None:
    event = Event.objects.get(id=event)
    known_shredders = event.get_data_shredders()

    with NamedTemporaryFile() as rawfile:
        with ZipFile(rawfile, 'w') as zipfile:
            ccode = get_random_string(6)
            zipfile.writestr(
                'CONFIRM_CODE.txt',
                ccode,
            )
            zipfile.writestr(
                'index.json',
                json.dumps({
                    'instance': settings.SITE_URL,
                    'organizer': event.organizer.slug,
                    'event': event.slug,
                    'time': now().isoformat(),
                    'shredders': shredders,
                    'confirm_code': ccode
                }, indent=4)
            )
            for s in shredders:
                shredder = known_shredders.get(s)
                if not shredder:
                    continue

                it = shredder.generate_files()
                if not it:
                    continue
                for fname, ftype, content in it:
                    zipfile.writestr(fname, content)

        rawfile.seek(0)

        cf = CachedFile()
        cf.date = now()
        cf.filename = event.slug + '.zip'
        cf.type = 'application/pdf'
        cf.expires = now() + timedelta(hours=1)
        cf.save()
        cf.file.save(cachedfile_name(cf, cf.filename), rawfile)

    return cf.pk
Beispiel #14
0
def export(self, event: Event, fileid: str, provider: str,
           form_data: Dict[str, Any]) -> None:
    def set_progress(val):
        if not self.request.called_directly:
            self.update_state(state='PROGRESS', meta={'value': val})

    file = CachedFile.objects.get(id=fileid)
    with language(event.settings.locale), override(event.settings.timezone):
        responses = register_data_exporters.send(event)
        for receiver, response in responses:
            ex = response(event, set_progress)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.'))
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename),
                               ContentFile(data))
                file.save()
    return file.pk
Beispiel #15
0
def multiexport(organizer: Organizer, user: User, fileid: str, provider: str,
                form_data: Dict[str, Any]) -> None:
    file = CachedFile.objects.get(id=fileid)
    with language(user.locale), override(user.timezone):
        allowed_events = user.get_events_with_permission('can_view_orders')

        events = allowed_events.filter(pk__in=form_data.get('events'))
        responses = register_multievent_data_exporters.send(organizer)

        for receiver, response in responses:
            ex = response(events)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.'))
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename),
                               ContentFile(data))
                file.save()
    return file.pk