Пример #1
0
    def edit(self):
        user = self.request.user
        form = Form(self.request,
                schema=GallerySchema)
        gallery = DBSession.query(Gallery).get(self.request.matchdict['id'])
        roles = DBSession.query(Role).all()
        if form.validate():
            gallery.modified = datetime.now()
            gallery.last_update_by = user.id
            gallery.title = form.data['title']
            gallery.description = form.data['description']
            gallery.gallery_date = form.data['gallery_date']
            #Need to make an object exists validator
            temp_perms = []
            for existing_gallery_permission in gallery.permission:
                DBSession.delete(existing_gallery_permission)
            for r_id in form.data['permissions']:
                temp_perms.append(GalleryPermission(gallery_id = gallery.id,
                    role_id = r_id))
            gallery.permission[:] = temp_perms
                
            return HTTPFound(self.request.route_url('gallery_view', id=gallery.id))

        return {'request' : self.request,
                'gallery' : gallery,
                'roles' : roles,
                'form_rend' : FormRenderer(form)}
Пример #2
0
 def delete(self):
     medium_id = self.request.POST['id']
     medium = DBSession.query(Medium).get(medium_id)
     #build the paths to delete
     phy_path = self.request.registry.settings['gallery.directory']
     sym_path = path.join(self.request.registry.settings['gallery.directory'], medium.gallery.directory_name)
     paths = [path.join(phy_path,'raw',medium.file_name),
             path.join(phy_path,'original',medium.file_name),
             path.join(phy_path,'thumbs',medium.file_name),
             path.join(phy_path,'web',medium.file_name),
             path.join(sym_path,'raw',medium.file_name),
             path.join(sym_path,'thumbs',medium.file_name),
             path.join(sym_path,'web',medium.file_name)]
     for file_path in paths:
         remove(file_path)
     DBSession.delete(medium)
     return Response('ok')
Пример #3
0
    def delete(self):
        gallery_id = self.request.POST['id']
        gallery = DBSession.query(Gallery).get(gallery_id)

        #Check if the gallery is empty
        if len(gallery.media):
            self.request.session.flash('Gallery %s is not empty. Only empty galleries can be deleted' % gallery.title)
            return HTTPFound(location=self.request.route_url('gallery_index'))

        #Get the paths
        directory_path = path.join(self.request.registry.settings['gallery.directory'], gallery.directory_name)
        paths = [path.join(directory_path,'thumbs'),
                path.join(directory_path,'web'),
                path.join(directory_path,'raw'),
                path.join(directory_path)]

        #Delete the paths
        for dir_path in paths:
            rmdir(dir_path)

        #Delete the database record
        DBSession.delete(gallery)
        self.request.session.flash('Gallery %s was deleted' % gallery.title)
        return HTTPFound(location=self.request.route_url('gallery_index'))
Пример #4
0
 def delete(self):
     entry_id = self.request.POST['id']
     entry = DBSession.query(Entry).get(entry_id)
     self.request.session.flash('Deleted "%s" entry' % entry.title)
     DBSession.delete(entry)
     return HTTPFound(location=self.request.route_url('entry_index'))