예제 #1
0
def add_excerpt(md5=None, pos=None):
    """
    Create a new clip
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, pos_end=b, pos_end_x=xb, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_end', 'ref_thing', 'ref_upload'])
    del form.ref_url

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        return jsonify({'message': 'Success! The excerpt has been created.'})
    else:
        pdf = None
        if b - t > 1:
            pdf = url_for("reference.preview", filename='compile/%s.pdf/%s-%s/pdf.pdf' %
                          (m, int(t), int(b)), _external=True)
        return render_template('reference/add_excerpt.html',
                               form=form,
                               pdf=pdf,
                               md5=m,
                               )
예제 #2
0
def add_reference(md5=None, pos=None):
    """
    Create a new reference
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_x', 'ref_pos_end', 'ref_pos_end_x', 'ref_thing', 'ref_upload'])

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        # data to return
        img = reference.preview(800, None)
        href = reference.ref_url
        return jsonify({
            'message': 'Success! The reference has been created.',
            'src': img,
            'href': href,
        })
    else:
        return render_template('reference/add_reference.html',
                               form=form,
                               md5=m,
                               pos=t
                               )
예제 #3
0
def add_reference(md5=None, pos=None):
    """
    Create a new reference
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_x', 'ref_pos_end', 'ref_pos_end_x', 'ref_thing', 'ref_upload'])

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        # data to return
        img = reference.preview(800, None)
        href = reference.ref_url
        return jsonify({
            'message': 'Success! The reference has been created.',
            'src': img,
            'href': href,
        })
    else:
        return render_template('reference/add_reference.html',
                               form=form,
                               md5=m,
                               pos=t
                               )
예제 #4
0
def add_excerpt(md5=None, pos=None):
    """
    Create a new clip
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, pos_end=b, pos_end_x=xb, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_end', 'ref_thing', 'ref_upload'])
    del form.ref_url

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        return jsonify({'message': 'Success! The excerpt has been created.'})
    else:
        pdf = None
        if b - t > 1:
            pdf = url_for("reference.preview", filename='compile/%s.pdf/%s-%s/pdf.pdf' %
                          (m, int(t), int(b)), _external=True)
        return render_template('reference/add_excerpt.html',
                               form=form,
                               pdf=pdf,
                               md5=m,
                               )
예제 #5
0
def add_clip(md5=None, pos=None):
    """
    Create a new clip
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, pos_end=b, pos_end_x=xb, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_end', 'ref_thing', 'ref_upload'])
    del form.ref_url

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        return jsonify({'message': 'Success! The clip has been created.'})
    else:
        pdf = None
        if b - t > 1:
            pdf = url_for("reference.preview", filename='compile/%s.pdf/%s-%s/pdf.pdf' %
                          (m, int(t), int(b)), _external=True)
        img = url_for("reference.preview", filename=u.preview(
            filename='%s-%sx%s.jpg' % (round(t, 3), round(b, 3), 500)), _external=True)
        highlight = url_for("reference.figleaf", md5=m, _anchor="%s,%s-%s,%s" %
                            (round(xt, 2), round(t, 2), round(xb, 2), round(b, 2)), _external=True)
        return render_template('reference/add_clip.html',
                               form=form,
                               img=img,
                               pdf=pdf,
                               md5=m,
                               highlight_url=highlight.replace('%2C', ',')
                               )
예제 #6
0
def add_clip(md5=None, pos=None):
    """
    Create a new clip
    """
    m = request.args.get('md5', None) if md5 is None else md5
    u = Upload.objects.filter(md5=m).first()
    if not u:
        abort(404)
    p = request.args.get('pos', None) if pos is None else pos
    xt, t, xb, b = parse_pos(p)
    # make the form
    form = ReferenceForm(formdata=request.form, pos=t, pos_x=xt, pos_end=b, pos_end_x=xb, exclude=[
                         'creator', 'thing', 'upload', 'ref_pos', 'ref_pos_end', 'ref_thing', 'ref_upload'])
    del form.ref_url

    if form.validate_on_submit():
        reference = Reference()
        form.populate_obj(reference)
        reference.tags = form.tags_proxy.data
        reference.upload = u
        reference.save()
        return jsonify({'message': 'Success! The clip has been created.'})
    else:
        pdf = None
        if b - t > 1:
            pdf = url_for("reference.preview", filename='compile/%s.pdf/%s-%s/pdf.pdf' %
                          (m, int(t), int(b)), _external=True)
        img = url_for("reference.preview", filename=u.preview(
            filename='%s-%sx%s.jpg' % (round(t, 3), round(b, 3), 500)), _external=True)
        highlight = url_for("reference.figleaf", md5=m, _anchor="%s,%s-%s,%s" %
                            (round(xt, 2), round(t, 2), round(xb, 2), round(b, 2)), _external=True)
        return render_template('reference/add_clip.html',
                               form=form,
                               img=img,
                               pdf=pdf,
                               md5=m,
                               highlight_url=highlight.replace('%2C', ',')
                               )
예제 #7
0
 def parse_ref_pos(self, s):
     self.ref_pos_x, self.ref_pos, self.ref_pos_end_x, self.ref_pos_end = parse_pos(s)
예제 #8
0
 def parse_pos(self, s):
     self.pos_x, self.pos, self.pos_end_x, self.pos_end = parse_pos(s)
     print self.pos_x, self.pos, self.pos_end_x, self.pos_end
예제 #9
0
 def parse_ref_pos(self, s):
     self.ref_pos_x, self.ref_pos, self.ref_pos_end_x, self.ref_pos_end = parse_pos(
         s)
예제 #10
0
 def parse_pos(self, s):
     self.pos_x, self.pos, self.pos_end_x, self.pos_end = parse_pos(s)
     print self.pos_x, self.pos, self.pos_end_x, self.pos_end