[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:
substantialnoninfringinguser 2009-06-10 05:37:53 +01:00
parent d89a4b6958
commit eed4fea255
8 changed files with 79 additions and 46 deletions

View File

@ -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,7 +30,6 @@ class SurveyAdmin(TroggleModelAdmin):
search_fields = ('expedition__year','wallet_number')
class QMsFoundInline(admin.TabularInline):
#form=QMsFoundInlineForm
model=QM
fk_name='found_by'

View File

@ -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>')
@ -38,14 +46,3 @@ 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

View File

@ -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
@ -364,8 +364,6 @@ class Cave(TroggleModel):
#return settings.URL_ROOT + '/cave/' + 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 += "&ndash;" + 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)

View File

@ -57,11 +57,20 @@ def wiki_to_html_short(value, autoescape=None):
value = re.sub("&#39;&#39;([^']+)&#39;&#39;", 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):
"""
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=''
@ -74,7 +83,7 @@ def wiki_to_html_short(value, autoescape=None):
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:

View File

@ -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."""
@ -33,7 +33,7 @@ def qm(request,cave_id,qm_id,year,grade=None):
return render_response(request,'qm.html',locals())
except QM.DoesNotExist:
url= settings.URL_ROOT + r'/admin/expo/qm/add/?'+ r'number=' + qm_id
url=urlparse.urljoin(settings.URL_ROOT, r'/admin/expo/qm/add/'+'?'+ r'number=' + qm_id)
if grade:
url += r'&grade=' + grade
return HttpResponseRedirect(url)

View File

@ -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;
}

View File

@ -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 %}

View File

@ -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"),