Beispiel #1
0
def mod_img(image, scale=2):
    pd = PageData()
    pd.scale = float(scale)

    try:
        modimg = SiteImage.create(image)
    except NoImage:
        return page_not_found()

    pd.image = modimg

    try:
        sql = 'select uid name from items where uid = %(uid)s;'
        pd.parent = doquery(sql, {"uid": modimg.parent})[0][0]

        sql = 'select * from imgmods where imgid = %(uid)s;'
        result = doquery(sql, {"uid": modimg.uid})

        if result[0][3] is None:
            user = '******'
        else:
            user = user_by_uid(result[0][3])

        pd.moduser = user
    except IndexError:
        return page_not_found()

    pd.ascii = SiteImage.create(modimg.uid).ascii(scale=pd.scale)

    return render_template('mod_img.html', pd=pd)
Beispiel #2
0
def mod_img(image, scale=2):
    pd = PageData()
    pd.scale = float(scale)

    try:
        modimg = SiteImage.create(image)
    except NoImage:
        return page_not_found()

    pd.image = modimg

    try:
        sql = 'select uid name from items where uid = %(uid)s;'
        pd.parent = doquery(sql, {"uid": modimg.parent})[0][0]

        sql = 'select * from imgmods where imgid = %(uid)s;'
        result = doquery(sql, {"uid": modimg.uid})

        if result[0][3] is None:
            user = '******'
        else:
            user = user_by_uid(result[0][3])
        
        pd.moduser = user
    except IndexError:
        return page_not_found()

    pd.ascii = SiteImage.create(modimg.uid).ascii(scale=pd.scale)

    return render_template('mod_img.html', pd=pd)
Beispiel #3
0
def serve_full(img_id):
    try:
        simg = SiteImage.create(img_id)

        resp = make_response(base64.b64decode(simg.image))
        resp.content_type = "image/png"
        return resp
    except (IOError, NoImage):
        return page_not_found(404)
Beispiel #4
0
def serve_full(img_id):
    try:
        simg = SiteImage.create(img_id)

        resp = make_response(base64.b64decode(simg.image))
        resp.content_type = "image/png"
        return resp
    except (IOError, NoImage):
        return page_not_found(404)
Beispiel #5
0
def resize_image(size, img_id):
    try:
        logger.info('resize fallback URL called for imgid {} - {}'.format(img_id, size))
        simg = SiteImage.create(img_id)
        image_string = cStringIO.StringIO(base64.b64decode(simg.image()))
        (x, y) = size.split('x')
        img = resize(image_string, float(x), float(y))
        return serve_pil_image(img)
    except (IOError, NoImage, ValueError):
        return page_not_found()
Beispiel #6
0
def resize_image(size, img_id):
    try:
        logger.info('resize fallback URL called for imgid {} - {}'.format(img_id, size))
        simg = SiteImage.create(img_id)
        image_string = cStringIO.StringIO(base64.b64decode(simg.image()))
        (x, y) = size.split('x')
        img = resize(image_string, float(x), float(y))
        return serve_pil_image(img)
    except (IOError, NoImage, ValueError):
        return page_not_found()
Beispiel #7
0
def show_image(img_id):
    pd = PageData()

    try:
        pd.img = SiteImage.create(img_id)
        pd.title = pd.img.tag
    except NoImage:
        return page_not_found(404)

    return render_template('image.html', pd=pd)
Beispiel #8
0
def show_image(img_id):
    pd = PageData()

    try:
        pd.img = SiteImage.create(img_id)
        pd.title=pd.img.tag
    except NoImage:
        return page_not_found(404)

    return render_template('image.html', pd=pd)
Beispiel #9
0
def flag_image(img_id):
    pd = PageData()

    try:
        flagimg = SiteImage.create(img_id)
        flagimg.flag()
    except NoImage:
        return page_not_found(404)

    flash("The image has been flagged and will be reviewed by a moderator.")

    return redirect_back('index')
Beispiel #10
0
def mod_img_approve(imageid):
    pd = PageData()

    try:
        modimg = SiteImage.create(imageid)
    except NoImage:
        flash('Error during moderation')
        return redirect(url_for('moderate'))

    modimg.approve()

    return redirect(url_for('moderate'))
Beispiel #11
0
def mod_img_approve(imageid):
    pd = PageData()

    try:
        modimg = SiteImage.create(imageid)
    except NoImage:
        flash('Error during moderation')
        return redirect(url_for('moderate'))

    modimg.approve()

    return redirect(url_for('moderate'))
Beispiel #12
0
def flag_image(img_id):
    pd = PageData()

    try:
        flagimg = SiteImage.create(img_id)
        flagimg.flag()
    except NoImage:
        return page_not_found(404)

    flash("The image has been flagged and will be reviewed by a moderator.")

    return redirect_back('index') 
Beispiel #13
0
def reallydelete_image(img_id):
    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
        delimg.delete()
    except NoImage:
        return page_not_found(404)

    pd.title = delimg.tag + " has been deleted"
    pd.accessreq = 10
    pd.conftext = delimg.tag + " has been deleted. I hope you meant to do that."
    pd.conftarget = ""
    pd.conflinktext = ""
    return render_template('confirm.html', pd=pd)
Beispiel #14
0
def serve_full(img_id):
    """
    :URL: /image/<img_id>/full

    Retrieve the raw image and return it.
    """

    try:
        simg = SiteImage.create(img_id)

        resp = make_response(base64.b64decode(simg.image()))
        resp.content_type = "image/jpeg"
        return resp
    except (IOError, NoImage):
        return page_not_found()
