Пример #1
0
def twisks():
    """Returns all twisks in JSON format. All of them."""
    if request.method == 'GET':
        twisks = Twisk.gql("ORDER BY when DESC LIMIT 20")
        return twisks
    elif request.method == 'POST':
        logging.debug(request.data)
        data = json.loads(request.data)

        twisk = Twisk(
            author=ndb.Key("TwiskUser", data['author']),
            content=data['content']
        )

        twisk.put()

        return twisk
Пример #2
0
def index():
    """Shows all the twisks from the logged-in user feed"""
    twisks = []
    if request.method == "POST":
        twisk = Twisk(
            author=current_user.key,
            content=request.form['content']
        )
        twisk.put()

        # Append the twisk to the feed because the DB probably won't have
        # finished to apply the changes by the time this function has finished
        # executing
        twisks.append(twisk)

        flash("Twisk successfully posted !")

    twisks.extend(current_user.get_feed())
    return render_template("index.html", twisks=twisks, trending_tags=Tag.get_trending())
Пример #3
0
def get_twisk(id):
    """Returns a single twisk, also accept DELETE"""
    twisk = Twisk.get_by_id(int(id))

    if not twisk:
        abort(404)

    if request.method == 'DELETE':
        twisk.delete()
    else:
        return twisk.content
Пример #4
0
def get_tag(tag):
    """Returns all twisks tagged with a given tag"""
    twisks = Twisk.get_tag_feed(tag)
    return twisks
Пример #5
0
def show_tag(tag):
    """Shows all the twisks tagged with the given tag"""
    twisks = Twisk.get_tag_feed(tag)
    return render_template("list_twisks.html", twisks=twisks,
                           no_twisks_message="No twisks with this tag !")
Пример #6
0
def show_user(username):
    """Shows all the twisks posted by a given user"""
    twisks = Twisk.gql("WHERE author = :1 ORDER BY when DESC LIMIT 50",
                       ndb.Key(TwiskUser, username))
    return render_template("list_twisks.html", twisks=twisks)