From 157f11b65900f7f36c7d9a060c8162c4250d584a Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> Date: Wed, 13 May 2009 06:08:04 +0100 Subject: [PATCH] [svn] Added QM wiki markup. The format is [[cave:204 QM:2005-04A]] with the grade (A) being optional. The links color red if the QM does not exist, and in that case clicking on them goes to an admin add page with fields prepopulated. Various other little things, e.g. filled in the footer with links. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8305 by aaron @ 3/16/2009 8:53 AM --- expo/admin.py | 13 ++++- expo/forms.py | 2 +- expo/models.py | 6 +- expo/templatetags/wiki_markup.py | 33 ++++++++++- expo/views_caves.py | 23 ++++++-- expo/views_logbooks.py | 13 ++++- expo/views_other.py | 4 ++ media/css/main3.css | 13 ++++- parsers/QMs.py | 4 +- templates/base.html | 56 ++++++------------- templates/logbookentry.html | 1 + templates/qm.html | 1 + .../registration/registration_complete.html | 2 +- urls.py | 8 ++- 14 files changed, 118 insertions(+), 61 deletions(-) diff --git a/expo/admin.py b/expo/admin.py index 24f6f2e..a1d4fe0 100644 --- a/expo/admin.py +++ b/expo/admin.py @@ -1,5 +1,7 @@ from troggle.expo.models import * from django.contrib import admin +from django.forms import ModelForm +import django.forms as forms #from troggle.reversion.admin import VersionAdmin #django-reversion version control class RoleInline(admin.TabularInline): @@ -16,9 +18,14 @@ class ScannedImageInline(admin.TabularInline): class SurveyAdmin(admin.ModelAdmin): inlines = (ScannedImageInline,) +class QMInline(admin.TabularInline): + model=QM + extra = 4 + #class LogbookEntryAdmin(VersionAdmin): class LogbookEntryAdmin(admin.ModelAdmin): search_fields = ('title','expedition__year') + #inlines = (QMInline,) #doesn't work because QM has two foreignkeys to Logbookentry- need workaround class PersonExpeditionInline(admin.TabularInline): model = PersonExpedition @@ -29,15 +36,17 @@ class PersonAdmin(admin.ModelAdmin): inlines = (PersonExpeditionInline,) class QMAdmin(admin.ModelAdmin): + search_fields = ('found_by__cave__kataster_number','number') def save_model(self, request, obj, form, change): obj.new_since_parsing=True obj.save() - + class PersonExpeditionAdmin(admin.ModelAdmin): search_fields = ('person__first_name','expedition__year') class CaveAdmin(admin.ModelAdmin): search_fields = ('official_name','kataster_number','unofficial_number') + #inlines = (QMInline,) extra = 4 @@ -57,7 +66,7 @@ admin.site.register(PersonExpedition,PersonExpeditionAdmin) admin.site.register(Role) admin.site.register(LogbookEntry, LogbookEntryAdmin) admin.site.register(PersonTrip) -admin.site.register(QM) +admin.site.register(QM, QMAdmin) admin.site.register(Survey, SurveyAdmin) admin.site.register(ScannedImage) diff --git a/expo/forms.py b/expo/forms.py index 91f39f0..882115f 100644 --- a/expo/forms.py +++ b/expo/forms.py @@ -7,4 +7,4 @@ class CaveForm(ModelForm): class PersonForm(ModelForm): class Meta: - model = Person \ No newline at end of file + model = Person diff --git a/expo/models.py b/expo/models.py index 592b2e8..56fbf01 100644 --- a/expo/models.py +++ b/expo/models.py @@ -19,7 +19,7 @@ class TroggleModel(models.Model): new_since_parsing = models.BooleanField(default=False, editable=False) def get_admin_url(self): - return settings.URL_ROOT + "/admin/expo/" + self._meta.object_name + "/" + str(self.pk) + return settings.URL_ROOT + "/admin/expo/" + self._meta.object_name.lower() + "/" + str(self.pk) class Meta: abstract = True @@ -214,8 +214,8 @@ class LogbookEntry(TroggleModel): #href = models.CharField(max_length=100) - logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True) - logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True) + #logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True) + #logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True) class Meta: verbose_name_plural = "Logbook Entries" diff --git a/expo/templatetags/wiki_markup.py b/expo/templatetags/wiki_markup.py index 9e68fef..30c9a08 100644 --- a/expo/templatetags/wiki_markup.py +++ b/expo/templatetags/wiki_markup.py @@ -2,7 +2,8 @@ from django import template from django.utils.html import conditional_escape from django.template.defaultfilters import stringfilter from django.utils.safestring import mark_safe -import troggle.settings as settings +from django.conf import settings +from expo.models import QM import re register = template.Library() @@ -55,7 +56,35 @@ def wiki_to_html_short(value, autoescape=None): value = re.sub("'''([^']+)'''", r"<b>\1</b>", value, re.DOTALL) value = re.sub("''([^']+)''", r"<i>\1</i>", value, re.DOTALL) #make cave links - value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/troggle/cave/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL) + value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL) + + + #function for replacing wikicode qm links with html qm links + def qmrepl(matchobj): + if len(matchobj.groups())==4: + grade=matchobj.groups()[3] + else: + grade='' + qmdict={'urlroot':settings.URL_ROOT,'cave':matchobj.groups()[0],'year':matchobj.groups()[1],'number':matchobj.groups()[2],'grade':grade} + try: + qm=QM.objects.get(found_by__cave__kataster_number=qmdict['cave'],found_by__date__year=qmdict['year'], number=qmdict['number']) + url=r'<a href=' + str(qm.get_absolute_url()) +'>' + str(qm) + '</a>' + except QM.DoesNotExist: + url = r'<a class="redtext" href="%(urlroot)s/cave/%(cave)s/%(year)s-%(number)s%(grade)s">%(cave)s:%(year)s-%(number)s%(grade)s</a>' % qmdict + return url + + #make qm links + value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\QM:(\d*)-(\d*)([ABCDX]?)\]\]",qmrepl, value, re.DOTALL) + + #qms=qmfinder.search(value) + #for qm in qms: + #if QM.objects.filter(cave__kataster_number=qm[0], found_by__year=qm[1], number=qm[2]).count >= 1: # If there is at lesat one QM matching this query + #replace qm with link in red + #else + #replace qm with link in blue + + #turn qm links red if nonexistant + #Make lists from lines starting with lists of [stars and hashes] outValue = "" listdepth = [] diff --git a/expo/views_caves.py b/expo/views_caves.py index 169dbec..68dd3d0 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -1,9 +1,12 @@ -from troggle.expo.models import Cave, CaveAndEntrance, Survey, Expedition +from troggle.expo.models import Cave, CaveAndEntrance, Survey, Expedition, QM import troggle.expo.models as models import troggle.settings as settings -from troggle.expo.forms import CaveForm +from django.forms.models import formset_factory import search +from django.core.urlresolvers import reverse from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this. +from django.http import HttpResponseRedirect +from django.conf import settings def getCave(cave_id): """Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm.""" @@ -21,11 +24,19 @@ def caveindex(request): def cavehref(request, cave_id='', offical_name=''): return render_response(request,'cave.html', {'cave': getCave(cave_id),}) - -def qm(request,cave_id,qm_id,year): + +def qm(request,cave_id,qm_id,year,grade=None): year=int(year) - qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) - return render_response(request,'qm.html',{'qm':qm,}) + try: + qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) + return render_response(request,'qm.html',locals()) + + except QM.DoesNotExist: + url= settings.URL_ROOT + r'/admin/expo/qm/add/?'+ r'number=' + qm_id + if grade: + url += r'&grade=' + grade + return HttpResponseRedirect(url) + def ent(request, cave_id, ent_letter): cave = Cave.objects.filter(kataster_number = cave_id)[0] diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index fae7491..cfc5d2f 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -71,7 +71,18 @@ def personexpedition(request, first_name='', last_name='', year=''): def logbookentry(request, logbookentry_pk): logbookentry = LogbookEntry.objects.get(pk = logbookentry_pk) - return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, }) + logsforcave=logbookentry.cave.logbookentry_set.all() + biggestQMnumber=0 + for log in logsforcave: + try: + biggestQMnumberInLog = logbookentry.QMs_found.order_by('-number')[0].number + except IndexError: + biggestQMnumberInLog = 0 + if biggestQMnumberInLog > biggestQMnumber: + biggestQMnumber = biggestQMnumberInLog + nextQMnumber=biggestQMnumber+1 + newQMlink=settings.URL_ROOT + r'/admin/expo/qm/add/?' + r'found_by=' + str(logbookentry.pk) +'&number=' + str(nextQMnumber) + return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink}) def logbookSearch(request, extra): query_string = '' diff --git a/expo/views_other.py b/expo/views_other.py index 9852ccc..f83c6e2 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -6,10 +6,14 @@ from troggle.parsers.people import LoadPersonsExpos import re from troggle.parsers.survex import LoadAllSurvexBlocks import randSent +from django.http import HttpResponse from django.core.urlresolvers import reverse from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this. +def showrequest(request): + return HttpResponse(request.GET) + def stats(request): statsDict={} statsDict['expoCount'] = int(Expedition.objects.count()) diff --git a/media/css/main3.css b/media/css/main3.css index 752d813..8cdcdcc 100644 --- a/media/css/main3.css +++ b/media/css/main3.css @@ -55,7 +55,7 @@ div#content div#footer { clear:both; - background-color:black; + background-color:#999; color:white; text-align:center; margin-left:auto; @@ -294,6 +294,17 @@ td { } +.redtext{ + color:#F00; + } + +a.redtext:link { + color:#F00; + +} + +.redtext + .menuBarItem { font-variant: small-caps; text-align: right; diff --git a/parsers/QMs.py b/parsers/QMs.py index bad95a7..c7e6789 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -33,9 +33,9 @@ def parseCaveQMs(cave,pathToCSV): year=int(line[0][1:5]) #check if placeholder exists for given year, create it if not if cave=='stein': - placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, text="placeholder for QMs in 204", defaults={"date": date(year, 1, 1),"cave":steinBr}) + placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 204", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":steinBr}) elif cave=='hauch': - placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, text="placeholder for QMs in 234", defaults={"date": date(year, 1, 1),"cave":hauchHl}) + placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 234", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":hauchHl}) if hadToCreate: print cave+" placeholder logbook entry for " + str(year) + " added to database" QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb") diff --git a/templates/base.html b/templates/base.html index 8c79f87..bf31676 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,16 +3,12 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/main3.css" /> - <title>{% block title %}THE TITLE{% endblock %}</title> - <script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script> {% block head %}{% endblock %} </head> - <body> - -<div> +<div class="wrapper"> <div id="expoHeader"> <img id="frontPageBanner" src="{{ settings.MEDIA_URL }}loserBanner.jpg"/> <div id="expoHeaderText"> <h1>CUCC Expeditions to Austria: 1976 - </h1> @@ -22,46 +18,28 @@ </div> </div> <hr/> - <div id="editLink"> - {% block loginInfo %} - {% if user.username %} - You are logged in as {{ user.username }}. - | <a href="{{ settings.URL_ROOT }}/accounts/logout">Log out</a> - {% else %} - <a href="{{ settings.URL_ROOT }}/accounts/register">Sign up</a> - | <a href="{{ settings.URL_ROOT }}/accounts/login">Log in</a> - {% endif %} + <div id="editLink"> {% block loginInfo %} + {% if user.username %} + You are logged in as {{ user.username }}. + | <a href="{{ settings.URL_ROOT }}/accounts/logout/">Log out</a> {% else %} <a href="{{ settings.URL_ROOT }}/accounts/register">Sign up</a> | <a href="{{ settings.URL_ROOT }}/accounts/login/">Log in</a> {% endif %} {% endblock%} | <a href="{{ settings.URL_ROOT }}">Home </a> | - {% block editLink %} - - {% endblock %} - </div> -</div> - - - + {% block editLink %} + + {% endblock %} </div> {% block nav %} <!-- Use id="nav" for the left side menu --> - {% endblock %} - - - -<div id="content" > -{% block contentheader %} -{% endblock %} -{% block content %} + {% endblock %} + <div id="content" > {% block contentheader %} + {% endblock %} + {% block content %} REPLACE : The content -{% endblock %} -<br class="clearfloat" /> <!--This is to ensure that the content div expands around floated objects*/--> + {% endblock %} <br class="clearfloat" /> + <!--This is to ensure that the content div expands around floated objects*/--> + </div> </div> - - -<div id="footer"> -{% block footer %} - THE FOOTER -{% endblock %} +<div class="push"></div> </div> +<div id="footer"> {% block footer %} <a href="http://cucc.survex.com"> CUCC website</a>| <a href="http://cucc.survex.com/expo"> Expedition website </a>| <a href="{% url frontpage %}"> Troggle front page </a>| <a href="{% url caveindex %}"> All caves </a>| <a href="{% url personindex %}"> All cavers </a>| <a href="{% url caveindex %}"> Virtual survey binder </a>| <a href="{% url survey %}"> Expedition statistics </a>| <a href="{% url calendar 2007 %}"> Expedition calendar </a> {% endblock %} </div> </body> </html> - diff --git a/templates/logbookentry.html b/templates/logbookentry.html index 5b972e8..812197a 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -56,6 +56,7 @@ </tr> {% endfor %} </table> +<a href="{{newQMlink}}">Add QM found on this trip</a> </div> <div id="col1"> diff --git a/templates/qm.html b/templates/qm.html index db3edc4..06e6e0e 100644 --- a/templates/qm.html +++ b/templates/qm.html @@ -18,6 +18,7 @@ {% endblock %} {% block content %} + <h3>Location</h3> {{qm.location_description}} diff --git a/templates/registration/registration_complete.html b/templates/registration/registration_complete.html index 5351574..263cce8 100644 --- a/templates/registration/registration_complete.html +++ b/templates/registration/registration_complete.html @@ -9,5 +9,5 @@ registration_complete.html | {{ block.super }} {% endblock %} {% block content %} -Thank you for signing up, {{ user.username }}. An email with the activation code has been sent to your inbox. If you have been on the expedition in the past, you already have a profile in the system; <a href={% url profiles_select_profile %}>click here </a> to find it and link it to your account. Otherwise, please <a href={% url profiles_create_profile %}> create yourself a new profile</a>. If you have been on the expedition in the past, this step allows existing expedition data to be linked to your new account. +Thank you for signing up, {{ user.username }}. An email with the activation code has been sent to your inbox. If you have been on the expedition in the past, you already have a profile in the system; <a href={% url profiles_select_profile %}>click here </a> to find it and link it to your account. Otherwise, please <a href={% url profiles_create_profile %}> create yourself a new profile</a>. {% endblock %} \ No newline at end of file diff --git a/urls.py b/urls.py index 21da230..978493f 100644 --- a/urls.py +++ b/urls.py @@ -4,7 +4,8 @@ import troggle.settings as settings from expo.views import * # flat import from expo.views_caves import * from expo.views_survex import * - +from expo.models import * +from django.views.generic.create_update import create_object from django.contrib import admin admin.autodiscover() @@ -41,7 +42,7 @@ urlpatterns = patterns('', url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"), url(r'^cave/(?P<cave_id>[^/]+)/?$', views_caves.cavehref), - url(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d\d)?$', views_caves.qm), + url(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d\d)(?P<grade>[ABCDX]?)?$', views_caves.qm, name="qm"), (r'^survex/(?P<survex_file>.*)\.svx$', svx), (r'^survex/(?P<survex_file>.*)\.3d$', threed), (r'^survex/(?P<survex_file>.*)\.log$', log), @@ -59,7 +60,8 @@ urlpatterns = patterns('', url(r'^survey/(?P<year>\d\d\d\d)\#(?P<wallet_number>\d*)$', survey, name="survey"), (r'^admin/doc/?', include('django.contrib.admindocs.urls')), - (r'^admin/(.*)', admin.site.root), + + url(r'^admin/', include(admin.site.urls),name="admin"), (r'^accounts/', include('registration.urls')), (r'^profiles/', include('profiles.urls')),