diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-02 04:10:51 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-02 04:10:51 +0100 |
commit | 5baddea474b068ece9d6b93bcc90f4d76f97e5a3 (patch) | |
tree | 8d6513d80f13bc2ea278e4a925c11c1db2bdf53d | |
parent | 3e377eb32ebd1b3b4d1663655c26ab25c75afe84 (diff) | |
download | troggle-5baddea474b068ece9d6b93bcc90f4d76f97e5a3.tar.gz troggle-5baddea474b068ece9d6b93bcc90f4d76f97e5a3.tar.bz2 troggle-5baddea474b068ece9d6b93bcc90f4d76f97e5a3.zip |
[svn] Add photos wiki syntaxes: e.g.
[[display:centre photo:andyc.jpg]] where centre is a class applied to image, and andyc.jpg is the filename of a Photo model instance. Image will be displayed as thumbnail with link to full size image.
[[photo:andyc.jpg]] will produce a link to the admin page for the andyc.jpg Photo model instance.
[[photo:andyc.jpg Title of the link]] will produce a link to the admin page for the andyc.jpg Photo model instance with link text "Title of the link"
-rw-r--r-- | README.txt | 7 | ||||
-rw-r--r-- | expo/templatetags/wiki_markup.py | 51 | ||||
-rw-r--r-- | parsers/QMs.py | 6 |
3 files changed, 45 insertions, 19 deletions
@@ -23,4 +23,9 @@ svn co http://troggle.googlecode.com/svn/ If you want to work on the source code and be able to commit, you will need to use https instead of http, and your google account will need to be added to the troggle project members list. Contact aaron dot curtis at cantab dot net to get this set up.
-Next, you need to fill in your local settings. Copy either localsettingsubuntu.py or localsettingsserver.py to a new file called localsettings.py. Follow the instructions contained in the file to fill out your settings.
\ No newline at end of file +Next, you need to fill in your local settings. Copy either localsettingsubuntu.py or localsettingsserver.py to a new file called localsettings.py. Follow the instructions contained in the file to fill out your settings.
+
+
+Importing legacy data
+---------------------
+Once troggle is running, log in and then go to "Import / export" data under "admin" on the menu
\ No newline at end of file diff --git a/expo/templatetags/wiki_markup.py b/expo/templatetags/wiki_markup.py index 8910065..4bcd07d 100644 --- a/expo/templatetags/wiki_markup.py +++ b/expo/templatetags/wiki_markup.py @@ -3,7 +3,7 @@ from django.utils.html import conditional_escape from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.conf import settings
-from expo.models import QM
+from expo.models import QM, Photo
import re, urlparse
register = template.Library()
@@ -76,30 +76,51 @@ def wiki_to_html_short(value, autoescape=None): [[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 there are four matched groups, the fourth one should be the QM grade
if len(matchobj.groups())==4:
- # if there are four matched groups, then
grade=matchobj.groups()[3]
else:
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>'
+ res=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
+ res = 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 res
value = re.sub(qmMatchPattern,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 photo links for [[photo:filename]] or [[photo:filename linktext]], and
+ #insert photos for [[display:left photo:filename]]
+ photoLinkPattern="\[\[\s*photo:(?P<photoName>[^\s]+)\s*(?P<linkText>.*)\]\]"
+ photoSrcPattern="\[\[\s*display:(?P<style>[^\s]+) photo:(?P<photoName>[^\s]+)\s*\]\]"
+ def photoLinkRepl(matchobj):
+ matchdict=matchobj.groupdict()
+ try:
+ linkText=matchdict['linkText']
+ except KeyError:
+ linkText=None
+
+ try:
+ photo=Photo.objects.get(file=matchdict['photoName'])
+ if not linkText:
+ linkText=str(photo)
+ res=r'<a href=' + photo.get_admin_url() +'>' + linkText + '</a>'
+ except Photo.DoesNotExist:
+ res = r'<a class="redtext" href="">make new photo</a>'
+ return res
+
+ def photoSrcRepl(matchobj):
+ matchdict=matchobj.groupdict()
+ style=matchdict['style']
+ try:
+ photo=Photo.objects.get(file=matchdict['photoName'])
+ res=r'<a href='+photo.file.url+'><img src=' + photo.thumbnail_image.url +' class='+style+' /></a>'
+ except Photo.DoesNotExist:
+ res = r'<a class="redtext" href="">make new photo</a>'
+ return res
+ value = re.sub(photoLinkPattern,photoLinkRepl, value, re.DOTALL)
+ value = re.sub(photoSrcPattern,photoSrcRepl, value, re.DOTALL)
#Make lists from lines starting with lists of [stars and hashes]
outValue = ""
diff --git a/parsers/QMs.py b/parsers/QMs.py index 571ec28..ef38c3f 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -82,9 +82,9 @@ def parseCaveQMs(cave,inputFile): except KeyError: #check on this one continue -# except IndexError: -# print "Index error in " + str(line) -# continue + except IndexError: + print "Index error in " + str(line) + continue def parse_KH_QMs(kh, inputFile): """import QMs from the 1623-161 (Kaninchenhöhle) html pages |