Commit 83fc54c7e59b30b8bb5d098f008827faed42990f

Authored by Matheus Lins
1 parent d41cff2f

create exercise #95

courses/views.py
@@ -636,8 +636,6 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView): @@ -636,8 +636,6 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView):
636 context['users'] = users 636 context['users'] = users
637 exercises = Exercise.objects.filter(Q(students=self.request.user)|Q(professors=self.request.user)) 637 exercises = Exercise.objects.filter(Q(students=self.request.user)|Q(professors=self.request.user))
638 context['exercises'] = exercises 638 context['exercises'] = exercises
639 - files = File.objects.all()  
640 - context['files'] = files  
641 639
642 context['topic'] = topic 640 context['topic'] = topic
643 context['subject'] = topic.subject 641 context['subject'] = topic.subject
exercise/models.py
@@ -20,16 +20,17 @@ It represents the Exercises inside topic. @@ -20,16 +20,17 @@ It represents the Exercises inside topic.
20 20
21 21
22 class Exercise(models.Model): 22 class Exercise(models.Model):
  23 +
23 name_exercise = models.CharField(_('Name'), max_length=100) 24 name_exercise = models.CharField(_('Name'), max_length=100)
24 description = models.TextField(_('Description'), blank=True) 25 description = models.TextField(_('Description'), blank=True)
25 init_date = models.DateField(_('Begin of Subject Date')) 26 init_date = models.DateField(_('Begin of Subject Date'))
26 end_date = models.DateField(_('End of Subject Date')) 27 end_date = models.DateField(_('End of Subject Date'))
27 grade = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'), null=True) 28 grade = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'), null=True)
28 - topic = models.ForeignKey(Topic, verbose_name=_('Topic'), related_name='exercises') 29 + topic = models.ForeignKey(Topic, verbose_name=_('Topic'), related_name='exercise_topic')
29 professors = models.ManyToManyField(User, verbose_name=_('Professors'), related_name='professors_exercise', blank=True) 30 professors = models.ManyToManyField(User, verbose_name=_('Professors'), related_name='professors_exercise', blank=True)
30 students = models.ManyToManyField(User, verbose_name=_('Students'), related_name='subject_exercise', blank = True) 31 students = models.ManyToManyField(User, verbose_name=_('Students'), related_name='subject_exercise', blank = True)
31 - file = models.FileField(upload_to=file_path)  
32 - file_type = models.ForeignKey(MimeType, verbose_name=_('Type file'), related_name='exercise_type') 32 + file = models.FileField(upload_to='uploads/%Y/%m/%d')
  33 + file_type = models.ForeignKey(MimeType, verbose_name=_('Type file'), related_name='exercise_type',null=True)
33 34
34 def __str__(self): 35 def __str__(self):
35 return self.name_exercise 36 return self.name_exercise
36 \ No newline at end of file 37 \ No newline at end of file
exercise/templates/exercise/card_list_user.html
@@ -36,10 +36,9 @@ @@ -36,10 +36,9 @@
36 <div class="resource_inline"> 36 <div class="resource_inline">
37 <h4>{% trans 'Delivery' %}</h4> 37 <h4>{% trans 'Delivery' %}</h4>
38 </div> 38 </div>
39 - {% for file in files %}  
40 - <li>{{file.exercise}}: <a href="{{file.file.url}}" target="_blank">{{file.name_file}}</a></li>  
41 - {% endfor %}  
42 - 39 + {% for exercise in exercises %}
  40 + <li><a href="{{exercise.file.url}}" target="_blank">{{exercise.name_exercise}}</a></li>
  41 + {% endfor %}
