diff --git a/expo/admin.py b/expo/admin.py index ffa00c5..1ef2fbf 100644 --- a/expo/admin.py +++ b/expo/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from feincms.admin import editor from django.forms import ModelForm import django.forms as forms -from expo.forms import LogbookEntryForm, QMsFoundInlineForm +from expo.forms import LogbookEntryForm from django.http import HttpResponse from django.core import serializers #from troggle.reversion.admin import VersionAdmin #django-reversion version control @@ -30,13 +30,12 @@ class SurveyAdmin(TroggleModelAdmin): search_fields = ('expedition__year','wallet_number') class QMsFoundInline(admin.TabularInline): - #form=QMsFoundInlineForm - model=QM - fk_name='found_by' + model=QM + fk_name='found_by' class QMsTickedOffInline(admin.TabularInline): - model=QM - fk_name='ticked_off_by' + model=QM + fk_name='ticked_off_by' class PhotoInline(admin.TabularInline): model = Photo diff --git a/expo/forms.py b/expo/forms.py index 9573c18..929c4e9 100644 --- a/expo/forms.py +++ b/expo/forms.py @@ -4,6 +4,7 @@ import django.forms as forms from django.forms.formsets import formset_factory from django.contrib.admin.widgets import AdminDateWidget import string +from datetime import date class CaveForm(ModelForm): class Meta: @@ -18,6 +19,13 @@ class LogbookEntryForm(ModelForm): model = LogbookEntry def wikiLinkHints(LogbookEntry=None): + """ + This function returns html-formatted paragraphs for each of the + wikilink types that are related to this logbookentry. Each paragraph + contains a list of all of the related wikilinks. + + Perhaps an admin javascript solution would be better. + """ res = ["Please use the following wikilinks, which are related to this logbook entry:"] res.append(r'

