make menu work
This commit is contained in:
parent
1e571960d0
commit
7c89f84b34
|
@ -29,6 +29,7 @@ class Section(View):
|
||||||
Attributes:
|
Attributes:
|
||||||
* template_name: template to use for rendering
|
* template_name: template to use for rendering
|
||||||
* tag: container's tags
|
* tag: container's tags
|
||||||
|
* name: set name/id of the section container
|
||||||
* css_class: css classes of the container
|
* css_class: css classes of the container
|
||||||
* attr: HTML attributes of the container
|
* attr: HTML attributes of the container
|
||||||
* hide_empty: if true, section is not rendered when content is empty
|
* hide_empty: if true, section is not rendered when content is empty
|
||||||
|
@ -41,12 +42,13 @@ class Section(View):
|
||||||
* object: (can be persistent) related object
|
* object: (can be persistent) related object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
template_name = 'aircox/cms/content_object.html'
|
template_name = 'aircox/cms/section.html'
|
||||||
|
|
||||||
tag = 'div'
|
tag = 'div'
|
||||||
|
name = ''
|
||||||
css_class = ''
|
css_class = ''
|
||||||
attrs = ''
|
attrs = None
|
||||||
hide_empty = False
|
# hide_empty = False
|
||||||
title = ''
|
title = ''
|
||||||
header = ''
|
header = ''
|
||||||
footer = ''
|
footer = ''
|
||||||
|
@ -54,7 +56,12 @@ class Section(View):
|
||||||
|
|
||||||
def __init__ (self, *args, **kwargs):
|
def __init__ (self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.css_class += ' section'
|
self.css_class = 'section' if not self.css_class else ' section'
|
||||||
|
if not self.attrs:
|
||||||
|
self.attrs = {}
|
||||||
|
if self.name:
|
||||||
|
self.attrs['name'] = self.name
|
||||||
|
self.attrs['id'] = self.name
|
||||||
|
|
||||||
def get_content(self):
|
def get_content(self):
|
||||||
return ''
|
return ''
|
||||||
|
@ -75,13 +82,10 @@ class Section(View):
|
||||||
def get(self, request, object=None, **kwargs):
|
def get(self, request, object=None, **kwargs):
|
||||||
if not self.object:
|
if not self.object:
|
||||||
self.object = object
|
self.object = object
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
# if not context['content'] and self.hide_empty:
|
|
||||||
# return ''
|
|
||||||
return render_to_string(self.template_name, context, request=request)
|
return render_to_string(self.template_name, context, request=request)
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,3 +242,34 @@ class Comments(List):
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class Menu(Section):
|
||||||
|
template_name = 'aircox/cms/section.html'
|
||||||
|
tag = 'nav'
|
||||||
|
classes = ''
|
||||||
|
attrs = ''
|
||||||
|
name = ''
|
||||||
|
enabled = True
|
||||||
|
position = '' # top, left, bottom, right, header, footer, page_top, page_bottom
|
||||||
|
sections = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.css_class += ' menu menu_{}'.format(self.name or self.position)
|
||||||
|
if not self.attrs:
|
||||||
|
self.attrs = {}
|
||||||
|
|
||||||
|
def get_context_data(self):
|
||||||
|
return {
|
||||||
|
'tag': self.tag,
|
||||||
|
'css_class': self.css_class,
|
||||||
|
'attrs': self.attrs,
|
||||||
|
'content': ''.join([
|
||||||
|
section.get(request=self.request, object=self.object)
|
||||||
|
for section in self.sections
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
<{{ tag }} class="{{ css_class }}"
|
<{{ tag }} class="{{ css_class }}"
|
||||||
{% for k, v in list.attrs.items %}
|
{% for k, v in attrs.items %}
|
||||||
{{ k }} = "{{ v|addslashes }}"
|
{{ k }} = "{{ v|addslashes }}"
|
||||||
{% endfor %} >
|
{% endfor %} >
|
||||||
|
|
||||||
|
|
38
cms/views.py
38
cms/views.py
|
@ -176,41 +176,3 @@ class PostDetailView(DetailView, PostBaseView):
|
||||||
return self.get(request, *args, **kwargs)
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Menu(View):
|
|
||||||
template_name = 'aircox/cms/section.html'
|
|
||||||
tag = 'nav'
|
|
||||||
classes = ''
|
|
||||||
attrs = ''
|
|
||||||
name = ''
|
|
||||||
enabled = True
|
|
||||||
position = '' # top, left, bottom, right, header, footer, page_top, page_bottom
|
|
||||||
sections = None
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.classes += ' menu menu_{}'.format(self.name or self.position)
|
|
||||||
if not self.attrs:
|
|
||||||
self.attrs = {}
|
|
||||||
if self.name:
|
|
||||||
self.attrs['name'] = self.name
|
|
||||||
self.attrs['id'] = self.name
|
|
||||||
|
|
||||||
def get_context_data(self, request, object = None, **kwargs):
|
|
||||||
kwargs['object'] = object
|
|
||||||
|
|
||||||
return {
|
|
||||||
'tag': self.tag,
|
|
||||||
'classes': self.classes,
|
|
||||||
'attrs': self.attrs,
|
|
||||||
'content': ''.join([
|
|
||||||
section.get(request, **kwargs)
|
|
||||||
for section in self.sections
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
def get(self, request, object = None, **kwargs):
|
|
||||||
self.request = request
|
|
||||||
context = self.get_context_data(request, object, **kwargs)
|
|
||||||
return render_to_string(self.template_name, context)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user