43 </div> 42 </div>
44 <div class="col-md-4"> 43 <div class="col-md-4">
45 <div class="resource_inline"> 44 <div class="resource_inline">
exercise/templates/exercise/card_topic_exercises.html
@@ -39,9 +39,7 @@ @@ -39,9 +39,7 @@
39 {% if exercise.file %} 39 {% if exercise.file %}
40 <div class="form-group"> 40 <div class="form-group">
41 <label for="DelExc" class="col-md-4 control-label"> <i class="fa fa-file-archive-o fa-3x" aria-hidden="true"> 41 <label for="DelExc" class="col-md-4 control-label"> <i class="fa fa-file-archive-o fa-3x" aria-hidden="true">
42 - {% for file in exercise.file %}  
43 - <a href="{{exercise.file.url}}">{% trans 'File' %}</a>  
44 - {% endfor %} 42 + <a href="{{exercise.file.url}}" target="_blank">{% trans 'File' %}</a>
45 </i> 43 </i>
46 </div> 44 </div>
47 {% else %} 45 {% else %}
exercise/views.py
@@ -47,13 +47,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix @@ -47,13 +47,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix
47 self.object = form.save(commit = False) 47 self.object = form.save(commit = False)
48 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) 48 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
49 self.object.topic = topic 49 self.object.topic = topic
50 - self.object.name = str(self.object)  
51 - self.object.exercise = self.object  
52 - self.object.professors = topic.subject.professors  
53 - self.object.students = topic.subject.students  
54 50
55 # Set MimeType 51 # Set MimeType
56 - exercise = self.request.FILES['exercise_url'] 52 + exercise = self.request.FILES['file']
57 try: 53 try:
58 if exercise: 54 if exercise:
59 exercise_type = exercise.content_type 55 exercise_type = exercise.content_type
@@ -73,6 +69,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix @@ -73,6 +69,9 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix
73 print('Exercise not uploaded') 69 print('Exercise not uploaded')
74 70
75 self.object.save() 71 self.object.save()
  72 + self.object.professors = topic.subject.professors.all()
  73 + self.object.students = topic.subject.students.all()
  74 + self.object.save()
76 #CREATE LOG 75 #CREATE LOG
77 self.log_context['topic_id'] = topic.id 76 self.log_context['topic_id'] = topic.id
78 self.log_context['topic_name'] = topic.name 77 self.log_context['topic_name'] = topic.name
@@ -86,12 +85,12 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix @@ -86,12 +85,12 @@ class CreateExercise(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMix
86 85
87 86
88 #CREATE NOTIFICATION 87 #CREATE NOTIFICATION
89 - super(CreateExercise, self).createNotification(message="uploaded a Exercise "+ self.object.name, actor=self.request.user,  
90 - resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), 88 + super(CreateExercise, self).createNotification(message="uploaded a Exercise "+ self.object.name_exercise, actor=self.request.user,
  89 + resource_name=self.object.name_exercise, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]),
91 users=self.object.topic.subject.students.all()) 90 users=self.object.topic.subject.students.all())
92 91
93 self.log_context['exercise_id'] = self.object.id 92 self.log_context['exercise_id'] = self.object.id
94 - self.log_context['exercise_name'] = self.object.name 93 + self.log_context['exercise_name'] = self.object.name_exercise
95 self.log_context['topic_id'] = self.object.topic.id 94 self.log_context['topic_id'] = self.object.topic.id
96 self.log_context['topic_name'] = self.object.topic.name 95 self.log_context['topic_name'] = self.object.topic.name
97 self.log_context['topic_slug'] = self.object.topic.slug 96 self.log_context['topic_slug'] = self.object.topic.slug
@@ -138,7 +137,7 @@ def render_exercise(request, id): @@ -138,7 +137,7 @@ def render_exercise(request, id):
138 137
139 log_context = {} 138 log_context = {}
140 log_context['exercise_id'] = exercise.id 139 log_context['exercise_id'] = exercise.id
141 - log_context['exercise_name'] = exercise.name 140 + log_context['exercise_name'] = exercise.name_exercise
142 log_context['topic_id'] = exercise.topic.id 141 log_context['topic_id'] = exercise.topic.id
143 log_context['topic_name'] = exercise.topic.name 142 log_context['topic_name'] = exercise.topic.name
144 log_context['topic_slug'] = exercise.topic.slug 143 log_context['topic_slug'] = exercise.topic.slug