Beispiel #1
0
def add_cell_text(id):
    cell = SplitFile.get(SplitFile.id == id)
    text = request.form['text']
    Text.create(source=cell, method='manual',
            text=text, user_id=request.form['user_id'])
    flash("Text version '{}' added.".format(text), 'success')

    return redirect_back(url_for('cell', id=id))
Beispiel #2
0
def handle_text(sender, **kwargs): 
    filename = kwargs.get('source_filename')
    md5 = kwargs.get('source_md5')
    method = kwargs.get('method')
    user = kwargs.get('user')
    text = kwargs.get('text')

    source = SplitFile.get(SplitFile.filename == filename, SplitFile.md5 == md5)
    Text.create(source=source, user_id=user, text=text, method=method)
Beispiel #3
0
    def update(self, pk):
        try:
            text = Text.get(Text.id == pk)
        except Text.DoesNotExist:
            text = Text()

        source = SplitFile.get(SplitFile.id == self.data['source'])
        text.source = source
        text.text = self.data['text']
        text.accepted = self.data['accepted']
        text.save()
        return text
Beispiel #4
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()
Beispiel #5
0
def cell(id):
    cell = SplitFile.get(SplitFile.id == id)
    source_file = cell.source.source
    project = source_file.project
    label = "Row {}, Column {}".format(cell.row, cell.column)
    next_view = get_redirect_target()
    breadcrumbs = [
        (project.name, url_for('project', slug=project.slug)),
        (source_file.filename,
         url_for('source_file', id=source_file.id)),
        (cell.source.filename, url_for('image_file', id=cell.source.id)),
        (label, None),
    ]
    return render_template('cell.html', cell=cell, breadcrumbs=breadcrumbs,
        next=next_view)
Beispiel #6
0
    def list(self):
        limit = self.request.args.get('limit', 20)
        text_lt = self.request.args.get('text_lt')
        no_accepted = 'no_accepted' in self.request.args
        random = 'random' in self.request.args

        objects = SplitFile.select(SplitFile,
                fn.Count(Text.id).alias('count')).join(Text,
                        JOIN_LEFT_OUTER).group_by(SplitFile)

        if text_lt is not None:
            text_lt = int(text_lt)
            objects = objects.having(fn.Count(Text.id) < text_lt)
        if no_accepted:
            objects= objects.where(Text.accepted == False)
        if random:
            objects = objects.order_by(fn.Random())

        return objects.limit(limit)
Beispiel #7
0
 def create(self):
     source = SplitFile.get(SplitFile.id == self.data['source'])
     return Text.create(source=source, method='manual',
         text=self.data['text'], user_id=self.data['user_id'])