Skip to content

Commit

Permalink
Simplify Collection constructor and get_user_collection()
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Apr 4, 2024
1 parent e042c47 commit 6836794
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions picard/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@

class Collection(QtCore.QObject):

def __init__(self, collection_id, name, size):
def __init__(self, collection_id):
self.id = collection_id
self.name = name
self.size = int(size)
self.name = ''
self.size = 0
self.pending_releases = set()
self.releases = set()

@property
def size(self):
return self._size

@size.setter
def size(self, value):
self._size = int(value)

def __repr__(self):
return '<Collection %s (%s)>' % (self.name, self.id)

Expand Down Expand Up @@ -105,13 +113,10 @@ def _success(self, count, callback, status_msg, debug_msg):
self.tagger.window.set_statusbar_message(status_msg, mparms, translate=None, echo=None)


def get_user_collection(collection_id, name, size, refresh=False):
def get_user_collection(collection_id):
collection = user_collections.get(collection_id)
if collection is None:
collection = user_collections[collection_id] = Collection(collection_id, name, size)
elif refresh:
collection.name = name
collection.size = size
collection = user_collections[collection_id] = Collection(collection_id)
return collection


Expand All @@ -134,10 +139,10 @@ def request_finished(document, reply, error):
if node['entity-type'] != 'release':
continue
col_id = node['id']
col_name = node['name']
col_size = node['release-count']
new_collections.add(col_id)
get_user_collection(col_id, col_name, col_size, refresh=True)
collection = get_user_collection(col_id)
collection.name = node['name']
collection.size = node['release-count']

# remove collections which aren't returned by the web service anymore
old_collections = set(user_collections) - new_collections
Expand All @@ -163,9 +168,9 @@ def add_release_to_user_collections(release_node):
username = config.persist['oauth_username'].lower()
for node in release_node['collections']:
if node['editor'].lower() == username:
col_id = node['id']
col_name = node['name']
col_size = node['release-count']
collection = get_user_collection(col_id, col_name, col_size)
collection = get_user_collection(node['id'])
collection.name = node['name']
collection.size = node['release-count']

collection.releases.add(release_id)
log.debug("Adding release %r to %r", release_id, collection)

0 comments on commit 6836794

Please sign in to comment.