Пример #1
0
def upload_picture2(request):
    username = request.session.get('username')
    tagger = users.objects.filter(username=username)[0]
    taggee = users.objects.filter(username=request.POST['taggee'])[0]
    comment = request.POST['comment']
    if not username:
        return HttpResponseRedirect("/")
    are_friends = fb_friend_map.objects.filter(fb_id=tagger.fb_id,fb_friend_id=taggee.fb_id)
    if not are_friends:
        t = loader.get_template(TEMPLATE_ROOT + "/upload_pic.html")
        error = "you crazy"
        c = Context({'error':error})
        return HttpResponse(t.render(c))
    file = request.FILES['file']
    timestamp = str(mktime(datetime.datetime.now().timetuple())).replace(".","") + str(datetime.datetime.now().microsecond)
    file_hash = hashlib.md5(file.name + timestamp).hexdigest()
    file_extension = file.name.split(".")[-1]
    full_file_name = file_hash + "." + file_extension
    destination = open(PIC_ROOT + full_file_name,'wb+')
    for chunk in file.chunks():
        destination.write(chunk)
    destination.close()
    new_pic = pictures(pic_id=file_hash,pic_url=full_file_name,tagger=tagger,taggee=taggee,comment=comment)
    new_pic.save()
    os.popen('echo "Subject: Tag, You\'re It!" | cat - /home/freezetag/mail/body.txt | sendmail -F"wizzzit" ' + taggee.email)
    return HttpResponseRedirect("/p/" + file_hash)
Пример #2
0
def upload_picture(request):
    val = validate_user(request)
    if val:
        return HttpResponse("you ain't signed in, mothra")
    tagger = users.objects.filter(username=request.session.get('username'))[0]
    taggee = users.objects.filter(username=request.POST['taggee'])[0]
    not_friends = validate_friendship(tagger,taggee)
    if not_friends:
        return HttpResponse("You ain't friends with them, mothra")
    comment = request.POST['comment']
    name = request.POST['name']
    file = request.FILES['file']
    unique_file_name = create_unique_filename(name)
    destination = open(PIC_ROOT + unique_file_name,'wb+')
    for chunk in file.chunks():
        destination.write(chunk)
    destination.close()
    img = Image.open(PIC_ROOT + unique_file_name)
    width = img.size[0]
    height = img.size[1]
    if width > height:
        t_width = 160
        t_height = height * (float(t_width) / float(width))
        m_width = 450
        m_height = height * (float(m_width) / float(width))
        if width > 1200:
            f_width = 1200
            f_height = height * (float(f_width) / float(width))
        else:
            f_width = width
            f_height = height
    else:
        t_height = 160
        t_width = height * (float(t_height) / float(height))
        m_height = 450
        m_width = height * (float(m_height) / float(height))
        if height > 1200:
            f_height = 1200
            f_width = width * (float(f_height) / float(height))
        else:
            f_height = height
            f_width = width
    thumbnail = thumbnailify(unique_file_name,t_width,t_height,"t_")
    big_toenail = thumbnailify(unique_file_name,m_width,m_height,"m_")
    full = thumbnailify(unique_file_name,f_width,f_height,"f_")
    new_pic = pictures(pic_id=unique_file_name.split(".")[0],pic_url=full,tagger=tagger,taggee=taggee,comment=comment,thumbnail=thumbnail,big_toenail=big_toenail)
    new_pic.save()
    send_email('user_tagged',tagger,taggee,taggee,unique_file_name.split(".")[0])
    taggee_friends_temp = fb_friend_map.objects.filter(fb_id=taggee.fb_id).values('fb_friend_id')
    taggee_friends = users.objects.filter(fb_id__in=taggee_friends_temp)
    for friend in taggee_friends:
        if not friend == tagger:
            send_email('friend_tagged',tagger,taggee,friend,unique_file_name.split(".")[0])
    response = {'response':{'message': 'pic uploaded','pic_url':full,'thumbnail':thumbnail,'big_toenail':big_toenail}}
    #return HttpResponse(simplejson.dumps(response),mimetype='application/json',status=201)
    return HttpResponseRedirect("/p/" + unique_file_name.split(".")[0])
Пример #3
0
def upload(request):
    val = validate_user(request)
    if val:
        return val
    tagger = users.objects.filter(username=request.session.get('username'))[0]
    #taggee = users.objects.filter(fb_id=request.POST['taggee'])[0]
    taggee = request.POST['taggee']
    if request.POST.has_key('fb_name'):
        fb_name = request.POST['fb_name']
    #Commenting out for now, to allow non-registered users to be tagged.  We may have to think about this though.
    #not_friends = validate_friendship(tagger,taggee)
    #if not_friends:
        #return not_friends
    comment = request.POST['comment']
    name = request.POST['name']
    file = request.FILES['file']
    unique_file_name = create_unique_filename(name)
    destination = open(PIC_ROOT + unique_file_name,'wb+')
    for chunk in file.chunks():
        destination.write(chunk)
    destination.close()
    img = Image.open(PIC_ROOT + unique_file_name)
    width = img.size[0]
    height = img.size[1]
    if width > height:
        t_width = 160
        t_height = height * (float(t_width) / float(width))
        m_width = 450
        m_height = height * (float(m_width) / float(width))
        if width > 1200:
            f_width = 1200
            f_height = height * (float(f_width) / float(width))
        else:
            f_width = width
            f_height = height 
    else:
        t_height = 160
        t_width = height * (float(t_height) / float(height))
        m_height = 450
        m_width = height * (float(m_height) / float(height))    
        if height > 1200:
            f_height = 1200
            f_width = width * (float(f_height) / float(height))
        else:
            f_height = height
            f_width = width
    thumbnail = thumbnailify(unique_file_name,t_width,t_height,"t_")
    big_toenail = thumbnailify(unique_file_name,m_width,m_height,"m_")
    full = thumbnailify(unique_file_name,f_width,f_height,"f_")
    if len(users.objects.filter(fb_id=taggee)) > 0:
        taggee = users.objects.filter(fb_id=taggee)[0]
        new_pic = pictures(pic_id=unique_file_name.split(".")[0],pic_url=full,tagger=tagger,taggee=taggee,comment=comment,thumbnail=thumbnail,big_toenail=big_toenail)
        new_pic.save()
    else:
        create_ghost_account(taggee,fb_name)
        ### we need the next line to re-purpose 'taggee', since it was nothing initially.  now that we've made the account, we can appropriately define the taggee.
        taggee = users.objects.filter(fb_id=taggee)[0]
        new_pic = pictures(pic_id=unique_file_name.split(".")[0],pic_url=full,tagger=tagger,taggee=taggee,comment=comment,thumbnail=thumbnail,big_toenail=big_toenail)
        new_pic.save()
    if email_on_tag(taggee):  
        send_email('user_tagged',tagger,taggee,taggee,unique_file_name.split(".")[0])
    taggee_friends_temp = fb_friend_map.objects.filter(fb_id=taggee.fb_id).values('fb_friend_id')
    taggee_friends = users.objects.filter(fb_id__in=taggee_friends_temp,settings__email_on_friend_tagged=1)
    for friend in taggee_friends:
        if not friend == tagger:
            send_email('friend_tagged',tagger,taggee,friend,unique_file_name.split(".")[0])
    response = {'response':{'taggee':taggee.username,'pic_id':unique_file_name.split(".")[0],'taggee_ghost_account':taggee.is_ghost_account,'message': 'pic uploaded','pic_url':full,'thumbnail':thumbnail,'big_toenail':big_toenail}}
    return HttpResponse(simplejson.dumps(response),mimetype='application/json',status=201)