Beispiel #15
0
def reallydelete_image(img_id):
    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
        delimg.delete()
    except NoImage:
        return page_not_found(404)

    pd.title = delimg.tag + " has been deleted"
    pd.accessreq = 10
    pd.conftext = delimg.tag + " has been deleted. I hope you meant to do that."
    pd.conftarget = ""
    pd.conflinktext = ""
    return render_template('confirm.html', pd=pd)
Beispiel #16
0
def serve_full(img_id):
    """
    :URL: /image/<img_id>/full

    Retrieve the raw image and return it.
    """

    try:
        simg = SiteImage.create(img_id)

        resp = make_response(base64.b64decode(simg.image()))
        resp.content_type = "image/png"
        return resp
    except (IOError, NoImage):
        return page_not_found()
Beispiel #17
0
def show_image(img_id):
    """
    :URL: /image/<img_id>

    Render a template for viewing an image.
    """

    pd = PageData()

    try:
        pd.img = SiteImage.create(img_id)
        pd.title = pd.img.tag
    except NoImage:
        return page_not_found()

    return render_template('image.html', pd=pd)
Beispiel #18
0
def delete_image(img_id):
    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
    except NoImage:
        return page_not_found(404)

    pd.title = delimg.tag

    pd.accessreq = 10
    pd.conftext = "Deleting image " + delimg.tag
    pd.conftarget = "/image/" + img_id + "/reallydelete"
    pd.conflinktext = "Yup, I'm sure"

    return render_template('confirm.html', pd=pd)
Beispiel #19
0
def delete_image(img_id):
    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
    except NoImage:
        return page_not_found(404)

    pd.title=delimg.tag

    pd.accessreq = 10
    pd.conftext = "Deleting image " + delimg.tag
    pd.conftarget = "/image/" + img_id + "/reallydelete"
    pd.conflinktext = "Yup, I'm sure"

    return render_template('confirm.html', pd=pd)
Beispiel #20
0
def show_image(img_id):
    """
    :URL: /image/<img_id>

    Render a template for viewing an image.
    """

    pd = PageData()

    try:
        pd.img = SiteImage.create(img_id)
        pd.title=pd.img.tag
    except NoImage:
        return page_not_found()

    return render_template('image.html', pd=pd)
Beispiel #21
0
def flag_image(img_id):
    """
    :URL: /image/<img_id>/flag

    Flag an image for review by a moderator.

    .. todo:: Add support for a note and record who flagged it.
    """

    pd = PageData()

    try:
        flagimg = SiteImage.create(img_id)
        flagimg.flag()
    except NoImage:
        return page_not_found()

    flash("The image has been flagged and will be reviewed by a moderator.")

    return redirect_back('index')
Beispiel #22
0
def flag_image(img_id):
    """
    :URL: /image/<img_id>/flag

    Flag an image for review by a moderator.

    .. todo:: Add support for a note and record who flagged it.
    """

    pd = PageData()

    try:
        flagimg = SiteImage.create(img_id)
        flagimg.flag()
    except NoImage:
        return page_not_found()

    flash("The image has been flagged and will be reviewed by a moderator.")

    return redirect_back('index') 
Beispiel #23
0
def delete_image(img_id):
    """
    :URL: /image/<img_id>/delete

    Delete an image
    """

    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
        parent = delimg.parent
        delimg.delete()
    except NoImage:
        return page_not_found()

    flash(delimg.tag + " has been deleted")

    if 'mod' in request.referrer:
        return redirect(url_for('moderate'))
    else:
        return redirect('/item/' + str(parent))
Beispiel #24
0
def delete_image(img_id):
    """
    :URL: /image/<img_id>/delete

    Delete an image
    """

    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
        parent = delimg.parent
        delimg.delete()
    except NoImage:
        return page_not_found()

    flash(delimg.tag + " has been deleted")

    if 'mod' in request.referrer:
        return redirect(url_for('moderate'))
    else:
        return redirect('/item/' + str(parent))
Beispiel #25
0
def facebook_image(img_id):
    try:
        simg = SiteImage.create(img_id)
        image_string = cStringIO.StringIO(base64.b64decode(simg.image()))
        img = Image.open(image_string)

        hsize = img.size[0]
        vsize = img.size[1]
 
        aspect = img.size[0] / img.size[1]
        newvsize = abs(int((aspect - 1.91) * img.size[1]))

        img_size = img.size
        fbimg_size = (img.size[0], newvsize)

        logger.info('fbimage URL called for imgid {} ({}, {}, {}, {}, {}, {})'.format(img_id, hsize, vsize, aspect, newvsize, img_size, fbimg_size))

        fbimg = Image.new("RGBA", fbimg_size, (255, 255, 255, 255))
        fbimg.paste(img, (0, (fbimg_size[1]-img.size[1])/2))

        return serve_pil_image(fbimg)
    except (IOError, NoImage, ValueError):
        return page_not_found()
Beispiel #26
0
def delete_image(img_id):
    """
    :URL: /image/<img_id>/delete

    Redirect to a confirmation page to make sure you want to delete an image.

    .. todo:: This should be re-done in javascript.
    """

    pd = PageData()

    try:
        delimg = SiteImage.create(img_id)
    except NoImage:
        return page_not_found()

    pd.title = delimg.tag

    pd.accessreq = 10
    pd.conftext = "Deleting image " + delimg.tag
    pd.conftarget = "/image/" + img_id + "/reallydelete"
    pd.conflinktext = "Yup, I'm sure"

    return render_template('confirm.html', pd=pd)