Commit 3eae01e8f9f95e6dc10ab9b6dcc9ab2005a5fea2
1 parent
49779ea0
Exists in
master
and in
3 other branches
modified link to have description_brief on it's model and created resource_card …
…but still has to adjust design on header and access link of links
Showing
7 changed files
with
121 additions
and
20 deletions
Show diff stats
links/forms.py
| ... | ... | @@ -29,14 +29,14 @@ class LinkForm(forms.ModelForm): |
| 29 | 29 | |
| 30 | 30 | class Meta: |
| 31 | 31 | model = Link |
| 32 | - fields = ['name','link_url', 'brief_description', 'all_students', 'students', 'groups', 'visible'] | |
| 32 | + fields = ['name','link_url', 'description_brief', 'all_students', 'students', 'groups', 'visible'] | |
| 33 | 33 | labels = { |
| 34 | 34 | 'name': _('Link name'), |
| 35 | 35 | 'end_view' : _('End View'), |
| 36 | 36 | 'end_view_date': _('End View Date') |
| 37 | 37 | } |
| 38 | 38 | widgets = { |
| 39 | - 'brief_description': forms.Textarea, | |
| 39 | + 'description_brief': forms.Textarea, | |
| 40 | 40 | 'students': forms.SelectMultiple, |
| 41 | 41 | 'groups': forms.SelectMultiple, |
| 42 | 42 | } | ... | ... |
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.10.4 on 2017-02-01 22:07 | |
| 3 | +from __future__ import unicode_literals | |
| 4 | + | |
| 5 | +from django.db import migrations | |
| 6 | + | |
| 7 | + | |
| 8 | +class Migration(migrations.Migration): | |
| 9 | + | |
| 10 | + dependencies = [ | |
| 11 | + ('links', '0006_auto_20170201_1756'), | |
| 12 | + ] | |
| 13 | + | |
| 14 | + operations = [ | |
| 15 | + migrations.RenameField( | |
| 16 | + model_name='link', | |
| 17 | + old_name='description', | |
| 18 | + new_name='description_brief', | |
| 19 | + ), | |
| 20 | + ] | ... | ... |
links/models.py
| ... | ... | @@ -10,7 +10,7 @@ from django.utils import timezone |
| 10 | 10 | class Link(Resource): |
| 11 | 11 | |
| 12 | 12 | |
| 13 | - description = models.TextField(_("simpler_description"), blank=True) | |
| 13 | + description_brief = models.TextField(_("simpler_description"), blank=True) | |
| 14 | 14 | |
| 15 | 15 | link_url = models.URLField(verbose_name = _("Link_URL")) |
| 16 | 16 | ... | ... |
links/templates/links/_form.html
| ... | ... | @@ -61,18 +61,18 @@ |
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
| 64 | - <label for="{{ form.brief_description.auto_id }}">{{ form.brief_description.label }}</label> | |
| 65 | - {% render_field form.brief_description class='form-control text_wysiwyg' %} | |
| 64 | + <label for="{{ form.description_brief.auto_id }}">{{ form.description_brief.label }}</label> | |
| 65 | + {% render_field form.description_brief class='form-control text_wysiwyg' %} | |
| 66 | 66 | |
| 67 | - <span id="helpBlock" class="help-block">{{ form.brief_description.help_text }}</span> | |
| 67 | + <span id="helpBlock" class="help-block">{{ form.description_brief.help_text }}</span> | |
| 68 | 68 | |
| 69 | - {% if form.brief_description.errors %} | |
| 69 | + {% if form.description_brief.errors %} | |
| 70 | 70 | <div class="alert alert-danger alert-dismissible" role="alert"> |
| 71 | 71 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
| 72 | 72 | <span aria-hidden="true">×</span> |
| 73 | 73 | </button> |
| 74 | 74 | <ul> |
| 75 | - {% for error in form.brief_description.errors %} | |
| 75 | + {% for error in form.description_brief.errors %} | |
| 76 | 76 | <li>{{ error }}</li> |
| 77 | 77 | {% endfor %} |
| 78 | 78 | </ul> | ... | ... |
subjects/templates/subjects/list_search.html
| ... | ... | @@ -35,11 +35,11 @@ |
| 35 | 35 | <div id="core-subjects-options-div"> |
| 36 | 36 | <ul class="core-subjects-options"> |
| 37 | 37 | {% if all %} |
| 38 | - <a href="{% url 'subjects:search' %}?search= {{tags}} "><li >{% trans "Subjects" %} ({{ totals.my_subjects }})</li></a> | |
| 39 | - <a href="" ><li class="active">{% trans "Resources" %} ({{ totals.resources }})</li></a> | |
| 38 | + <a href="{% url 'subjects:search' 'subjects' %}?search={{tags}} "><li >{% trans "Subjects" %} ({{ totals.my_subjects }})</li></a> | |
| 39 | + <a href="{% url 'subjects:search' 'resources' %}?search={{tags}}" ><li class="active">{% trans "Resources" %} ({{ totals.resources }})</li></a> | |
| 40 | 40 | {% else %} |
| 41 | - <a href="{% url 'subjects:search' %}?search={{tags}}"><li class="active">{% trans "Subjects" %} ({{ totals.my_subjects }})</li></a> | |
| 42 | - <a href="" ><li>{% trans "Resources" %} ({{ totals.resources }})</li></a> | |
| 41 | + <a href="{% url 'subjects:search' 'subjects' %}?search={{tags}}"><li class="active">{% trans "Subjects" %} ({{ totals.my_subjects }})</li></a> | |
| 42 | + <a href="{% url 'subjects:search' 'resources' %}?search={{tags}}" ><li>{% trans "Resources" %} ({{ totals.resources }})</li></a> | |
| 43 | 43 | {% endif %} |
| 44 | 44 | |
| 45 | 45 | </ul> |
| ... | ... | @@ -50,7 +50,7 @@ |
| 50 | 50 | <div class="col-md-12 cards-content"> |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - {% if subjects|length > 0 %} | |
| 53 | + {% if not all %} | |
| 54 | 54 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> |
| 55 | 55 | {% for subject in subjects %} |
| 56 | 56 | {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} |
| ... | ... | @@ -58,9 +58,17 @@ |
| 58 | 58 | |
| 59 | 59 | {% pagination request paginator page_obj %} |
| 60 | 60 | </div> |
| 61 | - {% else %} | |
| 62 | - | |
| 61 | + {% elif resources|length > 0 and all %} | |
| 62 | + <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | |
| 63 | + {% for resource in resources %} | |
| 64 | + {% include "subjects/resource_card.html" with resource=resource %} | |
| 65 | + {% endfor %} | |
| 66 | + | |
| 67 | + {% pagination request paginator page_obj %} | |
| 68 | + </div> | |
| 69 | + {% else %} | |
| 63 | 70 | {% endif %} |
| 71 | + | |
| 64 | 72 | </div> |
| 65 | 73 | |
| 66 | 74 | <div id="modal_course"> | ... | ... |
| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | + {% load static i18n permissions_tags subject_counter %} | |
| 2 | + | |
| 3 | + {% resource_permissions request.user resource as has_resource_permissions %} | |
| 4 | +{% subject_permissions request.user resource.topic.subject as has_subject_permissions %} | |
| 5 | + {% if has_resource_permissions %} | |
| 6 | + <div class="panel panel-info subject-panel"> | |
| 7 | + <div class="panel-heading"> | |
| 8 | + | |
| 9 | + <div class="row"> | |
| 10 | + <div class="col-md-12 category-header"> | |
| 11 | + <h4 class="panel-title"> | |
| 12 | + <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{resource.slug}}"> | |
| 13 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ resource }} | |
| 14 | + </a> | |
| 15 | + </h4> | |
| 16 | + | |
| 17 | + {% if has_subject_permissions %} | |
| 18 | + <div class="col-md-5 pull-right category-card-items"> | |
| 19 | + <span class="btn-group pull-right"> | |
| 20 | + <a class="btn btn-sm btn_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
| 21 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | |
| 22 | + </a> | |
| 23 | + <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> | |
| 24 | + <li><a href="{% url resource.update_link resource.topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
| 25 | + <li><a href="javascript:delete_resource('{% url resource.delete_link resource.slug %}')" class="delete"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>{% trans 'Remove' %}</a></li> | |
| 26 | + </ul> | |
| 27 | + </span> | |
| 28 | + </div> | |
| 29 | + {% endif %} | |
| 30 | + </div> | |
| 31 | + </div> | |
| 32 | + | |
| 33 | + | |
| 34 | + </div> | |
| 35 | + | |
| 36 | + <div id="{{resource.slug}}" class="panel-collapse collapse category-panel-content"> | |
| 37 | + <div class="row"> | |
| 38 | + <div class="col-md-6"> | |
| 39 | + {% if resource.topic.subject.professor.all|length > 0 %} | |
| 40 | + <h4><b>{% trans "Professor(s) " %}: </b> | |
| 41 | + {{ resource.topic.subject.professor.all|join:', ' }} | |
| 42 | + </h4> | |
| 43 | + {% else %} | |
| 44 | + <h4> {% trans "It doesn't possess professors" %} </h4> | |
| 45 | + {% endif %} | |
| 46 | + </div> | |
| 47 | + <div class="col-xs-6 col-md-3"> | |
| 48 | + <p><b>{% trans "Category" %}: </b> {{resource.topic.subject.category.name}}</p> | |
| 49 | + </div> | |
| 50 | + <div class="col-xs-6 col-md-3"> | |
| 51 | + <p><b>{% trans "Subject" %}:</b> {{resource.topic.subject.name}}</p> | |
| 52 | + </div> | |
| 53 | + </div> | |
| 54 | + {% if resource.description %} | |
| 55 | + <p>{{resource.description|safe}}</p> | |
| 56 | + {% elif resource.description_brief %} | |
| 57 | + <p>{{resource.description_brief|safe}}</p> | |
| 58 | + {% endif %} | |
| 59 | + | |
| 60 | + <a href="{% url resource.access_link resource.slug %}" class="btn btn-success btn-raised"> {% trans "Access Resource" %}</a> | |
| 61 | + | |
| 62 | + </div> | |
| 63 | + </div> | |
| 64 | + | |
| 65 | + | |
| 66 | +{% endif %} | ... | ... |
subjects/views.py
| ... | ... | @@ -28,6 +28,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
| 28 | 28 | from .forms import CreateSubjectForm, UpdateSubjectForm |
| 29 | 29 | from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page |
| 30 | 30 | from users.models import User |
| 31 | +from topics.models import Resource | |
| 31 | 32 | |
| 32 | 33 | |
| 33 | 34 | class HomeView(LoginRequiredMixin, ListView): |
| ... | ... | @@ -602,14 +603,19 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): |
| 602 | 603 | q = Q() |
| 603 | 604 | for tag in tags: |
| 604 | 605 | q = q | Q(tags__name__unaccent__icontains=tag ) |
| 605 | - | |
| 606 | + | |
| 606 | 607 | subjects = Subject.objects.filter(q).distinct() |
| 608 | + | |
| 609 | + self.resources = Resource.objects.filter(q).distinct() | |
| 607 | 610 | #pk = self.request.user.pk |
| 608 | 611 | #my_subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk) & Q(tags__name__in=tags) ).distinct() |
| 609 | 612 | |
| 610 | - self.totals = {'resources': subjects.count(), 'my_subjects': subjects.count()} | |
| 613 | + self.totals = {'resources': self.resources.count(), 'my_subjects': subjects.count()} | |
| 611 | 614 | #if self.kwargs.get('option'): |
| 612 | 615 | # subjects = my_subjects |
| 616 | + option = self.kwargs.get('option') | |
| 617 | + if option and option == 'resources': | |
| 618 | + return self.resources | |
| 613 | 619 | return subjects |
| 614 | 620 | |
| 615 | 621 | def get_context_data(self, **kwargs): |
| ... | ... | @@ -621,10 +627,11 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): |
| 621 | 627 | |
| 622 | 628 | context['show_buttons'] = True #So it shows subscribe and access buttons |
| 623 | 629 | context['totals'] = self.totals |
| 624 | - | |
| 625 | - if self.kwargs.get('option'): | |
| 630 | + option = self.kwargs.get('option') | |
| 631 | + if option and option == 'resources': | |
| 626 | 632 | context['all'] = True |
| 627 | - context['title'] = _('Subjects') | |
| 633 | + context['title'] = _('Resources') | |
| 634 | + context['resources'] = self.resources | |
| 628 | 635 | |
| 629 | 636 | context['subjects_menu_active'] = '' |
| 630 | 637 | ... | ... |