def test_get_class(self): overriding, overridable = apps.get_app_configs() AbstractArticle = apps.get_class('overridable.abstract_models', 'AbstractArticle') self.assertEqual(AbstractArticle.__module__, 'apps.overriding.abstract_models') self.assertEqual(AbstractArticle.__name__, 'AbstractArticle') self.assertEqual( AbstractArticle, overridable.get_class('abstract_models', 'AbstractArticle')) self.assertEqual( AbstractArticle, overriding.get_class('abstract_models', 'AbstractArticle')) AbstractAuthor = apps.get_class('overridable.abstract_models', 'AbstractAuthor') self.assertEqual(AbstractAuthor.__module__, 'apps.overridable.abstract_models') self.assertEqual(AbstractAuthor.__name__, 'AbstractAuthor') self.assertEqual( AbstractAuthor, overridable.get_class('abstract_models', 'AbstractAuthor')) with self.assertRaises(LookupError): overriding.get_class('abstract_models', 'AbstractAuthor')
# -*- coding:utf-8 -*- from __future__ import unicode_literals from yepes.apps import apps from yepes.conf import settings from yepes.view_mixins import CanonicalMixin from yepes.views import ListView BlogMixin = apps.get_class('blogs.view_mixins', 'BlogMixin') LinkCategoryMixin = apps.get_class('links.view_mixins', 'LinkCategoryMixin') Link = apps.get_model('links', 'Link') LinkCategory = apps.get_model('links', 'LinkCategory') class LinkListView(BlogMixin, ListView): """ Displays a list of links. """ model = Link require_blog = False class LinkCategoryDetailView(LinkCategoryMixin, CanonicalMixin, LinkListView): """ Displays a list of links that belong to the given category. """ require_blog = settings.BLOG_MULTIPLE require_link_category = True
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractComment = apps.get_class('comments.abstract_models', 'AbstractComment') AbstractCommentStatus = apps.get_class('comments.abstract_models', 'AbstractCommentStatus') class Comment(AbstractComment): pass class CommentStatus(AbstractCommentStatus): pass
# -*- coding:utf-8 -*- from __future__ import unicode_literals from django.conf.urls import url from yepes.apps import apps from yepes.contrib.sitemaps.views import SitemapIndexView from yepes.urlresolvers import full_reverse_lazy CommentAtomFeed = apps.get_class('comments.feeds', 'CommentAtomFeed') CommentRssFeed = apps.get_class('comments.feeds', 'CommentRssFeed') PostsAtomFeed = apps.get_class('posts.feeds', 'PostsAtomFeed') PostsRssFeed = apps.get_class('posts.feeds', 'PostsRssFeed') AuthorPostsAtomFeed = apps.get_class('posts.feeds', 'AuthorPostsAtomFeed') AuthorPostsRssFeed = apps.get_class('posts.feeds', 'AuthorPostsRssFeed') CategoryPostsAtomFeed = apps.get_class('posts.feeds', 'CategoryPostsAtomFeed') CategoryPostsRssFeed = apps.get_class('posts.feeds', 'CategoryPostsRssFeed') TagPostsAtomFeed = apps.get_class('posts.feeds', 'TagPostsAtomFeed') TagPostsRssFeed = apps.get_class('posts.feeds', 'TagPostsRssFeed') AuthorDetailView = apps.get_class('authors.views', 'AuthorDetailView') AuthorListView = apps.get_class('authors.views', 'AuthorListView') CategoryDetailView = apps.get_class('posts.views', 'CategoryDetailView') CategoryListView = apps.get_class('posts.views', 'CategoryListView') PostDetailView = apps.get_class('posts.views', 'PostDetailView') PostListView = apps.get_class('posts.views', 'PostListView') PostSearchView = apps.get_class('posts.views', 'PostSearchView') TagDetailView = apps.get_class('posts.views', 'TagDetailView') TagListView = apps.get_class('posts.views', 'TagListView')
# -*- coding:utf-8 -*- from django.conf.urls import url from yepes.apps import apps ConfigurationsTestView = apps.get_class('thumbnails.views', 'ConfigurationsTestView') OptionsTestView = apps.get_class('thumbnails.views', 'OptionsTestView') urlpatterns = [ url( r'^configurations/$', ConfigurationsTestView.as_view(), name='thumbnail_configurations', ), url( r'^options/$', OptionsTestView.as_view(), name='thumbnail_options', ), ]
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractConfiguration = apps.get_class('thumbnails.abstract_models', 'AbstractConfiguration') AbstractSource = apps.get_class('thumbnails.abstract_models', 'AbstractSource') AbstractThumbnail = apps.get_class('thumbnails.abstract_models', 'AbstractThumbnail') class Configuration(AbstractConfiguration): pass class Source(AbstractSource): pass class Thumbnail(AbstractThumbnail): pass
from yepes.contrib.registry import registry from yepes.loading import LazyModel from yepes.model_mixins import ( Enableable, Illustrated, Logged, MetaData, Orderable, Slugged, ) from yepes.utils.emails import normalize_email, validate_email from yepes.utils.html import extract_text from yepes.utils.properties import described_property from yepes.validators.email import DOMAIN_RE NewsletterManager = apps.get_class('newsletters.managers', 'NewsletterManager') Delivery = LazyModel('newsletters', 'Delivery') Domain = LazyModel('newsletters', 'Domain') class AbstractBounce(models.Model): message = models.ForeignKey('Message', on_delete=models.CASCADE, related_name='bounces', verbose_name=_('Message')) newsletter = models.ForeignKey('Newsletter', on_delete=models.CASCADE, related_name='bounces', verbose_name=_('Newsletter'))
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractBrowser = apps.get_class('metrics.abstract_models', 'AbstractBrowser') AbstractEngine = apps.get_class('metrics.abstract_models', 'AbstractEngine') AbstractPlatform = apps.get_class('metrics.abstract_models', 'AbstractPlatform') AbstractPage = apps.get_class('metrics.abstract_models', 'AbstractPage') AbstractPageView = apps.get_class('metrics.abstract_models', 'AbstractPageView') AbstractReferrer = apps.get_class('metrics.abstract_models', 'AbstractReferrer') AbstractReferrerPage = apps.get_class('metrics.abstract_models', 'AbstractReferrerPage') AbstractVisit = apps.get_class('metrics.abstract_models', 'AbstractVisit') AbstractVisitor = apps.get_class('metrics.abstract_models', 'AbstractVisitor') class Browser(AbstractBrowser): pass class Engine(AbstractEngine): pass class Platform(AbstractPlatform): pass class Page(AbstractPage): pass class PageView(AbstractPageView): pass class Referrer(AbstractReferrer):
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractBounce = apps.get_class('newsletters.abstract_models', 'AbstractBounce') AbstractClick = apps.get_class('newsletters.abstract_models', 'AbstractClick') AbstractDelivery = apps.get_class('newsletters.abstract_models', 'AbstractDelivery') AbstractDomain = apps.get_class('newsletters.abstract_models', 'AbstractDomain') AbstractMessage = apps.get_class('newsletters.abstract_models', 'AbstractMessage') AbstractMessageImage = apps.get_class('newsletters.abstract_models', 'AbstractMessageImage') AbstractMessageLink = apps.get_class('newsletters.abstract_models', 'AbstractMessageLink') AbstractNewsletter = apps.get_class('newsletters.abstract_models', 'AbstractNewsletter') AbstractOpen = apps.get_class('newsletters.abstract_models', 'AbstractOpen') AbstractSubscriber = apps.get_class('newsletters.abstract_models', 'AbstractSubscriber') AbstractSubscriberTag = apps.get_class('newsletters.abstract_models', 'AbstractSubscriberTag') AbstractSubscription = apps.get_class('newsletters.abstract_models', 'AbstractSubscription') AbstractUnsubscription = apps.get_class('newsletters.abstract_models', 'AbstractUnsubscription') AbstractUnsubscriptionReason = apps.get_class('newsletters.abstract_models', 'AbstractUnsubscriptionReason')
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractCountry = apps.get_class('standards.abstract_models', 'AbstractCountry') AbstractCountrySubdivision = apps.get_class('standards.abstract_models', 'AbstractCountrySubdivision') AbstractCurrency = apps.get_class('standards.abstract_models', 'AbstractCurrency') AbstractGeographicArea = apps.get_class('standards.abstract_models', 'AbstractGeographicArea') AbstractLanguage = apps.get_class('standards.abstract_models', 'AbstractLanguage') AbstractRegion = apps.get_class('standards.abstract_models', 'AbstractRegion') class Country(AbstractCountry): pass class CountrySubdivision(AbstractCountrySubdivision): pass class Currency(AbstractCurrency): pass class GeographicArea(AbstractGeographicArea): pass
# -*- coding:utf-8 -*- from django.core.urlresolvers import reverse from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ from yepes.apps import apps from yepes.conf import settings from yepes.model_mixins import Linked from yepes.urlresolvers import full_reverse User = apps.get_registered_model(*settings.AUTH_USER_MODEL.split('.')) AuthorManager = apps.get_class('authors.managers', 'AuthorManager') @python_2_unicode_compatible class Author(Linked, User): objects = AuthorManager() class Meta: proxy = True verbose_name = _('Author') verbose_name_plural = _('Authors') def __str__(self): return self.get_full_name() or self.get_username() def get_absolute_url(self): kwargs = {'author_name': self.get_username()}
def _setup(self): self._wrapped = apps.get_class(self._module_path, self._class_name)
# -*- coding:utf-8 -*- from __future__ import unicode_literals from yepes.apps import apps from yepes.contrib.sitemaps.views import SitemapView AuthorSitemap = apps.get_class('authors.sitemaps', 'AuthorSitemap') class AuthorSitemapView(SitemapView): sitemap_class = AuthorSitemap
from django.core.urlresolvers import reverse, NoReverseMatch from django.http import Http404, HttpResponseRedirect from django.template.response import TemplateResponse from django.utils import six from django.utils.text import capfirst from django.utils.translation import ugettext_lazy as _ from django.views.decorators.cache import never_cache from yepes import admin from yepes.apps import apps from yepes.conf import settings from marchena.admin import BlogModelAdmin from marchena.templatetags.desk_urls import add_preserved_filters AuthorMixin = apps.get_class('authors.admin', 'AuthorMixin') CategoryMixin = apps.get_class('posts.admin', 'CategoryMixin') CommentMixin = apps.get_class('comments.admin', 'CommentMixin') LinkMixin = apps.get_class('links.admin', 'LinkMixin') LinkCategoryMixin = apps.get_class('links.admin', 'LinkCategoryMixin') PostMixin = apps.get_class('posts.admin', 'PostMixin') Author = apps.get_model('authors', 'Author') Blog = apps.get_model('blogs', 'Blog') Category = apps.get_model('posts', 'Category') Comment = apps.get_model('comments', 'Comment') Link = apps.get_model('links', 'Link') LinkCategory = apps.get_model('links', 'LinkCategory') Post = apps.get_model('posts', 'Post') Tag = apps.get_model('posts', 'Tag')
# -*- coding:utf-8 -*- from __future__ import unicode_literals from django.template import Library from yepes.apps import apps from yepes.template import AssignTag, SingleTag ConfigurationProxy = apps.get_class('thumbnails.proxies', 'ConfigurationProxy') register = Library() ## {% get_thumbnail source config[ as variable_name] %} ######################## class GetThumbnailTag(AssignTag): """ Returns a thumbnail of the ``source`` image with the given ``config``. If a matching thumbnail already exists, it will simply be returned. Otherwise, a new thumbnail is generated. """ target_var = 'thumbnail' @classmethod def get_syntax(cls, tag_name='tag_name'): syntax = super(GetThumbnailTag, cls).get_syntax(tag_name) # `force_generation` parameter is only for internal tests. return syntax.replace('[ force_generation]', '')
# -*- coding:utf-8 -*- from __future__ import unicode_literals from yepes.apps import apps from yepes.contrib.sitemaps.views import SitemapView BlogSitemap = apps.get_class('blogs.sitemaps', 'BlogSitemap') class BlogSitemapView(SitemapView): sitemap_class = BlogSitemap
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractAttachment = apps.get_class('attachments.abstract_models', 'AbstractAttachment') AbstractAttachmentCategory = apps.get_class('attachments.abstract_models', 'AbstractAttachmentCategory') class Attachment(AbstractAttachment): pass class AttachmentCategory(AbstractAttachmentCategory): pass
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractLink = apps.get_class('links.abstract_models', 'AbstractLink') AbstractLinkCategory = apps.get_class('links.abstract_models', 'AbstractLinkCategory') class Link(AbstractLink): pass class LinkCategory(AbstractLinkCategory): pass
# -*- coding:utf-8 -*- from __future__ import unicode_literals from yepes.apps import apps from yepes.view_mixins import CanonicalMixin from yepes.views import ListView AuthorMixin = apps.get_class('authors.view_mixins', 'AuthorMixin') BlogMixin = apps.get_class('blogs.view_mixins', 'BlogMixin') PostListView = apps.get_class('posts.views', 'PostListView') Author = apps.get_model('authors', 'Author') class AuthorDetailView(AuthorMixin, BlogMixin, CanonicalMixin, PostListView): """ Displays a list of published posts that belong to the given author. """ author_field = 'authors' require_author = True require_blog = False def get_canonical_path(self, request): author = self.get_author() return author.get_absolute_url() def get_template_names(self): names = super(AuthorDetailView, self).get_template_names() author = self.get_author() if author is not None:
# -*- coding:utf-8 -*- from __future__ import unicode_literals from datetime import timedelta from django.utils import timezone from yepes.apps import apps from yepes.contrib.sitemaps.views import SitemapView CategorySitemap = apps.get_class('posts.sitemaps', 'CategorySitemap') NewsSitemap = apps.get_class('posts.sitemaps', 'NewsSitemap') PostSitemap = apps.get_class('posts.sitemaps', 'PostSitemap') TagSitemap = apps.get_class('posts.sitemaps', 'TagSitemap') class CategorySitemapView(SitemapView): sitemap_class = CategorySitemap def get_sitemap_kwargs(self): kwargs = super(CategorySitemapView, self).get_sitemap_kwargs() if 'blog_pk' in self.kwargs: kwargs['blog_pk'] = self.kwargs['blog_pk'] elif 'blog_slug' in self.kwargs: kwargs['blog_slug'] = self.kwargs['blog_slug'] return kwargs
from django.core.urlresolvers import reverse from django.db import models from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.formats import number_format from django.utils.six.moves.urllib.request import urlopen from django.utils.translation import ugettext_lazy as _ from yepes import fields from yepes.apps import apps from yepes.conf import settings from yepes.model_mixins import Calculated, Logged from yepes.utils import slugify from yepes.utils.html import make_double_tag, make_single_tag from yepes.utils.properties import cached_property SourceFile = apps.get_class('thumbnails.files', 'SourceFile') def file_upload_to(instance, filename): return instance.get_upload_path(filename) @python_2_unicode_compatible class AbstractAttachment(Logged, Calculated): guid = fields.GuidField(editable=False, verbose_name=_('Global Unique Identifier')) title = fields.CharField(max_length=63, verbose_name=_('Title')) caption = fields.CharField(max_length=255, blank=True,
from yepes.contrib.registry import registry from yepes.loading import LazyModel from yepes.model_mixins import ( Displayable, Illustrated, Logged, MetaData, Orderable, Slugged, ) from yepes.types import Undefined from yepes.urlresolvers import full_reverse from marchena.modules.attachments.processors import attachment_tags PostManager = apps.get_class('posts.managers', 'PostManager') PostRecordManager = apps.get_class('posts.managers', 'PostRecordManager') PostRecord = LazyModel('posts', 'PostRecord') FakeDate = namedtuple('FakeDate', 'year, month, day') @python_2_unicode_compatible class AbstractCategory(Illustrated, Slugged, MetaData): blog = fields.CachedForeignKey('blogs.Blog', related_name='categories', verbose_name=_('Blog')) name = fields.CharField(unique=True, max_length=63, verbose_name=_('Name'))
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractBlog = apps.get_class('blogs.abstract_models', 'AbstractBlog') class Blog(AbstractBlog): pass
# -*- coding:utf-8 -*- from django.db.models import F, Q from yepes.apps import apps from yepes.cache import LookupTable from yepes.managers import ( EnableableManager, EnableableQuerySet, NestableManager, ) GeographicAreaProxy = apps.get_class('standards.proxies', 'GeographicAreaProxy') class CountryManager(EnableableManager): def get_by_natural_key(self, code): if code.isdigit(): return self.get(number=code) elif len(code) == 2: return self.get(code=code) elif len(code) == 3: return self.get(code_long=code) else: raise self.model.DoesNotExists class CountrySubdivisionQuerySet(EnableableQuerySet): def disabled(self): """
View, ) from yepes.apps import apps from yepes.utils.views import decorate_view from yepes.utils.aggregates import SumIf from yepes.views import FormView, UpdateView Click = apps.get_model('newsletters', 'Click') Delivery = apps.get_model('newsletters', 'Delivery') Message = apps.get_model('newsletters', 'Message') Open = apps.get_model('newsletters', 'Open') Subscriber = apps.get_model('newsletters', 'Subscriber') Subscription = apps.get_model('newsletters', 'Subscription') ProfileForm = apps.get_class('newsletters.forms', 'ProfileForm') DispatchForm = apps.get_class('newsletters.forms', 'DispatchForm') SubscriptionForm = apps.get_class('newsletters.forms', 'SubscriptionForm') UnsubscriptionForm = apps.get_class('newsletters.forms', 'UnsubscriptionForm') UnsubscriptionReasonForm = apps.get_class('newsletters.forms', 'UnsubscriptionReasonForm') ImageMixin = apps.get_class('newsletters.view_mixins', 'ImageMixin') LinkMixin = apps.get_class('newsletters.view_mixins', 'LinkMixin') MessageMixin = apps.get_class('newsletters.view_mixins', 'MessageMixin') NewsletterMixin = apps.get_class('newsletters.view_mixins', 'NewsletterMixin') SubscriberMixin = apps.get_class('newsletters.view_mixins', 'SubscriberMixin') prerender = apps.get_class('newsletters.utils', 'prerender') render = apps.get_class('newsletters.utils', 'render')
from __future__ import unicode_literals from django.utils import six from django.utils.itercompat import is_iterable from django.views.generic import ( ArchiveIndexView, DayArchiveView, MonthArchiveView, YearArchiveView, ) from yepes.apps import apps from yepes.view_mixins import CacheMixin BlogMixin = apps.get_class('blogs.view_mixins', 'BlogMixin') Post = apps.get_model('posts', 'Post') class PostArchiveIndexView(BlogMixin, CacheMixin, ArchiveIndexView): context_object_name = 'post_list' date_field = 'publish_from' date_list_period = 'month' model = Post require_blog = False def get_queryset(self): qs = super(PostArchiveIndexView, self).get_queryset() qs = qs.published(self.request.user)
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractCategory = apps.get_class('posts.abstract_models', 'AbstractCategory') AbstractPost = apps.get_class('posts.abstract_models', 'AbstractPost') AbstractPostRecord = apps.get_class('posts.abstract_models', 'AbstractPostRecord') AbstractTag = apps.get_class('posts.abstract_models', 'AbstractTag') class Category(AbstractCategory): pass class Post(AbstractPost): pass class PostRecord(AbstractPostRecord): pass class Tag(AbstractTag): pass
Bounce = apps.get_model('newsletters', 'Bounce') Click = apps.get_model('newsletters', 'Click') Delivery = apps.get_model('newsletters', 'Delivery') Domain = apps.get_model('newsletters', 'Domain') Message = apps.get_model('newsletters', 'Message') MessageImage = apps.get_model('newsletters', 'MessageImage') MessageLink = apps.get_model('newsletters', 'MessageLink') Newsletter = apps.get_model('newsletters', 'Newsletter') Open = apps.get_model('newsletters', 'Open') Subscriber = apps.get_model('newsletters', 'Subscriber') SubscriberTag = apps.get_model('newsletters', 'SubscriberTag') Subscription = apps.get_model('newsletters', 'Subscription') Unsubscription = apps.get_model('newsletters', 'Unsubscription') UnsubscriptionReason = apps.get_model('newsletters', 'UnsubscriptionReason') DispatchView = apps.get_class('newsletters.views', 'DispatchView') class StatisticsMixin(object): def admin_bounce_count(self, obj): return getattr(obj, 'bounce_count', 0) admin_bounce_count.admin_order_field = 'bounce_count' admin_bounce_count.short_description = _('Bounces') def admin_click_count(self, obj): return getattr(obj, 'click_count', 0) admin_click_count.admin_order_field = 'click_count' admin_click_count.short_description = _('Clicks')
# -*- coding:utf-8 -*- from yepes.apps import apps AbstractConnection = apps.get_class('emails.abstract_models', 'AbstractConnection') AbstractDelivery = apps.get_class('emails.abstract_models', 'AbstractDelivery') AbstractMessage = apps.get_class('emails.abstract_models', 'AbstractMessage') class Connection(AbstractConnection): pass class Delivery(AbstractDelivery): pass class Message(AbstractMessage): pass
# -*- coding:utf-8 -*- from django.conf.urls import url from yepes.apps import apps ImageView = apps.get_class('newsletters.views', 'ImageView') LinkView = apps.get_class('newsletters.views', 'LinkView') MessageView = apps.get_class('newsletters.views', 'MessageView') #NewsletterDetailView = apps.get_class('newsletters.views', 'NewsletterDetailView') #NewsletterListView = apps.get_class('newsletters.views', 'NewsletterListView') ProfileView = apps.get_class('newsletters.views', 'ProfileView') ResubscriptionView = apps.get_class('newsletters.views', 'ResubscriptionView') SubscriptionView = apps.get_class('newsletters.views', 'SubscriptionView') UnsubscriptionView = apps.get_class('newsletters.views', 'UnsubscriptionView') UnsubscriptionReasonView = apps.get_class('newsletters.views', 'UnsubscriptionReasonView') urlpatterns = [ #url(r'^$', #NewsletterListView.as_view(), #name='newsletter_list', #), url(r'^images/(?P<image_guid>[0-9a-f]+)/$', ImageView.as_view(), name='image', ), url(r'^images/(?P<subscriber_guid>[0-9a-f]+)/(?P<message_guid>[0-9a-f]+)/(?P<image_guid>[0-9a-f]+)/$', ImageView.as_view(), name='image', ),