示例#1
0
def slap(request, username):    
    form = FullSlapForm(data=request.POST or None, request=request, slapee=username)
    if request.method == 'POST' and form.is_valid():
        slap = form.save(commit=False)
        slap.slapee = username
        slap.put()
        
        #Save Username and Password into Session
        if not request.session.get('username',False):
            request.session['username'] = request.POST['slaper']
            request.session['password'] = request.POST['password']
        
        #Load in Cleared form.
        form = FullSlapForm(None, request=request)    
            
    api=twitter.Api()
    user = api.GetUser(username)
    slapee_image_url = user.profile_image_url
           
    page_size = settings.SLAPS_PER_PAGE
    next = None
    slaps = Slap.all().order("-created_at").filter('slapee ==', username).fetch(page_size+1)
    if len(slaps) == page_size+1:
        next = slaps[-1].created_at
        slaps = slaps[:page_size]
        
    slap_count = get_count('total') 
    slapee_count = get_count('slaps_received_%s' % username)
    return render_to_response('slap.html', {'form' : form, 'username':username, 'slapee_image_url': slapee_image_url , 'slaps':slaps, 'slap_count': slap_count, 'slapee_count': slapee_count } , context_instance=RequestContext(request))
示例#2
0
def home(request):     
    form = FullSlapForm(data=request.POST or None, request=request)
    if request.method == 'POST' and form.is_valid():
        form.save()
        #Save Username and Password into Session
        if not request.session.get('username',False):
            request.session['username'] = request.POST['slaper']
            request.session['password'] = request.POST['password']
            
        return HttpResponseRedirect(reverse(slap, args=[request.POST['slapee']]))

    page_size = settings.SLAPS_PER_PAGE
    latest_slaps = Slap.all().order("-created_at").fetch(5)

    slap_count = get_count('total') 
    return render_to_response('home.html', {'form' : form, 'slap_count': slap_count, 'latest_slaps':latest_slaps } , context_instance=RequestContext(request))
示例#3
0
def latest_slap(requeat):
    from django.core import serializers
    latest_slap = Slap.all().order("-created_at").fetch(1)
    data = serializers.serialize("json", latest_slap)
    return data