Exemplo n.º 1
0
 def test_lazy_loading(self):
     cls = LazyClass('registry.base', 'asdfg')
     with self.assertRaises(MissingClassError):
         cls._meta
     with self.assertRaises(MissingClassError):
         cls._meta = None
     with self.assertRaises(MissingClassError):
         del cls._meta
Exemplo n.º 2
0
 def test_subclass_check(self):
     cls = LazyClass('registry.base', 'Registry')
     from yepes.contrib.registry.base import Registry
     self.assertFalse(issubclass(object, Registry))
     self.assertFalse(issubclass(object, cls))
     self.assertTrue(issubclass(Registry, Registry))
     self.assertTrue(issubclass(Registry, cls))
     self.assertTrue(issubclass(cls, Registry))
     self.assertTrue(issubclass(cls, cls))
Exemplo n.º 3
0
 def test_representation(self):
     cls = LazyClass('registry.base', 'Registry')
     self.assertEqual(repr(cls), '<LazyClass: registry.base.Registry>')
     cls = LazyClass('registry.base', 'asdfg')
     self.assertEqual(repr(cls), '<LazyClass: registry.base.asdfg>')
Exemplo n.º 4
0
 def test_instance_check(self):
     cls = LazyClass('registry.base', 'Registry')
     from yepes.contrib.registry.base import Registry
     self.assertIsInstance(Registry(), cls)
     self.assertIsInstance(cls(), cls)
Exemplo n.º 5
0
 def test_call(self):
     cls = LazyClass('registry.base', 'Registry')
     from yepes.contrib.registry.base import Registry
     self.assertIsInstance(cls(), object)
     self.assertIsInstance(cls(), Registry)
     self.assertIsInstance(cls(), cls)
Exemplo n.º 6
0
 def test_class(self):
     cls = LazyClass('registry.base', 'Registry')
     from yepes.contrib.registry.base import Registry
     self.assertEqual(cls.__class__, object.__class__)
     self.assertEqual(cls.__class__, Registry.__class__)
Exemplo n.º 7
0
# -*- coding:utf-8 -*-

from __future__ import unicode_literals

from django.utils.text import Truncator

from yepes.contrib.registry import registry
from yepes.loading import LazyClass, LazyModel
from yepes.utils.http import get_meta_data

Comment = LazyModel('comments', 'Comment')
CommentForm = LazyClass('comments.forms', 'CommentForm')


class CommentHandler(object):

    # PUBLIC METHODS

    @classmethod
    def create_comment(cls, post, data, request):

        if not post.allow_comments():
            return None

        author = cls._get_author(request)
        name = data['author_name']
        email = data['author_email']
        url = data['author_url']
        ip_address = cls._get_ip_address(request)
        user_agent = cls._get_user_agent(request)
        referer = cls._get_referer(request)
Exemplo n.º 8
0
# -*- coding:utf-8 -*-

from __future__ import unicode_literals

from django.utils import six

from yepes.contrib.datamigrations import BaseModelMigration, TextField
from yepes.loading import LazyClass, LazyModel
from yepes.utils.properties import cached_property

Subscriber = LazyModel('newsletters', 'Subscriber')
SubscriberPlan = LazyClass('newsletters.importation_plans', 'SubscriberPlan')


class SubscriberImportation(BaseModelMigration):

    can_create = True
    can_export = False
    can_update = False

    fields = [
        TextField('email_address'),
        TextField('first_name'),
        TextField('last_name'),
        TextField('newsletters'),
        TextField('tags'),
    ]

    def __init__(self):
        super(SubscriberImportation, self).__init__(Subscriber)