Example #1
0
def populate_images(imagedir="images"):
    session = DBSession()
    from trumpet.managers.admin.images import ImageManager

    im = ImageManager(session)
    import os

    for basename in os.listdir(imagedir):
        filename = os.path.join(imagedir, basename)
        imgfile = file(filename)
        im.add_image(basename, imgfile)
Example #2
0
def populate_images(imagedir='images'):
    import os
    if not os.path.isdir(imagedir):
        print "No Images to populate"
        return
    session = DBSession()
    from trumpet.managers.admin.images import ImageManager
    im = ImageManager(session)
    for basename in os.listdir(imagedir):
        filename = os.path.join(imagedir, basename)
        imgfile = file(filename)
        im.add_image(basename, imgfile)
Example #3
0
class ImageManagementViewer(AdminViewer):
    def __init__(self, request):
        super(ImageManagementViewer, self).__init__(request)
        prepare_main_data(self.request)
        self.images = ImageManager(self.request.db)
        self._dispatch_table = dict(
            list=self.list_images,
            add=self.add_image,
            delete=self.delete_image,
            confirmdelete=self.confirm_delete_image,)
        self.context = self.request.matchdict['context']
        self._view = self.context
        self.dispatch()
        
    def list_images(self):
        images = self.images.images_query().all()
        template = 'trumpet:templates/image-list.mako'
        env = dict(images=images)
        content = render(template, env, request=self.request)
        self.layout.content = content
        self.layout.resources.manage_images.need()

    def add_image(self):
        schema = AddImageSchema()
        form = deform.Form(schema, buttons=('submit',))
        self.layout.resources.deform_auto_need(form)
        if 'submit' in self.request.POST:
            controls = self.request.POST.items()
            self.layout.subheader = 'Image Submitted'
            try:
                data = form.validate(controls)
            except deform.ValidationFailure, e:
                self.layout.content = e.render()
                return
            upload = data['upload']
            fp = data['upload']['fp']
            name = data['name']
            image = self.images.add_image(name, fp)
            url = self.request.route_url('blob', filetype='thumb',
                                         id=image.id)
            content = '<img id="%d" src="%s"><br>' % (image.id, url)
            content += '<p>Image %s added.</p>' % image.name
            self.layout.content = content
            return
        rendered = form.render()
        self.layout.content = rendered
        self.layout.subheader = 'Upload an Image'
Example #4
0
 def __init__(self, request):
     super(ImageManagementViewer, self).__init__(request)
     prepare_main_data(self.request)
     self.images = ImageManager(self.request.db)
     self._dispatch_table = dict(
         list=self.list_images,
         add=self.add_image,
         delete=self.delete_image,
         confirmdelete=self.confirm_delete_image,)
     self.context = self.request.matchdict['context']
     self._view = self.context
     self.dispatch()
Example #5
0
 def __init__(self, request):
     super(SiteTextViewer, self).__init__(request)
     #prepare_main_data(self.request)
     self.images = ImageManager(self.request.db)
     self._dispatch_table = dict(
         list=self.list_site_text,
         add=self.create_site_text,
         delete=self.main,
         confirmdelete=self.main,
         viewentry=self.view_site_text,
         editentry=self.edit_site_text,
         create=self.create_site_text,
         download_wiki_archive=self.download_wiki_archive,
     )
     self.context = self.request.matchdict['context']
     self._view = self.context
     self.dispatch()