diff --git a/expo/models_logbooks.py b/expo/models_logbooks.py index e9cf391..89f2125 100644 --- a/expo/models_logbooks.py +++ b/expo/models_logbooks.py @@ -1,6 +1,6 @@ from django.db import models from django.contrib import admin - +from django.forms import ModelForm class Expedition(models.Model): year = models.CharField(max_length=20, unique=True) @@ -79,9 +79,4 @@ class PersonTrip(models.Model): is_logbook_entry_author = models.BooleanField() def __unicode__(self): - return "%s %s (%s)" % (self.person_expedition, self.place, self.date) - - - - - + return "%s %s (%s)" % (self.person_expedition, self.place, self.date) \ No newline at end of file diff --git a/expo/search.py b/expo/search.py new file mode 100644 index 0000000..5ec2ce2 --- /dev/null +++ b/expo/search.py @@ -0,0 +1,39 @@ +import re + +from django.db.models import Q + +# search script from http://www.julienphalip.com/blog/2008/08/16/adding-search-django-site-snap/ + +def normalize_query(query_string, + findterms=re.compile(r'"([^"]+)"|(\S+)').findall, + normspace=re.compile(r'\s{2,}').sub): + ''' Splits the query string in invidual keywords, getting rid of unecessary spaces + and grouping quoted words together. + Example: + + >>> normalize_query(' some random words "with quotes " and spaces') + ['some', 'random', 'words', 'with quotes', 'and', 'spaces'] + + ''' + return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)] + +def get_query(query_string, search_fields): + ''' Returns a query, that is a combination of Q objects. That combination + aims to search keywords within a model by testing the given search fields. + + ''' + query = None # Query to search for every search term + terms = normalize_query(query_string) + for term in terms: + or_query = None # Query to search for a given term in each field + for field_name in search_fields: + q = Q(**{"%s__icontains" % field_name: term}) + if or_query is None: + or_query = q + else: + or_query = or_query | q + if query is None: + query = or_query + else: + query = query & or_query + return query \ No newline at end of file diff --git a/expo/views.py b/expo/views.py index eed5872..718c720 100644 --- a/expo/views.py +++ b/expo/views.py @@ -1,3 +1,4 @@ from views_caves import * from views_survex import * from views_logbooks import * +from views_other import * diff --git a/expo/views_caves.py b/expo/views_caves.py index b2e1850..1f108f8 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -1,12 +1,15 @@ from django.shortcuts import render_to_response from troggle.expo.models import Cave, CaveAndEntrance import troggle.settings as settings +from troggle.expo.forms import CaveForm +import search def caveindex(request): caves = Cave.objects.all() return render_to_response('caveindex.html', {'caves': caves, 'settings': settings}) def cave(request, cave_id): + #hm, we're only choosing by the number within kataster, needs to be fixed. Caves in 1626 will presumably not work. - AC 7DEC08 cave = Cave.objects.filter(kataster_number = cave_id)[0] return render_to_response('cave.html', {'cave': cave, 'settings': settings}) @@ -17,3 +20,18 @@ def ent(request, cave_id, ent_letter): 'entrance': cave_and_ent.entrance, 'letter': cave_and_ent.entrance_letter, 'settings': settings}) + +def caveSearch(request): + query_string = '' + found_entries = None + if ('q' in request.GET) and request.GET['q'].strip(): + query_string = request.GET['q'] + entry_query = search.get_query(query_string, ['underground_description','official_name',]) + found_entries = Cave.objects.filter(entry_query) + + return render_to_response('cavesearch.html', + { 'query_string': query_string, 'found_entries': found_entries, 'settings': settings}) + #context_instance=RequestContext(request)) + + + diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index 9d69099..b44c770 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -1,6 +1,7 @@ from django.shortcuts import render_to_response from troggle.expo.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry import troggle.settings as settings +import search def personindex(request): persons = Person.objects.all() @@ -14,4 +15,14 @@ def logbookentry(request, logbookentry_id): logbookentry = LogbookEntry.objects.filter(id = logbookentry_id)[0] return render_to_response('logbookentry.html', {'logbookentry': logbookentry, 'settings': settings}) +def logbookSearch(request, extra): + query_string = '' + found_entries = None + if ('q' in request.GET) and request.GET['q'].strip(): + query_string = request.GET['q'] + entry_query = search.get_query(query_string, ['text','title',]) + found_entries = LogbookEntry.objects.filter(entry_query) + return render_to_response('logbooksearch.html', + { 'query_string': query_string, 'found_entries': found_entries, 'settings': settings}) + #context_instance=RequestContext(request)) \ No newline at end of file diff --git a/expo/views_other.py b/expo/views_other.py new file mode 100644 index 0000000..808238e --- /dev/null +++ b/expo/views_other.py @@ -0,0 +1,13 @@ +from django.shortcuts import render_to_response +from troggle.expo.models import Cave, Expedition, Person, LogbookEntry +import troggle.settings as settings +from django import forms +from django.db.models import Q + +def stats(request): + statsDict={} + statsDict['expoCount'] = int(Expedition.objects.count()) + statsDict['caveCount'] = int(Cave.objects.count()) + statsDict['personCount'] = int(Person.objects.count()) + statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count()) + return render_to_response('statistics.html', statsDict) \ No newline at end of file diff --git a/media/css/main2.css b/media/css/main2.css index 8f1f3d2..523b1f7 100644 --- a/media/css/main2.css +++ b/media/css/main2.css @@ -5,11 +5,12 @@ body, td, center, ul, p, input { color: #000; font-family: sans-serif; } a:link, a:visited { text-decoration: none; } div.centre img { vertical-align: middle; } -h1 { text-align: center; font-size: 210%; - line-height: 100%; } + +h1 { text-align: center; font-size: 210%; line-height: 100%; } h2 { color: #009900; } h3 { color: #2c105e; } h4 { color: #0d664c; } +h4.navbar {line-height: 0px;} img.onright, div.onright { vertical-align: top; float: right; margin-left: 10pt; margin-bottom: 10pt; margin-right: 8pt; } @@ -22,6 +23,10 @@ table.imgtable { margin-left: auto; margin-right: auto; } table.imgtable td { vertical-align: middle; text-align: center; padding: 10px; } +table.normal { border: thin; border-top:solid ; border-left:dotted ; border-bottom:dotted; border-right:hidden ; border-width:1px;} +table.normal td { border: thin; border-right:dotted ; border-width:1px; border-spacing:0px } +table.normal th { border-left:thin ; border-right:thin ; text-align: left} + /* "Traditional" table with borders.*/ table.trad { margin: 0pt; border: 1px solid #000; border-color: #c0c0c0 #8d8d8d #8d8d8d #c0c0c0; } @@ -29,6 +34,30 @@ table.bigfatborder { border-width: 6px; } table.trad td, table.trad th { margin: 0pt; border: 1px solid #aaa; border-color: #8d8d8d #c0c0c0 #c0c0c0 #8d8d8d; } +/*Divs for layout*/ +html, body, div.contents { +min-height: 100%; +height: 100%; +} +html>body, html>body div.contents { +height: auto; +} +body { +} +div.contents { +position: absolute; +top: 0; +left: 0; +} +div.footer { +position: fixed; +bottom: 2px; +right: 2px; +} +div.main { +margin-bottom: 3em; +} + /* You are not expected to understand this. It is necessary. */ table.centre { margin-left: auto; margin-right: auto; } table.centre td { text-align: left; } @@ -40,4 +69,4 @@ table#cavepage th#name { text-align: center; width: 50%; } table#cavepage th#status { text-align: right; width: 25%; } .command { color: #FF0000; } -.comment { color: #888888; font-style:italic;} \ No newline at end of file +.comment { color: #888888; font-style:italic;} diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 900022f..d0d4f4c 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -73,7 +73,7 @@ def LoadPersons(): # this fills in those peopl for whom 2008 was their first expo for name in expomissing: firstname, lastname = name.split() - is_guest = name in ["Eeva Makiranta", "Kieth Curtis"] + is_guest = name in ["Eeva Makiranta", "Keith Curtis"] pObject = models.Person(first_name = firstname, last_name = lastname, is_vfho = False, diff --git a/settings.py b/settings.py index f6a9703..2dd7cc0 100644 --- a/settings.py +++ b/settings.py @@ -29,7 +29,8 @@ USE_I18N = True # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = '/media-admin/' +# MOVED TO LOCALSETTINGS +MEDIA_ROOT = 'C:/Expo/expoweb/troggle/media/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). diff --git a/templates/base.html b/templates/base.html index cb84590..6acd6ac 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,11 +2,67 @@ - + {% block title %}{% endblock %} + + + + + +
+
{% block content %}{% endblock %} - {% block footer %}{% endblock %} +
+ {% block footer %} + + + + +

