Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: julienr/myzivi
base: 409aef0510
...
head fork: julienr/myzivi
compare: e2cb8882cd
  • 7 commits
  • 15 files changed
  • 0 commit comments
  • 1 contributor
View
15 rundev_scraper.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+DDIR=$PWD/_data/scraped_`date +%F-%T`
+mkdir -p $DDIR
+export SENTRY_DSN=""
+export SCRAPY_DATA_DIR=$DDIR
+export PYTHONPATH=.:/home/myzivi/django-myzivi:$PYTHONPATH
+export DJANGO_SETTINGS_MODULE=ziviweb.settings
+# Crawler
+scrapy crawl zivi
+# Postprocess (geotagging, translation, ...)
+python ziviscrap/postprocess.py
+# Insert into DB
+python zivimap/import_items.py
+# Delete old scraped directory
+python rotate_data.py
View
66 zivimap/api.py
@@ -1,8 +1,10 @@
import ziviweb.settings as settings
from django.core.urlresolvers import reverse
-from zivimap.models import WorkSpec, Address
-from tastypie.resources import ModelResource, Resource, Bundle
+from zivimap.models import WorkSpec, Address, DateRange
+from django.db.models import Q, Count
+from tastypie.resources import ModelResource, Resource, Bundle, ALL
from tastypie import fields, utils
+from datetime import datetime
class AddressResource(ModelResource):
class Meta:
@@ -11,21 +13,26 @@ class Meta:
include_resource_uri = False
limit = 0
-class MapSearchResource(ModelResource):
+class WorkSpecSearchResource(ModelResource):
"""
This is a specialized resource that returns a list of workspecs for a given
query. The workspecs description is shortened to only a few fields to
- save bandwidth.
+ reduce response size
"""
class Meta:
queryset = WorkSpec.objects.all()
- resource_name = 'search'
+ resource_name = 'workspec_search'
allowed_methods = ['get']
include_resource_uri = False
# Without that, resource_uri is empty in the view
api_name = settings.API_VERSION
limit = 0
- fields = ['address_id', 'shortname', 'raw_phid']
+ max_limit = 0
+ fields = ['address_id', 'shortname', 'raw_phid', 'phid']
+ filtering = {
+ 'activity_domain': ('in',),
+ 'language': ('in',),
+ }
def dehydrate(self, bundle):
bundle.data['addrid'] = bundle.obj.address_id
@@ -34,21 +41,42 @@ def dehydrate(self, bundle):
def build_filters(self, filters=None):
if filters is None:
filters = {}
- orm_filters = super(MapSearchResource, self).build_filters(filters)
-
- # We accept a "latlngbb=47.365,8.783,47.367,8.785" parameter
- # specifying a latlng bounding box (as the one returned by google maps
- # getBounds())
- if 'latlngbb' in filters:
- latlngbb = filters['latlngbb']
- swlat, swlng, nelat, nelng = map(float, latlngbb.split(','))
+ orm_filters = super(WorkSpecSearchResource, self).build_filters(filters)
+ # By default, tastypie doesn't allow to filter on fields that are
+ # not in Meta.fields. Overwrite this
+ lang_filters = filters.getlist('language__in')
+ if lang_filters:
+ orm_filters['language__in'] = lang_filters
+ domain_filters = filters.getlist('activity_domain__in')
+ if domain_filters:
+ orm_filters['activity_domain__in'] = domain_filters
+ return orm_filters
- assert swlat < nelat
- assert swlng < nelng
- orm_filters['address__latitude__range'] = (swlat, nelat)
- orm_filters['address__longitude__range'] = (swlng, nelng)
+ def apply_filters(self, request, applicable_filters):
+ res = super(WorkSpecSearchResource, self).apply_filters(request,
+ applicable_filters)
+ # Handle complex filters here
+ start_min = request.GET.get('start_min', None)
+ end_max = request.GET.get('end_max', None)
+ if start_min is not None or end_max is not None:
+ drfilters = Q()
+ if start_min is not None:
+ start_date = datetime.strptime(start_min.strip(),
+ '%Y-%m-%d').date()
+ drfilters &= Q(start__gte=start_date)
+ if end_max is not None:
+ end_date = datetime.strptime(end_max.strip(),
+ '%Y-%m-%d').date()
+ drfilters &= Q(end__lte=end_date)
+ ranges = DateRange.objects.filter(drfilters).values('workspec_id')\
+ .annotate()
+ # ID of workspecs that don't have a daterange
+ # TODO: This should be merged in the subsequent workspec query
+ no_ranges = WorkSpec.objects.annotate(rc=Count('daterange'))\
+ .filter(rc=0).values('phid').annotate()
+ res = res.filter(Q(phid__in=ranges) | Q(phid__in=no_ranges))
+ return res
- return orm_filters
class WorkSpecResource(ModelResource):
address = fields.ToOneField(AddressResource, 'address', full=True)
View
89 zivimap/forms.py
@@ -0,0 +1,89 @@
+"""
+Adaptation of django.forms.extra.SelectDateWidget to show only month and year
+"""
+from __future__ import unicode_literals
+
+import datetime
+import re
+import calendar
+
+from django.forms.widgets import Widget, Select
+from django.utils import datetime_safe
+from django.utils.dates import MONTHS
+from django.utils.encoding import force_str
+from django.utils.safestring import mark_safe
+from django.utils.formats import get_format
+from django.utils import six
+from django.conf import settings
+
+__all__ = ('SelectDateWidget',)
+
+class SelectMonthYearWidget(Widget):
+ """
+ A Widget that splits date input into two <select> boxes and allow selection
+ of month/year
+ """
+ none_value = (0, '---')
+ month_field = '%s_month'
+ year_field = '%s_year'
+
+ def __init__(self, defaultdate, day, attrs=None, years=None,
+ required=True):
+ # dayval is the value that will be set for the days. Can be 'first'
+ # or 'last'
+ # years is an optional list/tuple of years to use in the "year" select box.
+ self.attrs = attrs or {}
+ self.required = required
+ self.dayval = day
+ self.defaultdate = defaultdate
+ if years:
+ self.years = years
+ else:
+ this_year = datetime.date.today().year
+ self.years = range(this_year, this_year+10)
+
+ def render(self, name, value, attrs=None):
+ try:
+ year_val, month_val = value.year, value.month
+ except AttributeError:
+ year_val, month_val = self.defaultdate.year, self.defaultdate.month
+
+ choices = [(i, i) for i in self.years]
+ year_html = self.create_select(name, self.year_field, value, year_val, choices)
+ choices = list(six.iteritems(MONTHS))
+ month_html = self.create_select(name, self.month_field, value, month_val, choices)
+
+ output = [month_html, year_html]
+ return mark_safe('\n'.join(output))
+
+ def id_for_label(self, id_):
+ return '%s_month' % id_
+
+ def value_from_datadict(self, data, files, name):
+ y = data.get(self.year_field % name)
+ m = data.get(self.month_field % name)
+ if y == m == "0": # No selection
+ return None
+ if y and m:
+ y = int(y)
+ m = int(m)
+ if self.dayval == 'first':
+ day = 1
+ else:
+ day = calendar.monthrange(y, m)[1]
+ return datetime.date(int(y), int(m), day)
+ else:
+ return None
+
+ def create_select(self, name, field, value, val, choices):
+ if 'id' in self.attrs:
+ id_ = self.attrs['id']
+ else:
+ id_ = 'id_%s' % name
+ #if not (self.required and val):
+ #choices.insert(0, self.none_value)
+ local_attrs = self.build_attrs(id=field % id_)
+ local_attrs['class'] = field % 'select'
+ s = Select(choices=choices)
+ select_html = s.render(field % name, val, local_attrs)
+ return select_html
View
46 zivimap/locale/de/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-02-18 17:50+0100\n"
+"POT-Creation-Date: 2013-03-05 12:45+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -18,51 +18,60 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
-#: models.py:30
+#: models.py:32
msgid "Health"
msgstr "Gesundheitswesen"
-#: models.py:30
+#: models.py:32
msgid "Social"
msgstr "Sozialwesen"
-#: models.py:31
+#: models.py:33
msgid "Culture"
msgstr "Kulturgütererhaltung"
-#: models.py:31
+#: models.py:33
msgid "Nature protection"
msgstr "Umwelt- und Naturschutz"
-#: models.py:32
+#: models.py:34
msgid "Forest work"
msgstr "Forstwesen"
-#: models.py:32
+#: models.py:34
msgid "Agriculture"
msgstr "Landwirtschaft"
-#: models.py:33
+#: models.py:35
msgid "Development & cooperation"
msgstr "Entwicklungszusammenar..."
-#: models.py:34
+#: models.py:36
msgid "Disasters help"
msgstr "Bewältigung von Katast..."
-#: views.py:24
+#: views.py:29 templates/search_form.html:9
msgid "Domains"
msgstr "Tätigkeitsbereich"
-#: views.py:28
+#: views.py:33 templates/search_form.html:15
msgid "Languages"
msgstr "Sprache"
-#: templates/base.html:14 templates/base.html.py:26
-msgid "swiss civilian service search"
-msgstr "Schweizer zivildienst einsatz suche"
+#: views.py:41 templates/search_form.html:21
+msgid "Earliest start"
+msgstr "Frühester Start"
+
+#: views.py:45 templates/search_form.html:27
+msgid "Latest end"
+msgstr "Spätestes Ende"
-#: templates/base.html:58
+#: templates/base.html:16 templates/base.html.py:28
+#, fuzzy
+msgid "(non-official) swiss civilian service search"
+msgstr "Schweizer zivildienst einsatz suche (inoffiziell)"
+
+#: templates/base.html:60
#, python-format
msgid ""
"\n"
@@ -76,11 +85,14 @@ msgid ""
" "
msgstr ""
-#: templates/index.html:45
+#: templates/index.html:42
#, fuzzy
msgid "Search options"
msgstr "Suchen"
-#: templates/index.html:50
+#: templates/index.html:46
msgid "Search"
msgstr "Suchen"
+
+#~ msgid "swiss civilian service search"
+#~ msgstr "Schweizer zivildienst einsatz suche"
View
40 zivimap/locale/en/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-02-18 17:50+0100\n"
+"POT-Creation-Date: 2013-03-05 12:45+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,51 +17,59 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: models.py:30
+#: models.py:32
msgid "Health"
msgstr ""
-#: models.py:30
+#: models.py:32
msgid "Social"
msgstr ""
-#: models.py:31
+#: models.py:33
msgid "Culture"
msgstr ""
-#: models.py:31
+#: models.py:33
msgid "Nature protection"
msgstr ""
-#: models.py:32
+#: models.py:34
msgid "Forest work"
msgstr ""
-#: models.py:32
+#: models.py:34
msgid "Agriculture"
msgstr ""
-#: models.py:33
+#: models.py:35
msgid "Development & cooperation"
msgstr ""
-#: models.py:34
+#: models.py:36
msgid "Disasters help"
msgstr ""
-#: views.py:24
+#: views.py:29 templates/search_form.html:9
msgid "Domains"
msgstr ""
-#: views.py:28
+#: views.py:33 templates/search_form.html:15
msgid "Languages"
msgstr ""
-#: templates/base.html:14 templates/base.html.py:26
-msgid "swiss civilian service search"
+#: views.py:41 templates/search_form.html:21
+msgid "Earliest start"
+msgstr ""
+
+#: views.py:45 templates/search_form.html:27
+msgid "Latest end"
+msgstr ""
+
+#: templates/base.html:16 templates/base.html.py:28
+msgid "(non-official) swiss civilian service search"
msgstr ""
-#: templates/base.html:58
+#: templates/base.html:60
#, python-format
msgid ""
"\n"
@@ -75,10 +83,10 @@ msgid ""
" "
msgstr ""
-#: templates/index.html:45
+#: templates/index.html:42
msgid "Search options"
msgstr ""
-#: templates/index.html:50
+#: templates/index.html:46
msgid "Search"
msgstr ""
View
46 zivimap/locale/fr/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-02-18 17:50+0100\n"
+"POT-Creation-Date: 2013-03-05 12:45+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -18,51 +18,60 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
-#: models.py:30
+#: models.py:32
msgid "Health"
msgstr "Santé"
-#: models.py:30
+#: models.py:32
msgid "Social"
msgstr "Social"
-#: models.py:31
+#: models.py:33
msgid "Culture"
msgstr "Culture"
-#: models.py:31
+#: models.py:33
msgid "Nature protection"
msgstr "Protection de la nature"
-#: models.py:32
+#: models.py:34
msgid "Forest work"
msgstr "Travaux forestiers"
-#: models.py:32
+#: models.py:34
msgid "Agriculture"
msgstr "Agriculture"
-#: models.py:33
+#: models.py:35
msgid "Development & cooperation"
msgstr "Développement & coopéeration"
-#: models.py:34
+#: models.py:36
msgid "Disasters help"
msgstr "Aide en cas de catastrophe"
-#: views.py:24
+#: views.py:29 templates/search_form.html:9
msgid "Domains"
msgstr "Domaines"
-#: views.py:28
+#: views.py:33 templates/search_form.html:15
msgid "Languages"
msgstr "Langue"
-#: templates/base.html:14 templates/base.html.py:26
-msgid "swiss civilian service search"
-msgstr "recherche d'affectations pour le service civil suisse"
+#: views.py:41 templates/search_form.html:21
+msgid "Earliest start"
+msgstr "Début au plus tôt"
+
+#: views.py:45 templates/search_form.html:27
+msgid "Latest end"
+msgstr "Fin au plus tard"
-#: templates/base.html:58
+#: templates/base.html:16 templates/base.html.py:28
+#, fuzzy
+msgid "(non-official) swiss civilian service search"
+msgstr "recherche d'affectations pour le service civil suisse (non-officiel)"
+
+#: templates/base.html:60
#, python-format
msgid ""
"\n"
@@ -86,10 +95,13 @@ msgstr ""
" Pour plus d'informations, cliques sur \"About\".\n"
" "
-#: templates/index.html:45
+#: templates/index.html:42
msgid "Search options"
msgstr "Options de recherche"
-#: templates/index.html:50
+#: templates/index.html:46
msgid "Search"
msgstr "Chercher"
+
+#~ msgid "swiss civilian service search"
+#~ msgstr "recherche d'affectations pour le service civil suisse"
View
7 zivimap/static/css/main.css
@@ -84,3 +84,10 @@ ul#search_form label {
display: inline;
}
+#search_form select.select_month {
+ width: 100px;
+}
+
+#search_form select.select_year {
+ width: 100px;
+}
View
14 zivimap/static/js/map.js
@@ -14,9 +14,8 @@ function url_from_phid(phid) {
return ZIVI_WS_BASE + '&phid=' + phid;
}
-// initialWorkspecs is a list of JSON workspecs
// N is the namespace to use for this app
-function initMap(initialWorkspecs, initialAddresses, N) {
+function initMap(N) {
N.WorkSpec = Backbone.Model.extend({
urlRoot: SEARCH_API,
});
@@ -214,7 +213,7 @@ function initMap(initialWorkspecs, initialAddresses, N) {
},
});
- N.addresses = new N.AddressList(initialAddresses);
+ N.addresses = new N.AddressList();
N.workspecs = new N.WorkSpecList();
//N.listview = new N.ListView({
@@ -226,5 +225,12 @@ function initMap(initialWorkspecs, initialAddresses, N) {
addresses: N.addresses,
});
- N.workspecs.reset(initialWorkspecs);
+ // Workspecs depends on all addresses being loaded (otherwise MapView will
+ // fail). So chain them
+ // TODO: Need to handle potential ajax errors
+ N.addresses.fetch({success:
+ function(collection, response) {
+ N.workspecs.fetch();
+ }
+ });
}
View
4 zivimap/templates/base.html
@@ -13,7 +13,7 @@
rel="stylesheet" media="screen">
<link href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css"
rel="stylesheet" media="screen">
- <title>myzivi.ch | {% trans 'swiss civilian service search' %}</title>
+ <title>myzivi.ch | {% trans '(non-official) swiss civilian service search' %}</title>
</head>
<body>
<div id="top_navbar" class="navbar navbar-inverse navbar-static-top">
@@ -25,7 +25,7 @@
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">myzivi.ch <br />
- <span class="nav-small">{% trans 'swiss civilian service search' %}</span></a>
+ <span class="nav-small">{% trans '(non-official) swiss civilian service search' %}</span></a>
<div class="nav-collapse collapse">
<ul class="nav">
<!--<li class="active"><a href="#">Home</a></li>-->
View
29 zivimap/templates/index.html
@@ -15,26 +15,11 @@
</script>
<script type="text/javascript">
- // TODO: Do clean bootstraping http://backbonejs.org/#FAQ-bootstrap
- WORKSPEC_API = "{% url 'api_dispatch_list' api_name="v1" resource_name="workspec" %}";
- ADDRESS_API = "{% url 'api_dispatch_list' api_name="v1" resource_name="address" %}";
- SEARCH_API = "{% url 'api_dispatch_list' api_name="v1" resource_name="search" %}";
+ ADDRESS_API = "{{ address_url }}";
+ SEARCH_API = "{{ workspec_search_url }}";
- // Daterange picker
- var dateMin = Date.parse('{{daterange_min|safe}}');
- var dateMax = Date.parse('{{daterange_max|safe}}');
- $('.daterange').daterangepicker({
- minDate: dateMin,
- maxDate: dateMax,
- startDate: dateMin,
- endDate: dateMax,
- format: 'dd/MM/yyyy'});
- $('.daterange').data('daterangepicker').notify();
-
- var _workspecs = JSON.parse("{{ workspecs|escapejs }}");
- var _addresses = JSON.parse("{{ addresses|escapejs }}");
var App = {};
- $(initMap(_workspecs, _addresses, App));
+ $(initMap(App));
</script>
<!-- Social stuff -->
@@ -55,13 +40,11 @@
<div id="filters_overlay">
<div id="filters_container">
<h4>{% trans 'Search options' %}</h4>
- <form action="{% url 'zivimap.views.index' %}" method="GET">
- <ul id="search_form">
- {{ search_form.as_ul }}
- </ul>
+ <form id="search_form" action="{% url 'zivimap.views.index' %}" method="GET">
+ {% include "search_form.html" with form=search_form %}
+
<input class="btn btn-primary" type="submit" value="{% trans 'Search' %}" />
</form>
-
<!-- Social buttons -->
<div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-font="arial"></div>
View
32 zivimap/templates/search_form.html
@@ -0,0 +1,32 @@
+{% load i18n %}
+{% comment %}
+{{ form.as_ul }}
+{% endcomment %}
+
+<ul id="search_form">
+ {{ form.non_field_errors }}
+ <li>
+ <label for="id_domains_0">{% trans 'Domains' %}</label>
+ <ul>
+ {{ form.domains }}
+ </ul>
+ </li>
+ <li>
+ <label for="id_languages_0">{% trans 'Languages' %}</label>
+ <ul>
+ {{ form.languages }}
+ </ul>
+ </li>
+ <li>
+ <label for="id_start_min_month">{% trans 'Earliest start' %}</label>
+ <ul>
+ {{ form.start_min }}
+ </ul>
+ </li>
+ <li>
+ <label for="id_end_max_month">{% trans 'Latest end' %}</label>
+ <ul>
+ {{ form.end_max }}
+ </ul>
+ </li>
+</ul>
View
93 zivimap/views.py
@@ -1,13 +1,17 @@
from django.shortcuts import render, redirect
+from django.core.urlresolvers import reverse
from django.core import serializers
from django import forms
from zivimap.api import *
from zivimap.models import Address, WorkSpec, DateRange
from django.db.models import Q, Count
from django.conf import settings
+from django.utils.http import urlencode
+from django.utils.datastructures import MultiValueDict
from django.utils import translation
from django.utils.translation import ugettext_lazy as _
import json
+from zivimap.forms import SelectMonthYearWidget
from datetime import datetime
def all_resources(request, resource, queryset):
@@ -27,40 +31,19 @@ class SearchForm(forms.Form):
choices=WorkSpec.LANG_CHOICES,
widget=forms.CheckboxSelectMultiple,
label=_('Languages'))
- date_range = forms.CharField(required=False,
- widget=forms.TextInput(attrs={'class':'daterange',
- #'readonly':'readonly'
- }),
- label=_('Date range'))
-
-def search_workspecs(search_form):
- """Return a filter dict based on SearchForm cleaned_data"""
- assert search_form.is_valid()
- cd = search_form.cleaned_data
- Qfilters = Q()
- domains = cd['domains']
- if len(domains) > 0:
- Qfilters &= Q(activity_domain__in=domains)
- languages = cd['languages']
- if len(languages) > 0:
- Qfilters &= Q(language__in=languages)
- date_range = cd['date_range']
- if len(date_range) > 0:
- start_date, end_date = date_range.split('-')
- start_date = datetime.strptime(start_date.strip(), '%d/%m/%Y').date()
- end_date = datetime.strptime(end_date.strip(), '%d/%m/%Y').date()
- ranges = DateRange.objects.filter(start__gte=start_date,
- end__lte=end_date)
- ranges = ranges.values('workspec_id').annotate()
-
- # ID of workspecs that don't have a daterange
- no_ranges = WorkSpec.objects.annotate(rc=Count('daterange')).filter(rc=0).values('phid').annotate()
- Qfilters &= Q(phid__in=ranges) | Q(phid__in=no_ranges)
-
- # Need an order by here, otherwise, the clustering will change based
- # on the ordering of the WorkSpec set, which might be confusing (like
- # when searching without date range and with the whole date range)
- return WorkSpec.objects.filter(Qfilters).order_by('phid')
+ def __init__(self, date_min, date_max, *args, **kwargs):
+ super(SearchForm, self).__init__(*args, **kwargs)
+ years = range(date_min.year, date_max.year + 1)
+ self.fields.update({
+ 'start_min': forms.DateField(required=False,
+ input_formats=['%d.%m.%Y'],
+ widget=SelectMonthYearWidget(date_min, day='first', years=years),
+ label=_('Earliest start')),
+ 'end_max': forms.DateField(required=False,
+ input_formats=['%d.%m.%Y'],
+ widget=SelectMonthYearWidget(date_max, day='last', years=years),
+ label=_('Latest end'))
+ })
def sitemap(request):
return render(request, 'sitemap.xml')
@@ -70,22 +53,40 @@ def index(request):
lang = translation.get_language()
request.session['django_language'] = lang
- form = SearchForm(request.GET)
+ date_min, date_max = DateRange.get_min_max()
+ form = SearchForm(date_min, date_max, request.GET)
if form.is_valid():
cd = form.cleaned_data
- addresses = all_resources(request, AddressResource(),
- Address.objects.all())
- wsq = search_workspecs(form)
- ws = all_resources(request, MapSearchResource(), wsq)
+
first_time_message = not request.session.get('visited', False)
request.session['visited'] = True
- date_min, date_max = DateRange.get_min_max()
- context = {'addresses': addresses,
- 'workspecs' : ws,
- 'search_form' : form,
- 'daterange_min' : date_min,
- 'daterange_max' : date_max,
- 'first_time_message' : first_time_message}
+
+ workspec_search_url = reverse('api_dispatch_list', kwargs={
+ 'api_name': 'v1',
+ 'resource_name': 'workspec_search'})
+ query = MultiValueDict()
+ query['format'] = 'json'
+ for lang in cd['languages']:
+ query.appendlist('language__in', lang)
+ for dom in cd['domains']:
+ query.appendlist('activity_domain__in', dom)
+ start_min = cd['start_min']
+ end_max = cd['end_max']
+ if start_min:
+ query['start_min'] = start_min
+ if end_max:
+ query['end_max'] = end_max
+
+ workspec_search_url += '?' + urlencode(query, doseq=True)
+ address_url = reverse('api_dispatch_list', kwargs={
+ 'api_name': 'v1',
+ 'resource_name': 'address'})
+
+ context = {'search_form' : form,
+ 'first_time_message' : first_time_message,
+ 'workspec_search_url' : workspec_search_url,
+ 'address_url': address_url}
+
return render(request, 'index.html', context)
else:
return redirect('index')
View
9 ziviscrap/settings.py
@@ -31,17 +31,18 @@
LOG_FILE = os.path.join(DATA_DIR, 'log.txt')
LOG_LEVEL = 'DEBUG'
-DOWNLOAD_DELAY = 0.1
+DOWNLOAD_DELAY = 0.5
RETRY_ENABLED = True
RETRY_TIMES = 5
-
-# Disable redirect because the website redirects us on 500 error
-REDIRECT_ENABLED = False
# Retry 500 and 404 because sometimes, temporary errors seem to cause the
# server to return 404, but the page exists on next try
RETRY_HTTP_CODES = [500, 503, 504, 400, 404, 408, 300, 307]
+
+# Disable redirect because the website redirects us on 500 error
+REDIRECT_ENABLED = False
+
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'ziviscrap (+http://www.yourdomain.com)'
USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20120421 Firefox/11.0"
View
2  ziviweb/settings.py
@@ -162,7 +162,7 @@
'disable_existing_loggers': False,
'root': {
'level': 'WARNING',
- 'handlers': ['sentry', 'logfile'],
+ 'handlers': ['sentry', 'logfile', 'console'],
},
'filters': {
'require_debug_false': {
View
2  ziviweb/urls.py
@@ -11,7 +11,7 @@
v1_api = Api(api_name=settings.API_VERSION)
v1_api.register(AddressResource())
v1_api.register(WorkSpecResource())
-v1_api.register(MapSearchResource())
+v1_api.register(WorkSpecSearchResource())
print v1_api.urls

No commit comments for this range

Something went wrong with that request. Please try again.