Commit 7a958146d81c927d843a7ff6422c50328b335436

Authored by Matheus Lins
2 parents 090c0fef 4f3b88fa

search bar #189

amadeus/settings.py
@@ -30,8 +30,6 @@ SECRET_KEY = '$=8)c!5)iha85a&8q4+kv1pyg0yl7_xe_x^z=2cn_1d7r0hny4' @@ -30,8 +30,6 @@ SECRET_KEY = '$=8)c!5)iha85a&8q4+kv1pyg0yl7_xe_x^z=2cn_1d7r0hny4'
30 # SECURITY WARNING: don't run with debug turned on in production! 30 # SECURITY WARNING: don't run with debug turned on in production!
31 DEBUG = False 31 DEBUG = False
32 32
33 -ALLOWED_HOSTS = []  
34 -  
35 33
36 # Application definition 34 # Application definition
37 35
@@ -165,7 +163,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO','https') @@ -165,7 +163,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO','https')
165 ALLOWED_HOSTS = ['*'] 163 ALLOWED_HOSTS = ['*']
166 164
167 # Files 165 # Files
168 -MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'uploads') 166 +MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'uploads')
169 MEDIA_URL = '/uploads/' 167 MEDIA_URL = '/uploads/'
170 168
171 169
amadeus/uploads/ciencia-da-computacao/teorica/tipfef/Apresentacao_da_Cadidatura_a_Marketing_-_Matheus_Lins.pptx 0 → 100644
No preview for this file type
amadeus/uploads/ciencia-da-computacao/teorica/tipfef/Cartao_Outubro.pdf 0 → 100644
No preview for this file type
courses/templates/course/index.html
@@ -74,10 +74,10 @@ @@ -74,10 +74,10 @@
74 <form id="searchform" action="{% url 'course:manage' %}" method="get" accept-charset="utf-8"> 74 <form id="searchform" action="{% url 'course:manage' %}" method="get" accept-charset="utf-8">
75 <div class="input-group"> 75 <div class="input-group">
76 <div class="form-group is-empty"> 76 <div class="form-group is-empty">
77 - <input type="search" class="form-control" placeholder="Search Courses" name="q" id="searchbox"></div> 77 + <input type="text" class="form-control" placeholder="Search Courses" name="q"></div>
78 <span class="input-group-btn input-group-sm"> 78 <span class="input-group-btn input-group-sm">
79 - <button type="button" class="btn btn-fab btn-fab-mini">  
80 - <i class="material-icons">search</i> 79 + <button type="submit" class="btn btn-fab btn-fab-mini">
  80 + <i class="material-icons">{% trans 'Search' %}</i>
81 </button> 81 </button>
82 </span> 82 </span>
83 </div> 83 </div>
@@ -88,16 +88,14 @@ @@ -88,16 +88,14 @@
88 </fieldset> 88 </fieldset>
89 <div class="col-md-12 cards-content"> 89 <div class="col-md-12 cards-content">
90 {% if courses|length > 0 %} 90 {% if courses|length > 0 %}
91 - {% if request.GET.category == 'all' or none or request.GET.category == '' %} 91 + {% if request.GET.category == '' or aparece or request.GET.q == '' %}
92 {% for course in list_courses %} 92 {% for course in list_courses %}
93 {% include "course/course_card.html" %} 93 {% include "course/course_card.html" %}
94 {% endfor %} 94 {% endfor %}
95 - {% else %}  
96 - {% for course in courses_category %}  
97 - {% if course.category.name == request.GET.category %}  
98 - <!-- Put your content here! -->  
99 - {% include "course/course_card.html" %}  
100 - {% endif %} 95 + {% endif %}
  96 + {% if request.GET.category or request.GET.q %}
  97 + {% for course in courses %}
  98 + {% include "course/course_card.html" %}
101 {% endfor %} 99 {% endfor %}
102 {% endif %} 100 {% endif %}
103 {% else %} 101 {% else %}
courses/templates/course/view.html
@@ -76,7 +76,6 @@ @@ -76,7 +76,6 @@
76 </div> 76 </div>
77 </div> 77 </div>
78 <div class="panel-body"> 78 <div class="panel-body">
79 - <p><b>{% trans 'Course Name' %}: </b>{{ course.name }}</p>  
80 <p><b>{% trans 'Coordinator' %}: </b>{% for professor in course.professors.all %}{% if not forloop.first %},{% endif %} 79 <p><b>{% trans 'Coordinator' %}: </b>{% for professor in course.professors.all %}{% if not forloop.first %},{% endif %}
81 {{professor}}{% if forloop.last %}.{% endif %}{% endfor %}</p> 80 {{professor}}{% if forloop.last %}.{% endif %}{% endfor %}</p>
82 <p> 81 <p>
courses/templates/subject/form_view_teacher.html
@@ -135,8 +135,8 @@ @@ -135,8 +135,8 @@
135 </div> 135 </div>
136 <div class="form-group"> 136 <div class="form-group">
137 <div class="col-md-10"> 137 <div class="col-md-10">
138 - <button type="button" class="btn btn-raised btn-default edit_card_end">Cancel</button>  
139 - <button type="submit" class="btn btn-raised btn-primary edit_card_end">Submit</button> 138 + <button type="button" class="btn btn-raised btn-default edit_card_end">{% trans 'Cancel' %}</button>
  139 + <button type="submit" class="btn btn-raised btn-primary edit_card_end">{% trans 'Submit' %}</button>
