Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
def serve_avatar(username):
    try:
        user = SiteUser.create(username)
        avatar = user.profile().avatar()

        if not avatar:
            return page_not_found()

        resp = make_response(base64.b64decode(avatar))
        resp.content_type = "image/jpeg"
        return resp
    except (IOError, NoUser):
        return page_not_found()
Exemplo n.º 4
0
def serve_avatar(username):
    try:
        user = SiteUser.create(username)
        avatar = user.profile().avatar()

        if not avatar:
            return page_not_found()

        resp = make_response(base64.b64decode(avatar))
        resp.content_type = "image/png"
        return resp
    except (IOError, NoUser):
        return page_not_found()
Exemplo n.º 5
0
def show_user_profile_collections(username):
    pd = PageData()
    pd.title = "Collections for " + username
    pd.timezones = get_timezones()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    if pd.profileuser.accesslevel == 0:
        return page_not_found()

    return render_template('profile/collections.html', pd=pd)
Exemplo n.º 6
0
def show_user_profile_prefs(username):
    pd = PageData()
    pd.title = "Preferences for " + username
    pd.timezones = get_timezones()

    if not hasattr(pd, 'authuser') or pd.authuser.username != username:
        return page_not_found()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    return render_template('profile/preferences.html', pd=pd)
Exemplo n.º 7
0
def show_user_profile_prefs(username):
    pd = PageData()
    pd.title = "Preferences for " + username
    pd.timezones = get_timezones()

    if not hasattr(pd, 'authuser') or pd.authuser.username != username:
        return page_not_found()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    return render_template('profile/preferences.html', pd=pd)
Exemplo n.º 8
0
def reparent(img_id):
    """
    :URL: /reparent
    :Method: POST

    Reparent an image. 
    """
    pd = PageData()
    if request.method == 'POST':
        newid = request.form['parent']

        try:
            img = core.SiteImage.create(img_id)
            item = core.SiteItem.create(newid)
        except (core.NoItem, core.NoImage):
            return page_not_found()
            

        if img:
            img.reparent(newid)
            return redirect_back('/image/' + str(img))
        else:
            flash('Unable to reparent {}'.format(img_id))

        return redirect_back(url_for('index'))
Exemplo n.º 9
0
def show_item(item_id, edit=None):
    pd = PageData()

    if item_id is 'new':
        return redirect("/item/" + item_id + "/edit")

    try:
        showitem = SiteItem(item_id)

        if edit:
            showitem.old = True
            showitem.description = edit

        showitem.description_html = markdown.markdown(
            escape_html(str(showitem.body(edit))), md_extensions)
    except NoItem:
        return page_not_found(404)

    if 'username' in session:
        try:
            user = SiteUser.create(session['username'])
            pd.iteminfo = user.query_collection(showitem.uid)
        except (NoUser, NoItem):
            pass

    pd.title = showitem.name
    pd.item = showitem

    return render_template('item.html', pd=pd)
Exemplo n.º 10
0
def pm(username):
    pd = PageData()

    try:
        pd.recipient = SiteUser.create(username)
    except (NoItem, NoUser):
        return page_not_found(404)

    if 'username' in session:
        if request.method == 'POST':
            message = request.form['body']
            subject = request.form['subject']

            if 'parent' in request.form:
                parent = deobfuscate(request.form['parent'])
            else:
                parent = None

            if message and subject:
                messageid = send_pm(pd.authuser.uid, pd.recipient.uid, subject, message, messagestatus['unread_pm'], parent)

                if messageid:
                    flash('Message sent!')
                    if parent:
                        return redirect_back('/user/' + username + '/pm')
                    else:
                        return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate((messageid)))

            else:
# TODO re-fill form
                flash('No message or subject')
                return redirect_back('/user/' + username + '/pm')

    return render_template('sendpm.html', pd=pd)
