Beispiel #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
Beispiel #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())