140 </div> 140 </div>
141 </div> 141 </div>
142 </div><!--EndEditation--> 142 </div><!--EndEditation-->
@@ -198,13 +198,13 @@ @@ -198,13 +198,13 @@
198 </div> 198 </div>
199 </div> 199 </div>
200 <div class="form-group is-empty"> 200 <div class="form-group is-empty">
201 - <label for="number" class="col-md-2 control-label">Height</label> 201 + <label for="number" class="col-md-2 control-label">{% trans 'Height' %}</label>
202 <div class="col-md-4"> 202 <div class="col-md-4">
203 <input type="number" class="form-control" id="inputNumber" placeholder="Heiht"> 203 <input type="number" class="form-control" id="inputNumber" placeholder="Heiht">
204 </div> 204 </div>
205 </div> 205 </div>
206 <div class="form-group is-empty"> 206 <div class="form-group is-empty">
207 - <label for="number" class="col-md-2 control-label">Weight</label> 207 + <label for="number" class="col-md-2 control-label">{% trans 'Weight' %}</label>
208 <div class="col-md-4"> 208 <div class="col-md-4">
209 <input type="number" class="form-control" id="inputNumber" placeholder="Weight"> 209 <input type="number" class="form-control" id="inputNumber" placeholder="Weight">
210 </div> 210 </div>
courses/templates/subject/index.html
@@ -70,7 +70,8 @@ @@ -70,7 +70,8 @@
70 </div> 70 </div>
71 </div> 71 </div>
72 <div class="panel-body"> 72 <div class="panel-body">
73 - <p><b>{% trans "Professor" %}:</b> {{subject.professors}}</p> 73 + <p><b>{% trans "Professor" %}:</b> {% for professor in subject.professors.all %}{% if not forloop.first %},{% endif %}
  74 + {{professor}}{% if forloop.last %}.{% endif %}{% endfor %}</p>
74 <p> 75 <p>
75 <b>{% trans "Description" %}:</b> 76 <b>{% trans "Description" %}:</b>
76 {{subject.description|linebreaks}} 77 {{subject.description|linebreaks}}
courses/views.py
@@ -9,6 +9,8 @@ from django.core.urlresolvers import reverse_lazy @@ -9,6 +9,8 @@ from django.core.urlresolvers import reverse_lazy
9 from django.utils.translation import ugettext_lazy as _ 9 from django.utils.translation import ugettext_lazy as _
10 from rolepermissions.verifications import has_role 10 from rolepermissions.verifications import has_role
11 from django.db.models import Q 11 from django.db.models import Q
  12 +import operator
  13 +from functools import reduce
12 from rolepermissions.verifications import has_object_permission 14 from rolepermissions.verifications import has_object_permission
13 from django.http import HttpResponseRedirect, JsonResponse 15 from django.http import HttpResponseRedirect, JsonResponse
14 16
@@ -31,6 +33,29 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): @@ -31,6 +33,29 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView):
31 template_name = 'course/index.html' 33 template_name = 'course/index.html'
32 context_object_name = 'courses' 34 context_object_name = 'courses'
33 paginate_by = 5 35 paginate_by = 5
  36 + aparece = True
  37 +
  38 +
  39 + def get_queryset(self):
  40 + result = super(IndexView, self).get_queryset()
  41 +
  42 + course_search = self.request.GET.get('q', None)
  43 + category_search = self.request.GET.get('category', None)
  44 + if course_search:
  45 + self.aparece = False
  46 + query_list = course_search.split()
  47 + result = result.filter(
  48 + reduce(operator.and_,
  49 + (Q(name__icontains=q) for q in query_list))
  50 + )
  51 + if category_search:
  52 + self.aparece = False
  53 + query_list = category_search.split()
  54 + result = result.filter(
  55 + reduce(operator.and_,
  56 + (Q(category__name=category) for category in query_list))
  57 + )
  58 + return result
34 59
35 def get_context_data(self, **kwargs): 60 def get_context_data(self, **kwargs):
36 context = super(IndexView, self).get_context_data(**kwargs) 61 context = super(IndexView, self).get_context_data(**kwargs)
@@ -46,13 +71,6 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): @@ -46,13 +71,6 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView):
46 list_courses = Course.objects.filter(Q(students = True)|Q(students__name = self.request.user.name)).order_by('name') 71 list_courses = Course.objects.filter(Q(students = True)|Q(students__name = self.request.user.name)).order_by('name')
47 categorys_courses = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() 72 categorys_courses = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct()
48 73
49 - courses_category = Course.objects.filter(category__name = self.request.GET.get('category'))  
50 - none = None  
51 - q = self.request.GET.get('category', None)  
52 - if q is None:  
53 - none = True  
54 - context['none'] = none  
55 -  
56 paginator = Paginator(list_courses, self.paginate_by) 74 paginator = Paginator(list_courses, self.paginate_by)
57 page = self.request.GET.get('page') 75 page = self.request.GET.get('page')
58 76
@@ -63,23 +81,12 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): @@ -63,23 +81,12 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView):
63 except EmptyPage: 81 except EmptyPage:
64 list_courses = paginator.page(paginator.num_pages) 82 list_courses = paginator.page(paginator.num_pages)
65 83
66 - context['courses_category'] = courses_category  
67 context['list_courses'] = list_courses 84 context['list_courses'] = list_courses
68 context['categorys_courses'] = categorys_courses 85 context['categorys_courses'] = categorys_courses
  86 + context['aparece'] = self.aparece
69 87
70 return context 88 return context
71 -  
72 - def get_queryset(self):  
73 - try:  
74 - name = self.kwargs['q']  
75 - except:  
76 - name = ''  
77 - if (name != ''):  
78 - object_list = Course.objects.filter(name__icontains = name)  
79 - else:  
80 - object_list = Course.objects.all()  
81 - return object_list  
82 - 89 +
83 class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): 90 class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView):
84 91
85 allowed_roles = ['professor', 'system_admin'] 92 allowed_roles = ['professor', 'system_admin']