summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2014-12-28 12:24:22 +0000
committerMichaël Ball <michael.ball@gmail.com>2015-11-27 20:02:04 +0000
commit75beec91a8526fbbc0a90134140b9dff6af15c0c (patch)
tree02414e46da3e08000384c40c27b7aab9748de0fe /models
parenta2964845e3c03b9cf5f01583f53f7553c7d67caf (diff)
Initial frontend work
Diffstat (limited to 'models')
-rw-r--r--models/album.py13
-rw-r--r--models/track.py27
-rw-r--r--models/user.py52
3 files changed, 89 insertions, 3 deletions
diff --git a/models/album.py b/models/album.py
index 9ca3798..0d7cd54 100644
--- a/models/album.py
+++ b/models/album.py
@@ -99,7 +99,8 @@ class Album():
sql = " ".join(("UPDATE album"), set_clause, "WHERE id = :id")
cursor.execute(sql, dirty_attributes)
- def search(**search_params):
+ def search(order="album.id", direction="ASC", limit=None,
+ offset=None, **search_params):
"""Find an album with the given params
Args:
@@ -117,7 +118,14 @@ class Album():
value_params = {}
for (attr, value) in search_params.items():
where_params[attr] = value["operator"]
- value_params[attr] = value["data"]
+
+ if value["operator"] == "BETWEEN":
+ items = value["data"].split(" ")
+
+ value_params["".join((attr, "1"))] = items[0]
+ value_params["".join((attr, "2"))] = items[2]
+ else:
+ value_params[attr] = value["data"]
where_clause = utils.make_where_clause(where_params)
@@ -138,6 +146,7 @@ class Album():
def all(order="album.id", direction="ASC", limit=None, offset=None):
db = DbManager()
cursor = db.cursor()
+
albums = []
select_string = """SELECT * FROM album LEFT JOIN album_artist ON
diff --git a/models/track.py b/models/track.py
index dead1f8..688f6ff 100644
--- a/models/track.py
+++ b/models/track.py
@@ -361,7 +361,7 @@ class Track:
for artist_name in artist_names:
musicbrainz_artistid = None
- artistsort = None
+ artistsort = artist_name
try:
musicbrainz_artistid = musicbrainz_artist_ids[i]
except IndexError:
@@ -543,3 +543,28 @@ class Track:
db.commit()
return True
+
+ def all(order="track.id", direction="ASC", limit=None, offset=None):
+ db = DbManager()
+ tracks = []
+
+ select_string = """SELECT * FROM track LEFT JOIN artist_track ON
+ artist_track.track_id = track.id LEFT JOIN artist ON
+ artist_track.artist_id = artist.id LEFT JOIN album_track ON
+ album_track.track_id = track.id LEFT JOIN album ON
+ album_track.album_id = album.id ORDER BY %s %s""" % (order,
+ direction)
+
+ if limit is not None and offset is not None:
+ select_string = " ".join((select_string,
+ "LIMIT %s OFFSET %s" % (limit, offset)))
+
+ result = db.execute(select_string)
+
+ for row in result:
+ tracks.append(
+ Track(id=row[0], tracknumber=row[1], name=row[3],
+ grouping=row[3], filename=row[4])
+ )
+
+ return tracks
diff --git a/models/user.py b/models/user.py
new file mode 100644
index 0000000..f912e43
--- /dev/null
+++ b/models/user.py
@@ -0,0 +1,52 @@
+from common.security import pwd_context
+
+
+class User:
+ def __init__(self, **kwargs):
+ for (key, value) in kwargs.items():
+ setattr(self, key, value)
+
+ def get_id(self):
+ if self.id:
+ return str(self.id)
+ else:
+ raise ValueError("No user")
+
+ def is_authenticated(self):
+ if self.authenticated > 0:
+ return True
+ else:
+ return False
+
+ def is_active(self):
+ if self.active > 0:
+ return True
+ else:
+ return False
+
+ def is_anonymous(self):
+ if self.anonymous > 0:
+ return True
+ else:
+ return False
+
+ def verify(self, password):
+ if self.id and pwd_context.verify(password, self.password_hash):
+ self.authenticated = 1
+ return True
+ else:
+ return False
+
+ def new_password(self, password, category=None):
+ if self.id:
+ hash = None
+
+ if category:
+ hash = pwd_context.encrypt(password, category=category)
+ else:
+ hash = pwd_context.encrypt(password)
+
+ return hash
+
+ else:
+ raise ValueError("No user")