forked from rc/aircox
		
	work on lists
This commit is contained in:
		@ -56,6 +56,10 @@ class Route:
 | 
				
			|||||||
    def get_title (cl, model, request, **kwargs):
 | 
					    def get_title (cl, model, request, **kwargs):
 | 
				
			||||||
        return ''
 | 
					        return ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def get_view_name (cl, name):
 | 
				
			||||||
 | 
					        return name + '_' + cl.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def as_url (cl, name, model, view, view_kwargs = None):
 | 
					    def as_url (cl, name, model, view, view_kwargs = None):
 | 
				
			||||||
        pattern = '^{}/{}'.format(name, cl.name)
 | 
					        pattern = '^{}/{}'.format(name, cl.name)
 | 
				
			||||||
@ -77,7 +81,7 @@ class Route:
 | 
				
			|||||||
            kwargs.update(view_kwargs)
 | 
					            kwargs.update(view_kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return url(pattern, view, kwargs = kwargs,
 | 
					        return url(pattern, view, kwargs = kwargs,
 | 
				
			||||||
                   name = name + '_' + cl.name)
 | 
					                   name = cl.get_view_name(name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DetailRoute (Route):
 | 
					class DetailRoute (Route):
 | 
				
			||||||
@ -123,7 +127,7 @@ class ThreadRoute (Route):
 | 
				
			|||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def get_queryset (cl, website, model, request, thread_model, pk, **kwargs):
 | 
					    def get_queryset (cl, website, model, request, thread_model, pk, **kwargs):
 | 
				
			||||||
        if type(thread_model) is str:
 | 
					        if type(thread_model) is str:
 | 
				
			||||||
            thread_model = website.registry.get(thread_model).model
 | 
					            thread_model = website.registry.get(thread_model)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not thread_model:
 | 
					        if not thread_model:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@
 | 
				
			|||||||
{% load thumbnail %}
 | 
					{% load thumbnail %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% block content %}
 | 
					{% block content %}
 | 
				
			||||||
<div class="post_list {{ classes }}">
 | 
					<div class="post_list {{ classes }} {% if embed %}embed{% endif %}">
 | 
				
			||||||
{% for post in object_list %}
 | 
					{% for post in object_list %}
 | 
				
			||||||
    <a class="post_item"
 | 
					    <a class="post_item"
 | 
				
			||||||
       href="{{ post.detail_url }}">
 | 
					       href="{{ post.detail_url }}">
 | 
				
			||||||
@ -39,6 +39,27 @@
 | 
				
			|||||||
    </a>
 | 
					    </a>
 | 
				
			||||||
{% endfor %}
 | 
					{% endfor %}
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<nav>
 | 
				
			||||||
 | 
					    {% if embed %}
 | 
				
			||||||
 | 
					        {% with view.get_url as list_url %}
 | 
				
			||||||
 | 
					        {% if list_url %}
 | 
				
			||||||
 | 
					        <a href="{{list_url}}" title="More elements">⇲</a>
 | 
				
			||||||
 | 
					        {% endif %}
 | 
				
			||||||
 | 
					        {% endwith %}
 | 
				
			||||||
 | 
					    {% else %}
 | 
				
			||||||
 | 
					        {% if page_obj.has_previous %}
 | 
				
			||||||
 | 
					            <a href="?page={{ page_obj.previous_page_number }}">previous</a>
 | 
				
			||||||
 | 
					        {% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <span class="current">
 | 
				
			||||||
 | 
					            {{ page_obj.number }} / {{ page_obj.paginator.num_pages }}
 | 
				
			||||||
 | 
					        </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        {% if page_obj.has_next %}
 | 
				
			||||||
 | 
					            <a href="?page={{ page_obj.next_page_number }}">next</a>
 | 
				
			||||||
 | 
					        {% endif %}
 | 
				
			||||||
 | 
					    {% endif %}
 | 
				
			||||||
 | 
					</nav>
 | 
				
			||||||
{% endblock %}
 | 
					{% endblock %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -23,12 +23,12 @@
 | 
				
			|||||||
    {% endblock %}
 | 
					    {% endblock %}
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if bottom %}
 | 
					{% if footer %}
 | 
				
			||||||
<div class="section_bottom">
 | 
					<footer class="section_footer">
 | 
				
			||||||
    {% block section_bottom %}
 | 
					    {% block section_footer %}
 | 
				
			||||||
    {{ bottom }}
 | 
					    {{ footer }}
 | 
				
			||||||
    {% endblock %}
 | 
					    {% endblock %}
 | 
				
			||||||
</div>
 | 
					</footer>
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
{% endblock %}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								aircox_cms/utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								aircox_cms/utils.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					from django.contrib.contenttypes.models import ContentType
 | 
				
			||||||
 | 
					from django.core.urlresolvers import reverse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_url (website, route, model, kwargs):
 | 
				
			||||||
 | 
					    name = website.name_of_model(model)
 | 
				
			||||||
 | 
					    if not name:
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    name = route.get_view_name(name)
 | 
				
			||||||
 | 
					    return reverse(name, kwargs = kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def filter_thread (qs, object):
 | 
				
			||||||
 | 
					    model_type = ContentType.objects.get_for_model(object.__class__)
 | 
				
			||||||
 | 
					    return qs.filter(
 | 
				
			||||||
 | 
					        thread_pk = object.pk,
 | 
				
			||||||
 | 
					        thread_type__pk = model_type.pk
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -5,11 +5,13 @@ from django.shortcuts import render
 | 
				
			|||||||
from django.template.loader import render_to_string
 | 
					from django.template.loader import render_to_string
 | 
				
			||||||
from django.views.generic import ListView, DetailView
 | 
					from django.views.generic import ListView, DetailView
 | 
				
			||||||
from django.views.generic.base import View, TemplateResponseMixin
 | 
					from django.views.generic.base import View, TemplateResponseMixin
 | 
				
			||||||
 | 
					from django.core.paginator import Paginator
 | 
				
			||||||
from django.core import serializers
 | 
					from django.core import serializers
 | 
				
			||||||
from django.utils.translation import ugettext as _, ugettext_lazy
 | 
					from django.utils.translation import ugettext as _, ugettext_lazy
 | 
				
			||||||
from django.utils.html import escape
 | 
					from django.utils.html import escape
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import aircox_cms.routes as routes
 | 
					import aircox_cms.routes as routes
 | 
				
			||||||
 | 
					import aircox_cms.utils as utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PostBaseView:
 | 
					class PostBaseView:
 | 
				
			||||||
@ -31,7 +33,7 @@ class PostBaseView:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if not self.embed:
 | 
					        if not self.embed:
 | 
				
			||||||
            context['menus'] = {
 | 
					            context['menus'] = {
 | 
				
			||||||
                k: v.get(self.request, **kwargs)
 | 
					                k: v.get(self.request, website = self.website, **kwargs)
 | 
				
			||||||
                for k, v in {
 | 
					                for k, v in {
 | 
				
			||||||
                    k: self.website.get_menu(k)
 | 
					                    k: self.website.get_menu(k)
 | 
				
			||||||
                    for k in self.website.menu_layouts
 | 
					                    for k in self.website.menu_layouts
 | 
				
			||||||
@ -55,6 +57,7 @@ class PostListView (PostBaseView, ListView):
 | 
				
			|||||||
        order = 'desc'
 | 
					        order = 'desc'
 | 
				
			||||||
        reverse = False
 | 
					        reverse = False
 | 
				
			||||||
        fields = None
 | 
					        fields = None
 | 
				
			||||||
 | 
					        page = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def __init__ (self, query):
 | 
					        def __init__ (self, query):
 | 
				
			||||||
            if query:
 | 
					            if query:
 | 
				
			||||||
@ -69,6 +72,7 @@ class PostListView (PostBaseView, ListView):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    template_name = 'aircox_cms/list.html'
 | 
					    template_name = 'aircox_cms/list.html'
 | 
				
			||||||
    allow_empty = True
 | 
					    allow_empty = True
 | 
				
			||||||
 | 
					    paginate_by = 50
 | 
				
			||||||
    model = None
 | 
					    model = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    route = None
 | 
					    route = None
 | 
				
			||||||
@ -128,6 +132,12 @@ class PostListView (PostBaseView, ListView):
 | 
				
			|||||||
                                                    **self.kwargs)
 | 
					                                                    **self.kwargs)
 | 
				
			||||||
        return title
 | 
					        return title
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_url (self):
 | 
				
			||||||
 | 
					        if self.route:
 | 
				
			||||||
 | 
					            return utils.get_urls(self.website, self.route,
 | 
				
			||||||
 | 
					                                  self.model, self.kwargs)
 | 
				
			||||||
 | 
					        return ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PostDetailView (DetailView, PostBaseView):
 | 
					class PostDetailView (DetailView, PostBaseView):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
@ -161,7 +171,7 @@ class PostDetailView (DetailView, PostBaseView):
 | 
				
			|||||||
        context.update(self.get_base_context())
 | 
					        context.update(self.get_base_context())
 | 
				
			||||||
        context.update({
 | 
					        context.update({
 | 
				
			||||||
            'sections': [
 | 
					            'sections': [
 | 
				
			||||||
                section.get(self.request, **kwargs)
 | 
					                section.get(self.request, website = self.website, **kwargs)
 | 
				
			||||||
                    for section in self.sections
 | 
					                    for section in self.sections
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
@ -189,13 +199,15 @@ class Menu (View):
 | 
				
			|||||||
            'classes': self.classes,
 | 
					            'classes': self.classes,
 | 
				
			||||||
            'position': self.position,
 | 
					            'position': self.position,
 | 
				
			||||||
            'sections': [
 | 
					            'sections': [
 | 
				
			||||||
                section.get(self.request, object = None, **kwargs)
 | 
					                section.get(self.request, website = self.website,
 | 
				
			||||||
 | 
					                            object = None, **kwargs)
 | 
				
			||||||
                    for section in self.sections
 | 
					                    for section in self.sections
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get (self, request, **kwargs):
 | 
					    def get (self, request, website, **kwargs):
 | 
				
			||||||
        self.request = request
 | 
					        self.request = request
 | 
				
			||||||
 | 
					        self.website = website
 | 
				
			||||||
        context = self.get_context_data(**kwargs)
 | 
					        context = self.get_context_data(**kwargs)
 | 
				
			||||||
        return render_to_string(self.template_name, context)
 | 
					        return render_to_string(self.template_name, context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -225,8 +237,9 @@ class BaseSection (View):
 | 
				
			|||||||
            'content': self.content,
 | 
					            'content': self.content,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get (self, request, **kwargs):
 | 
					    def get (self, request, website, **kwargs):
 | 
				
			||||||
        self.request = request
 | 
					        self.request = request
 | 
				
			||||||
 | 
					        self.website = website
 | 
				
			||||||
        self.kwargs = kwargs
 | 
					        self.kwargs = kwargs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context = self.get_context_data()
 | 
					        context = self.get_context_data()
 | 
				
			||||||
@ -245,14 +258,14 @@ class Section (BaseSection):
 | 
				
			|||||||
    object_required = False
 | 
					    object_required = False
 | 
				
			||||||
    title = ''
 | 
					    title = ''
 | 
				
			||||||
    header = ''
 | 
					    header = ''
 | 
				
			||||||
    bottom = ''
 | 
					    footer = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data (self):
 | 
					    def get_context_data (self):
 | 
				
			||||||
        context = super().get_context_data()
 | 
					        context = super().get_context_data()
 | 
				
			||||||
        context.update({
 | 
					        context.update({
 | 
				
			||||||
            'title': self.title,
 | 
					            'title': self.title,
 | 
				
			||||||
            'header': self.header,
 | 
					            'header': self.header,
 | 
				
			||||||
            'bottom': self.bottom,
 | 
					            'footer': self.footer,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -277,7 +290,6 @@ class Sections:
 | 
				
			|||||||
                        static(self.url),
 | 
					                        static(self.url),
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    class PostContent (Section):
 | 
					    class PostContent (Section):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Render the content of the Post (format the text a bit and escape HTML
 | 
					        Render the content of the Post (format the text a bit and escape HTML
 | 
				
			||||||
@ -290,7 +302,6 @@ class Sections:
 | 
				
			|||||||
            content = re.sub(r'\n', r'<br>', content)
 | 
					            content = re.sub(r'\n', r'<br>', content)
 | 
				
			||||||
            return content
 | 
					            return content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    class PostImage (Section):
 | 
					    class PostImage (Section):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Render the image of the Post
 | 
					        Render the image of the Post
 | 
				
			||||||
@ -301,7 +312,6 @@ class Sections:
 | 
				
			|||||||
                        self.object.image.url
 | 
					                        self.object.image.url
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    class List (Section):
 | 
					    class List (Section):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Section to render list. The context item 'object_list' is used as list of
 | 
					        Section to render list. The context item 'object_list' is used as list of
 | 
				
			||||||
@ -342,7 +352,6 @@ class Sections:
 | 
				
			|||||||
            })
 | 
					            })
 | 
				
			||||||
            return context
 | 
					            return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    class Urls (List):
 | 
					    class Urls (List):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Render a list of urls of targets that are Posts
 | 
					        Render a list of urls of targets that are Posts
 | 
				
			||||||
@ -369,6 +378,9 @@ class Sections:
 | 
				
			|||||||
        icon_size = '64x64'
 | 
					        icon_size = '64x64'
 | 
				
			||||||
        fields = [ 'date', 'time', 'image', 'title', 'content' ]
 | 
					        fields = [ 'date', 'time', 'image', 'title', 'content' ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def get_url (self):
 | 
				
			||||||
 | 
					            return ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def get_object_list (self):
 | 
					        def get_object_list (self):
 | 
				
			||||||
            return []
 | 
					            return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,11 @@ class Website:
 | 
				
			|||||||
        self.urls = []
 | 
					        self.urls = []
 | 
				
			||||||
        self.__dict__.update(kwargs)
 | 
					        self.__dict__.update(kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def name_of_model (self, model):
 | 
				
			||||||
 | 
					        for name, _model in self.registry.items():
 | 
				
			||||||
 | 
					            if model is _model:
 | 
				
			||||||
 | 
					                return name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def register_model (self, name, model):
 | 
					    def register_model (self, name, model):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Register a model and return the name under which it is registered.
 | 
					        Register a model and return the name under which it is registered.
 | 
				
			||||||
 | 
				
			|||||||
@ -81,8 +81,8 @@ a:hover {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.page {
 | 
					.page {
 | 
				
			||||||
    width: 100%;
 | 
					    width: calc(100% - 0.4em);
 | 
				
			||||||
    padding: 1.5em 0em;
 | 
					    padding: 1.5em 0.2em;
 | 
				
			||||||
    background-color: rgba(255, 255, 255, 0.8);
 | 
					    background-color: rgba(255, 255, 255, 0.8);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -92,11 +92,20 @@ a:hover {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
main .post_list {
 | 
					.post_list {
 | 
				
			||||||
    background-color: #F2F2F2;
 | 
					    padding: 0.1em;
 | 
				
			||||||
    border: 1px #818181 dotted;
 | 
					    border: 1px #818181 dotted;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .post_list.embed + nav {
 | 
				
			||||||
 | 
					        text-align: right;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .post_list:not(.embed) + nav {
 | 
				
			||||||
 | 
					        text-align: center;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    main .post_list .post_item {
 | 
					    main .post_list .post_item {
 | 
				
			||||||
        min-height: 64px;
 | 
					        min-height: 64px;
 | 
				
			||||||
        padding: 0.2em;
 | 
					        padding: 0.2em;
 | 
				
			||||||
 | 
				
			|||||||
@ -72,6 +72,7 @@ website.register (
 | 
				
			|||||||
    'episode',
 | 
					    'episode',
 | 
				
			||||||
    Episode,
 | 
					    Episode,
 | 
				
			||||||
    sections = base_sections,
 | 
					    sections = base_sections,
 | 
				
			||||||
 | 
					    routes = base_routes,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
urlpatterns = website.urls
 | 
					urlpatterns = website.urls
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,8 @@ from django.utils import timezone as tz
 | 
				
			|||||||
from django.utils.translation import ugettext as _, ugettext_lazy
 | 
					from django.utils.translation import ugettext as _, ugettext_lazy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import aircox_programs.models as programs
 | 
					import aircox_programs.models as programs
 | 
				
			||||||
 | 
					import aircox_cms.routes as routes
 | 
				
			||||||
 | 
					import aircox_cms.utils as utils
 | 
				
			||||||
from aircox_cms.views import Sections
 | 
					from aircox_cms.views import Sections
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from website.models import *
 | 
					from website.models import *
 | 
				
			||||||
@ -39,7 +41,11 @@ class EpisodesSection (Sections.Posts):
 | 
				
			|||||||
    title = _('Episodes')
 | 
					    title = _('Episodes')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_object_list (self):
 | 
					    def get_object_list (self):
 | 
				
			||||||
        return Episode.objects.filter(related__program = self.object.related.pk)
 | 
					        return utils.filter_thread(Episode.objects, self.object)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_url (self):
 | 
				
			||||||
 | 
					        return utils.get_url(self.website, routes.ThreadRoute, Episode,
 | 
				
			||||||
 | 
					                             { 'thread_model': 'program', 'pk': self.object.pk})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PreviousDiffusions (Sections.Posts):
 | 
					class PreviousDiffusions (Sections.Posts):
 | 
				
			||||||
    title = _('Previous Diffusions')
 | 
					    title = _('Previous Diffusions')
 | 
				
			||||||
@ -65,4 +71,3 @@ class PreviousDiffusions (Sections.Posts):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return episodes
 | 
					        return episodes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user