Пример #1
0
def item_format(post):
    # Post format: (user, poster, message, image, time, id)
    data = {}
    data['poster_name'] = matedb.get_data(post[1], 'name')
    data['message'] = post[2]
    if post[3]:
        data['image'] = '<p><img src="' + post[3] + '"></img></p>';
    else:
        data['image'] = ''

    login = authbar.get_current_login()

    if login in matedb.get_all_mates(post[0]) or post[0] == login:
        data['comment_form'] = get_comment_form(post[5])
    else:
        data['comment_form'] = ''

    data['comments'] = ''
    comments = matedb.get_comments(post[5])
    comments.sort(key=lambda item: item[2])
    comments.reverse()
    for comment in comments:
        data['comments'] += comment_format(comment)

    return tempy.substitute('news_item.template', data) 
Пример #2
0
def get_user_data(user):   
    requester = authbar.get_current_login()
    mates = matedb.get_all_mates(user)
    
    data = matedb.get_user_data(user)
    for property in data.keys():
        if private (user, property) and requester not in mates and requester != user:
            data[property] = ''
    
    return data
Пример #3
0
def get_potential_mates(user):
    # Yep, this is O(n^2). It also doesn't cache the result. Scaling
    # is something that happens to other people...

    scores = dict()
    current_mates = db.get_all_mates(user)
    for mate in current_mates:
        for person in db.get_all_mates(mate):
            if person not in current_mates and person != user:
                if person not in scores:
                    scores[person] = 0
                scores[person] += 1

    for course in db.get_all_courses(user):
        for person in db.get_course_members(course):
            if person not in current_mates and person != user:
                if person not in scores:
                    scores[person] = 0
                scores[person] += 1

    return scores
Пример #4
0
def get_control_panel(user):
    panel = '<form method="post"><br />'

    login = authbar.get_current_login()
    
    if user == login:
        panel += '<p class="text-success"><b>Me!</b></p>'
    elif user in db.get_all_mates(login):
        panel += '<p class="text-success"><b>Mates</b></p>'
    elif login:
        panel += '<button class="btn" type="submit">Send Mate Request</button>\n'
        panel += '<input type="hidden" name="action" value="mate">\n'
        panel += '<input type="hidden" name="user" value="' + user + '">\n'

    panel += '</form>'
    return panel
Пример #5
0
def get_news_pane(user): 
    components = dict()
    login = authbar.get_current_login()

    if not privacy.permitted(user, 'news'):
        return ''

    if user in matedb.get_all_mates(login) or user == login:
        components['post_box'] = get_post_box(user)
    else:
        components['post_box'] = ''

    components['news_items'] = ''
    posts = matedb.get_news(user)
    # Sort by time. Could use a namedtuple, or a class. Could do lots of things...
    posts.sort(key=lambda item: item[4])
    posts.reverse()
    for post in posts:
        components['news_items'] += item_format(post)

    return tempy.substitute ('news.template', components)
Пример #6
0
def do_comment(request):
    poster = authbar.get_current_login()
    if 'news_item_id' in request:
        news_item_id = request['news_item_id'].value
    else:
        news_item_id = ''

    if 'message' in request:
        message = request['message'].value
    else:
        message = ''

    # Rip the value out of the resulting tuple, if it exists
    user = matedb.get_owner(news_item_id)
    if user:
        user = user[0]

    if news_item_id and message:
        if poster in matedb.get_all_mates(user) or user == poster:
            matedb.post_comment(news_item_id, poster, safety.make_safe(message))

    return '<script type="text/javascript">window.location.href="unswmate.cgi?who=' + user + '"</script>'
Пример #7
0
def do_news(request):
    poster = authbar.get_current_login()

    if 'user' in request:
        user = request['user'].value
    else:
        user = ''

    if 'message' in request:
        message = request['message'].value
    else:
        message = ''

    if 'image' in request:
        image = request['image'].value
    else:
        image = ''

    if user and message and poster:
        if poster in matedb.get_all_mates(user) or user == poster: 
            matedb.post_news(user, poster, safety.make_safe(message), safety.make_safe(image))

    return '<script type="text/javascript">window.location.href="unswmate.cgi?who=' + user + '"</script>'
Пример #8
0
def permitted (user, property):
    requester = authbar.get_current_login()
    mates = matedb.get_all_mates(user)
    
    return requester == user or requester in mates or not private (user, property)
Пример #9
0
def get_matelist(user):

    if not privacy.permitted (user, 'matelist'):
        return ''

    return userlist.render(db.get_all_mates(user))