Exemplo n.º 11
0
def edititem(item_id=None):
    pd = PageData()
    if request.method == 'POST':
        if 'username' in session:
            userid = pd.authuser.uid
        else:
            userid = 0 

        if 'desc' in request.form:
            if request.form['name'] == '':
                flash('No name for this item?')
                return redirect_back("/item/new")

            try:
                item = SiteItem.create(request.form['uid'])

                item_id = uid_by_item(request.form['name'])
                if not item_id or item_id == int(request.form['uid']):
                    uid = request.form['uid']
                    ip = request.remote_addr

                    if item.name != request.form['name']:
                        item.name = request.form['name']
                        item.update()

                    old = core.digest(item.body())
                    new = core.digest(request.form['desc'])

                    # silently discard null edits
                    if old != new:
                        new_edit(uid, request.form['desc'], userid, ip)
                        logger.info('item {} edited by user {} ({})'.format(uid, userid, ip))
                    else:
                        logger.info('null edit discarded for item {} by user {} ({})'.format(uid, userid, ip))

                    return redirect('/item/' + str(uid))
                else:
                    flash(item.name + " already exists!")
                    item_id = request.form['uid']
            except NoItem:
                if uid_by_item(request.form['name']):
                    flash(request.form['name'] + " already exists!")
                    return redirect_back("/item/new")

                uid = new_item(request.form['name'], request.form['desc'], userid, request.remote_addr)
                return redirect('/item/' + str(uid))

    if item_id:
        try:
            pd.item = SiteItem.create(item_id)
        except NoItem:
            return page_not_found()
     
        pd.title="Editing: %s" % pd.item.name
    else:
        pd.title="Editing: New Item"

    return render_template('edititem.html', pd=pd)
Exemplo n.º 12
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)
Exemplo n.º 13
0
def untag_item(item_id, tag_ob):
    try:
        item = SiteItem.create(item_id)
    except NoItem:
        return page_not_found()

    pd = PageData()
    item.remove_tag(pd.decode(tag_ob))
    return redirect('/item/' + str(item.uid))
Exemplo n.º 14
0
def untag_item(item_id, tag_ob):
    try:
        item = SiteItem.create(item_id)
    except NoItem: 
        return page_not_found()

    pd = PageData()
    item.remove_tag(pd.decode(tag_ob))
    return redirect('/item/' + str(item.uid))
Exemplo n.º 15
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)
Exemplo n.º 16
0
def itemaction(item_id, action):
    """
    :URL: /item/<item_id>/<action>
    :Methods: GET, POST

    Update or query the logged in user's record for an item.

    If a POST request is received then the current record is returned instead of a redirect back to the previous page.
    Setting the accept:application/json header will always return JSON regardless of request type.

    :Allowed actions:
     * 'status'    - Return the item's current status
     * 'have'      - Mark an item as part of the user's collection
     * 'donthave'  - Remove the item from the user's collection
     * 'show'      - If the item is in the user's collection mark it as visible to others
     * 'hide'      - If the item is in the user's collection hide it from others
     * 'willtrade' - Mark the item as available for trade
     * 'wonttrade' - Don't show this item as available for trade
     * 'want'      - Add this item to the user's want list
     * 'dontwant ' - Remove this item from the user's want list

    :Sample record:

    .. code-block:: javascript

        {"hidden": 1, "want": 0, "have": 1, "willtrade": 0}
    """

    try:
        user = SiteUser.create(session['username'])
    except (NoUser, KeyError):
        user = None

    def get_record():
        return json.dumps(user.query_collection(item_id).values())

    if action == 'status':
        if not user:
            return '{}'
        else:
            return get_record()

    if user:
        try: 
            ownwant(item_id, user.uid, actions[action])
        except (NoItem, KeyError, ValueError):
            return page_not_found()

        if request.method == 'POST' or request_wants_json():
            return get_record()
    else:
        if request_wants_json():
            return '{}', 400
        flash('You must be logged in to have a collection')

    return redirect_back('/item/' + item_id)