{% endblock %}

+ \ No newline at end of file diff --git a/templates/cave.html b/templates/cave.html index e8c597e..e76c3b8 100644 --- a/templates/cave.html +++ b/templates/cave.html @@ -73,4 +73,4 @@

Notes

{{ cave.notes|wiki_to_html }} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/statistics.html b/templates/statistics.html new file mode 100644 index 0000000..1fddd67 --- /dev/null +++ b/templates/statistics.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% load wiki_markup %} + +{% block title %}Database statistics{% endblock %} + +{% block content %} +Over the course of {{ expoCount }} expeditions, {{ personCount }} people have contributed {{ caveCount }} caves and {{ logbookEntryCount }} logbook entries. +{% endblock %} \ No newline at end of file diff --git a/urls.py b/urls.py index 4648a52..0afaa3b 100644 --- a/urls.py +++ b/urls.py @@ -1,6 +1,6 @@ from django.conf.urls.defaults import * from expo.views import * - +import troggle.settings as settings from django.contrib import admin admin.autodiscover() @@ -9,6 +9,8 @@ urlpatterns = patterns('', (r'^cave/$', caveindex), (r'^cave/(?P[^/]+)/$', cave), (r'^cave/(?P[^/]+)/(?P[^/]?)$', ent), + (r'^cave/(?P[^/]+)/edit/$', edit_cave), + (r'^cavesearch/$', caveSearch), (r'^survex/(?P.*)\.index$', index), (r'^survex/(?P.*)\.svx$', svx), @@ -20,11 +22,14 @@ urlpatterns = patterns('', (r'^person/(.*)$', person), (r'^logbookentry/(.*)$', logbookentry), + (r'^logbooksearch/(.*)$', logbookSearch), + + (r'^troggle/statistics/$', stats), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), - (r'^site_media/(?P.*)$', 'django.views.static.serve', - {'document_root': 'c:/expodjango/troggle/media/'}), + (r'^troggle/site_media/(?P.*)$', 'django.views.static.serve', + {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), )