- def urlid(self, sep='/'):
- stem = self.slug
- if self.language != settings.CATALOGUE_DEFAULT_LANGUAGE:
- stem += sep + self.language
- return stem
-
- def fileid(self):
- return self.urlid('_')
-
- @staticmethod
- def split_urlid(urlid, sep='/', default_lang=settings.CATALOGUE_DEFAULT_LANGUAGE):
- """Splits a URL book id into slug and language code.
-
- Returns a dictionary usable i.e. for object lookup, or None.
-
- >>> Book.split_urlid("a-slug/pol", default_lang="eng")
- {'slug': 'a-slug', 'language': 'pol'}
- >>> Book.split_urlid("a-slug", default_lang="eng")
- {'slug': 'a-slug', 'language': 'eng'}
- >>> Book.split_urlid("a-slug_pol", "_", default_lang="eng")
- {'slug': 'a-slug', 'language': 'pol'}
- >>> Book.split_urlid("a-slug/eng", default_lang="eng")
-
- """
- parts = urlid.rsplit(sep, 1)
- if len(parts) == 2:
- if parts[1] == default_lang:
- return None
- return {'slug': parts[0], 'language': parts[1]}
- else:
- return {'slug': urlid, 'language': default_lang}
-
- @classmethod
- def split_fileid(cls, fileid):
- return cls.split_urlid(fileid, '_')
-