Use list.sort's keyword parameters
[joel/kofoto.git] / src / packages / kofoto / gkofoto / albumdialog.py
1 from kofoto.gkofoto.environment import env
2 from kofoto.gkofoto.taganddescriptiondialog import TagAndDescriptionDialog
3 from kofoto.shelf import \
4     AlbumDoesNotExistError, BadAlbumTagError, verifyValidAlbumTag
5
6 class AlbumDialog(TagAndDescriptionDialog):
7     def __init__(self, title, albumId=None):
8         if albumId is not None:
9             self._album = env.shelf.getAlbum(albumId)
10             tagText = self._album.getTag()
11             descText = self._album.getAttribute(u"title")
12             if descText == None:
13                 descText = u""
14         else:
15             self._album = None
16             tagText = u""
17             descText = u""
18         TagAndDescriptionDialog.__init__(self, title, tagText, descText)
19         label = self._widgets.get_widget("titleLabel")
20         label.set_label(u"Title:")
21
22     def _isTagOkay(self, tagString):
23         try:
24             # Check that the tag name is valid.
25             verifyValidAlbumTag(tagString)
26         except BadAlbumTagError:
27             return False
28         try:
29             album = env.shelf.getAlbumByTag(tagString)
30             if album == self._album:
31                 # The tag exists, but is same as before.
32                 return True
33             else:
34                 # The tag is taken by another album.
35                 return False
36         except AlbumDoesNotExistError:
37             # The tag didn't exist.
38             return True