Esempio n. 1
0
def deck_api(deskname):
    if request.method == 'PUT':
        ppt = request.form
        up = {}
        for k, v in comb(ppt).iteritems():
            up['set__{}'.format(k)] = v
        Logic.objects(tid=deskname[:-5]).update(upsert=True, **up)
        return jsonify(message=1)
    else:
        Logic.objects(tid=deskname[:-5]).delete()
        return "", 200
Esempio n. 2
0
def deck_api(deskname):
    if request.method == 'PUT':
        ppt = request.form
        up = {}
        for k, v in comb(ppt).iteritems():
            up['set__{}'.format(k)] = v
        Logic.objects(tid=deskname[:-5]).update(upsert=True, **up)
        return jsonify(message=1)
    else:
        Logic.objects(tid=deskname[:-5]).delete()
        return "", 200
Esempio n. 3
0
def new(username):
    gid = Logic.objects.count() + 1
    uid = Logic.objects(username=username).count() + 1
    if checkuser(username):
        deskname = Logic.objects(username=username).order_by("+pubtime")
        new_desk = 'desk-' + str(uid)
        Logic(title=new_desk, tid=gid, username=username).save()
    else:
        user = User.objects(username=username)
        if len(user):
            gravatar_url = get_gravatar(user)
            return render_template(
                "noyet.html", username=username, img=gravatar_url,
                msg='You do not has edit {} authority yet :('.format(username))
    return redirect('/{}/{}/edit'.format(username, new_desk))
Esempio n. 4
0
def new(username):
    gid = Logic.objects.count() + 1
    uid = Logic.objects(username=username).count() + 1
    if checkuser(username):
        deskname = Logic.objects(username=username).order_by("+pubtime")
        new_desk = 'desk-' + str(uid)
        Logic(title=new_desk, tid=gid, username=username).save()
    else:
        user = User.objects(username=username)
        if len(user):
            gravatar_url = get_gravatar(user)
            return render_template(
                "noyet.html",
                username=username,
                img=gravatar_url,
                msg='You do not has edit {} authority yet :('.format(username))
    return redirect('/{}/{}/edit'.format(username, new_desk))
Esempio n. 5
0
def home(username):
    if checkuser(username):
        decks = Logic.objects(username=username).order_by("+pubtime")
        if not decks:
            return render_template("home.html")
    else:
        decks = Logic.objects(
            username=username, published=True).order_by("+pubtime")
        if not decks:
            user = User.objects(username=username)
            if user:
                gravatar_url = get_gravatar(user)
                return render_template(
                    "noyet.html", username=username, img=gravatar_url,
                    msg='{} hasn"t published any decks yet :'.format(username))
            return render_template("404.html")
    return render_template("home.html", decks=decks, username=username)
Esempio n. 6
0
def home(username):
    if checkuser(username):
        decks = Logic.objects(username=username).order_by("+pubtime")
        if not decks:
            return render_template("home.html")
    else:
        decks = Logic.objects(username=username,
                              published=True).order_by("+pubtime")
        if not decks:
            user = User.objects(username=username)
            if user:
                gravatar_url = get_gravatar(user)
                return render_template(
                    "noyet.html",
                    username=username,
                    img=gravatar_url,
                    msg='{} hasn"t published any decks yet :'.format(username))
            return render_template("404.html")
    return render_template("home.html", decks=decks, username=username)
Esempio n. 7
0
def deck(username, title):
    if checkuser(username):
        deck = Logic.objects(username=username, title=title)
        if not deck:
            return render_template("home.html")
        other_deck = Logic.objects(username=username, title__ne=title)[:4]

    else:
        deck = Logic.objects(username=username, title=title, published=True)
        if not deck:
            user = User.objects(username=username)
            if len(user):
                gravatar_url = get_gravatar(user)
                return render_template(
                    "noyet.html",
                    username=username,
                    img=gravatar_url,
                    msg='{} hasn"t published any decks yet :'.format(username))
            return render_template("404.html")
        other_deck = Logic.objects(username=username,
                                   title__ne=title,
                                   published=True)[:4]
    Logic.objects(username=username, title=title).update_one(inc__views=1)
    deck = deck[0]
    return render_template("deck.html",
                           username=username,
                           data=deck,
                           other=other_deck)
Esempio n. 8
0
def edit(username, title):
    user = User.objects(username=username)
    gravatar_url = get_gravatar(user)
    if not checkuser(username):
        return render_template(
            "noyet.html", username=username, img=gravatar_url,
            msg='You hasn"t operating authority yet :')
    qs = Logic.objects(username=username, title=title)
    if not qs:
        return render_template(
            "noyet.html", username=username, img=gravatar_url,
            msg='{You hasn"t published this deck!')
    return render_template("edit.html", data=qs[0], username=username)
Esempio n. 9
0
def edit(username, title):
    user = User.objects(username=username)
    gravatar_url = get_gravatar(user)
    if not checkuser(username):
        return render_template("noyet.html",
                               username=username,
                               img=gravatar_url,
                               msg='You hasn"t operating authority yet :')
    qs = Logic.objects(username=username, title=title)
    if not qs:
        return render_template("noyet.html",
                               username=username,
                               img=gravatar_url,
                               msg='{You hasn"t published this deck!')
    return render_template("edit.html", data=qs[0], username=username)
Esempio n. 10
0
def deck(username, title):
    if checkuser(username):
        deck = Logic.objects(username=username, title=title)
        if not deck:
            return render_template("home.html")
        other_deck = Logic.objects(username=username, title__ne=title)[:4]

    else:
        deck = Logic.objects(username=username, title=title, published=True)
        if not deck:
            user = User.objects(username=username)
            if len(user):
                gravatar_url = get_gravatar(user)
                return render_template(
                    "noyet.html", username=username, img=gravatar_url,
                    msg='{} hasn"t published any decks yet :'.format(username))
            return render_template("404.html")
        other_deck = Logic.objects(
            username=username, title__ne=title, published=True)[:4]
    Logic.objects(username=username, title=title).update_one(inc__views=1)
    deck = deck[0]
    return render_template("deck.html", username=username, data=deck, other=other_deck)