Example #1
0
File: views.py Project: fay/Nankin
def list(request, jots):
    try:
        page = int(request.GET['page'])
    except:
        page = 1  
    paginator = utils.createPaginator(page=page)
    for jot in jots:
        if jot.tags and jot.tags[0] != 'photo':
            jot.what = utils.strip_tags(jot.what)[:200] + "..."
    recent_posts = Jot.all().order('-when').fetch(RECENT_POST_SIZE, 0)
    recent_comments = Comment.all().order('-when').fetch(RECENT_POST_SIZE, 0)
    read_most = Jot.all().order('-read_num').fetch(RECENT_POST_SIZE, 0)
    return render_to_response('index.html', {'jots':jots, 'paginator':paginator,
                                             'recent_posts':recent_posts, 'recent_comments':recent_comments,
                                             'read_most':read_most},
                                             context_instance=RequestContext(request))
Example #2
0
File: views.py Project: fay/Nankin
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))
Example #3
0
File: views.py Project: fay/Nankin
def view_by_tag(request, tag):
    try:
        page = int(request.GET['page'])
    except:
        page = 1
    jots = Jot.all().filter('tags = ', tag).order('-when').fetch(utils.PAGE_SIZE, utils.PAGE_SIZE * (page - 1))
    return list(request, jots)
Example #4
0
File: views.py Project: fay/Nankin
def index(request):  
    try:
        page = int(request.GET['page'])
    except:
        page = 1  
    jots = Jot.all().order('-when').fetch(utils.PAGE_SIZE, utils.PAGE_SIZE * (page - 1))
    return list(request, jots)
Example #5
0
File: views.py Project: fay/Nankin
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
Example #6
0
File: views.py Project: fay/Nankin
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
Example #7
0
File: views.py Project: fay/Nankin
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("/")
Example #8
0
File: views.py Project: fay/Nankin
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
Example #9
0
File: feed.py Project: fay/Nankin
 def items(self,obj):
     jots = Jot.all().order('-when').fetch(10, 0)
     return jots
Example #10
0
File: views.py Project: fay/Nankin
def news(request):
    recent_posts = Jot.all().order('-when').fetch(RECENT_POST_SIZE, 0)
    recent_comments = Comment.all().order('-when').fetch(RECENT_POST_SIZE, 0)
    read_most = Jot.all().order('-read_num').fetch(RECENT_POST_SIZE, 0)
    return render_to_response('news.html', {'recent_posts':recent_posts, 'recent_comments':recent_comments, 'read_most':read_most}, context_instance=RequestContext(request))
Example #11
0
File: views.py Project: fay/Nankin
def about(request):
    about = Jot.all().filter('tags =', 'about').get()
    if about:
        return view(request, about.key())
    else:
        raise Http404
Example #12
0
File: views.py Project: fay/Nankin
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: