Add meta attributes
This commit is contained in:
		
					parent
					
						
							
								8d69fb107e
							
						
					
				
			
			
				commit
				
					
						63adbb1131
					
				
			
		
					 3 changed files with 100 additions and 54 deletions
				
			
		| 
						 | 
					@ -25,25 +25,65 @@ class BlogConfig(TranslatableModel, AppHookConfig):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BlogConfigForm(AppDataForm):
 | 
					class BlogConfigForm(AppDataForm):
 | 
				
			||||||
    default_published = forms.BooleanField(label=_('Post published by default'), required=False,
 | 
					    default_published = forms.BooleanField(
 | 
				
			||||||
                                           initial=get_setting('DEFAULT_PUBLISHED'))
 | 
					        label=_('Post published by default'), required=False,
 | 
				
			||||||
    use_placeholder = forms.BooleanField(label=_('Use placeholder and plugins for article body'),
 | 
					        initial=get_setting('DEFAULT_PUBLISHED')
 | 
				
			||||||
                                         required=False,
 | 
					    )
 | 
				
			||||||
                                         initial=get_setting('USE_PLACEHOLDER'))
 | 
					    use_placeholder = forms.BooleanField(
 | 
				
			||||||
    use_abstract = forms.BooleanField(label=_('Use abstract field'),
 | 
					        label=_('Use placeholder and plugins for article body'), required=False,
 | 
				
			||||||
                                      required=False,
 | 
					        initial=get_setting('USE_PLACEHOLDER')
 | 
				
			||||||
                                      initial=get_setting('USE_ABSTRACT'))
 | 
					    )
 | 
				
			||||||
    set_author = forms.BooleanField(label=_('Set author'),
 | 
					    use_abstract = forms.BooleanField(
 | 
				
			||||||
                                    required=False,
 | 
					        label=_('Use abstract field'), required=False,
 | 
				
			||||||
                                    help_text=_('Set author by default'),
 | 
					        initial=get_setting('USE_ABSTRACT')
 | 
				
			||||||
                                    initial=get_setting('AUTHOR_DEFAULT'))
 | 
					    )
 | 
				
			||||||
    paginate_by = forms.IntegerField(label=_('Paginate size'),
 | 
					    set_author = forms.BooleanField(
 | 
				
			||||||
                                     required=False,
 | 
					        label=_('Set author'), required=False, help_text=_('Set author by default'),
 | 
				
			||||||
                                     initial=get_setting('PAGINATION'),
 | 
					        initial=get_setting('AUTHOR_DEFAULT')
 | 
				
			||||||
                                     help_text=_('When paginating list views, '
 | 
					    )
 | 
				
			||||||
                                                 'how many articles per page?'))
 | 
					    paginate_by = forms.IntegerField(
 | 
				
			||||||
    template_prefix = forms.CharField(label=_('Template prefix'), required=False, initial='',
 | 
					        label=_('Paginate size'), required=False, initial=get_setting('PAGINATION'),
 | 
				
			||||||
                                      help_text=_('Alternative directory to load the blog '
 | 
					        help_text=_('When paginating list views, how many articles per page?')
 | 
				
			||||||
                                                  'templates from')
 | 
					    )
 | 
				
			||||||
                                      )
 | 
					    template_prefix = forms.CharField(
 | 
				
			||||||
 | 
					        label=_('Template prefix'), required=False, initial='',
 | 
				
			||||||
 | 
					        help_text=_('Alternative directory to load the blog templates from')
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    object_type = forms.ChoiceField(
 | 
				
			||||||
 | 
					        label=_('Object type'), required=False,
 | 
				
			||||||
 | 
					        choices=get_setting('TYPES_GENERIC'), initial=get_setting('TYPE')
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    og_type = forms.ChoiceField(
 | 
				
			||||||
 | 
					        label=_('Facebook type'), required=False,
 | 
				
			||||||
 | 
					        choices=get_setting('TYPES_FACEBOOK'), initial=get_setting('TYPES_FACEBOOK')[0][0]
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    og_app_id = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Facebook application ID'), required=False,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    og_profile_id = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Facebook profile ID'), required=False,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    og_publisher = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Facebook page URL'), required=False
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    og_author_url = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Facebook author URL'), required=False
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    twitter_type = forms.ChoiceField(
 | 
				
			||||||
 | 
					        label=_('Twitter type'), required=False,
 | 
				
			||||||
 | 
					        choices=get_setting('TYPES_TWITTER'), initial=get_setting('TYPES_TWITTER')[0][0]
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    twitter_site = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Twitter site handle'), required=False
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    twitter_author = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Twitter author handle'), required=False
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    gplus_type = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Google+ type'), required=False,
 | 
				
			||||||
 | 
					        choices=get_setting('TYPES_GPLUS'), initial=get_setting('TYPES_GPLUS')[0][0]
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    gplus_author = forms.CharField(
 | 
				
			||||||
 | 
					        max_length=200, label=_('Google+ author name'), required=False
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
setup_config(BlogConfigForm, BlogConfig)
 | 
					setup_config(BlogConfigForm, BlogConfig)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -144,20 +144,19 @@ class Post(ModelMeta, TranslatableModel):
 | 
				
			||||||
        'og_description': 'get_description',
 | 
					        'og_description': 'get_description',
 | 
				
			||||||
        'twitter_description': 'get_description',
 | 
					        'twitter_description': 'get_description',
 | 
				
			||||||
        'gplus_description': 'get_description',
 | 
					        'gplus_description': 'get_description',
 | 
				
			||||||
        'keywords': 'get_keywords',
 | 
					 | 
				
			||||||
        'locale': None,
 | 
					        'locale': None,
 | 
				
			||||||
        'image': 'get_image_full_url',
 | 
					        'image': 'get_image_full_url',
 | 
				
			||||||
        'object_type': get_setting('TYPE'),
 | 
					        'object_type': 'get_meta_attribute',
 | 
				
			||||||
        'og_type': get_setting('FB_TYPE'),
 | 
					        'og_type': 'get_meta_attribute',
 | 
				
			||||||
        'og_app_id': get_setting('FB_APPID'),
 | 
					        'og_app_id': 'get_meta_attribute',
 | 
				
			||||||
        'og_profile_id': get_setting('FB_PROFILE_ID'),
 | 
					        'og_profile_id': 'get_meta_attribute',
 | 
				
			||||||
        'og_publisher': get_setting('FB_PUBLISHER'),
 | 
					        'og_publisher': 'get_meta_attribute',
 | 
				
			||||||
        'og_author_url': get_setting('FB_AUTHOR_URL'),
 | 
					        'og_author_url': 'get_meta_attribute',
 | 
				
			||||||
        'twitter_type': get_setting('TWITTER_TYPE'),
 | 
					        'twitter_type': 'get_meta_attribute',
 | 
				
			||||||
        'twitter_site': get_setting('TWITTER_SITE'),
 | 
					        'twitter_site': 'get_meta_attribute',
 | 
				
			||||||
        'twitter_author': get_setting('TWITTER_AUTHOR'),
 | 
					        'twitter_author': 'get_meta_attribute',
 | 
				
			||||||
        'gplus_type': get_setting('GPLUS_TYPE'),
 | 
					        'gplus_type': 'get_meta_attribute',
 | 
				
			||||||
        'gplus_author': get_setting('GPLUS_AUTHOR'),
 | 
					        'gplus_author': 'get_meta_attribute',
 | 
				
			||||||
        'published_time': 'date_published',
 | 
					        'published_time': 'date_published',
 | 
				
			||||||
        'modified_time': 'date_modified',
 | 
					        'modified_time': 'date_modified',
 | 
				
			||||||
        'expiration_time': 'date_published_end',
 | 
					        'expiration_time': 'date_published_end',
 | 
				
			||||||
| 
						 | 
					@ -185,6 +184,13 @@ class Post(ModelMeta, TranslatableModel):
 | 
				
			||||||
                                                       any_language=True)}
 | 
					                                                       any_language=True)}
 | 
				
			||||||
        return reverse('%s:post-detail' % self.app_config.namespace, kwargs=kwargs)
 | 
					        return reverse('%s:post-detail' % self.app_config.namespace, kwargs=kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_meta_attribute(self, param):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Retrieves django-meta attributes from apphook config instance
 | 
				
			||||||
 | 
					        :param param: django-meta attribute passed as key
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        return getattr(self.app_config, param)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def save_translation(self, translation, *args, **kwargs):
 | 
					    def save_translation(self, translation, *args, **kwargs):
 | 
				
			||||||
        if not translation.slug and translation.title:
 | 
					        if not translation.slug and translation.title:
 | 
				
			||||||
            translation.slug = slugify(translation.title)
 | 
					            translation.slug = slugify(translation.title)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,11 @@ def get_setting(name):
 | 
				
			||||||
    from django.conf import settings
 | 
					    from django.conf import settings
 | 
				
			||||||
    from meta_mixin import settings as meta_settings
 | 
					    from meta_mixin import settings as meta_settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    OBJECT_TYPES = {
 | 
				
			||||||
 | 
					        'Article': _('Article'),
 | 
				
			||||||
 | 
					        'Website': _('Website'),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default = {
 | 
					    default = {
 | 
				
			||||||
        'BLOG_IMAGE_THUMBNAIL_SIZE': getattr(settings, 'BLOG_IMAGE_THUMBNAIL_SIZE', {
 | 
					        'BLOG_IMAGE_THUMBNAIL_SIZE': getattr(settings, 'BLOG_IMAGE_THUMBNAIL_SIZE', {
 | 
				
			||||||
            'size': '120x120',
 | 
					            'size': '120x120',
 | 
				
			||||||
| 
						 | 
					@ -23,30 +28,25 @@ def get_setting(name):
 | 
				
			||||||
        'BLOG_TAGCLOUD_MAX': getattr(settings, 'BLOG_TAGCLOUD_MAX', 10),
 | 
					        'BLOG_TAGCLOUD_MAX': getattr(settings, 'BLOG_TAGCLOUD_MAX', 10),
 | 
				
			||||||
        'BLOG_PAGINATION': getattr(settings, 'BLOG_PAGINATION', 10),
 | 
					        'BLOG_PAGINATION': getattr(settings, 'BLOG_PAGINATION', 10),
 | 
				
			||||||
        'BLOG_LATEST_POSTS': getattr(settings, 'BLOG_LATEST_POSTS', 5),
 | 
					        'BLOG_LATEST_POSTS': getattr(settings, 'BLOG_LATEST_POSTS', 5),
 | 
				
			||||||
        'BLOG_POSTS_LIST_TRUNCWORDS_COUNT': getattr(settings,
 | 
					        'BLOG_POSTS_LIST_TRUNCWORDS_COUNT': getattr(
 | 
				
			||||||
                                                    'BLOG_POSTS_LIST_TRUNCWORDS_COUNT',
 | 
					            settings, 'BLOG_POSTS_LIST_TRUNCWORDS_COUNT', 100
 | 
				
			||||||
                                                    100),
 | 
					        ),
 | 
				
			||||||
        'BLOG_TYPE': getattr(settings, 'BLOG_TYPE', 'Article'),
 | 
					        'BLOG_TYPE': getattr(settings, 'BLOG_TYPE', 'Article'),
 | 
				
			||||||
 | 
					        'BLOG_TYPES': getattr(settings, 'BLOG_TYPES', ),
 | 
				
			||||||
        'BLOG_FB_TYPE': getattr(settings, 'BLOG_FB_TYPE', 'Article'),
 | 
					        'BLOG_FB_TYPE': getattr(settings, 'BLOG_FB_TYPE', 'Article'),
 | 
				
			||||||
        'BLOG_FB_APPID': getattr(settings, 'BLOG_FB_APPID',
 | 
					        'BLOG_FB_TYPES': getattr(settings, 'BLOG_FB_TYPES', OBJECT_TYPES.items()),
 | 
				
			||||||
                                 meta_settings.FB_APPID),
 | 
					        'BLOG_FB_APPID': getattr(settings, 'BLOG_FB_APPID', meta_settings.FB_APPID),
 | 
				
			||||||
        'BLOG_FB_PROFILE_ID': getattr(settings, 'BLOG_FB_PROFILE_ID',
 | 
					        'BLOG_FB_PROFILE_ID': getattr(settings, 'BLOG_FB_PROFILE_ID', meta_settings.FB_PROFILE_ID),
 | 
				
			||||||
                                      meta_settings.FB_PROFILE_ID),
 | 
					        'BLOG_FB_PUBLISHER': getattr(settings, 'BLOG_FB_PUBLISHER', meta_settings.FB_PUBLISHER),
 | 
				
			||||||
        'BLOG_FB_PUBLISHER': getattr(settings, 'BLOG_FB_PUBLISHER',
 | 
					        'BLOG_FB_AUTHOR_URL': getattr(settings, 'BLOG_FB_AUTHOR_URL', 'get_author_url'),
 | 
				
			||||||
                                     meta_settings.FB_PUBLISHER),
 | 
					        'BLOG_FB_AUTHOR': getattr(settings, 'BLOG_FB_AUTHOR', 'get_author_name'),
 | 
				
			||||||
        'BLOG_FB_AUTHOR_URL': getattr(settings, 'BLOG_FB_AUTHOR_URL',
 | 
					 | 
				
			||||||
                                      'get_author_url'),
 | 
					 | 
				
			||||||
        'BLOG_FB_AUTHOR': getattr(settings, 'BLOG_FB_AUTHOR',
 | 
					 | 
				
			||||||
                                  'get_author_name'),
 | 
					 | 
				
			||||||
        'BLOG_TWITTER_TYPE': getattr(settings, 'BLOG_TWITTER_TYPE', 'Summary'),
 | 
					        'BLOG_TWITTER_TYPE': getattr(settings, 'BLOG_TWITTER_TYPE', 'Summary'),
 | 
				
			||||||
        'BLOG_TWITTER_SITE': getattr(settings, 'BLOG_TWITTER_SITE',
 | 
					        'BLOG_TWITTER_TYPES': getattr(settings, 'BLOG_TWITTER_TYPES', OBJECT_TYPES.items()),
 | 
				
			||||||
                                     meta_settings.TWITTER_SITE),
 | 
					        'BLOG_TWITTER_SITE': getattr(settings, 'BLOG_TWITTER_SITE', meta_settings.TWITTER_SITE),
 | 
				
			||||||
        'BLOG_TWITTER_AUTHOR': getattr(settings, 'BLOG_TWITTER_AUTHOR',
 | 
					        'BLOG_TWITTER_AUTHOR': getattr(settings, 'BLOG_TWITTER_AUTHOR', 'get_author_twitter'),
 | 
				
			||||||
                                       'get_author_twitter'),
 | 
					        'BLOG_GPLUS_TYPE': getattr(settings, 'BLOG_GPLUS_SCOPE_CATEGORY', 'Blog'),
 | 
				
			||||||
        'BLOG_GPLUS_TYPE': getattr(settings, 'BLOG_GPLUS_SCOPE_CATEGORY',
 | 
					        'BLOG_GPLUS_TYPES': getattr(settings, 'BLOG_GPLUS_TYPES', OBJECT_TYPES.items()),
 | 
				
			||||||
                                   'Blog'),
 | 
					        'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR', 'get_author_gplus'),
 | 
				
			||||||
        'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR',
 | 
					 | 
				
			||||||
                                     'get_author_gplus'),
 | 
					 | 
				
			||||||
        'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
 | 
					        'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
 | 
				
			||||||
        'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
 | 
					        'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
 | 
				
			||||||
        'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', True),
 | 
					        'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', True),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue