From 780ddd533c22893e9d903531744c3550718b79d3 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 13 Sep 2016 22:30:23 -0300 Subject: [PATCH] Adding admin home content with infinite scroll. [Issue: #45] --- app/templates/home.html | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- app/templates/home_admin_content.html | 17 +++++++++++++++++ app/views.py | 34 ++++++++++++++++++++++------------ core/templates/base.html | 8 +++++--- 4 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 app/templates/home_admin_content.html diff --git a/app/templates/home.html b/app/templates/home.html index d5100ec..c90558f 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -2,11 +2,59 @@ {% load static i18n django_bootstrap_breadcrumbs permission_tags %} -{% block breadcrumbs %} +{% block javascript %} + +{% endblock %} + +{% block breadcrumbs %} {% clear_breadcrumbs %} {% breadcrumb 'Home' 'app:index' %} - {% endblock %} {% block render_breadcrumbs %} @@ -45,7 +93,7 @@
  • {% trans 'Manage Users' %}
  • {% endif %} {% if user|has_role:'system_admin, professor' %} -
  • {% trans 'Manage Courses' %}
  • +
  • {% trans 'Manage Courses' %}
  • {% endif %} @@ -53,27 +101,18 @@ {% endblock %} {% block content %} -

    {% trans 'Courses' %}

    - {% if courses|length > 0 %} - {% for course in courses %} - -
    -
    -

    {{ course }}

    -
    - -
    -
    - {% endfor %} - {% else %} -

    {% trans "You didn't create any course yet." %}

    + {% if user|has_role:'system_admin' %} +

    {% trans 'Courses' %}

    {% endif %} + +
    + {% include page_template %} +
    + {% endblock %} {% block rightbar %} diff --git a/app/templates/home_admin_content.html b/app/templates/home_admin_content.html new file mode 100644 index 0000000..49f926d --- /dev/null +++ b/app/templates/home_admin_content.html @@ -0,0 +1,17 @@ +{% load i18n %} + +{% for course in courses %} +
    +
    +

    {{ course }}

    +
    + + +
    +{% endfor %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index b82f801..2acb45c 100644 --- a/app/views.py +++ b/app/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from django.views.generic import TemplateView +from django.views.generic import ListView from django.contrib.auth.mixins import LoginRequiredMixin from django.core.urlresolvers import reverse_lazy from core.mixins import LogMixin, NotificationMixin @@ -7,32 +7,42 @@ from core.models import Notification, Action, Resource, Action_Resource from users.models import User from courses.models import Course -class AppIndex(LoginRequiredMixin, LogMixin, TemplateView, NotificationMixin): +class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin): log_action = "Acessar" log_resource = "Home" - login_url = reverse_lazy("core:home") + + login_url = reverse_lazy("core:home") redirect_field_name = 'next' + template_name = "home.html" + context_object_name = 'courses' + paginate_by = 3 not_action = "Acessar" not_resource = "home" - def render_to_response(self, context, **response_kwargs): - context = {} - - if self.request.user.type_profile == 2: - template = "home_student.html" - context['courses'] = Course.objects.filter(user = self.request.user) + def get_queryset(self): + if self.request.user.is_staff: + objects = Course.objects.all() else: - template = self.get_template_names() - context['courses'] = Course.objects.filter(user = self.request.user) + objects = Notification.objects.filter(user = self.request.user) + + return objects + def render_to_response(self, context, **response_kwargs): + if self.request.user.is_staff: + context['page_template'] = "home_admin_content.html" + context['title'] = 'Amadeus' + + if self.request.is_ajax(): + self.template_name = "home_admin_content.html" + #super(AppIndex, self).createNotification("teste", not_resource="home", resource_link="users") notifications = Notification.objects.filter(user= self.request.user, read=False) context['notifications'] = notifications - return self.response_class(request = self.request, template = template, context = context, using = self.template_engine, **response_kwargs) + return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) diff --git a/core/templates/base.html b/core/templates/base.html index cee5976..1a2752c 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -32,9 +32,7 @@ - {% block javascript %} - - {% endblock %} +
    @@ -144,5 +142,9 @@
    + + {% block javascript %} + + {% endblock %} -- libgit2 0.21.2