Use list.sort's keyword parameters
[joel/kofoto.git] / src / packages / kofoto / gkofoto / categorydialog.py
1 from kofoto.gkofoto.environment import env
2 from kofoto.gkofoto.taganddescriptiondialog import TagAndDescriptionDialog
3 from kofoto.shelf import \
4     BadCategoryTagError, CategoryDoesNotExistError, verifyValidCategoryTag
5
6 class CategoryDialog(TagAndDescriptionDialog):
7     def __init__(self, title, categoryId=None):
8         if categoryId:
9             self._category = env.shelf.getCategory(categoryId)
10             tagText = self._category.getTag()
11             descText = self._category.getDescription()
12         else:
13             self._category = None
14             tagText = u""
15             descText = u""
16         TagAndDescriptionDialog.__init__(self, title, tagText, descText)
17
18     def _isTagOkay(self, tagString):
19         try:
20             # Check that the tag name is valid.
21             verifyValidCategoryTag(tagString)
22         except BadCategoryTagError:
23             return False
24         try:
25             category = env.shelf.getCategoryByTag(tagString)
26             if category == self._category:
27                 # The tag exists, but is same as before.
28                 return True
29             else:
30                 # The tag is taken by another category.
31                 return False
32         except CategoryDoesNotExistError:
33             # The tag didn't exist.
34             return True