Exemplo n.º 17
0
def itemaction(item_id, action):
    """
    :URL: /item/<item_id>/<action>
    :Methods: GET, POST

    Update or query the logged in user's record for an item.

    If a POST request is received then the current record is returned instead of a redirect back to the previous page.
    Setting the accept:application/json header will always return JSON regardless of request type.

    :Allowed actions:
     * 'status'    - Return the item's current status
     * 'have'      - Mark an item as part of the user's collection
     * 'donthave'  - Remove the item from the user's collection
     * 'show'      - If the item is in the user's collection mark it as visible to others
     * 'hide'      - If the item is in the user's collection hide it from others
     * 'willtrade' - Mark the item as available for trade
     * 'wonttrade' - Don't show this item as available for trade
     * 'want'      - Add this item to the user's want list
     * 'dontwant ' - Remove this item from the user's want list

    :Sample record:

    .. code-block:: javascript

        {"hidden": 1, "want": 0, "have": 1, "willtrade": 0}
    """

    try:
        user = SiteUser.create(session['username'])
    except (NoUser, KeyError):
        user = None

    def get_record():
        return json.dumps(user.query_collection(item_id).values())

    if action == 'status':
        if not user:
            return '{}'
        else:
            return get_record()

    if user:
        try: 
            ownwant(item_id, user.uid, actions[action])
        except (NoItem, KeyError):
            return page_not_found()

        if request.method == 'POST' or request_wants_json():
            return get_record()
    else:
        if request_wants_json():
            return '{}', 400
        flash('You must be logged in to have a collection')

    return redirect_back('/item/' + item_id)
Exemplo n.º 18
0
def show_user_profile(username):
    pd = PageData()
    pd.title = "Profile for " + username

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    return render_template('profile/main.html', pd=pd)
Exemplo n.º 19
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)
Exemplo n.º 20
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()
Exemplo n.º 21
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()
Exemplo n.º 22
0
def show_user_profile(username):
    pd = PageData()
    pd.title = "Profile for " + username

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    return render_template('profile/main.html', pd=pd)
Exemplo n.º 23
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)
Exemplo n.º 24
0
def show_user_profile_collections(username):
    pd = PageData()
    pd.title = "Collections for " + username
    pd.timezones = get_timezones()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found()

    return render_template('profile/collections.html', pd=pd)
Exemplo n.º 25
0
def show_user_profile(username):
    pd = PageData()
    pd.title = "Profile for " + username
    pd.timezones = get_timezones()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found(404)

    return render_template('profile.html', pd=pd)
Exemplo n.º 26
0
def show_user_profile(username):
    pd = PageData()
    pd.title = "Profile for " + username
    pd.timezones = get_timezones()

    try:
        pd.profileuser = SiteUser.create(username)
    except NoUser:
        return page_not_found(404)

    return render_template('profile.html', pd=pd)
Exemplo n.º 27
0
def accepttradeitem(username, messageid, action, item=None):
    pd = PageData()

    if not pd.authuser.username == username:
        return page_not_found(404)

    if 'username' in session:
        if item:
            try:
                ti = TradeItem(item)
            except NoItem:
                return page_not_found(404)

            if action == "accept":
                ti.accept()
            elif action == "reject":
                ti.reject()
            else:
                return page_not_found(404)
        else:
            try:
                t = TradeMessage.create(deobfuscate(messageid))
            except NoItem:
                return page_not_found(404)

            if action == "settle":
                t.settle()
            elif action == "cancel":
                t.cancel()
            elif action == "reject":
                t.reject()
            elif action == "reopen":
                t.unread()
                t.read()
            elif action == "add":
                flash('Coming soon...')
                return redirect_back('/')
            else:
                return page_not_found(404)

    return redirect_back('index')
Exemplo n.º 28
0
def accepttradeitem(username, messageid, action, item=None):
    pd = PageData()

    if not pd.authuser.username == username:
        return page_not_found(404)

    if 'username' in session:
        if item:
            try:
                ti = TradeItem(item)
            except NoItem:
                return page_not_found(404)

            if action == "accept":
                ti.accept()
            elif action == "reject":
                ti.reject()
            else:
                return page_not_found(404)
        else:
            try:
                t = TradeMessage.create(deobfuscate(messageid))
            except NoItem:
                return page_not_found(404)

            if action == "settle":
                t.settle()
            elif action == "cancel":
                t.cancel()
            elif action == "reject":
                t.reject()
            elif action == "reopen":
                t.unread()
                t.read()
            elif action == "add":
                flash('Coming soon...')
                return redirect_back('/')
            else:
                return page_not_found(404)

    return redirect_back('index')
Exemplo n.º 29
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')
Exemplo n.º 30
0
def reallydelete_item(item_id):
    try:
        delitem = SiteItem.create(item_id)
    except NoItem: 
        return page_not_found()

    delitem.delete()

    if request_wants_json():
        return '{}'
    else:
        return redirect(url_for('index'))
