Example #1
0
def outer_heaven(request):
    filelist=UserFile.all().order('-creationDate').fetch(FILE_MAX)
    for file in filelist:
        if not file.icon:
            try :
                filebin=file.filebin_set.get()
                file.icon=images.resize(filebin.bin, width=60)
                file.put()
            except:
                pass
    
    return render_to_response('upload/OuterHeaven.html',locals(),context_instance=RequestContext(request))
Example #2
0
def albumentry(request):
    if request.method == 'POST':
        if 'file' in request.FILES:
            file = request.FILES['file']
            userfile = UserFile(  mimetype=request.META['CONTENT_TYPE'],
                                    author = users.get_current_user(),
                                    size = file.size,
                                    name=file.name,
                                    comment=request.REQUEST.get('comment',''))
            bin=file.read()
            try:
                userfile.icon=images.resize(bin, width=60)
            except:
                pass
                
            userfile.save() 
            filebin = FileBin(userfile=userfile, bin=db.Blob(bin))
            filebin.save()
            file.close()
            if UserFile.all().count() > FILE_MAX:
                oldest_file = UserFile.all().order('-creationDate').get()
                oldest_file.delete()
            #flush cache in order to update the file list
            memcache.flush_all()
            return HttpResponseRedirect(reverse(albumentry))
        else:
            return HttpResponseRedirect(reverse(albumentry))

    else:
        filelist = UserFile.all().order('-creationDate').fetch(FILE_MAX)
        user = users.get_current_user()
        if user:
            sign_link = '<a href="%s">Logout</a>' % users.create_logout_url(reverse(albumentry))
        else:
            sign_link = '<a href="%s">Login</a>' % users.create_login_url(reverse(albumentry))
        displayFile=None
        if 'key' in request.REQUEST:
            displayFile=get_object_or_404(UserFile,request.REQUEST['key'])     
            
        email_form=EmailForm()       
        template_values = {
            'displayFile':displayFile,               
#            'user': user,
            'sign_link': sign_link,
            'filelist': filelist,
            'form':FileForm(),
            'email_form':email_form,
        }
        return render_to_response('upload/show_albumentry.html',template_values,context_instance=RequestContext(request))