예제 #1
0
def dashboard_handler(response):
    uid = util.get_current_user_id(response)
    user_mists = List.find_by_userid(uid)
    recent = sorted(user_mists, key = lambda list: list.id)
    recent.reverse()
    user_id = util.get_current_user_id(response)
    response.write(templater.render("templates/dashboard.html", mists=recent, page_title = "Dashboard", site_title = "M'lists", user_id=user_id, image_fetcher=IMDB.fetch_image))
예제 #2
0
def edit_post_handler(response, list_id):
    # Put this early otherwise all the items are removed!
    if response.get_field("title", "") == "":
        response.redirect("/list/{}/edit?fail=list_title_empty".format(list_id))
        return

    a_list = List.find(list_id)

    user_id = util.get_current_user_id(response)
    if not a_list.author == user_id:
        raise Exception

    a_list.name = response.get_field("title", "")
    a_list.save()

    # delete the old list items before adding the new ones
    for old_item in ListContent.find_by_list_id(list_id):
        ListContent.delete(list_id, old_item.item_order)

    list_items = response.get_arguments("list_item")
    list_items = filter(None, list_items)
    for i, item in enumerate(list_items):
        list_content = ListContent.create(a_list.id, i, item)

    response.redirect('/dashboard')
예제 #3
0
def edit_handler(response, list_id):
    user_id = util.get_current_user_id(response)
    list = List.find(list_id)

    if not list.author == user_id:
        raise Exception

    response.write(templater.render("templates/edit.html", mist = list, page_title = "Edit", site_title = "M'lists", fail=response.get_field('fail', '')))
예제 #4
0
def view_handler(response, list_id):
    list = List.find(list_id)
    try:
        user_id = util.get_current_user_id(response)
    except Exception as e:
        user_id = None

    response.write(templater.render("templates/view_list.html", mist = list, page_title = list.name, site_title = "M'lists", user_id=user_id, image_fetcher=IMDB.fetch_image))
예제 #5
0
def feed_handler(response):
    mists = List.find_all()

    popular = sorted(mists, key = lambda list: list.get_likes())
    popular.reverse()

    recent = sorted(mists, key = lambda list: list.id)
    recent.reverse()

    user_id = util.get_current_user_id(response)
    response.write(templater.render("templates/feed.html", mists=recent, popular=popular, page_title = "Feed", site_title = "M'lists", user_id=user_id))
예제 #6
0
def create_post_handler(response):
    title = response.get_field("title", "")
    if title.strip() == "":
        response.redirect("/create?fail=list_title_empty")
        return
    list_items = response.get_arguments("list_item")
    list_items = filter(None, list_items)
    a_list = List(title, util.get_current_user_id(response))
    a_list.save()
    for i, item in enumerate(list_items):
        list_content = ListContent.create(a_list.id, i, item)

    response.redirect('/dashboard')
예제 #7
0
def delete_handler(response, list_id):
    a_list = List.find(list_id)

    user_id = util.get_current_user_id(response)
    if not a_list.author == user_id:
        raise Exception

    # delete the old list items before adding the new ones
    for old_item in ListContent.find_by_list_id(list_id):
        ListContent.delete(list_id, old_item.item_order)

    a_list.delete()
    response.redirect('/dashboard')