[svn] * Fix bugs that were causing broken wikilinks. *Add edit link to mugshots. *make admin url trailing-slash tolerant

This commit is contained in:
substantialnoninfringinguser 2009-06-12 05:39:30 +01:00
parent 5946e159bc
commit 9b44731c33
7 changed files with 25 additions and 15 deletions

View File

@ -38,7 +38,8 @@ class TroggleImageModel(ImageModel):
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

View File

@ -4,10 +4,12 @@ from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.conf import settings
from expo.models import QM
import re
import re, urlparse
register = template.Library()
if settings.URL_ROOT.endswith('/'):
url_root=settings.URL_ROOT[:-1]
def wiki_list(line, listdepth):
l = ""
for d in listdepth:
@ -48,7 +50,9 @@ def wiki_to_html(value, autoescape=None):
@stringfilter
def wiki_to_html_short(value, autoescape=None):
"""
This is the tag which turns wiki syntax into html. Aaron wonders why it is called "short." It is long, and it operates on long things.
This is the tag which turns wiki syntax into html. Aaron wonders
why it is called "short." It is long, and it operates on long things.
It even has a long name itself.
"""
if autoescape:
value = conditional_escape(value)
@ -59,9 +63,9 @@ def wiki_to_html_short(value, autoescape=None):
value = re.sub("&#39;&#39;&#39;([^']+)&#39;&#39;&#39;", r"<b>\1</b>", value, re.DOTALL)
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)
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL)
#make people links
value = re.sub("\[\[\s*person:(.+)\]\]",r'<a href="%s/person/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL)
value = re.sub("\[\[\s*person:(.+)\]\]",r'<a href="%s/person/\1/">\1</a>' % url_root, value, re.DOTALL)
#make qm links. this takes a little doing
qmMatchPattern="\[\[\s*cave:([^\s]+)\s*\s*\QM:(\d*)-(\d*)([ABCDX]?)\]\]"
@ -77,7 +81,7 @@ def wiki_to_html_short(value, autoescape=None):
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}
qmdict={'urlroot':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>'

View File

@ -25,7 +25,7 @@ def caveindex(request):
def cave(request, cave_id='', offical_name=''):
cave=getCave(cave_id)
if cave.non_public:
if cave.non_public and not request.user.is_authenticated():
return render_response(request,'nonpublic.html', {'instance': cave})
else:
return render_response(request,'cave.html', {'cave': cave})

View File

@ -98,9 +98,13 @@ def newQMlink(logbookentry):
return settings.URL_ROOT + r'/admin/expo/qm/add/?' + r'found_by=' + str(logbookentry.pk) +'&number=' + str(nextQMnumber)
def logbookentry(request, date, slug):
logbookentry = LogbookEntry.objects.get(date=date, slug=slug)
return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink(logbookentry)})
logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
if len(logbookentry)>1:
return render_response(request, 'object_list.html',{'object_list':logbookentry})
else:
logbookentry=logbookentry[0]
return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink(logbookentry)})
def logbookSearch(request, extra):
query_string = ''

View File

@ -1,9 +1,9 @@
{% extends "base.html" %}
{% load link %}
{% block title %}Troggle: all {{object_list.1.meta.object_name}} objects{%endblock%}
{% block title %}Troggle: {{object_list.1.meta.object_name}} objects{%endblock%}
{% block contentheader %}
<h1>All {{object_list.0.object_name}} objects</h1>
<h1>{{object_list.0.object_name}} objects</h1>
{% endblock contentheader %}
{% block content %}

View File

@ -18,7 +18,8 @@
{% if pic.is_mugshot %}
<div class="figure">
<p> <img src="{{ pic.thumbnail_image.url }}" class="thumbnail" />
<p> {{ pic.caption }}
<p> {{ pic.caption }}</p>
<p> <a href="{{ pic.get_admin_url }}">edit {{pic}}</a> </>
</p>
</p>
</div>

View File

@ -67,7 +67,7 @@ urlpatterns = patterns('',
url(r'^cave/(?P<cave_id>[^/]+)(?P<subcave>/.*)/?$', subcave, name="subcave"),
(r'^admin/doc/?', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root),
(r'^admin/(.*)/?', admin.site.root),
#url(r'^admin/', include(admin.site.urls),name="admin"),
(r'^accounts/', include('registration.urls')),