Exemplo n.º 31
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') 
Exemplo n.º 32
0
def ownwant(item_id, values):
    try:
        moditem = SiteItem(item_id)
    except NoItem:
        return page_not_found(404)

    try:
        user = SiteUser.create(session['username'])
    except (NoUser, KeyError):
        flash('You must be logged in to add items to a collection')
        return redirect('newuser')

    OwnWant(item_id, user.uid).update(values)
Exemplo n.º 33
0
def edititem(item_id=None):
    pd = PageData()
    if request.method == 'POST':
        if 'username' in session:
            userid = pd.authuser.uid
        else:
            userid = 0

        if 'desc' in request.form:
            if request.form['name'] == '':
                flash('No name for this item?')
                return redirect_back("/item/new")

            try:
                item = SiteItem.create(request.form['uid'])

                item_id = uid_by_item(request.form['name'])
                if not item_id or item_id == int(request.form['uid']):
                    item.name = request.form['name']
                    item.update()

                    # todo: check for null edits
                    new_edit(request.form['uid'], request.form['desc'], userid,
                             request.remote_addr)

                    uid = request.form['uid']
                    flash('Edited item!')
                    return redirect('/item/' + str(uid))
                else:
                    flash(item.name + " already exists!")
                    item_id = request.form['uid']
            except NoItem:
                if uid_by_item(request.form['name']):
                    flash(request.form['name'] + " already exists!")
                    return redirect_back("/item/new")

                uid = new_item(request.form['name'], request.form['desc'],
                               userid, request.remote_addr)
                return redirect('/item/' + str(uid))

    if item_id:
        try:
            pd.item = SiteItem.create(item_id)
        except NoItem:
            return page_not_found()

        pd.title = "Editing: %s" % pd.item.name
    else:
        pd.title = "Editing: New Item"

    return render_template('edititem.html', pd=pd)
Exemplo n.º 34
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)
Exemplo n.º 35
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)
Exemplo n.º 36
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()
Exemplo n.º 37
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()
Exemplo n.º 38
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)
Exemplo n.º 39
0
def revert_item_edit(item_id, edit):
    pd = PageData()

    try:
        item = SiteItem.create(item_id)

        item.old = True
        item.edit = edit
    except NoItem:
        return page_not_found()

    pd.title="Reverting: " + item.name
    pd.item_name = item.name
    pd.item = item

    return render_template('edititem.html', pd=pd)
Exemplo n.º 40
0
def revert_item_edit(item_id, edit):
    pd = PageData()

    try:
        item = SiteItem.create(item_id)

        item.old = True
        item.edit = edit
    except NoItem:
        return page_not_found()

    pd.title = "Reverting: " + item.name
    pd.item_name = item.name
    pd.item = item

    return render_template('edititem.html', pd=pd)
Exemplo n.º 41
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)
Exemplo n.º 42
0
def delete_item(item_id):
    try:
        delitem = SiteItem.create(item_id)
    except NoItem:
        return page_not_found()

    pd = PageData()

    pd.title = delitem.name

    pd.accessreq = 255
    pd.conftext = "Deleting item " + delitem.name + ". This will also delete all trades but not the associated PMs. If this item has open trades you are going to confuse people. Are you really sure you want to do this?"
    pd.conftarget = "/item/" + str(delitem.uid) + "/reallydelete"
    pd.conflinktext = "Yup, I'm sure"

    return render_template('confirm.html', pd=pd)
Exemplo n.º 43
0
def delete_item(item_id):
    try:
        delitem = SiteItem.create(item_id)
    except NoItem: 
        return page_not_found()

    pd = PageData()

    pd.title=delitem.name

    pd.accessreq = 255
    pd.conftext =  "Items may take some time to disappear from the indexes."
    pd.conftarget = "/item/" + str(delitem.uid) + "/reallydelete"
    pd.conflinktext = "I want to delete '{}' and accept the consequences of this action.".format(delitem.name)

    return render_template('confirm.html', pd=pd)
