mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
[svn] Fixed a bug with QMs with numbers between 1 and 10, and fixed the links in the recent changes box.
This commit is contained in:
parent
4ce282b88b
commit
1d421b2d7c
@ -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
|
||||
|
@ -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'</p><p style="float: left;"><b>QMs found:</b>')
|
||||
@ -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
|
||||
|
||||
|
||||
self.fields['text'].help_text=self.wikiLinkHints()
|
@ -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)
|
||||
|
@ -57,24 +57,33 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
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/cave/\1/">\1</a>' % 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'<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
|
||||
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)
|
||||
value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL)
|
||||
|
||||
#qms=qmfinder.search(value)
|
||||
#for qm in qms:
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
{% if entry.is_deletion %}
|
||||
{{ entry.object_repr }}
|
||||
{% else %}
|
||||
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
|
||||
<a href="admin/{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
|
||||
{% endif %}
|
||||
<br/>
|
||||
{% if entry.content_type %}
|
||||
|
2
urls.py
2
urls.py
@ -40,7 +40,7 @@ urlpatterns = patterns('',
|
||||
#(r'^cavesearch', caveSearch),
|
||||
|
||||
|
||||
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"),
|
||||
url(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDX]?)?$', views_caves.qm, name="qm"),
|
||||
|
||||
#url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"),
|
||||
url(r'^survex/(?P<survex_file>.*?)\.svx$', svx, name="svx"),
|
||||
|
Loading…
Reference in New Issue
Block a user