Add Album.normalize_title and _description.
This commit is contained in:
		
							parent
							
								
									dddd8a3aa1
								
							
						
					
					
						commit
						6ee86431e5
					
				
					 3 changed files with 35 additions and 12 deletions
				
			
		|  | @ -5,6 +5,7 @@ but are returned by the PDB accesses. | |||
| 
 | ||||
| import os | ||||
| import PIL.Image | ||||
| import string | ||||
| import traceback | ||||
| 
 | ||||
| from . import constants | ||||
|  | @ -232,8 +233,8 @@ class Album(ObjectBase, GroupableMixin): | |||
|             db_row = dict(zip(constants.SQL_COLUMNS['albums'], db_row)) | ||||
| 
 | ||||
|         self.id = db_row['id'] | ||||
|         self.title = db_row['title'] or '' | ||||
|         self.description = db_row['description'] or '' | ||||
|         self.title = self.normalize_title(db_row['title']) | ||||
|         self.description = self.normalize_description(db_row['description']) | ||||
|         self.author_id = self.normalize_author_id(db_row['author_id']) | ||||
| 
 | ||||
|         self.name = 'Album %s' % self.id | ||||
|  | @ -249,6 +250,32 @@ class Album(ObjectBase, GroupableMixin): | |||
|     def __repr__(self): | ||||
|         return 'Album:{id}'.format(id=self.id) | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def normalize_description(description): | ||||
|         if description is None: | ||||
|             return '' | ||||
| 
 | ||||
|         if not isinstance(description, str): | ||||
|             raise TypeError('Description must be string, not %s' % type(description)) | ||||
| 
 | ||||
|         description = description.strip() | ||||
| 
 | ||||
|         return description | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def normalize_title(title): | ||||
|         if title is None: | ||||
|             return '' | ||||
| 
 | ||||
|         if not isinstance(title, str): | ||||
|             raise TypeError('Title must be string, not %s' % type(title)) | ||||
| 
 | ||||
|         title = title.strip() | ||||
|         for whitespace in string.whitespace: | ||||
|             title = title.replace(whitespace, ' ') | ||||
| 
 | ||||
|         return title | ||||
| 
 | ||||
|     def _uncache(self): | ||||
|         self._uncache_sums() | ||||
|         self.photodb.caches['album'].remove(self.id) | ||||
|  | @ -393,10 +420,10 @@ class Album(ObjectBase, GroupableMixin): | |||
|             return | ||||
| 
 | ||||
|         if title is not None: | ||||
|             self.title = title | ||||
|             self.title = self.normalize_title(title) | ||||
| 
 | ||||
|         if description is not None: | ||||
|             self.description = description | ||||
|             self.description = self.normalize_description(description) | ||||
| 
 | ||||
|         data = { | ||||
|             'id': self.id, | ||||
|  |  | |||
|  | @ -80,14 +80,10 @@ class PDBAlbumMixin: | |||
|         ''' | ||||
|         Create a new album. Photos can be added now or later. | ||||
|         ''' | ||||
|         album_id = self.generate_id('albums') | ||||
|         title = title or '' | ||||
|         description = description or '' | ||||
|         if not isinstance(title, str): | ||||
|             raise TypeError('Title must be string, not %s' % type(title)) | ||||
|         title = objects.Album.normalize_title(title) | ||||
|         description = objects.Album.normalize_description(description) | ||||
| 
 | ||||
|         if not isinstance(description, str): | ||||
|             raise TypeError('Description must be string, not %s' % type(description)) | ||||
|         album_id = self.generate_id('albums') | ||||
| 
 | ||||
|         self.log.debug('New Album: %s %s', album_id, title) | ||||
| 
 | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ p | |||
|     id="description_text" | ||||
|     data-editor-id="description" | ||||
|     data-editor-placeholder="description" | ||||
|     {% if album.description == "" %}class="hidden"{% endif %} | ||||
|     {% if not album.description %}class="hidden"{% endif %} | ||||
|     > | ||||
|         {{-album.description-}} | ||||
|     </pre> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue