Ejemplo n.º 1
0
    def new(self):
        user = self.request.user
        form = Form(self.request,
                schema=GallerySchema)
        if form.validate():
            #Generate a name for the new directory. Check if it exists.
            new_directory_name = None
            while not new_directory_name or (DBSession.query(Gallery).filter(Gallery.directory_name == new_directory_name).first()):
                new_directory_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(12))
                gallery_directory = self.request.registry.settings['gallery.directory']
                mkdir(path.join(gallery_directory, new_directory_name))
                mkdir(path.join(gallery_directory, new_directory_name, 'raw'))
                mkdir(path.join(gallery_directory, new_directory_name, 'thumbs'))
                mkdir(path.join(gallery_directory, new_directory_name, 'web'))
                data = form.data.copy()
                data['directory_name'] = new_directory_name
                data['created'] = datetime.now()
                data['creator'] = user.id
                #temporary
                del data['permissions']
            gallery = Gallery(**data)
            DBSession.add(gallery)
            DBSession.flush()
            return HTTPFound(self.request.route_url('gallery_view', id=gallery.id))

        return {'request' : self.request,
                'form_rend' : FormRenderer(form)}
Ejemplo n.º 2
0
    def new(self):

        entry_types = list((i.id, i.description) for i in DBSession.query(EntryType).all())
        entry_types.append(('', ''))

        form = Form(self.request,
                schema=EntrySchema)

        if form.validate():
            data = form.data.copy()
            data['date'] = datetime.now()
            DBSession.add(Entry(**data))
            return HTTPFound(location="/")

        return {'request' : self.request,
                'entry_types' : entry_types,
                'form_rend' : FormRenderer(form)}
Ejemplo n.º 3
0
    def upload(self):
        #--------------
        # ToDO
        # - Better exception handling
        # - Add cleanup when exception occurs
        #   - Remove any files that were uploaded, but be careful about errors
        #       that occur because the file already exists.
        #   - Remove media record if it exists.
        # - Add support for PNG?
        # - Videos?
        #--------------
        #check the directory in the request against the Gallery directory
        user = self.request.user
        gallery = DBSession.query(Gallery).get(self.request.POST['id'])
        if not gallery or gallery.directory_name != self.request.POST['dir']:
            return Response(status_int=409)

        try:
            self.__sanitize_file_name(self.request.POST['Filename'])
            self.__check_file_existance()
            #sys.exit()

            input_file = self.request.POST['Filedata'].file
            self.__save_jpeg(input_file, gallery, 'original', create_symlink = False)
            self.__save_jpeg(input_file, gallery, 'raw')
            self.__save_jpeg(input_file, gallery, 'thumbs', 150)
            self.__save_jpeg(input_file, gallery, 'web', 800)
        except UploadError:
            return Response(status_int=409)
        except:
            return Response(status_int=409)

        #add database record
        medium = Medium(file_name = self.upload_full_name, 
                      created = datetime.now(),
                      creator = user.id,
                      gallery_id = gallery.id,
                      media_type = MediumType.IMAGE)
        DBSession.add(medium)
            
        return Response('ok', status_int=200)