From 22b71966d2d9b9096da3fd33cc84c9d13d5a3873 Mon Sep 17 00:00:00 2001 From: Felipe Henrique de Almeida Bormann Date: Sun, 11 Dec 2016 19:04:39 -0300 Subject: [PATCH] removed matheuslins code, which is represented as the exercise app and checked if nothing else was affected when removing it --- amadeus/settings.py | 1 - amadeus/urls.py | 1 - courses/templates/subject/form_view_student.html | 2 +- courses/templates/topic/update.html | 3 +-- courses/templates/topic/view.html | 6 +++--- courses/urls.py | 1 - courses/views.py | 3 +-- exercise/__init__.py | 0 exercise/admin.py | 8 -------- exercise/apps.py | 5 ----- exercise/forms.py | 32 -------------------------------- exercise/locale/pt_BR/LC_MESSAGES/django.po | 125 ----------------------------------------------------------------------------------------------------------------------------- exercise/migrations/0001_initial.py | 32 -------------------------------- exercise/migrations/0002_auto_20161124_1217.py | 36 ------------------------------------ exercise/migrations/__init__.py | 0 exercise/models.py | 36 ------------------------------------ exercise/static/js/exercise.js | 7 ------- exercise/templates/exercise/card_list_user.html | 64 ---------------------------------------------------------------- exercise/templates/exercise/card_topic_exercises.html | 59 ----------------------------------------------------------- exercise/templates/exercise/create_exercise.html | 113 ----------------------------------------------------------------------------------------------------------------- exercise/templates/exercise/delete_exercise.html | 66 ------------------------------------------------------------------ exercise/templates/exercise/exercise_edit.html | 7 ------- exercise/templates/exercise/exercise_list.html | 6 ------ exercise/templates/exercise/render_exercise.html | 1 - exercise/templates/exercise/update_exercise.html | 120 ------------------------------------------------------------------------------------------------------------------------ exercise/templatetags/__init__.py | 0 exercise/templatetags/list_topic_exercises.py | 25 ------------------------- exercise/tests.py | 3 --- exercise/urls.py | 9 --------- exercise/views.py | 253 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 30 files changed, 6 insertions(+), 1018 deletions(-) delete mode 100644 exercise/__init__.py delete mode 100644 exercise/admin.py delete mode 100644 exercise/apps.py delete mode 100644 exercise/forms.py delete mode 100644 exercise/locale/pt_BR/LC_MESSAGES/django.po delete mode 100644 exercise/migrations/0001_initial.py delete mode 100644 exercise/migrations/0002_auto_20161124_1217.py delete mode 100644 exercise/migrations/__init__.py delete mode 100644 exercise/models.py delete mode 100644 exercise/static/js/exercise.js delete mode 100644 exercise/templates/exercise/card_list_user.html delete mode 100644 exercise/templates/exercise/card_topic_exercises.html delete mode 100644 exercise/templates/exercise/create_exercise.html delete mode 100644 exercise/templates/exercise/delete_exercise.html delete mode 100644 exercise/templates/exercise/exercise_edit.html delete mode 100644 exercise/templates/exercise/exercise_list.html delete mode 100644 exercise/templates/exercise/render_exercise.html delete mode 100644 exercise/templates/exercise/update_exercise.html delete mode 100644 exercise/templatetags/__init__.py delete mode 100644 exercise/templatetags/list_topic_exercises.py delete mode 100644 exercise/tests.py delete mode 100644 exercise/urls.py delete mode 100644 exercise/views.py diff --git a/amadeus/settings.py b/amadeus/settings.py index be72e3a..ab3230f 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -60,7 +60,6 @@ INSTALLED_APPS = [ 'poll', 'links', 'files', - 'exercise', ] diff --git a/amadeus/urls.py b/amadeus/urls.py index b75fe7c..84ba7f7 100644 --- a/amadeus/urls.py +++ b/amadeus/urls.py @@ -23,7 +23,6 @@ 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 286ea88..3b3d81d 100644 --- a/courses/templates/subject/form_view_student.html +++ b/courses/templates/subject/form_view_student.html @@ -1,4 +1,4 @@ -{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %} +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access %} {% professor_subject topic.subject user as professor_links %} {% block javascript %} diff --git a/courses/templates/topic/update.html b/courses/templates/topic/update.html index 358dffd..70f1092 100644 --- a/courses/templates/topic/update.html +++ b/courses/templates/topic/update.html @@ -1,4 +1,4 @@ -{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises course_value_field %} +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access course_value_field %}
{% csrf_token %} @@ -84,7 +84,6 @@ diff --git a/courses/templates/topic/view.html b/courses/templates/topic/view.html index 21e258b..9962e6b 100644 --- a/courses/templates/topic/view.html +++ b/courses/templates/topic/view.html @@ -1,4 +1,4 @@ -{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %} +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access %} @@ -51,7 +51,7 @@ @@ -61,7 +61,7 @@ {% endif %} diff --git a/courses/urls.py b/courses/urls.py index e86872c..cd9e21b 100644 --- a/courses/urls.py +++ b/courses/urls.py @@ -33,7 +33,6 @@ urlpatterns = [ url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'), url(r'^subjects/file-material-view/(?P[\w_-]+)/$', views.FileMaterialView.as_view(), name='file_material_view'), url(r'^links/',include('links.urls',namespace = 'links')), - url(r'^exercise/', include('exercise.urls', namespace='exercise')), url(r'^topic/(?P[\w_-]+)/$', views.topic_log, name='topic_log'), url(r'^(?P[\w_-]+)/', include([ url(r'^$', views.CourseView.as_view(), name='view'), diff --git a/courses/views.py b/courses/views.py index 69050e3..e7c961c 100644 --- a/courses/views.py +++ b/courses/views.py @@ -16,7 +16,7 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.views import generic -from exercise.models import Exercise + from files.forms import FileForm from files.models import TopicFile from functools import reduce @@ -623,7 +623,6 @@ class SubjectsView(AccessMixin, LogMixin, generic.ListView): context['course'] = subject.course context['subject'] = subject context['topics'] = Topic.objects.filter(subject = subject) - context['exercise'] = Exercise.objects.filter(topic__subject=subject) context['title'] = subject.name if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): context['files'] = TopicFile.objects.filter(professor__name = self.request.user.name) diff --git a/exercise/__init__.py b/exercise/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/exercise/__init__.py +++ /dev/null diff --git a/exercise/admin.py b/exercise/admin.py deleted file mode 100644 index 0c0deb5..0000000 --- a/exercise/admin.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.contrib import admin -from .models import Exercise - -class ExerciseAdmin(admin.ModelAdmin): - list_display = ['name_exercise'] - search_fields = ['name_exercise'] - -admin.site.register(Exercise, ExerciseAdmin) diff --git a/exercise/apps.py b/exercise/apps.py deleted file mode 100644 index 9ff568a..0000000 --- a/exercise/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class ExerciseConfig(AppConfig): - name = 'exercise' diff --git a/exercise/forms.py b/exercise/forms.py deleted file mode 100644 index fcb4930..0000000 --- a/exercise/forms.py +++ /dev/null @@ -1,32 +0,0 @@ -from .models import Exercise -from django import forms -from django.core.exceptions import ValidationError, FieldError -from django.utils.translation import ugettext_lazy as _ -import requests - - -class ExerciseForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(ExerciseForm, self).__init__(*args, **kwargs) - self.fields["allowed"].required = False - self.fields["allowed"].initial = False - - # def clean_allowed(self): - # if('allowed' in self.data): - # allowed = self.data['allowed'] - # raise forms.ValidationError(_('It is required one these fields.')) - # return True - - class Meta: - model = Exercise - fields = ['name_exercise', 'description', - 'end_date', 'file', 'allowed'] - - -class UpdateExerciseForm(forms.ModelForm): - - class Meta: - model = Exercise - fields = ['name_exercise', 'description', - 'end_date', 'file'] diff --git a/exercise/locale/pt_BR/LC_MESSAGES/django.po b/exercise/locale/pt_BR/LC_MESSAGES/django.po deleted file mode 100644 index d9f9bad..0000000 --- a/exercise/locale/pt_BR/LC_MESSAGES/django.po +++ /dev/null @@ -1,125 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-11-24 00:05-0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" - -#: .\models.py:24 -msgid "Name" -msgstr "Nome" - -#: .\models.py:25 .\templates\exercise\card_topic_exercises.html:11 -msgid "Description" -msgstr "Descrição" - -#: .\models.py:26 .\templates\exercise\card_topic_exercises.html:22 -msgid "Delivery Date" -msgstr "Data de entrega" - -#: .\models.py:28 -msgid "Topic" -msgstr "Tópico" - -#: .\models.py:29 -msgid "Professors" -msgstr "Professores" - -#: .\models.py:30 -msgid "Students" -msgstr "Estudantes" - -#: .\models.py:32 -msgid "Type file" -msgstr "Tipo de arquivo" - -#: .\models.py:33 -msgid "Allowed delivery after end date?" -msgstr "Permitido entregar após a data de término?" - -#: .\templates\exercise\card_list_user.html:23 -#: .\templates\exercise\card_topic_exercises.html:26 -msgid "Grade" -msgstr "Nota" - -#: .\templates\exercise\card_list_user.html:30 -msgid "Give a grade" -msgstr "Dar a nota" - -#: .\templates\exercise\card_list_user.html:37 -msgid "Delivery" -msgstr "Entregar" - -#: .\templates\exercise\card_list_user.html:45 -msgid "Create" -msgstr "Criar" - -#: .\templates\exercise\card_list_user.html:52 -msgid "Create a specific exercise" -msgstr "Criar um exercício específico" - -#: .\templates\exercise\card_topic_exercises.html:15 -msgid "Don't have description" -msgstr "Não possui descrição" - -#: .\templates\exercise\card_topic_exercises.html:34 -msgid "Not yet" -msgstr "Ainda não" - -#: .\templates\exercise\card_topic_exercises.html:41 -msgid "File" -msgstr "Arquivo" - -#: .\templates\exercise\card_topic_exercises.html:45 -msgid "Exercise not yet" -msgstr "Sem exercícios por enquanto" - -#: .\templates\exercise\card_topic_exercises.html:49 -msgid "Teacher waiting corretion" -msgstr "Aguardando correção do professor" - -#: .\templates\exercise\create_exercise.html:8 -msgid "Create a New Material" -msgstr "Criar um novo Material" - -#: .\templates\exercise\create_exercise.html:36 -msgid "Choose your file..." -msgstr "Escolha seu arquivo..." - -#: .\templates\exercise\create_exercise.html:66 -msgid "The file size shouldnt exceed 10MB" -msgstr "O tamanho do arquivo não pode exceder 10MB" - -#: .\templates\exercise\create_exercise.html:72 -#: .\templates\exercise\delete_exercise.html:24 -msgid "Close" -msgstr "Fechar" - -#: .\templates\exercise\create_exercise.html:73 -msgid "Submit" -msgstr "Enviar" - -#: .\templates\exercise\delete_exercise.html:12 -msgid "Delete Exercise" -msgstr "Apagar exercício" - -#: .\templates\exercise\delete_exercise.html:20 -msgid "Are you sure to delete the exercise " -msgstr "Você tem certeza que quer deletar o exercício " - -#: .\templates\exercise\delete_exercise.html:25 -msgid "Delete" -msgstr "Apagar" diff --git a/exercise/migrations/0001_initial.py b/exercise/migrations/0001_initial.py deleted file mode 100644 index 3073f98..0000000 --- a/exercise/migrations/0001_initial.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-11-24 15:17 -from __future__ import unicode_literals - -from decimal import Decimal -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('core', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Exercise', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name_exercise', models.CharField(max_length=100, verbose_name='Name')), - ('description', models.TextField(blank=True, verbose_name='Description')), - ('end_date', models.DateField(verbose_name='Delivery Date')), - ('grade', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=20, null=True)), - ('file', models.FileField(upload_to='uploads/%Y/%m/%d')), - ('allowed', models.BooleanField(default=False, verbose_name='Allowed delivery after end date?')), - ('file_type', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='exercise_type', to='core.MimeType', verbose_name='Type file')), - ], - ), - ] diff --git a/exercise/migrations/0002_auto_20161124_1217.py b/exercise/migrations/0002_auto_20161124_1217.py deleted file mode 100644 index a61ebed..0000000 --- a/exercise/migrations/0002_auto_20161124_1217.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-11-24 15:17 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('exercise', '0001_initial'), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('courses', '0002_auto_20161124_1217'), - ] - - operations = [ - migrations.AddField( - model_name='exercise', - name='professors', - field=models.ManyToManyField(blank=True, 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'), - ), - migrations.AddField( - model_name='exercise', - name='topic', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exercise_topic', to='courses.Topic', verbose_name='Topic'), - ), - ] diff --git a/exercise/migrations/__init__.py b/exercise/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/exercise/migrations/__init__.py +++ /dev/null diff --git a/exercise/models.py b/exercise/models.py deleted file mode 100644 index df0c25a..0000000 --- a/exercise/models.py +++ /dev/null @@ -1,36 +0,0 @@ -from courses.models import Topic -from decimal import Decimal -from django.db import models -from django.utils.translation import ugettext_lazy as _ -from users.models import User -from core.models import MimeType - -""" - Function to return the path where the file should be saved -""" - - -def file_path(instance, filename): - return '/'.join([instance.topic.subject.course.slug, instance.topic.subject.slug, instance.topic.slug, filename]) - - -""" -It represents the Exercises inside topic. -""" - - -class Exercise(models.Model): - - name_exercise = models.CharField(_('Name'), max_length=100) - description = models.TextField(_('Description'), blank=True) - end_date = models.DateField(_('Delivery Date')) - grade = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'), null=True) - topic = models.ForeignKey(Topic, verbose_name=_('Topic'), related_name='exercise_topic') - professors = models.ManyToManyField(User, verbose_name=_('Professors'), related_name='professors_exercise', blank=True) - students = models.ManyToManyField(User, verbose_name=_('Students'), related_name='subject_exercise', blank = True) - file = models.FileField(upload_to='uploads/%Y/%m/%d') - file_type = models.ForeignKey(MimeType, verbose_name=_('Type file'), related_name='exercise_type',null=True) - allowed = models.BooleanField(_('Allowed delivery after end date?'), default=False) - - def __str__(self): - return self.name_exercise diff --git a/exercise/static/js/exercise.js b/exercise/static/js/exercise.js deleted file mode 100644 index 15559aa..0000000 --- a/exercise/static/js/exercise.js +++ /dev/null @@ -1,7 +0,0 @@ -function get_modal_exercise(url, id,div_content){ - $.get(url, function (data) { - $(div_content).detach(); - $(div_content).append(data); - $(id).modal('show'); - }); -} diff --git a/exercise/templates/exercise/card_list_user.html b/exercise/templates/exercise/card_list_user.html deleted file mode 100644 index 53b4ce7..0000000 --- a/exercise/templates/exercise/card_list_user.html +++ /dev/null @@ -1,64 +0,0 @@ -{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %} - -
-
-
- -
-
-
-
-
-

{% trans 'Grade' %}

-
-
- {# dropdown de create exercício #} - -
-
-
-
-

{% trans 'Delivery' %}

-
- {% for exercise in exercises %} -
  • {{exercise.name_exercise}}
  • - {% endfor %} -
    -
    -
    -

    {% trans 'Create' %}

    -
    -
    - {# dropdown de create exercício #} - -
    - {% include "exercise/create_exercise.html" %} -
    -
    -
    -
    -
    -
    -
    -
    \ No newline at end of file diff --git a/exercise/templates/exercise/card_topic_exercises.html b/exercise/templates/exercise/card_topic_exercises.html deleted file mode 100644 index 5acd8c1..0000000 --- a/exercise/templates/exercise/card_topic_exercises.html +++ /dev/null @@ -1,59 +0,0 @@ -{% load static widget_tweaks i18n %} - -
    -
    -
    - -
    -
    {{exercise.name_exercise}}
    -
    -
    -
    - {% if exercise.description%} - {{exercise.description}} - {% else %} - {% trans "Don't have description" %} - {% endif %} -
    -
    - -
    -
    -
    {{exercise.end_date}} - -
    -
    - -
    - {% if exercise.file %} - - {% else %} -

    {% trans 'Exercise not yet' %}

    - {% endif %} - {% if not exercise.grade %} -
    -
    - {% endif %} -
    - -
    - - -
    -
    -
    \ No newline at end of file diff --git a/exercise/templates/exercise/create_exercise.html b/exercise/templates/exercise/create_exercise.html deleted file mode 100644 index 87d5e92..0000000 --- a/exercise/templates/exercise/create_exercise.html +++ /dev/null @@ -1,113 +0,0 @@ -{% load widget_tweaks i18n static %} - - - - diff --git a/exercise/templates/exercise/delete_exercise.html b/exercise/templates/exercise/delete_exercise.html deleted file mode 100644 index 4b7a289..0000000 --- a/exercise/templates/exercise/delete_exercise.html +++ /dev/null @@ -1,66 +0,0 @@ -{% load static widget_tweaks i18n %} - - - - -
    - -
    - - - diff --git a/exercise/templates/exercise/exercise_edit.html b/exercise/templates/exercise/exercise_edit.html deleted file mode 100644 index 1b6221d..0000000 --- a/exercise/templates/exercise/exercise_edit.html +++ /dev/null @@ -1,7 +0,0 @@ -{% load static i18n list_topic_foruns permission_tags %} -
    - {% for exercise in exercises %} -
  • -
  • {{exercise.name_exercise}}
  • - {% endfor %} -
    diff --git a/exercise/templates/exercise/exercise_list.html b/exercise/templates/exercise/exercise_list.html deleted file mode 100644 index 3b5a44f..0000000 --- a/exercise/templates/exercise/exercise_list.html +++ /dev/null @@ -1,6 +0,0 @@ -{% load static i18n list_topic_foruns permission_tags %} -
    -{% for exercise in exercises %} -
  • {{exercise.name_exercise}}
  • -{% endfor %} -
    diff --git a/exercise/templates/exercise/render_exercise.html b/exercise/templates/exercise/render_exercise.html deleted file mode 100644 index 8c928b4..0000000 --- a/exercise/templates/exercise/render_exercise.html +++ /dev/null @@ -1 +0,0 @@ -
  • {{ exercise.file_type.icon }} {{ exercise.name }}
  • \ No newline at end of file diff --git a/exercise/templates/exercise/update_exercise.html b/exercise/templates/exercise/update_exercise.html deleted file mode 100644 index ede3f67..0000000 --- a/exercise/templates/exercise/update_exercise.html +++ /dev/null @@ -1,120 +0,0 @@ -{% load static widget_tweaks i18n %} - - - - -
    - -
    - -{% block script_file %} - - {# // #} - -{% endblock script_file %} - \ No newline at end of file diff --git a/exercise/templatetags/__init__.py b/exercise/templatetags/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/exercise/templatetags/__init__.py +++ /dev/null diff --git a/exercise/templatetags/list_topic_exercises.py b/exercise/templatetags/list_topic_exercises.py deleted file mode 100644 index 19d6a46..0000000 --- a/exercise/templatetags/list_topic_exercises.py +++ /dev/null @@ -1,25 +0,0 @@ -from django import template -from exercise.models import Exercise - -register = template.Library() - - -@register.inclusion_tag('exercise/exercise_list.html') -def list_topic_exercise(request, topic): - context = { - 'request': request, - } - context['exercises'] = Exercise.objects.filter(topic=topic) - - return context - - -@register.inclusion_tag('exercise/exercise_edit.html') -def list_topic_exercise_edit(request, topic): - context = { - 'request': request, - } - context['exercises'] = Exercise.objects.filter(topic=topic) - context['topic'] = topic - - return context diff --git a/exercise/tests.py b/exercise/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/exercise/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/exercise/urls.py b/exercise/urls.py deleted file mode 100644 index d2ac137..0000000 --- a/exercise/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.conf.urls import url -from . import views - -urlpatterns = [ - 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'), - url(r'^render-exercise/(?P[0-9]+)/$', views.render_exercise, name='render_exercise'), -] diff --git a/exercise/views.py b/exercise/views.py deleted file mode 100644 index c765fe1..0000000 --- a/exercise/views.py +++ /dev/null @@ -1,253 +0,0 @@ -from .forms import ExerciseForm, UpdateExerciseForm -from .models import Exercise -from core.decorators import log_decorator -from core.mixins import LogMixin, NotificationMixin -from core.models import Log, MimeType -from courses.models import Topic -from datetime import datetime -from django.conf import settings -from django.contrib import messages -from django.contrib.auth.mixins import LoginRequiredMixin -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 CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.CreateView): - log_component = 'exercise' - log_resource = 'exercise' - log_action = 'create' - log_component = {} - - allowed_roles = ['professor', 'student'] - login_url = reverse_lazy("core:home") - redirect_field_name = 'next' - model = Exercise - template_name = 'exercise/create_exercise.html' - form_class = ExerciseForm - success_url = reverse_lazy('course:exercise:render_exercise') - - log_component = "subject" - log_resource = "exercise" - log_action = "create" - log_context = {} - - def form_invalid(self, form, **kwargs): - context = super(CreateExercise, self).form_invalid(form) - context.status_code = 400 - - return context - - def form_valid(self, form): - self.object = form.save(commit = False) - topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) - self.object.topic = topic - - # Set MimeType - exercise = self.request.FILES['file'] - try: - if exercise: - exercise_type = exercise.content_type - - # Check if exist a mimetype in database - try: - self.object.file_type = MimeType.objects.get(typ = exercise_type) - # Create if not - except: - mtype = MimeType.objects.create( - typ = exercise_type, - icon = mime_type_to_material_icons[exercise_type] - ) - mtype.save() - self.object.file_type = mtype - except: - print('Exercise not uploaded') - - self.object.save() - self.object.professors = topic.subject.professors.all() - self.object.students = topic.subject.students.all() - self.object.save() - #CREATE LOG - self.log_context['topic_id'] = topic.id - self.log_context['topic_name'] = topic.name - self.log_context['topic_slug'] = topic.slug - self.log_context['subject_id'] = topic.subject.id - self.log_context['subject_name'] = topic.subject.name - self.log_context['subject_slug'] = topic.subject.slug - - super(CreateExercise, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - - - - #CREATE NOTIFICATION - super(CreateExercise, self).createNotification(message="uploaded a Exercise "+ self.object.name_exercise, actor=self.request.user, - resource_name=self.object.name_exercise, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), - users=self.object.topic.subject.students.all()) - - self.log_context['exercise_id'] = self.object.id - self.log_context['exercise_name'] = self.object.name_exercise - self.log_context['topic_id'] = self.object.topic.id - self.log_context['topic_name'] = self.object.topic.name - self.log_context['topic_slug'] = self.object.topic.slug - self.log_context['subject_id'] = self.object.topic.subject.id - self.log_context['subject_name'] = self.object.topic.subject.name - self.log_context['subject_slug'] = self.object.topic.subject.slug - self.log_context['course_id'] = self.object.topic.subject.course.id - self.log_context['course_name'] = self.object.topic.subject.course.name - self.log_context['course_slug'] = self.object.topic.subject.course.slug - self.log_context['course_category_id'] = self.object.topic.subject.course.category.id - self.log_context['course_category_name'] = self.object.topic.subject.course.category.name - - super(CreateExercise, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - - return self.get_success_url() - - def get_context_data(self, **kwargs): - context = super(CreateExercise, self).get_context_data(**kwargs) - topic = get_object_or_404(Topic, slug=self.kwargs.get('slug')) - context['topic'] = topic - context['subject'] = topic.subject - context['subjects'] = topic.subject.course.subjects.all() - context['form'] = self.form_class - - try: - context['latest_exercise'] = Exercise.objects.latest('id') - except: - pass - return context - - def get_success_url(self): - self.success_url = redirect('course:exercise:render_exercise', id = self.object.id) - - return self.success_url - - -def render_exercise(request, id): - template_name = 'exercise/render_exercise.html' - exercise = get_object_or_404(Exercise, id = id) - - context = { - 'exercise': exercise - } - - log_context = {} - log_context['exercise_id'] = exercise.id - log_context['exercise_name'] = exercise.name_exercise - log_context['topic_id'] = exercise.topic.id - log_context['topic_name'] = exercise.topic.name - log_context['topic_slug'] = exercise.topic.slug - log_context['subject_id'] = exercise.topic.subject.id - log_context['subject_name'] = exercise.topic.subject.name - log_context['subject_slug'] = exercise.topic.subject.slug - log_context['course_id'] = exercise.topic.subject.course.id - log_context['course_name'] = exercise.topic.subject.course.name - log_context['course_slug'] = exercise.topic.subject.course.slug - log_context['course_category_id'] = exercise.topic.subject.course.category.id - log_context['course_category_name'] = exercise.topic.subject.course.category.name - - request.log_context = log_context - - return render(request, template_name, context) - - -class UpdateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView): - log_component = 'exercise' - log_resource = 'exercise' - log_action = 'update' - log_context = {} - - allowed_roles = ['student'] - login_url = reverse_lazy("core:home") - redirect_field_name = 'next' - model = Exercise - template_name = 'exercise/update_exercise.html' - form_class = UpdateExerciseForm - context_object_name = 'exercise' - success_url = reverse_lazy('course:exercise:render_exercise') - - def form_invalid(self, form, **kwargs): - context = super(UpdateExercise, self).form_invalid(form) - context.status_code = 400 - - return context - - - def form_valid(self, form): - self.object = form.save() - - self.log_context['exercise_id'] = self.object.id - self.log_context['exercise_name'] = self.object.name - self.log_context['topic_id'] = self.object.topic.id - self.log_context['topic_name'] = self.object.topic.name - self.log_context['topic_slug'] = self.object.topic.slug - self.log_context['subject_id'] = self.object.topic.subject.id - self.log_context['subject_name'] = self.object.topic.subject.name - self.log_context['subject_slug'] = self.object.topic.subject.slug - self.log_context['course_id'] = self.object.topic.subject.course.id - self.log_context['course_name'] = self.object.topic.subject.course.name - self.log_context['course_slug'] = self.object.topic.subject.course.slug - self.log_context['course_category_id'] = self.object.topic.subject.course.category.id - self.log_context['course_category_name'] = self.object.topic.subject.course.category.name - - super(UpdateExercise, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - - return super(UpdateExercise, self).form_valid(form) - - def get_object(self, queryset=None): - return get_object_or_404(Exercise, slug = self.kwargs.get('slug')) - - def get_success_url(self): - self.success_url = reverse_lazy('course:exercise:render_exercise', args = (self.object.id, )) - - return self.success_url - - -class DeleteExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.DeleteView): - log_component = 'exercise' - log_resource = 'exercise' - log_action = 'delete' - log_context = {} - - allowed_roles = ['student'] - login_url = reverse_lazy("core:home") - redirect_field_name = 'next' - model = Exercise - template_name = 'exercise/delete_exercise.html' - - def dispatch(self, *args, **kwargs): - exercise = get_object_or_404(Exercise, slug = self.kwargs.get('slug')) - if(not (exercise.topic.owner == self.request.user) and not(has_role(self.request.user, 'system_admin')) ): - return self.handle_no_permission() - return super(DeleteExercise, self).dispatch(*args, **kwargs) - - def get_context_data(self, **kwargs): - context = super(DeleteExercise, self).get_context_data(**kwargs) - context['course'] = self.object.topic.subject.course - context['subject'] = self.object.topic.subject - context['exercise'] = self.object - context["topic"] = self.object.topic - return context - - def get_success_url(self): - self.log_context['exercise_id'] = self.object.id - self.log_context['exercise_name'] = self.object.name - self.log_context['topic_id'] = self.object.topic.id - self.log_context['topic_name'] = self.object.topic.name - self.log_context['topic_slug'] = self.object.topic.slug - self.log_context['subject_id'] = self.object.topic.subject.id - self.log_context['subject_name'] = self.object.topic.subject.name - self.log_context['subject_slug'] = self.object.topic.subject.slug - self.log_context['course_id'] = self.object.topic.subject.course.id - self.log_context['course_name'] = self.object.topic.subject.course.name - self.log_context['course_slug'] = self.object.topic.subject.course.slug - self.log_context['course_category_id'] = self.object.topic.subject.course.category.id - self.log_context['course_category_name'] = self.object.topic.subject.course.category.name - - super(DeleteExercise, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - - return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) \ No newline at end of file -- libgit2 0.21.2