Commit 3eae01e8f9f95e6dc10ab9b6dcc9ab2005a5fea2

Authored by Felipe Henrique de Almeida Bormann
1 parent 49779ea0

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
links/forms.py
@@ -29,14 +29,14 @@ class LinkForm(forms.ModelForm): @@ -29,14 +29,14 @@ class LinkForm(forms.ModelForm):
29 29
30 class Meta: 30 class Meta:
31 model = Link 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 labels = { 33 labels = {
34 'name': _('Link name'), 34 'name': _('Link name'),
35 'end_view' : _('End View'), 35 'end_view' : _('End View'),
36 'end_view_date': _('End View Date') 36 'end_view_date': _('End View Date')
37 } 37 }
38 widgets = { 38 widgets = {
39 - 'brief_description': forms.Textarea, 39 + 'description_brief': forms.Textarea,
40 'students': forms.SelectMultiple, 40 'students': forms.SelectMultiple,
41 'groups': forms.SelectMultiple, 41 'groups': forms.SelectMultiple,
42 } 42 }
links/migrations/0007_auto_20170201_1907.py 0 → 100644
@@ -0,0 +1,20 @@ @@ -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,7 +10,7 @@ from django.utils import timezone
10 class Link(Resource): 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 link_url = models.URLField(verbose_name = _("Link_URL")) 15 link_url = models.URLField(verbose_name = _("Link_URL"))
16 16
links/templates/links/_form.html
@@ -61,18 +61,18 @@ @@ -61,18 +61,18 @@
61 61
62 62
63 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> 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 <div class="alert alert-danger alert-dismissible" role="alert"> 70 <div class="alert alert-danger alert-dismissible" role="alert">
71 <button type="button" class="close" data-dismiss="alert" aria-label="Close"> 71 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
72 <span aria-hidden="true">&times;</span> 72 <span aria-hidden="true">&times;</span>
73 </button> 73 </button>
74 <ul> 74 <ul>
75 - {% for error in form.brief_description.errors %} 75 + {% for error in form.description_brief.errors %}
76 <li>{{ error }}</li> 76 <li>{{ error }}</li>
77 {% endfor %} 77 {% endfor %}
78 </ul> 78 </ul>
subjects/templates/subjects/list_search.html
@@ -35,11 +35,11 @@ @@ -35,11 +35,11 @@
35 <div id="core-subjects-options-div"> 35 <div id="core-subjects-options-div">
36 <ul class="core-subjects-options"> 36 <ul class="core-subjects-options">
37 {% if all %} 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 {% else %} 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 {% endif %} 43 {% endif %}
44 44
45 </ul> 45 </ul>
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 <div class="col-md-12 cards-content"> 50 <div class="col-md-12 cards-content">
51 51
52 52
53 - {% if subjects|length > 0 %} 53 + {% if not all %}
54 <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> 54 <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true">
55 {% for subject in subjects %} 55 {% for subject in subjects %}
56 {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} 56 {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %}
@@ -58,9 +58,17 @@ @@ -58,9 +58,17 @@
58 58
59 {% pagination request paginator page_obj %} 59 {% pagination request paginator page_obj %}
60 </div> 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 {% endif %} 70 {% endif %}
  71 +
64 </div> 72 </div>
65 73
66 <div id="modal_course"> 74 <div id="modal_course">
subjects/templates/subjects/resource_card.html 0 → 100644
@@ -0,0 +1,66 @@ @@ -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,6 +28,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
28 from .forms import CreateSubjectForm, UpdateSubjectForm 28 from .forms import CreateSubjectForm, UpdateSubjectForm
29 from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page 29 from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page
30 from users.models import User 30 from users.models import User
  31 +from topics.models import Resource
31 32
32 33
33 class HomeView(LoginRequiredMixin, ListView): 34 class HomeView(LoginRequiredMixin, ListView):
@@ -602,14 +603,19 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): @@ -602,14 +603,19 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView):
602 q = Q() 603 q = Q()
603 for tag in tags: 604 for tag in tags:
604 q = q | Q(tags__name__unaccent__icontains=tag ) 605 q = q | Q(tags__name__unaccent__icontains=tag )
605 - 606 +
606 subjects = Subject.objects.filter(q).distinct() 607 subjects = Subject.objects.filter(q).distinct()
  608 +
  609 + self.resources = Resource.objects.filter(q).distinct()
607 #pk = self.request.user.pk 610 #pk = self.request.user.pk
608 #my_subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk) & Q(tags__name__in=tags) ).distinct() 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 #if self.kwargs.get('option'): 614 #if self.kwargs.get('option'):
612 # subjects = my_subjects 615 # subjects = my_subjects
  616 + option = self.kwargs.get('option')
  617 + if option and option == 'resources':
  618 + return self.resources
613 return subjects 619 return subjects
614 620
615 def get_context_data(self, **kwargs): 621 def get_context_data(self, **kwargs):
@@ -621,10 +627,11 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): @@ -621,10 +627,11 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView):
621 627
622 context['show_buttons'] = True #So it shows subscribe and access buttons 628 context['show_buttons'] = True #So it shows subscribe and access buttons
623 context['totals'] = self.totals 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 context['all'] = True 632 context['all'] = True
627 - context['title'] = _('Subjects') 633 + context['title'] = _('Resources')
  634 + context['resources'] = self.resources
628 635
629 context['subjects_menu_active'] = '' 636 context['subjects_menu_active'] = ''
630 637