QMs found:') @@ -37,15 +45,4 @@ class LogbookEntryForm(ModelForm): def __init__(self, *args, **kwargs): super(LogbookEntryForm, self).__init__(*args, **kwargs) - self.fields['text'].help_text=self.wikiLinkHints() - -class QMsFoundInlineForm(ModelForm): - class Meta: - model = QM - exclude = 'ticked_off_by' - - def __init__(self, *args, **kwargs): - super(QMsFoundInlineForm, self).__init__(*args, **kwargs) - #self.fields['number'].initial=nextQMinyear()#work on that one - - \ No newline at end of file + self.fields['text'].help_text=self.wikiLinkHints() \ No newline at end of file diff --git a/expo/models.py b/expo/models.py index 3ab53aa..ea73cd4 100644 --- a/expo/models.py +++ b/expo/models.py @@ -26,7 +26,7 @@ class TroggleModel(models.Model): return self._meta.object_name def get_admin_url(self): - return settings.URL_ROOT + "/admin/expo/" + self.object_name().lower() + "/" + str(self.pk) + return urlparse.urljoin(settings.URL_ROOT, "/admin/expo/" + self.object_name().lower() + "/" + str(self.pk)) class Meta: abstract = True @@ -362,10 +362,8 @@ class Cave(TroggleModel): else: href = official_name.lower() #return settings.URL_ROOT + '/cave/' + href + '/' - return urlparse.urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,})) + return urlparse.urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,})) - - def __unicode__(self): if self.kataster_number: if self.kat_area(): @@ -385,8 +383,10 @@ class Cave(TroggleModel): for a in self.area.all(): if a.kat_area(): return a.kat_area() + def entrances(self): return CaveAndEntrance.objects.filter(cave=self) + def entrancelist(self): rs = [] res = "" @@ -415,7 +415,12 @@ class Cave(TroggleModel): res += "–" + prevR return res - + def nextQMnumber(self, year=datetime.date.today().year): + """ + Given a cave and the current year, returns the next QM number. + """ + res=QM.objects.filter(found_by__date__year=year, found_by__cave=self).order_by('-number')[0] + return res.number+1 class OtherCaveName(TroggleModel): name = models.CharField(max_length=160) diff --git a/expo/templatetags/wiki_markup.py b/expo/templatetags/wiki_markup.py index 30c9a08..eeacced 100644 --- a/expo/templatetags/wiki_markup.py +++ b/expo/templatetags/wiki_markup.py @@ -57,24 +57,33 @@ def wiki_to_html_short(value, autoescape=None): value = re.sub("''([^']+)''", r"\1", value, re.DOTALL) #make cave links value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'\1' % settings.URL_ROOT, value, re.DOTALL) + #make people links - #function for replacing wikicode qm links with html qm links + qmMatchPattern="\[\[\s*cave:([^\s]+)\s*\s*\QM:(\d*)-(\d*)([ABCDX]?)\]\]" + def qmrepl(matchobj): - if len(matchobj.groups())==4: - grade=matchobj.groups()[3] - else: - grade='' + """ + A function for replacing wikicode qm links with html qm links. + Given a matchobj matching a wikilink in the format + [[cave:204 QM:1999-24C]] where the grade (C) is optional. + If the QM does not exist, the function will return a link for creating it. + """ + if len(matchobj.groups())==4: + # if there are four matched groups, then + 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'' + str(qm) + '' - except QM.DoesNotExist: - url = r'%(cave)s:%(year)s-%(number)s%(grade)s' % qmdict + try: + qm=QM.objects.get(found_by__cave__kataster_number=qmdict['cave'],found_by__date__year=qmdict['year'], number=qmdict['number']) + url=r'' + str(qm) + '' + except QM.DoesNotExist: + url = r'%(cave)s:%(year)s-%(number)s%(grade)s' % qmdict return url #make qm links - value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\QM:(\d*)-(\d*)([ABCDX]?)\]\]",qmrepl, value, re.DOTALL) + value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL) #qms=qmfinder.search(value) #for qm in qms: diff --git a/expo/views_caves.py b/expo/views_caves.py index 64ec6e2..10355d6 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -7,7 +7,7 @@ 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 -import re +import re, urlparse 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.""" @@ -30,13 +30,13 @@ def qm(request,cave_id,qm_id,year,grade=None): year=int(year) try: qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) - return render_response(request,'qm.html',locals()) + 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) + url=urlparse.urljoin(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): @@ -87,9 +87,9 @@ def survey(request,year,wallet_number): current_expedition=Expedition.objects.filter(year=year)[0] if wallet_number!='': - current_survey=Survey.objects.filter(expedition=current_expedition,wallet_number=wallet_number)[0] - notes=current_survey.scannedimage_set.filter(contents='notes') - planSketches=current_survey.scannedimage_set.filter(contents='plan') - elevationSketches=current_survey.scannedimage_set.filter(contents='elevation') + current_survey=Survey.objects.filter(expedition=current_expedition,wallet_number=wallet_number)[0] + notes=current_survey.scannedimage_set.filter(contents='notes') + planSketches=current_survey.scannedimage_set.filter(contents='plan') + elevationSketches=current_survey.scannedimage_set.filter(contents='elevation') return render_response(request,'survey.html', locals()) diff --git a/media/css/main3.css b/media/css/main3.css index 3c229e0..4f0a3e8 100644 --- a/media/css/main3.css +++ b/media/css/main3.css @@ -405,3 +405,26 @@ div#related color:#666666; } +.addlink { + padding-left: 12px; + background: url(../icon_addlink.gif) 0 .2em no-repeat; +} + +.changelink { + padding-left: 12px; + background: url(../icon_changelink.gif) 0 .2em no-repeat; +} + +.deletelink { + padding-left: 12px; + background: url(../icon_deletelink.gif) 0 .25em no-repeat; +} + +a.deletelink:link, a.deletelink:visited { + color: #CC3434; +} + +a.deletelink:hover { + color: #993333; +} + diff --git a/templates/frontpage.html b/templates/frontpage.html index 20028a3..bf04709 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -20,7 +20,7 @@ {% if entry.is_deletion %} {{ entry.object_repr }} {% else %} - {{ entry.object_repr }} + {{ entry.object_repr }} {% endif %}
{% if entry.content_type %} diff --git a/urls.py b/urls.py index 8636b4b..50c9bbf 100644 --- a/urls.py +++ b/urls.py @@ -40,7 +40,7 @@ urlpatterns = patterns('', #(r'^cavesearch', caveSearch), - url(r'^cave/(?P[^/]+)/(?P\d\d\d\d)-(?P\d\d)(?P[ABCDX]?)?$', views_caves.qm, name="qm"), + url(r'^cave/(?P[^/]+)/(?P\d\d\d\d)-(?P\d*)(?P[ABCDX]?)?$', views_caves.qm, name="qm"), #url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"), url(r'^survex/(?P.*?)\.svx$', svx, name="svx"),