Beispiel #1
0
def photo(request):
	context = {}
	gu = gen_user.objects.get(user=request.user)
	if request.method == 'POST':
		print 'in POST'
		form = PictureForm(request.POST, request.FILES)
		if form.is_valid():
			print 'form is valid'
			newpic = picture(picfile=request.FILES['picfile'])
			newpic.save()
			gu.picture = newpic
			gu.save()
			return homeviews.home(request)
	context['picture'] = gu.picture
	context['form'] = PictureForm()
	return render(request, 'accounts/upload_photo.html', context)
Beispiel #2
0
def photo(request):
    context = {}
    gu = gen_user.objects.get(user=request.user)
    if request.method == 'POST':
        print 'in POST'
        form = PictureForm(request.POST, request.FILES)
        if form.is_valid():
            print 'form is valid'
            newpic = picture(picfile=request.FILES['picfile'])
            newpic.save()
            gu.picture = newpic
            gu.save()
            return homeviews.home(request)
    context['picture'] = gu.picture
    context['form'] = PictureForm()
    return render(request, 'accounts/upload_photo.html', context)
Beispiel #3
0
def xiuxiu_upload(request):
    if request.method == 'POST':
        images= request.FILES.getlist('images')
        image = images[0]
        place = request.GET["place"]
        username = request.GET["username2"]
        pic_id = request.GET["picid2"]
        m = picture(image = image,name = image.name,username=username,place=place)
#        m = picture(image=image, username="******",place=u"成都")
        m.save()
        request.session["id_after_beautify"] = m.id
        m.src = "http://photomanage-picfolder2.stor.sinaapp.com/pic_folder%2F"+str(m.image)[11:]
        m.save()
        pic_del = picture.objects.get(id =pic_id)
        pic_del.image.delete()
        pic_del.delete()
       
        return HttpResponse("success")
    else:
        return render_to_response("xiuxiu_Upload.html")
Beispiel #4
0
def xiuxiu_upload(request):
    if request.method == 'POST':
        images = request.FILES.getlist('images')
        image = images[0]
        place = request.GET["place"]
        username = request.GET["username2"]
        pic_id = request.GET["picid2"]
        m = picture(image=image,
                    name=image.name,
                    username=username,
                    place=place)
        #        m = picture(image=image, username="******",place=u"成都")
        m.save()
        request.session["id_after_beautify"] = m.id
        m.src = "http://photomanage-picfolder2.stor.sinaapp.com/pic_folder%2F" + str(
            m.image)[11:]
        m.save()
        pic_del = picture.objects.get(id=pic_id)
        pic_del.image.delete()
        pic_del.delete()

        return HttpResponse("success")
    else:
        return render_to_response("xiuxiu_Upload.html")
Beispiel #5
0
def home(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/accounts/login/")
    if request.method == 'POST':
        images= request.FILES.getlist('images')
        flag2 = True
        for image in images:
            n = image.name
            m = picture(image = image,name = n,username=request.user.username)
            m.save()
            m.src = "http://photomanage-picfolder2.stor.sinaapp.com/pic_folder%2F"+str(m.image)[11:]
            m.save()
            c = sae.storage.Connection()
            bucket = c.get_bucket('picfolder2')
            path = unicode(str(m.image),"utf-8")
            srcx = bucket.get_object_contents(path)
            pic = Image.open(StringIO(srcx))
            m.place = u"外星"
            try:
                if hasattr(pic, '_getexif' ):
                    ret = {}
                    exifinfo = pic._getexif()
                    flag = True
                    for tag, value in exifinfo.items():
                        decoded = TAGS.get(tag, tag)
                        ret[decoded] = value
                    try:
                        xy = ret["GPSInfo"]
                    except:
                        flag = False
                        flag2 = False
                          
                    if(flag):
                        try:
                            lt = xy[4][0][0]*1.0/xy[4][0][1]+\
                            xy[4][1][0]*1.0/xy[4][1][1]/60+xy[4][2][0]*1.0\
                            /xy[4][2][1]/3600
                            ln = xy[2][0][0]*1.0/xy[2][0][1]+\
                            xy[2][1][0]*1.0/xy[2][1][1]/60+xy[2][2][0]*1.0\
                            /xy[2][2][1]/3600
                        except:
                            flag =False
                            flag2 = False
                        if(flag):
                            bm = xBaiduMap()
                            add = bm.getAddress(ln, lt)
                            start = False
                            add2=""
                            for char in add:
                                if(char==u"市" or char==u"县"):
                                    break
                                if(start):
                                    add2+=char
                                if(char == u"省" or char == u"区"):
                                    start = True
                            if(add2):
                                m.place = add2                             
                    m.save()
                else:
                    m.save()
            except:
                flag2 = False
                m.save()
        return render_to_response("home.html",{"up":True,"flag":flag2})    
    return	render_to_response("home.html")
Beispiel #6
0
def upload_pictures(f, my_admin):
	with open(f, 'rb') as csvfile:
		myreader = csv.reader(csvfile, delimiter=',', quotechar='"')
		for row in myreader:
			p = picture(picture_ID = my_admin.max_picture_ID, url =row[2], current_rating = 1200, past_comparisons = [], tags = [], artist = row[0], title = row[1], description = "")
			my_admin.max_picture_ID += 1
Beispiel #7
0
def home(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/accounts/login/")
    if request.method == 'POST':
        images = request.FILES.getlist('images')
        flag2 = True
        for image in images:
            n = image.name
            m = picture(image=image, name=n, username=request.user.username)
            m.save()
            m.src = "http://photomanage-picfolder2.stor.sinaapp.com/pic_folder%2F" + str(
                m.image)[11:]
            m.save()
            c = sae.storage.Connection()
            bucket = c.get_bucket('picfolder2')
            path = unicode(str(m.image), "utf-8")
            srcx = bucket.get_object_contents(path)
            pic = Image.open(StringIO(srcx))
            m.place = u"外星"
            try:
                if hasattr(pic, '_getexif'):
                    ret = {}
                    exifinfo = pic._getexif()
                    flag = True
                    for tag, value in exifinfo.items():
                        decoded = TAGS.get(tag, tag)
                        ret[decoded] = value
                    try:
                        xy = ret["GPSInfo"]
                    except:
                        flag = False
                        flag2 = False

                    if (flag):
                        try:
                            lt = xy[4][0][0]*1.0/xy[4][0][1]+\
                            xy[4][1][0]*1.0/xy[4][1][1]/60+xy[4][2][0]*1.0\
                            /xy[4][2][1]/3600
                            ln = xy[2][0][0]*1.0/xy[2][0][1]+\
                            xy[2][1][0]*1.0/xy[2][1][1]/60+xy[2][2][0]*1.0\
                            /xy[2][2][1]/3600
                        except:
                            flag = False
                            flag2 = False
                        if (flag):
                            bm = xBaiduMap()
                            add = bm.getAddress(ln, lt)
                            start = False
                            add2 = ""
                            for char in add:
                                if (char == u"市" or char == u"县"):
                                    break
                                if (start):
                                    add2 += char
                                if (char == u"省" or char == u"区"):
                                    start = True
                            if (add2):
                                m.place = add2
                    m.save()
                else:
                    m.save()
            except:
                flag2 = False
                m.save()
        return render_to_response("home.html", {"up": True, "flag": flag2})
    return render_to_response("home.html")