Merge pull request #228 from nephila/feature/should_knock
Add option to customize the knocker behavior
This commit is contained in:
		
				commit
				
					
						746e5ec8af
					
				
			
		
					 7 changed files with 96 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -191,6 +191,12 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
 | 
			
		|||
                ),
 | 
			
		||||
                'classes': ('collapse',)
 | 
			
		||||
            }),
 | 
			
		||||
            ('Notifications', {
 | 
			
		||||
                'fields': (
 | 
			
		||||
                    'config.send_knock_create', 'config.send_knock_update'
 | 
			
		||||
                ),
 | 
			
		||||
                'classes': ('collapse',)
 | 
			
		||||
            }),
 | 
			
		||||
            ('Sitemap', {
 | 
			
		||||
                'fields': (
 | 
			
		||||
                    'config.sitemap_changefreq', 'config.sitemap_priority',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,4 +125,13 @@ class BlogConfigForm(AppDataForm):
 | 
			
		|||
        max_length=200, label=_('Google+ author name'), required=False,
 | 
			
		||||
        initial=get_setting('GPLUS_AUTHOR')
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    send_knock_create = forms.BooleanField(
 | 
			
		||||
        label=_('Send notifications on post publish'), required=False, initial=False,
 | 
			
		||||
        help_text=_('Emits a desktop notification -if enabled- when publishing a new post')
 | 
			
		||||
    )
 | 
			
		||||
    send_knock_update = forms.BooleanField(
 | 
			
		||||
        label=_('Send notifications on post update'), required=False, initial=False,
 | 
			
		||||
        help_text=_('Emits a desktop notification -if enabled- when editing a published post')
 | 
			
		||||
    )
 | 
			
		||||
setup_config(BlogConfigForm, BlogConfig)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -265,6 +265,10 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
 | 
			
		|||
        return title.strip()
 | 
			
		||||
 | 
			
		||||
    def get_keywords(self):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the list of keywords (as python list)
 | 
			
		||||
        :return: list
 | 
			
		||||
        """
 | 
			
		||||
        return self.safe_translation_getter('meta_keywords', default='').strip().split(',')
 | 
			
		||||
 | 
			
		||||
    def get_locale(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -282,10 +286,16 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
 | 
			
		|||
        return ''
 | 
			
		||||
 | 
			
		||||
    def get_tags(self):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the list of object tags as comma separated list
 | 
			
		||||
        """
 | 
			
		||||
        taglist = [tag.name for tag in self.tags.all()]
 | 
			
		||||
        return ','.join(taglist)
 | 
			
		||||
 | 
			
		||||
    def get_author(self):
 | 
			
		||||
        """
 | 
			
		||||
        Return the author (user) objects
 | 
			
		||||
        """
 | 
			
		||||
        return self.author
 | 
			
		||||
 | 
			
		||||
    def _set_default_author(self, current_user):
 | 
			
		||||
| 
						 | 
				
			
			@ -309,6 +319,9 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
 | 
			
		|||
            return get_setting('IMAGE_FULL_SIZE')
 | 
			
		||||
 | 
			
		||||
    def get_full_url(self):
 | 
			
		||||
        """
 | 
			
		||||
        Return the url with protocol and domain url
 | 
			
		||||
        """
 | 
			
		||||
        return self.build_absolute_uri(self.get_absolute_url())
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
| 
						 | 
				
			
			@ -321,6 +334,15 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
 | 
			
		|||
                (self.date_published_end is None or self.date_published_end > timezone.now())
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def should_knock(self, created=False):
 | 
			
		||||
        """
 | 
			
		||||
        Returns whether to emit knocks according to the post state
 | 
			
		||||
        """
 | 
			
		||||
        new = (self.app_config.send_knock_create and self.is_published and
 | 
			
		||||
               self.date_published == self.date_modified)
 | 
			
		||||
        updated = self.app_config.send_knock_update and self.is_published
 | 
			
		||||
        return new or updated
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BasePostPlugin(CMSPlugin):
 | 
			
		||||
    app_config = AppHookConfigField(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue