def setUpClass(cls): super(AppTestCase, cls).setUpClass() # Avoid early import, triggers AppCache from django.template.loaders import app_directories User = get_user_model() if cls.install_apps: # When running this app via `./manage.py test fluent_pages`, auto install the test app + models. run_syncdb = False for appname in cls.install_apps: if appname not in settings.INSTALLED_APPS: print('Adding {0} to INSTALLED_APPS'.format(appname)) settings.INSTALLED_APPS = (appname,) + tuple(settings.INSTALLED_APPS) run_syncdb = True # Flush caches testapp = import_module(appname) loading.cache.loaded = False app_directories.app_template_dirs += ( os.path.join(os.path.dirname(testapp.__file__), 'templates'), ) if run_syncdb: call_command('syncdb', verbosity=0) # may run south's overlaid version # Create basic objects # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does. Site.objects.get_or_create(id=settings.SITE_ID, defaults=dict(domain='django.localhost', name='django at localhost')) cls.user, _ = User.objects.get_or_create(is_superuser=True, is_staff=True, username="******") # Create tree. # Reset data first because the testcase class setup runs outside the transaction UrlNode.objects.all().delete() cls.setUpTree()
def setUpClass(cls): super(AppTestCase, cls).setUpClass() # Avoid early import, triggers AppCache User = get_user_model() if cls.install_apps: # When running this app via `./manage.py test fluent_pages`, auto install the test app + models. run_syncdb = False for appname in cls.install_apps: if appname not in settings.INSTALLED_APPS: print('Adding {0} to INSTALLED_APPS'.format(appname)) settings.INSTALLED_APPS = (appname, ) + tuple( settings.INSTALLED_APPS) run_syncdb = True testapp = import_module(appname) # Flush caches if django.VERSION < (1, 9): from django.template.loaders import app_directories from django.db.models import loading loading.cache.loaded = False app_directories.app_template_dirs += (os.path.join( os.path.dirname(testapp.__file__), 'templates'), ) else: from django.template.utils import get_app_template_dirs get_app_template_dirs.cache_clear() if run_syncdb: if django.VERSION < (1, 7): call_command( 'syncdb', verbosity=0) # may run south's overlaid version else: call_command('migrate', verbosity=0) # Create basic objects # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does. Site.objects.get_or_create(id=settings.SITE_ID, defaults=dict(domain='django.localhost', name='django at localhost')) cls.user, _ = User.objects.get_or_create(is_superuser=True, is_staff=True, username="******") # Create tree. # Reset data first because the testcase class setup runs outside the transaction UrlNode.objects.all().delete() cls.setUpTree()
def setUpClass(cls): super(AppTestCase, cls).setUpClass() # Avoid early import, triggers AppCache User = get_user_model() if cls.install_apps: # When running this app via `./manage.py test fluent_pages`, auto install the test app + models. run_syncdb = False for appname in cls.install_apps: if appname not in settings.INSTALLED_APPS: print('Adding {0} to INSTALLED_APPS'.format(appname)) settings.INSTALLED_APPS = (appname,) + tuple(settings.INSTALLED_APPS) run_syncdb = True testapp = import_module(appname) # Flush caches if django.VERSION < (1, 9): from django.template.loaders import app_directories from django.db.models import loading loading.cache.loaded = False app_directories.app_template_dirs += ( os.path.join(os.path.dirname(testapp.__file__), 'templates'), ) else: from django.template.utils import get_app_template_dirs get_app_template_dirs.cache_clear() if run_syncdb: if django.VERSION < (1, 7): call_command('syncdb', verbosity=0) # may run south's overlaid version else: call_command('migrate', verbosity=0) # Create basic objects # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does. Site.objects.get_or_create(id=settings.SITE_ID, defaults=dict(domain='django.localhost', name='django at localhost')) cls.user, _ = User.objects.get_or_create(is_superuser=True, is_staff=True, username="******")
def get_queryset(self): self.author = get_object_or_404(get_user_model(), pk=self.kwargs['author_id']) return super(EntryAuthorArchive, self).get_queryset().filter(author=self.author)
from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.sitemaps import Sitemap from fluent_blogs.models import get_entry_model, get_category_model from fluent_blogs.urlresolvers import blog_reverse from fluent_utils.django_compat import get_user_model from parler.models import TranslatableModel User = get_user_model() EntryModel = get_entry_model() CategoryModel = get_category_model() class EntrySitemap(Sitemap): """ The sitemap definition for the pages created with django-fluent-blogs. """ def items(self): qs = EntryModel.objects.published().order_by('-publication_date') if issubclass(EntryModel, TranslatableModel): # Note that .active_translations() can't be combined with other filters for translations__.. fields. qs = qs.active_translations() return qs.order_by('-publication_date', 'translations__language_code') else: return qs.order_by('-publication_date') def lastmod(self, urlnode): """Return the last modification of the entry.""" return urlnode.modification_date
def get_user(self, slug): User = get_user_model() return get_object_or_404(User, username=slug)
def get_object(self, request, author_id): User = get_user_model() return get_object_or_404(User, pk=author_id)
def get_object(self, request, slug): User = get_user_model() return get_object_or_404(User, username=slug)
def get_queryset(self): self.author = get_object_or_404(get_user_model(), username=self.kwargs['slug']) return super(EntryAuthorArchive, self).get_queryset().filter(author=self.author)