Exemple #1
0
def myProfilePage():
    if not session['logged_in']:
        return 'You are not logged in'
    subscriptions = db.getSubscriptions(session['username'])
    if subscriptions is None:
        return 'You have no subscriptions'

    s_rels, s_com_rels = [], []
    s_item_ids, s_com_item_ids = [], []

    for s in subscriptions:
        s_item_ids.append(s['item'])
        s_rels.extend(
            db.getChildRels(s['item'], {
                'comment_parent': None,
                'time_linked': {
                    '$gte': s['seen']
                },
            }))
        if s['comments']:
            s_com_item_ids.append(s['item'])
            s_com_rels.extend(
                db.getCommentRels(s['item'],
                                  {'time_linked': {
                                      '$gte': s['comment_seen']
                                  }}))

    new_rels = list(
        db.dbcon.relations.Relation.find({
            'parent': {
                '$in': s_item_ids
            },
            'comment_parent': None,
        }).sort('time_linked', -1).limit(10))

    new_com_rels = list(
        db.dbcon.relations.Relation.find({
            'comment_parent': {
                '$in': s_com_item_ids
            }
        }).sort('time_linked', -1).limit(10))

    items = set([db.getItem(rel.parent) for rel in new_rels + s_rels])
    items.update(
        [db.getItem(rel.comment_parent) for rel in new_com_rels + s_com_rels])
    new_dict = {
        's_rels': db.prepareForClient(s_rels),
        's_com_rels': db.prepareForClient(s_com_rels),
        'new_rels': db.prepareForClient(new_rels),
        'new_com_rels': db.prepareForClient(new_com_rels),
        'items': db.prepareForClient(items)
    }
    return render_template('profile.html', nd=new_dict, tab='view-tab')
Exemple #2
0
def viewItem(item_id):
    item_id = ObjectId(item_id)
    if db.getItem(item_id) is None:
        return 'This item does not exist'
    session['current_item'] = item_id
    need = {"parent_items": True, "child_items": True, "child_rels": True}
    item_info = db.getItemInfo(item_id, need, True)
    item_info['comment_rels'] = db.getCommentRels(item_id)
    item_info['comment_items'] = db.prepareForClient(
        [db.getItem(rel['child']) for rel in item_info['comment_rels']])
    item_info['comment_rels'] = db.prepareForClient(item_info['comment_rels'])

    if session['logged_in']:
        db.markSeen(session['username'], item_id, True)

    return render_template('view.html', ii=item_info, tab='view-tab')
Exemple #3
0
def viewItem(item_id):
    item_id = ObjectId(item_id)
    if db.getItem(item_id) is None:
        return 'This item does not exist'
    session['current_item'] = item_id
    need = {
        "parent_items": True,
        "child_items": True,
        "child_rels": True
    }
    item_info = db.getItemInfo(item_id, need, True)
    item_info['comment_rels'] = db.getCommentRels(item_id)
    item_info['comment_items'] = db.prepareForClient([db.getItem(rel['child']) for rel in item_info['comment_rels']])
    item_info['comment_rels'] = db.prepareForClient(item_info['comment_rels'])

    if session['logged_in']:
        db.markSeen(session['username'], item_id, True)

    return render_template('view.html', ii=item_info, tab='view-tab')
Exemple #4
0
def myProfilePage():
    if not session['logged_in']:
        return 'You are not logged in'
    subscriptions = db.getSubscriptions(session['username'])
    if subscriptions is None:
        return 'You have no subscriptions'

    s_rels, s_com_rels = [], []
    s_item_ids, s_com_item_ids = [], []

    for s in subscriptions:
        s_item_ids.append(s['item'])
        s_rels.extend(db.getChildRels(s['item'], {
            'comment_parent': None,
            'time_linked': {'$gte': s['seen']},
        }))
        if s['comments']:
            s_com_item_ids.append(s['item'])
            s_com_rels.extend(db.getCommentRels(s['item'], {
                'time_linked': {'$gte': s['comment_seen']}
            }))

    new_rels = list(db.dbcon.relations.Relation.find({
            'parent': {'$in': s_item_ids},
            'comment_parent': None,
        }).sort('time_linked', -1).limit(10))

    new_com_rels = list(db.dbcon.relations.Relation.find({
            'comment_parent': {'$in': s_com_item_ids}
        }).sort('time_linked', -1).limit(10))

    items = set([db.getItem(rel.parent) for rel in new_rels + s_rels])
    items.update([db.getItem(rel.comment_parent) for rel in new_com_rels + s_com_rels])
    new_dict = {
        's_rels': db.prepareForClient(s_rels),
        's_com_rels': db.prepareForClient(s_com_rels),
        'new_rels': db.prepareForClient(new_rels),
        'new_com_rels': db.prepareForClient(new_com_rels),
        'items': db.prepareForClient(items)
    }
    return render_template('profile.html', nd=new_dict, tab='view-tab')