Ejemplo n.º 1
0
    def _generate(self, template):
        file = os.path.join(self.tempdir, 'test-%s' % template)
        collection = Collection.objects.create(title='Simple Collection', description='Simple collection')
        AccessControl.objects.create(content_object=collection, read=True)
        field = Field.objects.get(name='title', standard__prefix='dc')
        creatorField = Field.objects.get(name='creator', standard__prefix='dc')
        sourceField = Field.objects.get(name='source', standard__prefix='dc')
        presentation = Presentation.objects.create(title='Simple Presentation',
                                                   description='This is a PowerPoint presentation created from a template and populated with data.',
                                                   owner=User.objects.get(username='******'))
        for n in range(1, 11):
            record = Record.objects.create()
            FieldValue.objects.create(record=record, field=field, value='Record %s' % n)
            FieldValue.objects.create(record=record, field=creatorField, value='RecordCreator %s' % n)
            FieldValue.objects.create(record=record, field=sourceField, value='RecordSource %s' % n)

            CollectionItem.objects.create(collection=collection, record=record)
            PresentationItem.objects.create(presentation=presentation, record=record, order=n)
            media = Media.objects.create(record=record, storage=self.storage, mimetype='image/jpeg')
            with open(os.path.join(os.path.dirname(__file__), 'viewers', 'powerpoint', 'test_data', '%02d.jpg' % n), 'rb') as f:
                media.save_file('%02d.jpg' % n, f)

        g = PowerPointGenerator(presentation, AnonymousUser())

        self.assertTrue(g.generate(template, file))
Ejemplo n.º 2
0
def download(request, id, template):

    return_url = request.GET.get('next', reverse('presentation-browse'))
    presentation = Presentation.get_by_id_for_request(id, request)
    if not presentation:
        return HttpResponseRedirect(return_url)

    g = PowerPointGenerator(presentation, request.user)
    filename = os.tempnam()
    try:
        g.generate(template, filename)
        with open(filename, mode="rb") as f:
            response = HttpResponse(
                content=f.read(),
                mimetype=
                'application/vnd.openxmlformats-officedocument.presentationml.presentation'
            )
        response[
            'Content-Disposition'] = 'attachment; filename=%s.pptx' % presentation.name
        return response
    finally:
        try:
            os.unlink(filename)
        except:
            pass
Ejemplo n.º 3
0
    def _generate(self, template):
        file = os.path.join(self.tempdir, 'test-%s' % template)
        collection = Collection.objects.create(title='Simple Collection',
                                               description='Simple collection')
        AccessControl.objects.create(content_object=collection, read=True)
        field = Field.objects.get(name='title', standard__prefix='dc')
        creator_field = Field.objects.get(name='creator',
                                          standard__prefix='dc')
        source_field = Field.objects.get(name='source', standard__prefix='dc')
        presentation = Presentation.objects.create(
            title='Simple Presentation',
            description='This is a PowerPoint presentation created from a '
            'template and populated with data.',
            owner=User.objects.get(username='******'))
        for n in range(1, 11):
            record = Record.objects.create()
            FieldValue.objects.create(record=record,
                                      field=field,
                                      value='Record %s' % n)
            FieldValue.objects.create(record=record,
                                      field=creator_field,
                                      value='RecordCreator %s' % n)
            FieldValue.objects.create(record=record,
                                      field=source_field,
                                      value='RecordSource %s' % n)

            CollectionItem.objects.create(collection=collection, record=record)
            PresentationItem.objects.create(presentation=presentation,
                                            record=record,
                                            order=n)
            media = Media.objects.create(record=record,
                                         storage=self.storage,
                                         mimetype='image/jpeg')
            with open(
                    os.path.join(os.path.dirname(__file__), 'test_data',
                                 '%02d.jpg' % n), 'rb') as f:
                media.save_file('%02d.jpg' % n, f)

        g = PowerPointGenerator(presentation, AnonymousUser())

        self.assertTrue(g.generate(template, file))
Ejemplo n.º 4
0
def download(request, id, template):

    return_url = request.GET.get('next', reverse('presentation-browse'))
    presentation = Presentation.get_by_id_for_request(id, request)
    if not presentation:
        return HttpResponseRedirect(return_url)

    g = PowerPointGenerator(presentation, request.user)
    filename = os.tempnam()
    try:
        g.generate(template, filename)
        with open(filename, mode="rb") as f:
            response = HttpResponse(content=f.read(),
                mimetype='application/vnd.openxmlformats-officedocument.presentationml.presentation')
        response['Content-Disposition'] = 'attachment; filename=%s.pptx' % presentation.name
        return response
    finally:
        try:
            os.unlink(filename)
        except:
            pass