diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-06 08:31:24 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-07-06 08:31:24 +0100 |
commit | bfa202078b17494d5dc7b92633dc697541b2b417 (patch) | |
tree | e5f128f3318a831defdbf5639520eadb8525544b /core/views_other.py | |
parent | ff199f0d2f15bdd23e9036ae17a840387c730d1b (diff) | |
download | troggle-bfa202078b17494d5dc7b92633dc697541b2b417.tar.gz troggle-bfa202078b17494d5dc7b92633dc697541b2b417.tar.bz2 troggle-bfa202078b17494d5dc7b92633dc697541b2b417.zip |
[svn] * Make Q< wikilinks work again
* Add new ajax bit in LogbookEntry admin which checks for QMs not in wikilink format and allows one click fixes. Soon to be expanded to check for wikilinks that aren't in foreignkey.
* Tweaks to admin including using raw_id_fields for PersonExpedition & other foreignkeyed models with lots of instances.
Diffstat (limited to 'core/views_other.py')
-rw-r--r-- | core/views_other.py | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/core/views_other.py b/core/views_other.py index 4a10a53..b2bc9cd 100644 --- a/core/views_other.py +++ b/core/views_other.py @@ -1,5 +1,5 @@ -from troggle.core.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo
-import troggle.settings as settings
+from troggle.core.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo, QM
+from django.conf import settings
from django import forms
from django.template import loader, Context
from django.db.models import Q
@@ -146,7 +146,7 @@ def ajax_test(request): mimetype="application/json")
def eyecandy(request):
- return render_with_context(request,'eyecandy.html', {})
+ return
def ajax_QM_number(request):
if request.method=='POST':
@@ -156,4 +156,55 @@ def ajax_QM_number(request): print exp
res=cave.new_QM_number(exp.year)
- return HttpResponse(res)
\ No newline at end of file + return HttpResponse(res)
+
+def logbook_entry_suggestions(request):
+ """
+ Generates a html box with suggestions about what to do with QMs
+ in logbook entry text.
+ """
+ unwiki_QM_pattern=r"(?P<whole>(?P<explorer_code>[ABC]?)(?P<cave>\d*)-?(?P<year>\d\d\d?\d?)-(?P<number>\d\d)(?P<grade>[ABCDXV]?)(?=\s))"
+ unwiki_QM_pattern=re.compile(unwiki_QM_pattern)
+ wikilink_QM_pattern=settings.QM_PATTERN
+
+ slug=request.POST['slug']
+ date=request.POST['date']
+ lbo=LogbookEntry.objects.get(slug=slug, date=date)
+
+ #unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
+ unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
+
+ print unwiki_QMs
+ for qm in unwiki_QMs:
+ if len(qm['year'])==2:
+ if int(qm['year'])<50:
+ qm['year']='20'+qm['year']
+ else:
+ qm['year']='19'+qm['year']
+
+ temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
+ try:
+ temp_QM.grade=unwiki_QM['grade']
+ except:
+ pass
+ qm['wikilink']=temp_QM.wiki_link()
+
+ print unwiki_QMs
+
+
+ wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
+ attached_QMs=lbo.QMs_found.all()
+ unmentioned_attached_QMs=''#not implemented, fill this in by subtracting wiklink_QMs from attached_QMs
+
+ #Find unattached_QMs. We only look at the QMs with a proper wiki link.
+ #for qm in wikilink_QMs:
+ #Try to look up the QM.
+
+ print 'got 208'
+ any_suggestions=True
+ print 'got 210'
+ return render_with_context(request,'suggestions.html',
+ {
+ 'unwiki_QMs':unwiki_QMs,
+ 'any_suggestions':any_suggestions
+ })
\ No newline at end of file |