From 824fb68147f25f1e0da489602a8b14c3e8b504d7 Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Wed, 15 Feb 2017 19:49:57 +0100 Subject: [PATCH] Add date range in thesis search form. --- scipost/static/scipost/assets/js/scripts.js | 1 - scipost/templates/scipost/base.html | 2 ++ theses/forms.py | 2 ++ theses/managers.py | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scipost/static/scipost/assets/js/scripts.js b/scipost/static/scipost/assets/js/scripts.js index b3c0ab7ce..001f02c0e 100644 --- a/scipost/static/scipost/assets/js/scripts.js +++ b/scipost/static/scipost/assets/js/scripts.js @@ -2,7 +2,6 @@ function hide_all_alerts() { $(".alert").fadeOut(300); } - $(function(){ // Remove all alerts in screen automatically after 10sec. setTimeout(function() {hide_all_alerts()}, 10000); diff --git a/scipost/templates/scipost/base.html b/scipost/templates/scipost/base.html index 4a3105f7a..baa04274b 100644 --- a/scipost/templates/scipost/base.html +++ b/scipost/templates/scipost/base.html @@ -18,6 +18,8 @@ <title>SciPost{% block pagetitle %}{% endblock pagetitle %}</title> <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script> + <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> + <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> {% block headsup %} {% endblock headsup %} diff --git a/theses/forms.py b/theses/forms.py index 3f5dfcc0e..6f8a0e2c1 100644 --- a/theses/forms.py +++ b/theses/forms.py @@ -108,3 +108,5 @@ class ThesisLinkSearchForm(forms.Form): title_keyword = forms.CharField(max_length=100, label="Title", required=False) abstract_keyword = forms.CharField(max_length=1000, required=False, label="Abstract") supervisor = forms.CharField(max_length=100, required=False, label="Supervisor") + from_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False) + to_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False) diff --git a/theses/managers.py b/theses/managers.py index 68dc44574..ecd55472d 100644 --- a/theses/managers.py +++ b/theses/managers.py @@ -1,13 +1,20 @@ +import datetime + from django.db import models +from django.utils import timezone class ThesisLinkManager(models.Manager): def search_results(self, form): + from_date = form.cleaned_data['from_date'] if form.cleaned_data['from_date'] else datetime.date(1600, 1, 1) + to_date = form.cleaned_data['to_date'] if form.cleaned_data['to_date'] else timezone.now() + return self.vetted().filter( title__icontains=form.cleaned_data['title_keyword'], author__icontains=form.cleaned_data['author'], abstract__icontains=form.cleaned_data['abstract_keyword'], supervisor__icontains=form.cleaned_data['supervisor'], + defense_date__range=(from_date, to_date) ).order_by('-defense_date') def latest(self, n): -- GitLab