Skip to content

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.
...
  • 16 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 34 additions and 16 deletions.
  1. +3 −0 tunnel_sentry.sh
  2. +14 −7 zivimap/views.py
  3. +17 −9 ziviweb/settings.py
View
3 tunnel_sentry.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+# Make the remote sentry available on local port 9000
+ssh -L 9000:localhost:62155 myzivi@s8.wservices.ch
View
21 zivimap/views.py
@@ -3,7 +3,7 @@
from django import forms
from zivimap.api import *
from zivimap.models import Address, WorkSpec, DateRange
-from django.db.models import Q
+from django.db.models import Q, Count
from django.conf import settings
from django.utils import translation
from django.utils.translation import ugettext_lazy as _
@@ -33,7 +33,7 @@ class SearchForm(forms.Form):
}),
label=_('Date range'))
-def build_workspecs_filter(search_form):
+def search_workspecs(search_form):
"""Return a filter dict based on SearchForm cleaned_data"""
assert search_form.is_valid()
cd = search_form.cleaned_data
@@ -49,10 +49,18 @@ def build_workspecs_filter(search_form):
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()
- Qfilters &= Q(daterange__start__gte=start_date)
- Qfilters &= Q(daterange__end__lte=end_date)
- return Qfilters
+ 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 sitemap(request):
return render(request, 'sitemap.xml')
@@ -67,8 +75,7 @@ def index(request):
cd = form.cleaned_data
addresses = all_resources(request, AddressResource(),
Address.objects.all())
- Qws = build_workspecs_filter(form)
- wsq = WorkSpec.objects.filter(Qws)
+ wsq = search_workspecs(form)
ws = all_resources(request, MapSearchResource(), wsq)
first_time_message = not request.session.get('visited', False)
request.session['visited'] = True
View
26 ziviweb/settings.py
@@ -1,4 +1,5 @@
import os
+import sys
from django.conf import global_settings
# Django settings for ziviweb project.
@@ -161,7 +162,7 @@
'disable_existing_loggers': False,
'root': {
'level': 'WARNING',
- 'handlers': ['sentry'],
+ 'handlers': ['sentry', 'logfile'],
},
'filters': {
'require_debug_false': {
@@ -176,6 +177,13 @@
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
+ },
+ 'logfile': {
+ 'level': 'DEBUG',
+ 'class': 'logging.handlers.RotatingFileHandler',
+ 'filename': 'logs/log.txt',
+ 'maxBytes': 50000,
+ 'backupCount': 2,
}
#'mail_admins': {
#'level': 'ERROR',
@@ -184,25 +192,25 @@
#}
},
'loggers': {
- #'django.request': {
- #'handlers': ['mail_admins'],
- #'level': 'ERROR',
- #'propagate': True,
- #},
+ 'django.request': {
+ 'handlers': ['console'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
'django.db.backends':{
'level': 'ERROR',
'handlers': ['console'],
- 'propagate': False,
+ 'propagate': True,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
- 'propagate': False,
+ 'propagate': True,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
- 'propagate': False,
+ 'propagate': True,
},
}
}

No commit comments for this range

Something went wrong with that request. Please try again.