diff --git a/courses/views.py b/courses/views.py index 7df623e..35143b7 100644 --- a/courses/views.py +++ b/courses/views.py @@ -636,8 +636,6 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView): context['users'] = users exercises = Exercise.objects.filter(Q(students=self.request.user)|Q(professors=self.request.user)) context['exercises'] = exercises - files = File.objects.all() - context['files'] = files context['topic'] = topic context['subject'] = topic.subject diff --git a/exercise/models.py b/exercise/models.py index 9ecd5ae..f91fcfc 100644 --- a/exercise/models.py +++ b/exercise/models.py @@ -20,16 +20,17 @@ It represents the Exercises inside topic. class Exercise(models.Model): + name_exercise = models.CharField(_('Name'), max_length=100) description = models.TextField(_('Description'), blank=True) init_date = models.DateField(_('Begin of Subject Date')) end_date = models.DateField(_('End of Subject 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='exercises') + 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=file_path) - file_type = models.ForeignKey(MimeType, verbose_name=_('Type file'), related_name='exercise_type') + file = models.FileField(upload_to='uploads/%Y/%m/%d') + file_type = models.ForeignKey(MimeType, verbose_name=_('Type file'), related_name='exercise_type',null=True) def __str__(self): return self.name_exercise \ No newline at end of file diff --git a/exercise/templates/exercise/card_list_user.html b/exercise/templates/exercise/card_list_user.html index 995b5c1..53b4ce7 100644 --- a/exercise/templates/exercise/card_list_user.html +++ b/exercise/templates/exercise/card_list_user.html @@ -36,10 +36,9 @@

{% trans 'Delivery' %}

- {% for file in files %} -
  • {{file.exercise}}: {{file.name_file}}
  • - {% endfor %} - + {% for exercise in exercises %} +
  • {{exercise.name_exercise}}
  • + {% endfor %}
    diff --git a/exercise/templates/exercise/card_topic_exercises.html b/exercise/templates/exercise/card_topic_exercises.html index f5e06af..cc08296 100644 --- a/exercise/templates/exercise/card_topic_exercises.html +++ b/exercise/templates/exercise/card_topic_exercises.html @@ -39,9 +39,7 @@ {% if exercise.file %}
    {% else %} diff --git a/exercise/views.py b/exercise/views.py index 542d375..c765fe1 100644 --- a/exercise/views.py +++ b/exercise/views.py @@ -47,13 +47,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix self.object = form.save(commit = False) topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) self.object.topic = topic - self.object.name = str(self.object) - self.object.exercise = self.object - self.object.professors = topic.subject.professors - self.object.students = topic.subject.students # Set MimeType - exercise = self.request.FILES['exercise_url'] + exercise = self.request.FILES['file'] try: if exercise: exercise_type = exercise.content_type @@ -73,6 +69,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix 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 @@ -86,12 +85,12 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix #CREATE NOTIFICATION - super(CreateExercise, self).createNotification(message="uploaded a Exercise "+ self.object.name, actor=self.request.user, - resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), + 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 + 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 @@ -138,7 +137,7 @@ def render_exercise(request, id): log_context = {} log_context['exercise_id'] = exercise.id - log_context['exercise_name'] = exercise.name + 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 -- libgit2 0.21.2