From ad886494baab59c536939456aa7d50b90815024a Mon Sep 17 00:00:00 2001 From: Matheus Lins Date: Wed, 16 Nov 2016 21:14:13 -0300 Subject: [PATCH] improvimenting the exercise's model --- amadeus/urls.py | 1 + courses/templates/subject/form_view_student.html | 27 --------------------------- courses/templates/subject/form_view_teacher.html | 15 ++------------- exercise/migrations/0002_auto_20161116_2111.py | 27 +++++++++++++++++++++++++++ exercise/models.py | 3 +++ exercise/templates/exercise/card_list_user.html | 42 ++++++++++++++++++++++++++++++++++++++++++ exercise/templates/exercise/exercise_edit.html | 2 +- exercise/templates/exercise/home.html | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exercise/templatetags/list_topic_exercises.py | 10 +++++----- exercise/urls.py | 1 + exercise/views.py | 26 ++++++++++++++++++++++++-- 11 files changed, 182 insertions(+), 48 deletions(-) create mode 100644 exercise/migrations/0002_auto_20161116_2111.py create mode 100644 exercise/templates/exercise/card_list_user.html create mode 100644 exercise/templates/exercise/home.html diff --git a/amadeus/urls.py b/amadeus/urls.py index 84ba7f7..b75fe7c 100644 --- a/amadeus/urls.py +++ b/amadeus/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ url(r'^home/', include('app.urls', namespace = 'app')), url(r'^courses/', include('courses.urls', namespace = 'course')), url(r'^users/', include('users.urls', namespace = 'users')), + url(r'^exercise/', include('exercise.urls', namespace = 'exercise')), url(r'^admin/', admin.site.urls), url(r'^', include('core.urls', namespace = 'core')), #API diff --git a/courses/templates/subject/form_view_student.html b/courses/templates/subject/form_view_student.html index 0e8cde6..a09929e 100644 --- a/courses/templates/subject/form_view_student.html +++ b/courses/templates/subject/form_view_student.html @@ -63,33 +63,6 @@ -
-
-

{% trans 'Exercises' %}

