Commit 82f3a3e4ef877c5f397adbe3c855105891cdae2e
1 parent
2fb52821
Exists in
master
and in
5 other branches
filter courses for category
Showing
3 changed files
with
122 additions
and
48 deletions
Show diff stats
courses/models.py
... | ... | @@ -31,7 +31,7 @@ class Course(models.Model): |
31 | 31 | init_date = models.DateField(_('Begin of Course Date')) |
32 | 32 | end_date = models.DateField(_('End of Course Date')) |
33 | 33 | image = models.ImageField(verbose_name = _('Image'), blank = True, upload_to = 'courses/') |
34 | - category = models.ForeignKey(CourseCategory, verbose_name = _('Category')) | |
34 | + category = models.ForeignKey(CourseCategory, verbose_name = _('Category'), related_name='course_category') | |
35 | 35 | professors = models.ManyToManyField(User,verbose_name=_('Professors'), related_name='courses_professors') |
36 | 36 | students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='courses_student') |
37 | 37 | ... | ... |
courses/templates/course/index.html
... | ... | @@ -63,6 +63,20 @@ |
63 | 63 | </span> |
64 | 64 | </div> |
65 | 65 | </div> |
66 | + <div class="col-md-12"> | |
67 | + {% if user|has_role:'professor, system_admin' %} | |
68 | + {% else%} | |
69 | + | |
70 | + <div class="btn-group btn-group-justified btn-group-raised"> | |
71 | + <a href="?category=all" class="btn btn-raised btn-info">Todos</a> | |
72 | + {% for category_course in categorys_courses %} | |
73 | + <a href="?category={{category_course.name}}" class="btn btn-raised btn-primary">{{category_course.name}}</a> | |
74 | + {% endfor %} | |
75 | + </div> | |
76 | + {% endif %} | |
77 | + </div> | |
78 | + | |
79 | +</fieldset> | |
66 | 80 | {% if user|has_role:'professor, system_admin' %} |
67 | 81 | <div class="col-md-12"> |
68 | 82 | {% if courses|length > 0 %} |
... | ... | @@ -141,55 +155,107 @@ |
141 | 155 | </div> |
142 | 156 | {% else %} |
143 | 157 | {% if courses|length > 0 %} |
144 | - {% for course in courses_student %} | |
145 | - <div class="col-md-12"> | |
146 | - <div class="panel panel-info"> | |
147 | - <!--{% if course.image %} | |
148 | - <img src="{{ course.image_url }}" class="img-responsive" /> | |
149 | - {% else %} | |
150 | - <img src="" class="img-responsive" /> | |
151 | - {% endif %} --> | |
152 | - <div class="panel-heading"> | |
153 | - <div class="row"> | |
154 | - <div class="col-md-9"> | |
155 | - <h3 class="panel-title">{{course.name}}</h3> | |
156 | - </div> | |
157 | - <div class="col-md-3"> | |
158 | - <span class="label label-info">{{ course.category }}</span> | |
159 | - <span class="label label-warning">{{ course.max_students }} {% trans 'students tops' %}</span> | |
160 | - </div> | |
158 | + {% if request.GET.category == 'all' or none %} | |
159 | + {% for course in courses_student %} | |
160 | + <div class="col-md-12"> | |
161 | + <div class="panel panel-info"> | |
162 | + <!--{% if course.image %} | |
163 | + <img src="{{ course.image_url }}" class="img-responsive" /> | |
164 | + {% else %} | |
165 | + <img src="" class="img-responsive" /> | |
166 | + {% endif %} --> | |
167 | + <div class="panel-heading"> | |
168 | + <div class="row"> | |
169 | + <div class="col-md-9"> | |
170 | + <h3 class="panel-title">{{course.name}}</h3> | |
171 | + </div> | |
172 | + <div class="col-md-3"> | |
173 | + <span class="label label-info">{{ course.category }}</span> | |
174 | + <span class="label label-warning">{{ course.max_students }} {% trans 'students tops' %}</span> | |
175 | + </div> | |
176 | + </div> | |
177 | + </div> | |
178 | + <div class="panel-body"> | |
179 | + <p><b>Course Name: </b>{{ course.name }}</p> | |
180 | + <p><b>Duration (in semesters): </b>09</p> | |
181 | + <p><b>Coordinator: </b>{{course.professors}}</p> | |
182 | + <p> | |
183 | + <b>Description:</b> | |
184 | + <i> | |
185 | + {% if couse.description %} | |
186 | + {{course.description|linebreaks}} | |
187 | + {% else %} | |
188 | + {% trans 'No description' %} | |
189 | + {% endif %} | |
190 | + </i> | |
191 | + </p> | |
192 | + | |
193 | + <!--{% if user|has_role:'professor, system_admin' %} | |
194 | + <a href="{% url 'course:update' course.slug %}" class="btn btn-sm btn-primary"> | |
195 | + <span class="glyphicon glyphicon-edit"></span> | |
196 | + </a> | |
197 | + <a href="{% url 'course:delete' course.slug %}" class="btn btn-sm btn-danger"> | |
198 | + <span class="glyphicon glyphicon-trash"></span> | |
199 | + </a> | |
200 | + {% endif %}--> | |
201 | + | |
202 | + <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course</a> | |
161 | 203 | </div> |
162 | - </div> | |
163 | - <div class="panel-body"> | |
164 | - <p><b>Course Name: </b>{{ course.name }}</p> | |
165 | - <p><b>Duration (in semesters): </b>09</p> | |
166 | - <p><b>Coordinator: </b>{{course.professors}}</p> | |
167 | - <p> | |
168 | - <b>Description:</b> | |
169 | - <i> | |
170 | - {% if couse.description %} | |
171 | - {{course.description|linebreaks}} | |
172 | - {% else %} | |
173 | - {% trans 'No description' %} | |
174 | - {% endif %} | |
175 | - </i> | |
176 | - </p> | |
177 | - | |
178 | - <!--{% if user|has_role:'professor, system_admin' %} | |
179 | - <a href="{% url 'course:update' course.slug %}" class="btn btn-sm btn-primary"> | |
180 | - <span class="glyphicon glyphicon-edit"></span> | |
181 | - </a> | |
182 | - <a href="{% url 'course:delete' course.slug %}" class="btn btn-sm btn-danger"> | |
183 | - <span class="glyphicon glyphicon-trash"></span> | |
184 | - </a> | |
185 | - {% endif %}--> | |
186 | - | |
187 | - <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course</a> | |
188 | - </div> | |
189 | - </div> | |
190 | - </div> | |
204 | + </div> | |
205 | + </div> | |
206 | + {% endfor %} | |
207 | + {% else %} | |
208 | + {% for course in courses_student %} | |
209 | + {% if course.category.name == request.GET.category %} | |
210 | + <div class="col-md-12"> | |
211 | + <div class="panel panel-info"> | |
212 | + <!--{% if course.image %} | |
213 | + <img src="{{ course.image_url }}" class="img-responsive" /> | |
214 | + {% else %} | |
215 | + <img src="" class="img-responsive" /> | |
216 | + {% endif %} --> | |
217 | + <div class="panel-heading"> | |
218 | + <div class="row"> | |
219 | + <div class="col-md-9"> | |
220 | + <h3 class="panel-title">{{course.name}}</h3> | |
221 | + </div> | |
222 | + <div class="col-md-3"> | |
223 | + <span class="label label-info">{{ course.category }}</span> | |
224 | + <span class="label label-warning">{{ course.max_students }} {% trans 'students tops' %}</span> | |
225 | + </div> | |
226 | + </div> | |
227 | + </div> | |
228 | + <div class="panel-body"> | |
229 | + <p><b>Course Name: </b>{{ course.name }}</p> | |
230 | + <p><b>Duration (in semesters): </b>09</p> | |
231 | + <p><b>Coordinator: </b>{{course.professors}}</p> | |
232 | + <p> | |
233 | + <b>Description:</b> | |
234 | + <i> | |
235 | + {% if couse.description %} | |
236 | + {{course.description|linebreaks}} | |
237 | + {% else %} | |
238 | + {% trans 'No description' %} | |
239 | + {% endif %} | |
240 | + </i> | |
241 | + </p> | |
242 | + | |
243 | + <!--{% if user|has_role:'professor, system_admin' %} | |
244 | + <a href="{% url 'course:update' course.slug %}" class="btn btn-sm btn-primary"> | |
245 | + <span class="glyphicon glyphicon-edit"></span> | |
246 | + </a> | |
247 | + <a href="{% url 'course:delete' course.slug %}" class="btn btn-sm btn-danger"> | |
248 | + <span class="glyphicon glyphicon-trash"></span> | |
249 | + </a> | |
250 | + {% endif %}--> | |
191 | 251 | |
192 | - {% endfor %} | |
252 | + <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course</a> | |
253 | + </div> | |
254 | + </div> | |
255 | + </div> | |
256 | + {% endif %} | |
257 | + {% endfor %} | |
258 | + {% endif %} | |
193 | 259 | |
194 | 260 | <nav aria-label="Page navigation"> |
195 | 261 | <ul class="pagination"> | ... | ... |
courses/views.py
... | ... | @@ -32,6 +32,14 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): |
32 | 32 | context['categories'] = CourseCategory.objects.all() |
33 | 33 | context['courses_teacher'] = Course.objects.filter(professors__name = self.request.user.name) |
34 | 34 | context['courses_student'] = Course.objects.filter(students__name = self.request.user.name) |
35 | + context['categorys_courses'] = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() | |
36 | + courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) | |
37 | + context['courses_category'] = courses_category | |
38 | + none = None | |
39 | + q = self.request.GET.get('category', None) | |
40 | + if q is None: | |
41 | + none = True | |
42 | + context['none'] = none | |
35 | 43 | |
36 | 44 | return context |
37 | 45 | ... | ... |