@@ -332,35 +332,6 @@ class Post(models.Model):
332332
333333 objects = GenericDateTaggedManager ()
334334
335- _metadata = {
336- "title" : "get_title" ,
337- "description" : "get_description" ,
338- "keywords" : "get_keywords" ,
339- "og_description" : "get_description" ,
340- "twitter_description" : "get_description" ,
341- "schemaorg_description" : "get_description" ,
342- "locale" : "get_locale" ,
343- "image" : "get_image_full_url" ,
344- "image_width" : "get_image_width" ,
345- "image_height" : "get_image_height" ,
346- "object_type" : "get_meta_attribute" ,
347- "og_type" : "get_meta_attribute" ,
348- "og_app_id" : "get_meta_attribute" ,
349- "og_profile_id" : "get_meta_attribute" ,
350- "og_publisher" : "get_meta_attribute" ,
351- "og_author_url" : "get_meta_attribute" ,
352- "og_author" : "get_meta_attribute" ,
353- "twitter_type" : "get_meta_attribute" ,
354- "twitter_site" : "get_meta_attribute" ,
355- "twitter_author" : "get_meta_attribute" ,
356- "schemaorg_type" : "get_meta_attribute" ,
357- "published_time" : "date_published" ,
358- "modified_time" : "date_modified" ,
359- "expiration_time" : "date_published_end" ,
360- "tag" : "get_tags" ,
361- "url" : "get_absolute_url" ,
362- }
363-
364335 class Meta :
365336 verbose_name = _ ("post" )
366337 verbose_name_plural = _ ("posts" )
@@ -590,6 +561,35 @@ class Meta:
590561 # objects = GenericDateTaggedManager()
591562 # admin_manager = AdminDateTaggedManager()
592563
564+ _metadata = {
565+ "title" : "get_title" ,
566+ "description" : "get_description" ,
567+ "keywords" : "get_keywords" ,
568+ "og_description" : "get_description" ,
569+ "twitter_description" : "get_description" ,
570+ "schemaorg_description" : "get_description" ,
571+ "locale" : "get_locale" ,
572+ "image" : "get_image_full_url" ,
573+ "image_width" : "get_image_width" ,
574+ "image_height" : "get_image_height" ,
575+ "object_type" : "get_meta_attribute" ,
576+ "og_type" : "get_meta_attribute" ,
577+ "og_app_id" : "get_meta_attribute" ,
578+ "og_profile_id" : "get_meta_attribute" ,
579+ "og_publisher" : "get_meta_attribute" ,
580+ "og_author_url" : "get_meta_attribute" ,
581+ "og_author" : "get_meta_attribute" ,
582+ "twitter_type" : "get_meta_attribute" ,
583+ "twitter_site" : "get_meta_attribute" ,
584+ "twitter_author" : "get_meta_attribute" ,
585+ "schemaorg_type" : "get_meta_attribute" ,
586+ "published_time" : "date_published" ,
587+ "modified_time" : "date_modified" ,
588+ "expiration_time" : "date_published_end" ,
589+ "tag" : "get_tags" ,
590+ "url" : "get_absolute_url" ,
591+ }
592+
593593 @property
594594 def author (self ):
595595 return self .post .author
@@ -602,6 +602,10 @@ def date_published(self):
602602 def date_published_end (self ):
603603 return self .post .date_published_end
604604
605+ @property
606+ def date_modified (self ):
607+ return self .post .date_modified
608+
605609 @property
606610 def app_config (self ):
607611 return self .post .app_config
@@ -641,6 +645,57 @@ def get_template(self):
641645 else :
642646 return f"{ folder } /{ self .no_structure_template } "
643647
648+ def get_title (self ):
649+ title = self .meta_title
650+ if not title :
651+ title = self .title or _ ("No title" )
652+ return title .strip ()
653+
654+ def get_keywords (self ):
655+ """
656+ Returns the list of keywords (as python list)
657+ :return: list
658+ """
659+ keywords = self .meta_keywords .strip ()
660+ if "" .join (keywords ) == "" :
661+ return []
662+ return [keyword .strip () for keyword in keywords .split ("," )]
663+
664+ def get_description (self ):
665+ description = self .meta_description
666+ if not description :
667+ description = self .abstract
668+ return strip_tags (description ).strip ()
669+
670+ def get_image_full_url (self ):
671+ if self .post .main_image :
672+ if thumbnail_options := get_setting ("META_IMAGE_SIZE" ):
673+ thumbnail_url = get_thumbnailer (self .post .main_image ).get_thumbnail (thumbnail_options ).url
674+ return self .build_absolute_uri (thumbnail_url )
675+ return self .build_absolute_uri (self .post .main_image .url )
676+ return ""
677+
678+ def get_image_width (self ):
679+ if self .post .main_image :
680+ thumbnail_options = get_setting ("META_IMAGE_SIZE" )
681+ if thumbnail_options :
682+ return get_thumbnailer (self .post .main_image ).get_thumbnail (thumbnail_options ).width
683+ return self .post .main_image .width
684+
685+ def get_image_height (self ):
686+ if self .post .main_image :
687+ thumbnail_options = get_setting ("META_IMAGE_SIZE" )
688+ if thumbnail_options :
689+ return get_thumbnailer (self .post .main_image ).get_thumbnail (thumbnail_options ).height
690+ return self .post .main_image .height
691+
692+ def get_tags (self ):
693+ """
694+ Returns the list of object tags as comma separated list
695+ """
696+ taglist = [tag .name for tag in self .tags .all ()]
697+ return "," .join (taglist )
698+
644699 def __str__ (self ):
645700 return self .title or _ ("Untitled" )
646701
0 commit comments