Esempio n. 1
0
    def get(self, id=None):
        db = database.connect()
        db.row_factory = database.row_factory(['album', 'cover'])
        if id:
            album = db.execute(
                "SELECT Album.*, '#', Photo.* FROM albums as Album LEFT JOIN photos as Photo ON Album.cover = Photo.id WHERE Album.id=:id",
                {
                    'id': id
                }).fetchone()
            print(album)
            item = album['album']
            if album['cover']['id']:
                item['cover'] = photos.preparePhoto(album['cover'])
            return success(item)

        albums = db.execute(
            "SELECT Album.*, '#', Photo.* FROM albums as Album LEFT JOIN photos as Photo ON Album.cover = Photo.id"
        ).fetchall()

        db.close()
        data = []
        for album in albums:
            item = album['album']
            if album['cover']['id']:
                item['cover'] = photos.preparePhoto(album['cover'])
            data.append(item)
        data.append({'title': 'unsorted', 'id': 'unsorted', 'cover': None})

        return success(data)
Esempio n. 2
0
	def get(self, id=None):
		db = database.connect()
		db.row_factory = database.row_factory(['album', 'cover'])
		if id:
			album = db.execute("SELECT Album.*, '#', Photo.* FROM albums as Album LEFT JOIN photos as Photo ON Album.cover = Photo.id WHERE Album.id=:id", {'id':id}).fetchone()
			print(album)
			item = album['album']
			if album['cover']['id']:
				item['cover'] = photos.preparePhoto(album['cover'])
			return success(item)

		albums = db.execute("SELECT Album.*, '#', Photo.* FROM albums as Album LEFT JOIN photos as Photo ON Album.cover = Photo.id").fetchall()

		db.close()
		data = []
		for album in albums:
			item = album['album']
			if album['cover']['id']:
				item['cover'] = photos.preparePhoto(album['cover'])
			data.append(item)
		data.append({
				'title':'unsorted',
				'id':'unsorted',
				'cover':None
			})

		return success(data)
Esempio n. 3
0
    def smart(self, type):

        db = database.connect()
        cur = db.execute(
            """SELECT * FROM photos  WHERE id NOT IN (SELECT albums_photos.photo_id FROM albums_photos)"""
        ).fetchall()
        db.close()
        return success([photos.preparePhoto(dict(a)) for a in cur])
Esempio n. 4
0
	def photosAlbums(self, id):
		db = database.connect()
		cur = db.execute("""SELECT albums.name, albums.id FROM albums 
			INNER JOIN albums_photos AS r ON r.album_id = albums.id
			INNER JOIN photos             ON r.photo_id = photos.id
			WHERE photos.id=:id""", {'id':id}).fetchall()
		db.close()
		return success([dict(a) for a in cur])
Esempio n. 5
0
	def delete_photo(self, album_id, photo_id):
		db = database.connect()
		cur = db.execute("DELETE FROM albums_photos WHERE album_id = :album_id AND photo_id = :photo_id", 
			{
				'album_id': album_id,
				'photo_id': photo_id
			})
		db.commit()
		db.close()
		return success()
Esempio n. 6
0
    def delete(self, id):
        query = ''

        value = {'id': id}

        db = database.connect()
        db.execute("DELETE FROM albums_photos WHERE album_id = :id", value)
        db.execute("DELETE FROM albums WHERE id = :id", value)
        db.commit()
        db.close()
        return success()
Esempio n. 7
0
    def photosAlbums(self, id):
        db = database.connect()
        cur = db.execute(
            """SELECT albums.name, albums.id FROM albums 
			INNER JOIN albums_photos AS r ON r.album_id = albums.id
			INNER JOIN photos             ON r.photo_id = photos.id
			WHERE photos.id=:id""", {
                'id': id
            }).fetchall()
        db.close()
        return success([dict(a) for a in cur])
Esempio n. 8
0
 def delete_photo(self, album_id, photo_id):
     db = database.connect()
     cur = db.execute(
         "DELETE FROM albums_photos WHERE album_id = :album_id AND photo_id = :photo_id",
         {
             'album_id': album_id,
             'photo_id': photo_id
         })
     db.commit()
     db.close()
     return success()
Esempio n. 9
0
	def delete(self, id):
		query = ''

		value = {'id': id}

		db = database.connect()
		db.execute("DELETE FROM albums_photos WHERE album_id = :id", value)
		db.execute("DELETE FROM albums WHERE id = :id", value)
		db.commit()
		db.close()
		return success()
