Пример #1
0
def vote(request):
    choice = request.GET.get('choice', None)
    id = request.GET.get('id', None)
    who = users.get_current_user()
    if not who:
        who = users.User(email=User.all().get().email)

    jot = Jot.get(id)
    meta = Meta.get()
    
    if choice == 'y':
        jot.like = jot.like + 1
        if jot.like > meta.max_like:
            meta.max_like = jot.like
    elif choice == 'n':
        jot.unlike = jot.unlike + 1
        if jot.unlike > meta.max_unlike:
            meta.max_unlike = jot.unlike
    meta.save()
    unlike = standard_ratio(meta.max_unlike, 0, jot.unlike)
    like = standard_ratio(meta.max_like, 0, jot.like)
    vote = Vote(who=who, jot=jot)
    jot.save()
    vote.put()
    return render_to_response('vote_stat.html', {'jot':{'like':like, 'unlike':unlike}}, context_instance=RequestContext(request))
Пример #2
0
def edit(request, key):
    mode = request.GET.get('mode', None)
    user = users.get_current_user()
    try:
        jot = Jot.get(key)
    except Exception, e:
        raise Httindexp404
Пример #3
0
def comment(request, key):
    what = request.POST.get('what', None)
    #google user
    user = users.get_current_user()
    #django user
    user = User.all().filter('user = ', user).get()
    try:
        jot = Jot.get(key)
    except Exception, e:
        raise Http404
Пример #4
0
def view(request, key):
    try:
        page = int(request.GET['page'])
    except:
        page = 1
    paginator = utils.createPaginator(page)
    
    try:
        jot = Jot.get(key)
        jot.read_num += 1
        jot.put()
    except Exception, e:
        raise Http404
Пример #5
0
def post(request):
    title = request.POST.get('title', None)
    what = request.POST.get('what', None)
    user = users.get_current_user()
    #django user
    user = User.all().filter('user = '******'tags', None)
    tags = tags.split(",")
    edit_key = request.POST.get('edit-key', None)
    if title and what:
        if edit_key:
            jot = Jot.get(edit_key)
            jot.title = title
            jot.what = what
            jot.tags = tags
            jot.put()
        else:
            jot = Jot(title=title, what=what, tags=tags, who=user)
            jot.create()
    return HttpResponseRedirect("/")
Пример #6
0
def publish(request):
    mode = request.GET.get('mode', None)
    return render_to_response('publish.html', {'mode':mode}, context_instance=RequestContext(request))

@login_required
def delete(request, key):
    user = users.get_current_user()
    type = request.GET.get('type')
    if type == 'comment':
        try:
            model = Comment.get(key)
        except Exception, e:
            raise Http404
    else:
        try:
            model = Jot.get(key)
        except Exception, e:
            raise Http404
    if not (model.who.user == user):
        return HttpResponseRedirect('/')
    model.remove()
    return HttpResponseRedirect('/')

@login_required
def comment(request, key):
    what = request.POST.get('what', None)
    #google user
    user = users.get_current_user()
    #django user
    user = User.all().filter('user = ', user).get()
    try: