Example #1
0
    def list(self):
        objs = super(TextResource, self).list()

        image_file_id = self.request.args.get('image_file')
        if image_file_id:
            image_file = ImageFile.get(ImageFile.id == image_file_id)
            objs = objs.join(SplitFile).where(SplitFile.source == image_file)

        return objs
Example #2
0
def image_file(id):
    image_file = ImageFile.get(ImageFile.id == id)
    project = image_file.source.project
    breadcrumbs = [
        (project.name, url_for('project', slug=project.slug)),
        (image_file.source.filename,
         url_for('source_file', id=image_file.source.id)),
        (image_file.filename, None),
    ]
    return render_template('image_file.html', image_file=image_file,
        breadcrumbs=breadcrumbs)
Example #3
0
def image_split(sender, **kwargs): 
    input_md5 = kwargs.get('input_md5')
    filename = kwargs.get('filename')
    md5 = kwargs.get('md5')
    column = kwargs.get('column')
    row = kwargs.get('row')
    left = kwargs.get('left')
    upper = kwargs.get('upper')
    right = kwargs.get('right')
    lower = kwargs.get('lower')

    source = ImageFile.get(ImageFile.md5 == input_md5)
    split = SplitFile.create(filename=filename, md5=md5, source=source,
        row=row, column=column, left=left, upper=upper, right=right, lower=lower)
    split.create_png()
Example #4
0
def image_extracted(sender, input_filename, input_md5, filename,
        md5, page, project=None):
    try:
        project_obj = Project.get(Project.slug == project)
    except Project.DoesNotExist:
        project_obj = None

    try:
        input_file = SourceFile.get(SourceFile.md5 == input_md5, SourceFile.project == project_obj) 
    except SourceFile.DoesNotExist:
        input_file = SourceFile.create(md5=input_md5, filename=input_filename,
            project=project_obj)

    image = ImageFile.create(md5=md5, filename=filename,
        source=input_file, page=page)
    image.create_png()
    image.create_thumbnail_png()
Example #5
0
def image_csv(id):
    image_file = ImageFile.get(ImageFile.id == id)
    csvfile = StringIO()
    writer = csv.writer(csvfile)

    def generate():
        for row in image_file.get_data():
            writer.writerow(row)
            csvfile.seek(0)
            data = csvfile.read()
            csvfile.seek(0)
            csvfile.truncate()
            yield data

    base, ext = os.path.splitext(image_file.filename)
    csv_filename = "{}{}".format(base, ".csv") 
    resp = Response(generate(), mimetype='text/csv')
    resp.headers["Content-Disposition"] = "attachment; filename={}".format(csv_filename)
   
    return resp
Example #6
0
def handle_columns(sender, **kwargs):
    md5 = kwargs.get('md5')
    columns = kwargs.get('columns')
    image = ImageFile.get(ImageFile.md5 == md5)
    image.num_columns = columns
    image.save()
Example #7
0
def handle_rows(sender, **kwargs):
    md5 = kwargs.get('md5')
    rows = kwargs.get('rows')
    image = ImageFile.get(ImageFile.md5 == md5)
    image.num_rows = rows
    image.save()