-
-
- {# dropdown de create exercício #} - -
-
- {# exercício do tópico no modo de visualização #} -
    - {% list_topic_exercise request %} -
-
-
- {# exercício do tópico no modo de edição #} -
    - {% list_topic_exercise_edit request exercise %} -
-
-
- {% include "exercise/create_exercise.html" %} {% endif %} diff --git a/courses/templates/subject/form_view_teacher.html b/courses/templates/subject/form_view_teacher.html index 2cb437c..26a8332 100644 --- a/courses/templates/subject/form_view_teacher.html +++ b/courses/templates/subject/form_view_teacher.html @@ -125,21 +125,10 @@
-

{% trans 'Exercises' %}

-
-
- {# exercício do tópico no modo de visualização #} -
    - {% list_topic_exercise request %} -
-
-
- {# exercício do tópico no modo de edição #} -
    - {% list_topic_exercise_edit request exercise %} -
+

{% trans 'Exercises' %}

+ {% include "exercise/create_exercise.html" %} {# opções de cancelar e editar no modo de edição #} diff --git a/exercise/migrations/0002_auto_20161116_2111.py b/exercise/migrations/0002_auto_20161116_2111.py new file mode 100644 index 0000000..1bdff12 --- /dev/null +++ b/exercise/migrations/0002_auto_20161116_2111.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-11-17 00:11 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('exercise', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='exercise', + name='professors', + field=models.ManyToManyField(related_name='professors_exercise', to=settings.AUTH_USER_MODEL, verbose_name='Professors'), + ), + migrations.AddField( + model_name='exercise', + name='students', + field=models.ManyToManyField(blank=True, related_name='subject_exercise', to=settings.AUTH_USER_MODEL, verbose_name='Students'), + ), + ] diff --git a/exercise/models.py b/exercise/models.py index f2664f8..8db0af3 100644 --- a/exercise/models.py +++ b/exercise/models.py @@ -1,6 +1,7 @@ from django.db import models from courses.models import Topic from django.utils.translation import ugettext_lazy as _ +from users.models import User """ Function to return the path where the file should be saved @@ -18,5 +19,7 @@ It represents the Exercises inside topic. class Exercise(models.Model): topic = models.ForeignKey(Topic, verbose_name=_('Topic'), related_name='exercises') + professors = models.ManyToManyField(User, verbose_name=_('Professors'), related_name='professors_exercise') + students = models.ManyToManyField(User, verbose_name=_('Students'), related_name='subject_exercise', blank = True) file = models.FileField(upload_to='uploads/%Y/%m/%d') name = models.CharField(max_length=100) diff --git a/exercise/templates/exercise/card_list_user.html b/exercise/templates/exercise/card_list_user.html new file mode 100644 index 0000000..5816c18 --- /dev/null +++ b/exercise/templates/exercise/card_list_user.html @@ -0,0 +1,42 @@ +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %} + +{% block javascript %} + + + + +{% endblock %} +
+
+
+ +
+
+
+

+ + + +

+ +
+
+
+ +
+ +
+ +
+
\ No newline at end of file diff --git a/exercise/templates/exercise/exercise_edit.html b/exercise/templates/exercise/exercise_edit.html index b14c1ee..a398412 100644 --- a/exercise/templates/exercise/exercise_edit.html +++ b/exercise/templates/exercise/exercise_edit.html @@ -1,5 +1,5 @@ {% load static i18n list_topic_foruns permission_tags %} -
+
{% for exercise in exercises %}
  • {{exercise.name}}
  • diff --git a/exercise/templates/exercise/home.html b/exercise/templates/exercise/home.html new file mode 100644 index 0000000..0f1978a --- /dev/null +++ b/exercise/templates/exercise/home.html @@ -0,0 +1,76 @@ +{% extends 'home.html' %} + +{% load static i18n permission_tags professor_access %} + +{% block javascript %} + + + + + + + +{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block content %} +
    +
    +
    +
    +

    {{subject}}

    +
    + + {# dropdown de subject com as opções de replicar, editar e deletar #} + + +
    +
    + + {# informações do subject(professor, descrição etc) #} +
    +

    {% trans "Professor" %}: {% for professor in subject.professors.all %}{% if not forloop.first %},{% endif %} + {{professor}}{% if forloop.last %}.{% endif %}{% endfor %}

    +

    + {% trans "Description" %}: + {{subject.description|safe}} +

    +
    +
    +

    {% trans "Beginning" %}: {{subject.init_date}}

    +
    +
    +

    {% trans "End" %}: {{subject.end_date}}

    +
    +
    +
    + +
    + + {# lista de usuários #} + {% for user in users %} + {% include "exercise/card_list_user.html" %} + {% endfor %} + + {% endblock %} diff --git a/exercise/templatetags/list_topic_exercises.py b/exercise/templatetags/list_topic_exercises.py index 34afbb7..51d853f 100644 --- a/exercise/templatetags/list_topic_exercises.py +++ b/exercise/templatetags/list_topic_exercises.py @@ -5,21 +5,21 @@ register = template.Library() @register.inclusion_tag('exercise/exercise_list.html') -def list_topic_exercise(request): +def list_topic_exercise(request, topic): context = { 'request': request, } - context['exercises'] = Exercise.objects.all() + context['exercises'] = Exercise.objects.filter(topic=topic) return context @register.inclusion_tag('exercise/exercise_edit.html') -def list_topic_exercise_edit(request, exercise): +def list_topic_exercise_edit(request, topic): context = { 'request': request, } - context['exercises'] = Exercise.objects.all() - context['exercise'] = exercise + context['exercises'] = Exercise.objects.filter(topic = topic) + context['topic'] = topic return context diff --git a/exercise/urls.py b/exercise/urls.py index d2ac137..96d27b3 100644 --- a/exercise/urls.py +++ b/exercise/urls.py @@ -2,6 +2,7 @@ from django.conf.urls import url from . import views urlpatterns = [ + url(r'^home/(?P[\w_-]+)/$', views.HomeExercise.as_view(), name='home'), url(r'^create_exercise/(?P[\w_-]+)/$', views.CreateExercise.as_view(), name='create_exercise'), url(r'^delete_exercise/(?P[\w_-]+)/$', views.DeleteExercise.as_view(), name='delete_exercise'), url(r'^update_exercise/(?P[\w_-]+)/$', views.UpdateExercise.as_view(), name='update_exercise'), diff --git a/exercise/views.py b/exercise/views.py index 5b26728..6dd2426 100644 --- a/exercise/views.py +++ b/exercise/views.py @@ -1,6 +1,5 @@ from .forms import ExerciseForm, UpdateExerciseForm from .models import Exercise -from files.utils import mime_type_to_material_icons from core.decorators import log_decorator from core.mixins import LogMixin, NotificationMixin from core.models import Log, MimeType @@ -13,8 +12,31 @@ from django.core.urlresolvers import reverse_lazy from django.shortcuts import render, get_object_or_404, redirect from django.urls import reverse from django.views import generic +from files.utils import mime_type_to_material_icons from rolepermissions.mixins import HasRoleMixin from rolepermissions.verifications import has_role +from users.models import User + + +class HomeExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.ListView): + + allowed_roles = ['student', 'professor'] + login_url = reverse_lazy("core:home") + redirect_field_name = 'next' + queryset = User.objects.all() + template_name = 'exercise/home.html' + context_object_name = 'users' + paginate_by = 10 + + def get_context_data(self, **kwargs): + context = super(HomeExercise, self).get_context_data(**kwargs) + topic = get_object_or_404(Topic, slug=self.kwargs.get('slug')) + # users = self.queryset.filter(subject_student = ) + context['topic'] = topic + # context['users'] = users + context['subject'] = topic.subject + + return context class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.CreateView): @@ -23,7 +45,7 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix log_action = 'create' log_component = {} - allowed_roles = ['student'] + allowed_roles = ['student', 'professor'] login_url = reverse_lazy("core:home") redirect_field_name = 'next' model = Exercise -- libgit2 0.21.2