summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/models.py25
-rw-r--r--core/templatetags/wiki_markup.py6
2 files changed, 27 insertions, 4 deletions
diff --git a/core/models.py b/core/models.py
index facc5ff..7c23ad9 100644
--- a/core/models.py
+++ b/core/models.py
@@ -1,4 +1,4 @@
-import urllib, urlparse, string, os, datetime, logging
+import urllib, urlparse, string, os, datetime, logging, re
from django.forms import ModelForm
from django.db import models
from django.contrib import admin
@@ -13,6 +13,21 @@ getcontext().prec=2 #use 2 significant figures for decimal calculations
from models_survex import *
+def get_related_by_wikilinks(wiki_text):
+ found=re.findall(settings.QM_PATTERN,wiki_text)
+ res=[]
+ for wikilink in found:
+ qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
+ try:
+ qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
+ found_by__date__year = qmdict['year'],
+ number = qmdict['number'])
+ res.append(qm)
+ except QM.DoesNotExist:
+ print 'fail on '+str(wikilink)
+
+ return res
+
logging.basicConfig(level=logging.DEBUG,
filename=settings.LOGFILE,
filemode='w')
@@ -524,6 +539,14 @@ class CaveDescription(TroggleModel):
def get_absolute_url(self):
return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
+
+ def save(self):
+ super(CaveDescription, self).save()
+ qm_list=get_related_by_wikilinks(self.description)
+ print qm_list
+ for qm in qm_list:
+ self.linked_qms.add(qm)
+ super(CaveDescription, self).save()
class NewSubCave(TroggleModel):
name = models.CharField(max_length=200, unique = True)
diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py
index b4d97ac..ec8a997 100644
--- a/core/templatetags/wiki_markup.py
+++ b/core/templatetags/wiki_markup.py
@@ -40,7 +40,7 @@ def wiki_list(line, listdepth):
def wiki_to_html(value, autoescape=None):
"""
This is the tag which turns wiki syntax into html. It is intended for long pieces of wiki.
- Hence it splits the wiki into paragraphs double line feeds.
+ Hence it splits the wiki into HTML paragraphs based on double line feeds.
"""
#find paragraphs
outValue = ""
@@ -55,7 +55,7 @@ def wiki_to_html(value, autoescape=None):
def wiki_to_html_short(value, autoescape=None):
"""
This is the tag which turns wiki syntax into html. It is intended for short pieces of wiki.
- Hence it is not split the wiki into paragraphs using where it find double line feeds.
+ Hence it is not split the wiki into paragraphs using where it finds double line feeds.
"""
if autoescape:
value = conditional_escape(value)
@@ -71,7 +71,7 @@ def wiki_to_html_short(value, autoescape=None):
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*[Qq][Mm]:([ABC]?)(\d{4})-(\d*)-(\d*)\]\]"
+ qmMatchPattern=settings.QM_PATTERN
def qmrepl(matchobj):
"""
A function for replacing wikicode qm links with html qm links.