Example #1
0
def photo(request, id):
	user = request.user
	# DELETE Request - Deletes the photo
	if request.method == "DELETE":
		try:
			Photo.objects.get(owner=user, id=id).delete()	
			return createJsonData()
		except Photo.DoesNotExist:
			raise Http404

	# GET Request - Returns all Data for the photo
	else:
		try:
			photo = Photo.objects.get(owner=user, id=id)

			data = {
				"id": photo.id,
				"name": photo.name,
				"raw_name": photo.raw_name,
				"caption": photo.caption,
				"created": time.mktime(photo.created.timetuple()),
				"processed": photo.processed,
				"extension": photo.extension,
				"flag": int(photo.flag),
				"photourls": {
					"download": generate_photourl(photo),
					"thumb": generate_photourl(photo, size="thumb"),
					"big": generate_photourl(photo, size="big"),
				}
			}

			return createJsonData(obj=data)

		except Photo.DoesNotExist, e:
			return createJsonData(success=False, errorcode=2)
Example #2
0
def album(request, id):
	user = request.user
	# DELETE Request - Deletes the album
	if request.method == "DELETE":
		try:
			Album.objects.get(owner=user, id=id).delete()	
			return createJsonData()
		except Album.DoesNotExist:
			raise Http404
			
	# GET Request - Returns all infos & photos for the album
	else:
		try:
			requested_album = Album.objects.get(id=id, owner=user)
			requested_photos = Photo.objects.filter(album=requested_album, owner=user)

			# Create photolist with all information that should be visible
			photodata = []
			for photo in requested_photos:
				tmp = {
					"id": photo.id,
					"name": photo.name,
					"raw_name": photo.raw_name,
					"caption": photo.caption,
					"created": time.mktime(photo.created.timetuple()),
					"processed": photo.processed,
					"flag": int(photo.flag),
					"photourls": {
						"download": generate_photourl(photo, albumid=requested_album.id),
						"thumb": generate_photourl(photo, albumid=requested_album.id, size="thumb"),
						"big": generate_photourl(photo, albumid=requested_album.id, size="big"),
					}
				}

				photodata.append(tmp)

			# Same for the album itself. Show all information that should be visible
			albuminfo = {
				"id": requested_album.id,
				"name": requested_album.name,
				"is_public": requested_album.is_public,
				"has_password": requested_album.is_protected,
				"created": time.mktime(requested_album.created.timetuple()),
				"count": len(photodata),
				"photos": photodata
			}
			return createJsonData(obj=albuminfo)

		except Album.DoesNotExist, e:
			return createJsonData(success=False, errorcode=1)
Example #3
0
def photos(request):
	user = request.user
	# POST Request - Adds new photo
	if request.method == "POST": 
		# TODO: implement
		assert False

	# GET Request - Returns all Photos
	else:
		requested_photos = Photo.objects.filter(owner=user)[:30]

		photodata = []
		for photo in requested_photos:
			tmp = {
				"id": photo.id,
				"name": photo.name,
				"raw_name": photo.raw_name,
				"caption": photo.caption,
				"created": time.mktime(photo.created.timetuple()),
				"processed": photo.processed,
				"flag": int(photo.flag),
				"extension": photo.extension,
				"photourls": {
					"download": generate_photourl(photo),
					"thumb": generate_photourl(photo, size="thumb"),
					"big": generate_photourl(photo, size="big"),
				}
			}

			photodata.append(tmp)

		json = {
			"photos": photodata,
			"count": len(photodata)
		}

		return createJsonData(obj=json)