コード例 #1
0
ファイル: cache.py プロジェクト: vilos/django-post_office
 def test_basic_cache_operations(self):
     """
         Test basic cache operations
     """
     # clean test cache
     cache.cache_backend.clear()
     self.assertEqual(None, cache.get("test-cache"))
     cache.set("test-cache", "awesome content")
     self.assertTrue("awesome content", cache.get("test-cache"))
     cache.delete("test-cache")
     self.assertEqual(None, cache.get("test-cache"))
コード例 #2
0
 def test_basic_cache_operations(self):
     """
         Test basic cache operations
     """
     # clean test cache
     cache.cache_backend.clear()
     self.assertEqual(None, cache.get('test-cache'))
     cache.set('test-cache', 'awesome content')
     self.assertTrue('awesome content', cache.get('test-cache'))
     cache.delete('test-cache')
     self.assertEqual(None, cache.get('test-cache'))
コード例 #3
0
ファイル: cache.py プロジェクト: 42cc/django-post_office
 def test_basic_cache_operations(self):
     """
         Test basic cache operations
     """
     # clean test cache
     cache.cache_backend.clear()
     self.assertEqual(None, cache.get('test-cache'))
     cache.set('test-cache', 'awesome content')
     self.assertTrue('awesome content', cache.get('test-cache'))
     cache.delete('test-cache')
     self.assertEqual(None, cache.get('test-cache'))
コード例 #4
0
def get_email_template(name):
    """
    Function that returns an email template instance, from cache or DB.
    """
    if hasattr(settings, 'POST_OFFICE_CACHE') and settings.POST_OFFICE_TEMPLATE_CACHE is False:
        return EmailTemplate.objects.get(name=name)
    else:
        email_template = cache.get(name)
        if email_template is not None:
            return email_template
        else:
            email_template = EmailTemplate.objects.get(name=name)
            cache.set(name, email_template)
            return email_template
コード例 #5
0
ファイル: utils.py プロジェクト: 42cc/django-post_office
def get_email_template(name):
    """
    Function to get email template object that checks from cache first if caching is enabled
    """
    if hasattr(settings, 'POST_OFFICE_CACHE') and settings.POST_OFFICE_TEMPLATE_CACHE is False:
        return EmailTemplate.objects.get(name=name)
    else:
        email_template = cache.get(name)
        if email_template is not None:
            return email_template
        else:
            email_template = EmailTemplate.objects.get(name=name)
            cache.set(name, email_template)
            return email_template
コード例 #6
0
ファイル: utils.py プロジェクト: LeGast00n/django-post_office
def get_email_template(name):
    """
    Function that returns an email template instance, from cache or DB.
    """
    if hasattr(settings, 'POST_OFFICE_CACHE'
               ) and settings.POST_OFFICE_TEMPLATE_CACHE is False:
        return EmailTemplate.objects.get(name=name)
    else:
        email_template = cache.get(name)
        if email_template is not None:
            return email_template
        else:
            email_template = EmailTemplate.objects.get(name=name)
            cache.set(name, email_template)
            return email_template
コード例 #7
0
def get_email_template(name, language=''):
    """
    Function that returns an email template instance, from cache or DB.
    """
    use_cache = getattr(settings, 'POST_OFFICE_CACHE', True)
    if use_cache:
        use_cache = getattr(settings, 'POST_OFFICE_TEMPLATE_CACHE', True)
    if not use_cache:
        return EmailTemplate.objects.get(name=name, language=language)
    else:
        composite_name = '%s:%s' % (name, language)
        email_template = cache.get(composite_name)
        if email_template is None:
            email_template = EmailTemplate.objects.get(name=name,
                                                       language=language)
            cache.set(composite_name, email_template)
        return email_template
コード例 #8
0
ファイル: utils.py プロジェクト: SeiryuZ/django-post_office
def get_email_template(name, language=''):
    """
    Function that returns an email template instance, from cache or DB.
    """
    use_cache = getattr(settings, 'POST_OFFICE_CACHE', True)
    if use_cache:
        use_cache = getattr(settings, 'POST_OFFICE_TEMPLATE_CACHE', True)
    if not use_cache:
        return EmailTemplate.objects.get(name=name, language=language)
    else:
        composite_name = '%s:%s' % (name, language)
        email_template = cache.get(composite_name)
        if email_template is not None:
            return email_template
        else:
            email_template = EmailTemplate.objects.get(name=name,
                                                       language=language)
            cache.set(composite_name, email_template)
            return email_template