Exemplo n.º 1
0
 def test_default_model(self):
     """The cccontact.model.Contact models is the default model"""
     self.assertEqual(
             get_model()._meta.module_name,
             'item')
     self.assertEqual(
             get_model()._meta.app_label,
             'ccgallery')
Exemplo n.º 2
0
 def test_nonsense_model(self):
     """ if a custom model doesn't exists we get the
     bundled model returned"""
     # set thesettings.CCCONTACT_MODEL custom model
     settings.CCGALLERY_MODEL = 'nonsense.JabberWocky'
     reload(c_settings)
     self.assertEqual(
             get_model()._meta.module_name,
             'item')
     self.assertEqual(
             get_model()._meta.app_label,
             'ccgallery')
Exemplo n.º 3
0
 def test_custom_model(self):
     """The custom model can be overridden"""
     # set thesettings.CCCONTACT_MODEL custom model
     settings.CCGALLERY_MODEL = 'ccgallery.tests.test_settings.FakeModel'
     reload(c_settings)
     # we have the fake model
     self.assertEqual('FakeModel', get_model().__name__)
Exemplo n.º 4
0
 def render(self, context):
     items = get_model().objects\
             .visible()
     if self.categories is not None:
         try:
             categories = self.categories.split(',')
         except AttributeError:
             categories = [self.categories]
         items = items.filter(
                 categories__pk__in=categories)
     context[self.varname] = items
     return ''
Exemplo n.º 5
0
def category(request, slug):

    try:
        category = Category.objects.visible().get(slug=slug)
    except Category.DoesNotExist:
        raise Http404('Category slug not found')

    items = get_model().objects\
            .visible()\
            .filter(categories=category)

    return render_to_response(
            'ccgallery/category.html', {
                'category': category,
                'items': items,
                }, RequestContext(request))
Exemplo n.º 6
0
def item(request, slug, category_slug=None):
    model_cls = get_model()
    category = None

    try:
        item = model_cls.objects.visible().get(slug=slug)
    except model_cls.DoesNotExist:
        raise Http404('Item slug not found')

    if category_slug != None:
        try:
            category = Category.objects.visible().get(
                    slug=category_slug)
        except Category.DoesNotExist:
            pass

    return render_to_response(
            'ccgallery/item.html', {
                'item': item,
                'category': category,
                }, RequestContext(request))
Exemplo n.º 7
0
import ccsitemaps
from ccgallery.models import get_model


Item = get_model()


class GallerySiteMap(ccsitemaps.SiteMap):

    model = Item

    @staticmethod
    def last_mod():
        try:
            last_mod = Item.objects.visible().order_by("-created")[0]
            return last_mod.created
        except IndexError:
            return None

    @staticmethod
    def get_objects():
        return Item.objects.visible()


ccsitemaps.register(GallerySiteMap)
Exemplo n.º 8
0
 def render(self, context):
     items = get_model().objects\
             .visible()\
             .order_by('?')[:self.display]
     context[self.varname] = items
     return ''