Exemplo n.º 44
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)
Exemplo n.º 45
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)
Exemplo n.º 46
0
def reallydelete_item(item_id):
    try:
        delitem = SiteItem(item_id)
    except NoItem:
        return page_not_found(404)

    pd = PageData()

    pd.title = delitem.name + " has been deleted"

    delitem.delete()

    pd.accessreq = 255
    pd.conftext = delitem.name + " has been deleted. I hope you meant to do that."
    pd.conftarget = ""
    pd.conflinktext = ""
    return render_template('confirm.html', pd=pd)
Exemplo n.º 47
0
def tagitem():
    pd = PageData()
    if request.method == 'POST':
        if 'username' in session:
            userid = pd.authuser.uid
        else:
            userid = 0

        if 'tag' in request.form:
            if request.form['tag'] == '':
                return redirect_back('index')

            try:
                item = SiteItem.create(request.form['uid'])
                item.add_tag(request.form['tag'][:64])
                return redirect('/item/' + str(item.uid))
            except NoItem:
                return page_not_found()
Exemplo n.º 48
0
def tagitem():
    pd = PageData()
    if request.method == 'POST':
        if 'username' in session:
            userid = pd.authuser.uid
        else:
            userid = 0 

        if 'tag' in request.form:
            if request.form['tag'] == '':
                return redirect_back('index')

            try:
                item = SiteItem.create(request.form['uid'])
                item.add_tag(request.form['tag'][:64])
                return redirect('/item/' + str(item.uid))
            except NoItem:
                return page_not_found()
Exemplo n.º 49
0
def mod_tag(tag):
    pd = PageData()

    pd.tree = Tags()
    try:
        pd.tag = pd.decode(tag)

        all_tags = pd.tree.all_children_of(pd.tree.root)

        # remove children and ourself from the reparent list
        subtract = pd.tree.all_children_of(pd.tag)
        subtract.append(pd.tag)
        pd.reparent_list = list(set(all_tags) ^ set(subtract))

        pd.root_tree = pd.tree.draw_tree(pd.tree.root)

        return render_template('tag.html', pd=pd)
    except TypeError:
        return page_not_found(404)
Exemplo n.º 50
0
def mod_tag(tag):
    pd = PageData()

    pd.tree = Tags()
    try:
        pd.tag = pd.decode(tag)

        all_tags = pd.tree.all_children_of(pd.tree.root)

        # remove children and ourself from the reparent list
        subtract = pd.tree.all_children_of(pd.tag)
        subtract.append(pd.tag)
        pd.reparent_list = list(set(all_tags) ^ set(subtract))

        pd.root_tree = pd.tree.draw_tree(pd.tree.root)

        return render_template('tag.html', pd=pd)
    except TypeError:
        return page_not_found()
Exemplo n.º 51
0
def pm(username):
    pd = PageData()

    try:
        pmuser = SiteUser.create(username)
    except (NoItem, NoUser):
        return page_not_found()

    if 'username' in session:
        if session['username'] == username:
            pd.profileuser = pmuser
            return render_template('profile/messages.html', pd=pd)
        else:
            pd.recipient = pmuser

        if request.method == 'POST':
            message = request.form['body']
            subject = request.form['subject']

            if 'parent' in request.form:
                parent = deobfuscate(request.form['parent'])
            else:
                parent = None

            if message and subject:
                messageid = send_pm(pd.authuser.uid, pd.recipient.uid, subject,
                                    message, None, parent)

                if messageid:
                    flash('Message sent!')
                    if parent:
                        return redirect_back('/user/' + username + '/pm')
                    else:
                        return redirect('/user/' + pd.authuser.username +
                                        '/pm/' + obfuscate((messageid)))

            else:
                # TODO re-fill form
                flash('No message or subject')
                return redirect_back('/user/' + username + '/pm')

    return render_template('sendpm.html', pd=pd)
