コード例 #1
0
def cms(request):
    path = request.path
    Lang = oe_session.get_model('res.lang')
    langs = Lang.objects.all()

    host = request.get_host()

    site = oe_session.get_model('cms.site').objects.filter(host_ids__hostname = host)[0]

    Title = oe_session.get_model('cms.title')


    query = Q(page_id__published=True, page_id__in_navigation=True)

    if request.LANGUAGE_ID:
        query &= Q(language_id=request.LANGUAGE_ID)
    else:
        query &= Q(language_id__code=settings.LANGUAGE_CODE)

    w_path = path[1:].split('/')
    if len(w_path[0]) == 2:
        w_path = w_path[1:]

    def get_menu(path, qu='page_id__parent_id__title_ids__path'):
        add_q = {qu: path}
        menu_list = Title.objects.filter(query, **add_q).order_by('page_sequence')
        menu_list = _only_published(menu_list)
        for m in menu_list:
            m.child_menu_list = get_menu(m.path)
            if not m.path.endswith('/'):
                m.path += '/'
        return menu_list

    menu_list = []
    w_path = [p for p in w_path if p]
    w_path.insert(0, '')
    curr_path = ''
    for path in w_path:
        menus = get_menu(path)
        if path:
            if curr_path:
                curr_path += '/%s' % path
            else:
                curr_path = path
            for m in menu_list[-1]:
                if m.path[:-1] == curr_path:
                    m.active_menu = True
        if not menus:
            break
        menu_list.append(menus)

    context_extras = {
        'language_list': langs,
        'menu_list': menu_list
    }

    for pc in oe_session.get_model('cms.placeholder').objects.filter(title_id__isnull=True):
        context_extras[pc.slot_id.name] = mark_safe(pc.body)

    return context_extras
コード例 #2
0
def cms(request, path):
    host = request.get_host()
    if path.endswith('/'):
        path = path[:-1]
    w_path = path.split('/', 1)
    if len(w_path[0]) == 2:
        if len(w_path) == 1:
            path = ''
        else:
            path = '%s' % w_path[1]

    site = get_list_or_404(oe_session.get_model('cms.site'), host_ids__hostname = host)[0]
    query = {'page_id__published':True,
             'page_id__site_id__id':site.pk}
    if request.LANGUAGE_ID:
        query['language_id'] = request.LANGUAGE_ID
    else:
        query['language_id__code'] = settings.LANGUAGE_CODE

    Title = oe_session.get_model('cms.title')
    full_path = request.get_full_path()[1:]
    if full_path != path:
        query['old_path'] = full_path
    else:
        query['path'] = path
    try:
        title = Title.objects.get(**query)
    except Title.DoesNotExist:
        if 'path' in query:
            raise Http404
        del query['old_path']
        query['path'] = path
        try:
            title = Title.objects.get(**query)
        except Title.DoesNotExist:
            raise Http404
    else:
        if 'old_path' in query:
            return redirect(cms, path=title.path, permanent=True)

    if title.publication_date and title.publication_date > now:
        raise Http404
    if title.publication_end_date and \
               title.publication_end_date < now:
        raise Http404

    ctx = {
        'site_name': site.name,
        'title': title,
        'is_catalogue': path.startswith('catalogue')
        }
    for pc in oe_session.get_model('cms.placeholder').objects.filter(title_id=title):
        ctx[pc.slot_id.name] = mark_safe(pc.body)

    return render_to_response('cms/%s' % title.template_name, ctx,
                              context_instance=RequestContext(request))
コード例 #3
0
    def _get_lang_code(self, request):
        full_path = request.get_full_path()
        w_path = full_path[1:].split('/', 1)
        request.PATH_LANG = ''
        request.PATH_WITHOUT_LANG = ''
        language = settings.LANGUAGE_CODE
        request.LANGUAGE_ID = None

        if len(w_path[0]) == 2:
            try:
                lang = oe_session.get_model('res.lang').objects.get(iso_code=w_path[0])
            except:
                pass
            else:
                language = lang.code
                request.PATH_LANG = w_path[0]
                request.LANGUAGE_ID = lang.id
            if len(w_path) == 2:
                request.PATH_WITHOUT_LANG = w_path[1]
        else:
            request.PATH_WITHOUT_LANG = full_path
        if oe_session._default_context is None:
            oe_session._default_context = {}
        oe_session._default_context.update(lang=language)
        return language
コード例 #4
0
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.list_detail import object_list, object_detail
from djoe.base.backends import oe_session


oe_session.get_model('wiki.groups')


urlpatterns = patterns('djoe.examples.wiki.views',
    url(r'^$', object_list, {
        'queryset': oe_session.get_model('wiki.wiki').objects.all(),
        'template_name': 'wiki/list.html',
        'template_object_name': 'wiki',
        }, name='wiki'),
    url(r'^pages/(?P<object_id>[-a-z0-9]+)/$', 'wiki_page', name='wiki_page')
)
コード例 #5
0
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.list_detail import object_list, object_detail
from djoe.base.backends import oe_session


# TODO: Tuples should be replaced with url() function.
# TODO: Replace it with class-based generic views.
oe_session.get_model('product.category')


urlpatterns = patterns('',
    url(r'^$', object_list, {
        'queryset': oe_session.get_model('product.product').objects.filter(active=True),
        'template_name': 'store/list.html',
        'template_object_name': 'product',
        'paginate_by': 10,
        'page': 1,
        }, name='store'),
    url(r'^products/(?P<object_id>[-a-z0-9]+)/$', object_detail, {
        'queryset': oe_session.get_model('product.product').objects.filter(active=True),
        'template_name': 'store/detail.html',
        'template_object_name': 'product'
        }, name='product'),
)