mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 14:21:27 +00:00
[svn] override save for CaveDescriptions to scan qm wikilinks and add into the manytomany field linked_qms
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user