Commit e6860b2cd2d91bbb9e36638b724863ab943ff05e
1 parent
3d05b2c1
Exists in
master
and in
3 other branches
renamed courses app for categories
Showing
35 changed files
with
390 additions
and
309 deletions
Show diff stats
amadeus/settings.py
amadeus/urls.py
| ... | ... | @@ -25,7 +25,7 @@ urlpatterns = [ |
| 25 | 25 | url(r'^users/', include('users.urls', namespace = 'users')), |
| 26 | 26 | url(r'^admin/', admin.site.urls), |
| 27 | 27 | url(r'^$', index, name = 'home'), |
| 28 | - url(r'^courses/', include('courses.urls', namespace = 'courses')), | |
| 28 | + url(r'^categories/', include('categories.urls', namespace = 'categories')), | |
| 29 | 29 | #API |
| 30 | 30 | url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), |
| 31 | 31 | #S3Direct | ... | ... |
amadeus/views.py
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.10 on 2016-12-21 03:51 | |
| 3 | +from __future__ import unicode_literals | |
| 4 | + | |
| 5 | +import autoslug.fields | |
| 6 | +from django.conf import settings | |
| 7 | +from django.db import migrations, models | |
| 8 | +import django.db.models.deletion | |
| 9 | + | |
| 10 | + | |
| 11 | +class Migration(migrations.Migration): | |
| 12 | + | |
| 13 | + initial = True | |
| 14 | + | |
| 15 | + dependencies = [ | |
| 16 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
| 17 | + ] | |
| 18 | + | |
| 19 | + operations = [ | |
| 20 | + migrations.CreateModel( | |
| 21 | + name='Category', | |
| 22 | + fields=[ | |
| 23 | + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |
| 24 | + ('name', models.CharField(max_length=100, verbose_name='Name')), | |
| 25 | + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True, verbose_name='Slug')), | |
| 26 | + ('description', models.CharField(max_length=300, verbose_name='description')), | |
| 27 | + ('visible', models.BooleanField(verbose_name='visible')), | |
| 28 | + ('create_date', models.DateTimeField(auto_now_add=True, verbose_name='Creation Date')), | |
| 29 | + ('modified_date', models.DateTimeField(auto_now_add=True, verbose_name='Modified Date')), | |
| 30 | + ('category_father', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='category_parent', to='categories.Category')), | |
| 31 | + ('coordinators', models.ManyToManyField(related_name='coordinators', to=settings.AUTH_USER_MODEL)), | |
| 32 | + ], | |
| 33 | + options={ | |
| 34 | + 'verbose_name_plural': 'Categories', | |
| 35 | + 'verbose_name': 'Category', | |
| 36 | + }, | |
| 37 | + ), | |
| 38 | + ] | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +from django.db import models | |
| 2 | +from autoslug.fields import AutoSlugField | |
| 3 | +from django.utils.translation import ugettext_lazy as _ | |
| 4 | +from users.models import User | |
| 5 | + | |
| 6 | +class Category(models.Model): | |
| 7 | + """Represents a Course """ | |
| 8 | + | |
| 9 | + category_father = models.ForeignKey('Category', related_name =_("category_parent"), on_delete = models.CASCADE) | |
| 10 | + name = models.CharField(_("Name"), max_length = 100) | |
| 11 | + slug = AutoSlugField(_("Slug"),populate_from='name',unique=True) | |
| 12 | + description = models.CharField(_("description"), max_length = 300) | |
| 13 | + visible = models.BooleanField(_("visible")) | |
| 14 | + coordinators = models.ManyToManyField(User, related_name = _("coordinators")) | |
| 15 | + create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) | |
| 16 | + modified_date = models.DateTimeField(_('Modified Date'), auto_now_add = True) | |
| 17 | + | |
| 18 | + class Meta: | |
| 19 | + verbose_name = _('Category') | |
| 20 | + verbose_name_plural = _('Categories') | |
| 21 | + | |
| 22 | + def __str__(self): | |
| 23 | + return self.name | |
| 0 | 24 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +import os | |
| 2 | +import sys | |
| 3 | + | |
| 4 | +import django | |
| 5 | +from django.conf import settings | |
| 6 | +from django.test.utils import get_runner | |
| 7 | + | |
| 8 | +if __name__ == "__main__": | |
| 9 | + os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings' | |
| 10 | + django.setup() | |
| 11 | + TestRunner = get_runner(settings) | |
| 12 | + test_runner = TestRunner() | |
| 13 | + failures = test_runner.run_tests(["tests"]) | |
| 14 | + sys.exit(bool(failures)) | |
| 0 | 15 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,64 @@ |
| 1 | +{% extends 'course/index.html' %} | |
| 2 | + | |
| 3 | +{% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs %} | |
| 4 | + | |
| 5 | +{% block breadcrumbs %} | |
| 6 | + {{ block.super }} | |
| 7 | + {% breadcrumb 'Create Course' 'course:create' %} | |
| 8 | +{% endblock %} | |
| 9 | + | |
| 10 | +{% block content %} | |
| 11 | +<div class="card card-content"> | |
| 12 | + <div class="card-body"> | |
| 13 | + <form method="post" action="" enctype="multipart/form-data"> | |
| 14 | + {% csrf_token %} | |
| 15 | + {% for field in form %} | |
| 16 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | |
| 17 | + {% if field.auto_id != 'id_public' %} | |
| 18 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
| 19 | + {% endif %} | |
| 20 | + {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} | |
| 21 | + <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | |
| 22 | + {% elif field.auto_id == 'id_public' %} | |
| 23 | + <div class="checkbox"> | |
| 24 | + <label> | |
| 25 | + <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | |
| 26 | + </label> | |
| 27 | + </div> | |
| 28 | + {% else %} | |
| 29 | + {% render_field field class='form-control' %} | |
| 30 | + {% endif %} | |
| 31 | + <span class="help-block">{{ field.help_text }}</span> | |
| 32 | + {% if field.errors %} | |
| 33 | + <div class="row"> | |
| 34 | + </br> | |
| 35 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 36 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 37 | + <span aria-hidden="true">×</span> | |
| 38 | + </button> | |
| 39 | + <ul> | |
| 40 | + {% for error in field.errors %} | |
| 41 | + <li>{{ error }}</li> | |
| 42 | + {% endfor %} | |
| 43 | + </ul> | |
| 44 | + </div> | |
| 45 | + </div> | |
| 46 | + {% endif %} | |
| 47 | + </div> | |
| 48 | + {% endfor %} | |
| 49 | + <div class="row text-center"> | |
| 50 | + <input type="submit" value="{% trans 'Create' %}" class="btn btn-primary btn-raised" /> | |
| 51 | + </div> | |
| 52 | + </form> | |
| 53 | + </div> | |
| 54 | +</div> | |
| 55 | +</br> | |
| 56 | +</br> | |
| 57 | +</br> | |
| 58 | +<script type="text/javascript"> | |
| 59 | + var locale = navigator.language || navigator.userLanguage; | |
| 60 | + $('.date-picker').datepicker({ | |
| 61 | + language: locale, | |
| 62 | + }); | |
| 63 | +</script> | |
| 64 | +{% endblock %} | |
| 0 | 65 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,33 @@ |
| 1 | +{% extends 'base.html' %} | |
| 2 | + | |
| 3 | +{% load static i18n django_bootstrap_breadcrumbs permission_tags %} | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | +{% block breadcrumbs %} | |
| 8 | + {% clear_breadcrumbs %} | |
| 9 | + {% breadcrumb 'Home' 'app:index' %} | |
| 10 | +{% endblock %} | |
| 11 | + | |
| 12 | + | |
| 13 | +{% block render_breadcrumbs %} | |
| 14 | + {% render_breadcrumbs %} | |
| 15 | +{% endblock %} | |
| 16 | + | |
| 17 | +{% block content %} | |
| 18 | + {% if user|has_role:'system_admin' %} | |
| 19 | + <h3>{% trans 'categories' %}</h3> | |
| 20 | + <div id="timeline"> | |
| 21 | + {% include page_template %} | |
| 22 | + </div> | |
| 23 | + {% else %} | |
| 24 | + <div id="timeline"> | |
| 25 | + {% include page_template %} | |
| 26 | + </div> | |
| 27 | + {% endif %} | |
| 28 | + <div id="loading" class="alert alert-primary" role="alert" style="display: none"> | |
| 29 | + <center> | |
| 30 | + <span class="fa fa-spin fa-circle-o-notch"></span> | |
| 31 | + </center> | |
| 32 | + </div> | |
| 33 | +{% endblock %} | ... | ... |
categories/templates/categories/home_teacher_student_content.html
0 → 100755
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +{% load static i18n %} | |
| 2 | + | |
| 3 | +{% for notification in objects %} | |
| 4 | + | |
| 5 | + | |
| 6 | + <div class="well timeLine"> | |
| 7 | + | |
| 8 | + <div class="row"> | |
| 9 | + <div class="col-xs-2 col-md-1"> | |
| 10 | + <img class="imgTimeLine" src="{{ notification.actor.image_url }}"> | |
| 11 | + </div> | |
| 12 | + <div class="col-xs-10 col-md-11"> | |
| 13 | + <h4 class="resource_inline"><b>{{ notification.actor.username }}</b></h4> | |
| 14 | + <p class="resource_inline">{{notification.message}} {% trans 'at' %} : <a href="#">{{ notification.action_resource.resource.name }}</a></p> | |
| 15 | + <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p> | |
| 16 | + </div> | |
| 17 | + </div> | |
| 18 | +</div> | |
| 19 | +{% endfor %} | |
| 20 | + | ... | ... |
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +{% extends 'home.html' %} | |
| 2 | + | |
| 3 | +{% load static i18n permission_tags %} | |
| 4 | +{% load django_bootstrap_breadcrumbs %} | |
| 5 | + | |
| 6 | +{% block javascript%} | |
| 7 | + {{ block.super }} | |
| 8 | +{% endblock%} | |
| 9 | + | |
| 10 | +{% block breadcrumbs %} | |
| 11 | + | |
| 12 | +{{ block.super }} | |
| 13 | +{% breadcrumb 'categories' 'course:manage' %} | |
| 14 | + | |
| 15 | +{% endblock %} | |
| 16 | + | |
| 17 | +{% block content %} | |
| 18 | +{% if messages %} | |
| 19 | +{% for message in messages %} | |
| 20 | + <script type="text/javascript"> | |
| 21 | + alertify.success('{{message}}'); | |
| 22 | + </script> | |
| 23 | +{% endfor %} | |
| 24 | +{% endif %} | |
| 25 | + | |
| 26 | +<div class="col-md-12 cards-content"> | |
| 27 | + <form id="searchform" method="get" accept-charset="utf-8"> | |
| 28 | + <div class="input-group"> | |
| 29 | + <div class="form-group is-empty"> | |
| 30 | + <input type="text" class="form-control" placeholder="{% trans 'Search for categories' %}" name="q"> | |
| 31 | + </div> | |
| 32 | + <span class="input-group-btn input-group-sm"> | |
| 33 | + <button type="submit" class="btn btn-fab btn-fab-mini"> | |
| 34 | + <i class="fa fa-search" aria-hidden="true"></i> | |
| 35 | + </button> | |
| 36 | + </span> | |
| 37 | + </div> | |
| 38 | + </form> | |
| 39 | +</div> | |
| 40 | +<!-- Code for listing categories --> | |
| 41 | +<div class="col-md-12 cards-content"> | |
| 42 | + {% for category in categorys_categories %} | |
| 43 | + <div class="panel-group course-card-group"> | |
| 44 | + <div class="panel panel-default"> | |
| 45 | + <div class="panel-heading"> | |
| 46 | + <div class="row"> | |
| 47 | + <div class="col-md-12"> | |
| 48 | + <h4 class="panel-title"> | |
| 49 | + <a class="category-course-link" data-toggle="collapse" href="#{{category.slug}}">{{category.name}}</a> | |
| 50 | + </h4> | |
| 51 | + </div> | |
| 52 | + </div> | |
| 53 | + </div> | |
| 54 | + <div id="{{category.slug}}" class="panel-collapse collapse"> | |
| 55 | + {% for course in category.course_category %} | |
| 56 | + {% include "course/course_card.html" %} | |
| 57 | + {% endfor %} | |
| 58 | + </div> | |
| 59 | + </div> | |
| 60 | + </div> | |
| 61 | + {% endfor %} | |
| 62 | +</div> | |
| 63 | +<div id="modal_course"> | |
| 64 | + | |
| 65 | +</div> | |
| 66 | +<script type="text/javascript" src="{% static 'js/course.js' %}"></script> | |
| 67 | +{% endblock %} | ... | ... |
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +from django.test import TestCase, RequestFactory | |
| 2 | +from users.models import User | |
| 3 | +from django.contrib.auth.models import AnonymousUser | |
| 4 | +from .. import views | |
| 5 | + | |
| 6 | +class Index_Test(TestCase): | |
| 7 | + | |
| 8 | + def setUp(self): | |
| 9 | + self.factory = RequestFactory() | |
| 10 | + self.user = User.objects.create(username="felipe", email="felipe.bormann@gmail.com", password="teste") | |
| 11 | + | |
| 12 | + def test_index_get_auth(self): | |
| 13 | + request = self.factory.get('categories/') | |
| 14 | + | |
| 15 | + request.user = self.user | |
| 16 | + | |
| 17 | + response = views.IndexView.as_view()(request) | |
| 18 | + | |
| 19 | + self.assertEqual(response.status_code, 200) | |
| 20 | + | |
| 21 | + def test_index_get_unauth(self): | |
| 22 | + | |
| 23 | + request = self.factory.get('categories/') | |
| 24 | + | |
| 25 | + request.user = AnonymousUser() | |
| 26 | + | |
| 27 | + response = views.IndexView.as_view()(request) | |
| 28 | + | |
| 29 | + self.assertEqual(response.status_code, 302) #Which means it is been redirected to login page | |
| 0 | 30 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,69 @@ |
| 1 | +from django.shortcuts import render | |
| 2 | +from django.views.generic import ListView, CreateView | |
| 3 | +from .models import Category | |
| 4 | +from django.core.urlresolvers import reverse_lazy | |
| 5 | +from rolepermissions.verifications import has_role | |
| 6 | + | |
| 7 | +from django.utils.translation import ugettext_lazy as _ | |
| 8 | + | |
| 9 | +from django.contrib.auth.mixins import LoginRequiredMixin | |
| 10 | + | |
| 11 | +from rolepermissions.mixins import HasRoleMixin | |
| 12 | +from .forms import CategoryForm | |
| 13 | + | |
| 14 | +class IndexView(LoginRequiredMixin, ListView): | |
| 15 | + | |
| 16 | + login_url = reverse_lazy("users:login") | |
| 17 | + redirect_field_name = 'next' | |
| 18 | + queryset = Category.objects.all() | |
| 19 | + template_name = 'categories/home.html' | |
| 20 | + context_object_name = 'categories' | |
| 21 | + | |
| 22 | + | |
| 23 | + def get_queryset(self): | |
| 24 | + result = super(IndexView, self).get_queryset() | |
| 25 | + | |
| 26 | + | |
| 27 | + return result | |
| 28 | + | |
| 29 | + def render_to_response(self, context, **response_kwargs): | |
| 30 | + if self.request.user.is_staff: | |
| 31 | + context['page_template'] = "categories/home_admin_content.html" | |
| 32 | + else: | |
| 33 | + context['page_template'] = "categories/home_teacher_student_content.html" | |
| 34 | + | |
| 35 | + context['title'] = _('Home') | |
| 36 | + | |
| 37 | + if self.request.is_ajax(): | |
| 38 | + if self.request.user.is_staff: | |
| 39 | + self.template_name = "home_admin_content.html" | |
| 40 | + else: | |
| 41 | + self.template_name = "home_teacher_student_content.html" | |
| 42 | + | |
| 43 | + return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) | |
| 44 | + | |
| 45 | + def get_context_data(self, **kwargs): | |
| 46 | + context = super(IndexView, self).get_context_data(**kwargs) | |
| 47 | + list_categories = None | |
| 48 | + if has_role(self.request.user,'system_admin'): | |
| 49 | + list_categories = self.get_queryset().order_by('name') | |
| 50 | + # categorys_categories = CourseCategory.objects.all() | |
| 51 | + elif has_role(self.request.user,'professor'): | |
| 52 | + pass | |
| 53 | + #list_categories = self.get_queryset().filter(professors__in = [self.request.user]).order_by('name') | |
| 54 | + # categorys_categories = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() | |
| 55 | + elif has_role(self.request.user, 'student'): | |
| 56 | + pass | |
| 57 | + #list_categories = self.get_queryset().filter(students__in = [self.request.user]).order_by('name') | |
| 58 | + | |
| 59 | + | |
| 60 | + context['title'] = _('Categories') | |
| 61 | + | |
| 62 | + return context | |
| 63 | + | |
| 64 | +class createCategory(HasRoleMixin, CreateView): | |
| 65 | + | |
| 66 | + allowed_rules = ['system_admin'] | |
| 67 | + login_url = reverse_lazy('users:login') | |
| 68 | + form_class = CategoryForm | |
| 69 | + template_name = 'categories/create.html' | ... | ... |
courses/__init__.py
courses/admin.py
courses/apps.py
courses/migrations/0001_initial.py
| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | -# -*- coding: utf-8 -*- | |
| 2 | -# Generated by Django 1.10 on 2016-12-21 03:51 | |
| 3 | -from __future__ import unicode_literals | |
| 4 | - | |
| 5 | -import autoslug.fields | |
| 6 | -from django.conf import settings | |
| 7 | -from django.db import migrations, models | |
| 8 | -import django.db.models.deletion | |
| 9 | - | |
| 10 | - | |
| 11 | -class Migration(migrations.Migration): | |
| 12 | - | |
| 13 | - initial = True | |
| 14 | - | |
| 15 | - dependencies = [ | |
| 16 | - migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
| 17 | - ] | |
| 18 | - | |
| 19 | - operations = [ | |
| 20 | - migrations.CreateModel( | |
| 21 | - name='Category', | |
| 22 | - fields=[ | |
| 23 | - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |
| 24 | - ('name', models.CharField(max_length=100, verbose_name='Name')), | |
| 25 | - ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True, verbose_name='Slug')), | |
| 26 | - ('description', models.CharField(max_length=300, verbose_name='description')), | |
| 27 | - ('visible', models.BooleanField(verbose_name='visible')), | |
| 28 | - ('create_date', models.DateTimeField(auto_now_add=True, verbose_name='Creation Date')), | |
| 29 | - ('modified_date', models.DateTimeField(auto_now_add=True, verbose_name='Modified Date')), | |
| 30 | - ('category_father', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='category_parent', to='courses.Category')), | |
| 31 | - ('coordinators', models.ManyToManyField(related_name='coordinators', to=settings.AUTH_USER_MODEL)), | |
| 32 | - ], | |
| 33 | - options={ | |
| 34 | - 'verbose_name_plural': 'Categories', | |
| 35 | - 'verbose_name': 'Category', | |
| 36 | - }, | |
| 37 | - ), | |
| 38 | - ] |
courses/migrations/__init__.py
courses/models.py
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -from django.db import models | |
| 2 | -from autoslug.fields import AutoSlugField | |
| 3 | -from django.utils.translation import ugettext_lazy as _ | |
| 4 | -from users.models import User | |
| 5 | - | |
| 6 | -class Category(models.Model): | |
| 7 | - """Represents a Course """ | |
| 8 | - | |
| 9 | - category_father = models.ForeignKey('Category', related_name =_("category_parent"), on_delete = models.CASCADE) | |
| 10 | - name = models.CharField(_("Name"), max_length = 100) | |
| 11 | - slug = AutoSlugField(_("Slug"),populate_from='name',unique=True) | |
| 12 | - description = models.CharField(_("description"), max_length = 300) | |
| 13 | - visible = models.BooleanField(_("visible")) | |
| 14 | - coordinators = models.ManyToManyField(User, related_name = _("coordinators")) | |
| 15 | - create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) | |
| 16 | - modified_date = models.DateTimeField(_('Modified Date'), auto_now_add = True) | |
| 17 | - | |
| 18 | - class Meta: | |
| 19 | - verbose_name = _('Category') | |
| 20 | - verbose_name_plural = _('Categories') | |
| 21 | - | |
| 22 | - def __str__(self): | |
| 23 | - return self.name | |
| 24 | 0 | \ No newline at end of file |
courses/runtests.py
| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | -import os | |
| 2 | -import sys | |
| 3 | - | |
| 4 | -import django | |
| 5 | -from django.conf import settings | |
| 6 | -from django.test.utils import get_runner | |
| 7 | - | |
| 8 | -if __name__ == "__main__": | |
| 9 | - os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings' | |
| 10 | - django.setup() | |
| 11 | - TestRunner = get_runner(settings) | |
| 12 | - test_runner = TestRunner() | |
| 13 | - failures = test_runner.run_tests(["tests"]) | |
| 14 | - sys.exit(bool(failures)) | |
| 15 | 0 | \ No newline at end of file |
courses/templates/courses/home.html
| ... | ... | @@ -1,33 +0,0 @@ |
| 1 | -{% extends 'base.html' %} | |
| 2 | - | |
| 3 | -{% load static i18n django_bootstrap_breadcrumbs permission_tags %} | |
| 4 | - | |
| 5 | - | |
| 6 | - | |
| 7 | -{% block breadcrumbs %} | |
| 8 | - {% clear_breadcrumbs %} | |
| 9 | - {% breadcrumb 'Home' 'app:index' %} | |
| 10 | -{% endblock %} | |
| 11 | - | |
| 12 | - | |
| 13 | -{% block render_breadcrumbs %} | |
| 14 | - {% render_breadcrumbs %} | |
| 15 | -{% endblock %} | |
| 16 | - | |
| 17 | -{% block content %} | |
| 18 | - {% if user|has_role:'system_admin' %} | |
| 19 | - <h3>{% trans 'Courses' %}</h3> | |
| 20 | - <div id="timeline"> | |
| 21 | - {% include page_template %} | |
| 22 | - </div> | |
| 23 | - {% else %} | |
| 24 | - <div id="timeline"> | |
| 25 | - {% include page_template %} | |
| 26 | - </div> | |
| 27 | - {% endif %} | |
| 28 | - <div id="loading" class="alert alert-primary" role="alert" style="display: none"> | |
| 29 | - <center> | |
| 30 | - <span class="fa fa-spin fa-circle-o-notch"></span> | |
| 31 | - </center> | |
| 32 | - </div> | |
| 33 | -{% endblock %} |
courses/templates/courses/home_admin_content.html
courses/templates/courses/home_teacher_student_content.html
| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | -{% load static i18n %} | |
| 2 | - | |
| 3 | -{% for notification in objects %} | |
| 4 | - | |
| 5 | - | |
| 6 | - <div class="well timeLine"> | |
| 7 | - | |
| 8 | - <div class="row"> | |
| 9 | - <div class="col-xs-2 col-md-1"> | |
| 10 | - <img class="imgTimeLine" src="{{ notification.actor.image_url }}"> | |
| 11 | - </div> | |
| 12 | - <div class="col-xs-10 col-md-11"> | |
| 13 | - <h4 class="resource_inline"><b>{{ notification.actor.username }}</b></h4> | |
| 14 | - <p class="resource_inline">{{notification.message}} {% trans 'at' %} : <a href="#">{{ notification.action_resource.resource.name }}</a></p> | |
| 15 | - <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p> | |
| 16 | - </div> | |
| 17 | - </div> | |
| 18 | -</div> | |
| 19 | -{% endfor %} | |
| 20 | - |
courses/templates/courses/list.html
| ... | ... | @@ -1,66 +0,0 @@ |
| 1 | -{% extends 'home.html' %} | |
| 2 | - | |
| 3 | -{% load static i18n permission_tags %} | |
| 4 | -{% load django_bootstrap_breadcrumbs %} | |
| 5 | - | |
| 6 | -{% block javascript%} | |
| 7 | - {{ block.super }} | |
| 8 | -{% endblock%} | |
| 9 | - | |
| 10 | -{% block breadcrumbs %} | |
| 11 | - | |
| 12 | -{{ block.super }} | |
| 13 | -{% breadcrumb 'Courses' 'course:manage' %} | |
| 14 | - | |
| 15 | -{% endblock %} | |
| 16 | - | |
| 17 | -{% block content %} | |
| 18 | -{% if messages %} | |
| 19 | -{% for message in messages %} | |
| 20 | - <script type="text/javascript"> | |
| 21 | - alertify.success('{{message}}'); | |
| 22 | - </script> | |
| 23 | -{% endfor %} | |
| 24 | -{% endif %} | |
| 25 | - | |
| 26 | -<div class="col-md-12 cards-content"> | |
| 27 | - <form id="searchform" method="get" accept-charset="utf-8"> | |
| 28 | - <div class="input-group"> | |
| 29 | - <div class="form-group is-empty"> | |
| 30 | - <input type="text" class="form-control" placeholder="{% trans 'Search for Courses' %}" name="q"> | |
| 31 | - </div> | |
| 32 | - <span class="input-group-btn input-group-sm"> | |
| 33 | - <button type="submit" class="btn btn-fab btn-fab-mini"> | |
| 34 | - <i class="fa fa-search" aria-hidden="true"></i> | |
| 35 | - </button> | |
| 36 | - </span> | |
| 37 | - </div> | |
| 38 | - </form> | |
| 39 | -</div> | |
| 40 | -<div class="col-md-12 cards-content"> | |
| 41 | - {% for category in categorys_courses %} | |
| 42 | - <div class="panel-group course-card-group"> | |
| 43 | - <div class="panel panel-default"> | |
| 44 | - <div class="panel-heading"> | |
| 45 | - <div class="row"> | |
| 46 | - <div class="col-md-12"> | |
| 47 | - <h4 class="panel-title"> | |
| 48 | - <a class="category-course-link" data-toggle="collapse" href="#{{category.slug}}">{{category.name}}</a> | |
| 49 | - </h4> | |
| 50 | - </div> | |
| 51 | - </div> | |
| 52 | - </div> | |
| 53 | - <div id="{{category.slug}}" class="panel-collapse collapse"> | |
| 54 | - {% for course in category.course_category %} | |
| 55 | - {% include "course/course_card.html" %} | |
| 56 | - {% endfor %} | |
| 57 | - </div> | |
| 58 | - </div> | |
| 59 | - </div> | |
| 60 | - {% endfor %} | |
| 61 | -</div> | |
| 62 | -<div id="modal_course"> | |
| 63 | - | |
| 64 | -</div> | |
| 65 | -<script type="text/javascript" src="{% static 'js/course.js' %}"></script> | |
| 66 | -{% endblock %} |
courses/tests/__init__.py
courses/tests/test_views.py
| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | -from django.test import TestCase, RequestFactory | |
| 2 | -from users.models import User | |
| 3 | -from django.contrib.auth.models import AnonymousUser | |
| 4 | -from .. import views | |
| 5 | - | |
| 6 | -class Index_Test(TestCase): | |
| 7 | - | |
| 8 | - def setUp(self): | |
| 9 | - self.factory = RequestFactory() | |
| 10 | - self.user = User.objects.create(username="felipe", email="felipe.bormann@gmail.com", password="teste") | |
| 11 | - | |
| 12 | - def test_index_get_auth(self): | |
| 13 | - request = self.factory.get('courses/') | |
| 14 | - | |
| 15 | - request.user = self.user | |
| 16 | - | |
| 17 | - response = views.IndexView.as_view()(request) | |
| 18 | - | |
| 19 | - self.assertEqual(response.status_code, 200) | |
| 20 | - | |
| 21 | - def test_index_get_unauth(self): | |
| 22 | - | |
| 23 | - request = self.factory.get('courses/') | |
| 24 | - | |
| 25 | - request.user = AnonymousUser() | |
| 26 | - | |
| 27 | - response = views.IndexView.as_view()(request) | |
| 28 | - | |
| 29 | - self.assertEqual(response.status_code, 302) #Which means it is been redirected to login page | |
| 30 | 0 | \ No newline at end of file |
courses/urls.py
courses/views.py
| ... | ... | @@ -1,60 +0,0 @@ |
| 1 | -from django.shortcuts import render | |
| 2 | -from django.views.generic import ListView | |
| 3 | -from .models import Category | |
| 4 | -from django.core.urlresolvers import reverse_lazy | |
| 5 | -from rolepermissions.verifications import has_role | |
| 6 | - | |
| 7 | -from django.utils.translation import ugettext_lazy as _ | |
| 8 | - | |
| 9 | -from django.contrib.auth.mixins import LoginRequiredMixin | |
| 10 | - | |
| 11 | -class IndexView(LoginRequiredMixin, ListView): | |
| 12 | - | |
| 13 | - login_url = reverse_lazy("users:login") | |
| 14 | - redirect_field_name = 'next' | |
| 15 | - queryset = Category.objects.all() | |
| 16 | - template_name = 'courses/home.html' | |
| 17 | - context_object_name = 'categories' | |
| 18 | - | |
| 19 | - | |
| 20 | - def get_queryset(self): | |
| 21 | - result = super(IndexView, self).get_queryset() | |
| 22 | - | |
| 23 | - | |
| 24 | - return result | |
| 25 | - | |
| 26 | - def render_to_response(self, context, **response_kwargs): | |
| 27 | - if self.request.user.is_staff: | |
| 28 | - context['page_template'] = "courses/home_admin_content.html" | |
| 29 | - else: | |
| 30 | - context['page_template'] = "courses/home_teacher_student_content.html" | |
| 31 | - | |
| 32 | - context['title'] = _('Home') | |
| 33 | - | |
| 34 | - if self.request.is_ajax(): | |
| 35 | - if self.request.user.is_staff: | |
| 36 | - self.template_name = "home_admin_content.html" | |
| 37 | - else: | |
| 38 | - self.template_name = "home_teacher_student_content.html" | |
| 39 | - | |
| 40 | - return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) | |
| 41 | - | |
| 42 | - def get_context_data(self, **kwargs): | |
| 43 | - context = super(IndexView, self).get_context_data(**kwargs) | |
| 44 | - list_courses = None | |
| 45 | - if has_role(self.request.user,'system_admin'): | |
| 46 | - list_courses = self.get_queryset().order_by('name') | |
| 47 | - # categorys_courses = CourseCategory.objects.all() | |
| 48 | - elif has_role(self.request.user,'professor'): | |
| 49 | - pass | |
| 50 | - #list_courses = self.get_queryset().filter(professors__in = [self.request.user]).order_by('name') | |
| 51 | - # categorys_courses = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() | |
| 52 | - elif has_role(self.request.user, 'student'): | |
| 53 | - pass | |
| 54 | - #list_courses = self.get_queryset().filter(students__in = [self.request.user]).order_by('name') | |
| 55 | - | |
| 56 | - | |
| 57 | - context['title'] = _('Categories') | |
| 58 | - | |
| 59 | - return context | |
| 60 | - |