Commit db1ba29daa7ab502e04aee79779120a55880cee6

Authored by Gustavo Bernardo
2 parents e6b1fd3f 16bb6b6c

Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev

courses/models.py
... ... @@ -116,19 +116,6 @@ class Material(Resource):
116 116 all_students = models.BooleanField(_('All Students'), default=False)
117 117  
118 118 """
119   -Topic File
120   -"""
121   -class File(Material):
122   - description = models.TextField(_('Description'), blank=True)
123   - content = models.FileField(upload_to='uploads/courses/subject/topic/%Y/%m/%d/')
124   - typ = models.ForeignKey(MymeType, verbose_name= _('Type'), related_name='file')
125   -
126   - class Meta:
127   - verbose_name = _('Topic file')
128   - verbose_name_plural = _('Topic files')
129   -
130   -
131   -"""
132 119 It is a category for each subject.
133 120 """
134 121 class SubjectCategory(models.Model):
... ...
courses/templates/subject/form_view_teacher.html
... ... @@ -226,62 +226,10 @@
226 226 </div>
227 227 </div>
228 228 </div>
229   - <!-- EndModal -->
230 229  
231   - <!-- MODAL CREATE FILE -->
232   - <div class="modal fade" id="createFileModal" tabindex="-1" role="dialog" aria-labelledby="createFileLabel" style="display: none;">
233   - <div class="modal-dialog" role="document">
234   - <div class="modal-content">
235   - <div class="modal-header">
236   - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
237   - <h4 class="modal-title" id="createFileLabel">Add File</h4>
238   - </div>
239   - <div class="modal-body">
240   - <!-- Card -->
241   -
242   - <form class="form-horizontal">
243   - <fieldset>
244   -
245   - <div class="form-group is-empty">
246   - <label for="inputName" class="col-md-2 control-label">Name</label>
247   -
248   - <div class="col-md-10">
249   - <input type="text" class="form-control" id="inputText" placeholder="Name">
250   - </div>
251   - </div>
252   -
253   - <div class="form-group is-empty is-fileinput">
254   - <label for="inputFile" class="col-md-2 control-label">File</label>
255   -
256   - <div class="col-md-10">
257   - <input type="text" readonly="" class="form-control" placeholder="Browse...">
258   - <input type="file" id="inputFile" multiple="">
259   - </div>
260   - </div>
261   -
262   -
263   - <div class="form-group">
264   - <div class="col-md-12 text-center">
265   - <p><b>The file size shouldn't exceed 10MB</b></p>
266   - </div>
267   - </div>
268   -
269   - <div class="form-group">
270   - <div class="col-md-12">
271   - <a href="javascript:void(0)" class="btn btn-raised btn-default">Cancel<div class="ripple-container"></div></a>
272   - <a href="javascript:void(0)" class="btn btn-raised btn-primary">Submit</a>
273   - </div>
274   - </div>
275   - </fieldset>
276   - </form>
277   -
278   -
279   - <!-- .end Card -->
280   - </div>
281   - </div>
282   - </div>
283   - </div>
284   - <!-- EndModal -->
  230 +{% if user|has_role:'system_admin' or topic.owner == user%}
  231 + {% include "files/create_file.html" %}
  232 +{% endif %}
285 233  
286 234 <!-- MODAL REMOVE FILE -->
287 235 <div class="modal" id="removeFileModal">
... ...
courses/views.py
... ... @@ -16,6 +16,7 @@ from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm
16 16 from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity
17 17 from core.mixins import NotificationMixin
18 18 from users.models import User
  19 +from files.forms import FileForm
19 20  
20 21 from datetime import date
21 22  
... ... @@ -303,6 +304,7 @@ class SubjectsView(LoginRequiredMixin, generic.ListView):
303 304 context = super(SubjectsView, self).get_context_data(**kwargs)
304 305 context['course'] = subject.course
305 306 context['subject'] = subject
  307 + context['form_file'] = FileForm
306 308 context['topics'] = Topic.objects.filter(subject = subject)
307 309 return context
308 310  
... ...
files/forms.py 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +from django import forms
  2 +from .models import TopicFile
  3 +from django.utils.translation import ugettext_lazy as _
  4 +
  5 +class FileForm(forms.ModelForm):
  6 +
  7 + class Meta:
  8 + model = TopicFile
  9 + fields = ['name', 'file_url']
0 10 \ No newline at end of file
... ...
files/templates/files/create_file.html 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +{% load widget_tweaks i18n %}
  2 +<!-- MODAL CREATE FILE -->
  3 +<div class="modal fade" id="createFileModal" tabindex="-1" role="dialog" aria-labelledby="createFileLabel" style="display: none;">
  4 + <div class="modal-dialog" role="document">
  5 + <div class="modal-content">
  6 + <div class="modal-header">
  7 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  8 + <h4 class="modal-title" id="createFileLabel">{% trans 'Add File' %}</h4>
  9 + </div>
  10 + <div class="modal-body">
  11 + <!-- Card -->
  12 + <form class="form-horizontal">
  13 + {% csrf_token %}
  14 + {% if messages %}
  15 + {% for message in messages %}
  16 + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert">
  17 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  18 + <span aria-hidden="true">&times;</span>
  19 + </button>
  20 + <p>{{ message }}</p>
  21 + </div>
  22 + {% endfor %}
  23 + {% endif %}
  24 + <fieldset>
  25 + {% for field in form_file %}
  26 + <div class="form-group is-empy{% if form.has_error %} has-error {% endif %} is-fileinput">
  27 + <div class="col-md-12">
  28 + {% if field.field.required %}
  29 + <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label>
  30 + {% else %}
  31 + <label for="{{ field.auto_id }}" class=" control-label">{{ field.label }}</label>
  32 + {% endif %}
  33 + {% if field.auto_id == 'id_file_url' %}
  34 + {% render_field field class='form-control input-sm' %}
  35 + <div class="input-group">
  36 + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
  37 + <span class="input-group-btn input-group-sm">
  38 + <button type="button" class="btn btn-fab btn-fab-mini">
  39 + <i class="material-icons">attach_file</i>
  40 + </button>
  41 + </span>
  42 + </div>
  43 + {% else %}
  44 + {% render_field field class='form-control input-sm' %}
  45 + <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
  46 + {% endif %}
  47 + </div>
  48 +
  49 + {% if field.errors %}
  50 + <div class="alert alert-danger alert-dismissible" role="alert">
  51 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  52 + <span aria-hidden="true">&times;</span>
  53 + </button>
  54 + <ul>
  55 + {% for error in field.errors %}
  56 + <li>{{ error }}</li>
  57 + {% endfor %}
  58 + </ul>
  59 + </div>
  60 + {% endif %}
  61 + </div>
  62 + {% endfor %}
  63 +
  64 + <div class="form-group">
  65 + <div class="col-md-12 text-center">
  66 + <p><b>The file size shouldn't exceed 10MB</b></p>
  67 + </div>
  68 + </div>
  69 +
  70 + <div class="form-group">
  71 + <div class="col-md-12">
  72 + <a href="javascript:void(0)" class="btn btn-raised btn-default">Cancel<div class="ripple-container"></div></a>
  73 + <a href="javascript:void(0)" class="btn btn-raised btn-primary">Submit</a>
  74 + </div>
  75 + </div>
  76 + </fieldset>
  77 + </form>
  78 + <!-- .end Card -->
  79 + </div>
  80 + </div>
  81 + </div>
  82 +</div>
  83 +<!-- EndModal -->
0 84 \ No newline at end of file
... ...