Exemplo n.º 52
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')
Exemplo n.º 53
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') 
Exemplo n.º 54
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))
Exemplo n.º 55
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))
Exemplo n.º 56
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()
Exemplo n.º 57
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)
Exemplo n.º 58
0
def trade(username, itemid=None, messageid=None):
    pd = PageData()

    status = messagestatus['unread_trade']

    try:
        pd.tradeuser = SiteUser.create(username)
    except NoUser:
        return page_not_found(404)

    if 'username' in session:
        if request.method == 'POST':
            authuseritems = request.form.getlist('authuseritem')
            tradeuseritems = request.form.getlist('tradeuseritem')
            message = request.form['body']
            subject = request.form['subject']

            if 'parent' in request.form:
                parent = request.form['parent']
            else:
                if messageid:
                    parent = core.deobfuscate(messageid)
                    messageid = parent
                    status = messagestatus['unread_pm']
                    flashmsg = 'Message sent!'
                else:
                    parent = None
                    messageid = None
                    flashmsg = 'Submitted trade request!'

            if message and subject:
                pmid = send_pm(pd.authuser.uid, pd.tradeuser.uid, subject, message, status, parent)

                if not messageid:
                    messageid = pmid
                elif tradeuseritems or authuseritems:
                    flashmsg = 'Trade updated'

                for item in authuseritems:
                    add_tradeitem(item, messageid, pd.authuser.uid, tradeitemstatus['accepted'])

                for item in tradeuseritems:
                    add_tradeitem(item, messageid, pd.tradeuser.uid, tradeitemstatus['unmarked'])

                flash(flashmsg)
                return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate(messageid))

            if message == '':
                flash('Please add a message')

            return redirect_back('/')

    pd.title = "Trading with {}".format(username)

    try:
        pd.authuser.ownwant = pd.authuser.query_collection(itemid)
    except AttributeError:
        pass

    try:
        pd.tradeuser.ownwant = pd.tradeuser.query_collection(itemid)
        pd.item = SiteItem(itemid)
    except NoItem:
        if messageid:
            try:
                pd.trademessage = TradeMessage.create(deobfuscate(messageid))
            except NoItem:
                return page_not_found(404)
        else:
            return page_not_found(404)

    return render_template('trade.html', pd=pd)
Exemplo n.º 59
0
def edit_image(img_id):
    """
    :URL: /image/<img_id>/edit

    Very basic image editor. Applies a list of operations to an image
    and either presents a preview back to the user or saves it to the
    database as a new image.
    """

    pd = PageData()
    min_size = 200

    try:
        img = SiteImageEditor(img_id)
    except NoImage:
        return page_not_found()

    preview = request.args.get('preview')
    save = request.args.get('save')

    pd.img = img
    pd.ops = ''
    pd.num_ops = 0

    for op in range(1,20):
        command = request.args.get('op{}'.format(op))
        if command:
            if command == 'rotate':
                degrees = request.args.get('op{}_degrees'.format(op))

                try:
                    degrees = int(degrees)
                except:
                    return page_not_found()

                img.rotate(degrees)
                pd.ops = "{}&op{}=rotate&op{}_degrees={}".format(pd.ops, op, op, degrees)
                pd.num_ops = op
            elif command == 'crop':
                x1 = request.args.get('op{}_x1'.format(op))
                y1 = request.args.get('op{}_y1'.format(op))
                x2 = request.args.get('op{}_x2'.format(op))
                y2 = request.args.get('op{}_y2'.format(op))

                try:
                    x1 = int(x1)
                    y1 = int(y1)
                    x2 = int(x2)
                    y2 = int(y2)
                except:
                    return page_not_found()

                new_width = x2 - x1
                new_height = y2 - y1

                if new_width < min_size:
                    flash("The selection is too narrow, please make a larger selection. If your image is below {} pixels in width you will not be able to crop it.".format(min_size))
                    return redirect_back(url_for('index'))
                if new_height < min_size:
                    flash("The selection is too short, please make a larger selection. If your image is below {} pixels in width you will not be able to crop it.".format(min_size))
                    return redirect_back(url_for('index'))

                img.crop(x1, y1, x2, y2)
                pd.ops = "{base}&op{op}=crop&op{op}_x1={x1}&op{op}_y1={y1}&op{op}_x2={x2}&op{op}_y2={y2}".format(base=pd.ops, op=op, x1=x1, y1=y1, x2=x2, y2=y2)
                pd.num_ops = op
            else:
                return page_not_found()
 
    if preview == 'true':
        return send_file(img.preview(), mimetype='image/jpeg')

    if save:
        if 'username' in session:
            userid = pd.authuser.uid
        else:
            userid = None

        new_img = img.save(userid, request.remote_addr)
        return redirect('/image/' + str(new_img))

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