Esempio n. 10
0
	def add(self, title):
		created_on = int(time.time())
		value = {
			'title'       : title,
			'created_on' : created_on,
			'modified_on': created_on
		}
		db = database.connect()
		cur = db.execute("INSERT INTO albums (title, created_on, modified_on) VALUES (:title, :created_on, :modified_on)", value)
		db.commit()
		db.close()
		return success({'id': cur.lastrowid})
Esempio n. 11
0
 def add(self, title):
     created_on = int(time.time())
     value = {
         'title': title,
         'created_on': created_on,
         'modified_on': created_on
     }
     db = database.connect()
     cur = db.execute(
         "INSERT INTO albums (title, created_on, modified_on) VALUES (:title, :created_on, :modified_on)",
         value)
     db.commit()
     db.close()
     return success({'id': cur.lastrowid})
Esempio n. 12
0
	def add_photo(self, album_id, photo_id):
		db = database.connect()

		cur = db.execute("SELECT * FROM albums_photos WHERE album_id=:album_id AND photo_id = :photo_id", 
			{
				'album_id': album_id,
				'photo_id': photo_id
			}).fetchone()
		if not cur:
			cur = db.execute("INSERT INTO albums_photos (album_id, photo_id) VALUES (:album_id, :photo_id)", 
				{
					'album_id': album_id,
					'photo_id': photo_id
				})
		db.commit()
		db.close()
		return success()
Esempio n. 13
0
def echo():
    return success({
        "config": {
            "version": "030003",
            "thumbQuality": "90",
            "checkForUpdates": "1",
            "sortingPhotos": "ORDER BY takestamp DESC",
            "sortingAlbums": "ORDER BY id DESC",
            "medium": "1",
            "imagick": "1",
            "dropboxKey": "",
            "skipDuplicates": "0",
            "plugins": "",
            "location": "/home/bramas/Lychee/",
            "login": true
        },
        "status": 2
    })
Esempio n. 14
0
    def add_photo(self, album_id, photo_id):
        db = database.connect()

        cur = db.execute(
            "SELECT * FROM albums_photos WHERE album_id=:album_id AND photo_id = :photo_id",
            {
                'album_id': album_id,
                'photo_id': photo_id
            }).fetchone()
        if not cur:
            cur = db.execute(
                "INSERT INTO albums_photos (album_id, photo_id) VALUES (:album_id, :photo_id)",
                {
                    'album_id': album_id,
                    'photo_id': photo_id
                })
        db.commit()
        db.close()
        return success()
Esempio n. 15
0
	def update(self, id):
		query = ''

		value = {'id': id}

		acceptedFields = ['title']

		for i in acceptedFields:
			if i in request.params: 
				value[i] = request.params[i]
				query += "SET "+i+" = :"+i
		if len(query) == 0:
			return error('no data sent (accepted fields: '+(','.join(acceptedFields))+')')

		db = database.connect()
		query = "UPDATE albums "+query+" WHERE id = :id"

		cur = db.execute(query, value)
		db.commit()
		db.close()
		return success()
Esempio n. 16
0
    def update(self, id):
        query = ''

        value = {'id': id}

        acceptedFields = ['title']

        for i in acceptedFields:
            if i in request.params:
                value[i] = request.params[i]
                query += "SET " + i + " = :" + i
        if len(query) == 0:
            return error('no data sent (accepted fields: ' +
                         (','.join(acceptedFields)) + ')')

        db = database.connect()
        query = "UPDATE albums " + query + " WHERE id = :id"

        cur = db.execute(query, value)
        db.commit()
        db.close()
        return success()
Esempio n. 17
0
def echo(message):
	return success({'message':message})
Esempio n. 18
0
def albumsPhotosOptions(id, pid=None):
    response.set_header('Access-Control-Allow-Methods',
                        'GET, POST, DELETE, PUT')
    return success()
Esempio n. 19
0
def albumsPhotosOptions(id, pid=None):
	response.set_header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT')
	return success()
Esempio n. 20
0
	def smart(self, type):

		db = database.connect()
		cur = db.execute("""SELECT * FROM photos  WHERE id NOT IN (SELECT albums_photos.photo_id FROM albums_photos)""").fetchall()
		db.close()
		return success([photos.preparePhoto(dict(a)) for a in cur])