mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
[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.
This commit is contained in:
parent
8a9eb32aaf
commit
8ad044cb2c
@ -2,7 +2,6 @@ from troggle.core.models import *
|
||||
from django.contrib import admin
|
||||
from django.forms import ModelForm
|
||||
import django.forms as forms
|
||||
from core.forms import LogbookEntryForm
|
||||
from django.http import HttpResponse
|
||||
from django.core import serializers
|
||||
from core.views_other import downloadLogbook
|
||||
@ -42,6 +41,7 @@ class QMsFoundInline(admin.TabularInline):
|
||||
model=QM
|
||||
fk_name='found_by'
|
||||
fields=('number','grade','location_description','comment')#need to add foreignkey to cave part
|
||||
extra=1
|
||||
|
||||
class PhotoInline(admin.TabularInline):
|
||||
model = Photo
|
||||
@ -51,6 +51,7 @@ class PhotoInline(admin.TabularInline):
|
||||
class PersonTripInline(admin.TabularInline):
|
||||
model = PersonTrip
|
||||
exclude = ['persontrip_next','Delete']
|
||||
raw_id_fields = ('person_expedition',)
|
||||
extra = 1
|
||||
|
||||
#class LogbookEntryAdmin(VersionAdmin):
|
||||
@ -59,8 +60,10 @@ class LogbookEntryAdmin(TroggleModelAdmin):
|
||||
search_fields = ('title','expedition__year')
|
||||
date_heirarchy = ('date')
|
||||
inlines = (PersonTripInline, PhotoInline, QMsFoundInline)
|
||||
form = LogbookEntryForm
|
||||
|
||||
class Media:
|
||||
css = {
|
||||
"all": ("css/troggleadmin.css",)
|
||||
}
|
||||
actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt')
|
||||
|
||||
def export_logbook_entries_as_html(modeladmin, request, queryset):
|
||||
@ -87,6 +90,7 @@ class QMAdmin(TroggleModelAdmin):
|
||||
list_display_links = ('__unicode__',)
|
||||
list_editable = ('found_by','ticked_off_by','grade')
|
||||
list_per_page = 20
|
||||
raw_id_fields=('found_by','ticked_off_by')
|
||||
|
||||
class PersonExpeditionAdmin(TroggleModelAdmin):
|
||||
search_fields = ('person__first_name','expedition__year')
|
||||
|
@ -549,7 +549,7 @@ class QM(TroggleModel):
|
||||
return u"%s %s" % (self.code(), self.grade)
|
||||
|
||||
def code(self):
|
||||
return u"%s-%s-%s" % (self.found_by.date.year, self.found_by.cave, self.number
|
||||
return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number)
|
||||
|
||||
def get_absolute_url(self):
|
||||
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
||||
@ -562,10 +562,7 @@ class QM(TroggleModel):
|
||||
return QM.objects.get(id=self.id-1)
|
||||
|
||||
def wiki_link(self):
|
||||
res = '[[cave:' + str(self.found_by.cave.kataster_number) + ' '
|
||||
res += 'QM:' + str(self.found_by.date.year) + '-'
|
||||
res += str(self.number) + self.grade + ']]'
|
||||
return res
|
||||
return u"%s%s%s" % ('[[QM:',self.code(),']]')
|
||||
|
||||
photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
|
||||
class Photo(TroggleImageModel):
|
||||
|
@ -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 core.models import QM, Photo
|
||||
from core.models import QM, Photo, LogbookEntry, Cave
|
||||
import re, urlparse
|
||||
|
||||
register = template.Library()
|
||||
@ -79,14 +79,23 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
[[QM:C204-1999-24]]
|
||||
If the QM does not exist, the function will return a link for creating it.
|
||||
"""
|
||||
qmdict={'urlroot':url_root,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]}
|
||||
qmdict={'urlroot':url_root,'cave':matchobj.groups()[1],'year':matchobj.groups()[2],'number':matchobj.groups()[3]}
|
||||
try:
|
||||
qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
|
||||
found_by__date__year = qmdict['year'],
|
||||
number = qmdict['number'])
|
||||
return r'<a href="%s" id="q%s">%s %s</a>' % ("insert url lookup here", qm.code, unicode(qm))
|
||||
except QM.DoesNotExist:
|
||||
return 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 r'<a href="%s" id="q%s">%s</a>' % (qm.get_absolute_url(), qm.code, unicode(qm))
|
||||
except QM.DoesNotExist: #bother aaron to make him clean up the below code
|
||||
try:
|
||||
placeholder=LogbookEntry.objects.get(date__year=qmdict['year'],cave__kataster_number=qmdict['cave'], title__icontains='placeholder')
|
||||
except LogbookEntry.DoesNotExist:
|
||||
placeholder=LogbookEntry(
|
||||
date='01-01'+qmdict['year'],
|
||||
cave=Cave.objects.get(kataster_number=qmdict['cave']),
|
||||
title='placeholder'
|
||||
)
|
||||
qm=QM(found_by = placeholder, number = qmdict['number'])
|
||||
return r'<a class="redtext" href="%s" id="q%s">%s %s</a>' % (qm.get_absolute_url, qm.code, unicode(qm))
|
||||
|
||||
value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL)
|
||||
|
||||
|
@ -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)
|
||||
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
|
||||
})
|
@ -1,5 +1,6 @@
|
||||
$(document).ready(function(){
|
||||
|
||||
/*begin ajax query stuff for getting next QM number*/
|
||||
$('.number:first').append("<a href='javascript:void(0)' class='next_qm_link'>get next number</a>");
|
||||
|
||||
new_qm_link=function(e){
|
||||
@ -16,5 +17,63 @@ alert('Please choose a cave and try again.')
|
||||
};
|
||||
|
||||
$('.next_qm_link').bind("click", new_qm_link);
|
||||
/*end ajax query stuff for getting next QM number*/
|
||||
|
||||
/*begin ajax query stuff for getting suggestions view*/
|
||||
|
||||
|
||||
|
||||
suggestions_query=function(){
|
||||
slug=$('#id_slug')[0].value;
|
||||
date=$('#id_date')[0].value;
|
||||
$.post('/lbo_suggestions/',{'slug':slug,'date':date}, function(data){
|
||||
if ($('#suggestions').length>0){
|
||||
$('#suggestions').replaceWith(data);
|
||||
}
|
||||
else{
|
||||
$('#id_text').parent().append(data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$('#id_text').parent().append("<a href='javascript:void(0)' class='update_suggestions'>get / update suggestions</a>");
|
||||
|
||||
$(".update_suggestions").bind("click", suggestions_query);
|
||||
|
||||
replace=function(from,to){
|
||||
$('#id_text').text($('#id_text').text().replace(from,to))
|
||||
$('[name=_continue]').click()
|
||||
|
||||
}
|
||||
|
||||
suggestions_query();
|
||||
/*end*/
|
||||
|
||||
|
||||
|
||||
/*begin reccomendations stuff*/
|
||||
|
||||
|
||||
/*search for QMs
|
||||
suspect_QMs=$('#id_text')[0].value.match(/\b(\d\d)-(\d\d\w?)\b/g);
|
||||
linked_QMs=
|
||||
|
||||
$('#suggestions').append(
|
||||
"\
|
||||
<h2>May I reccomend:</h2>\
|
||||
Putting in wikilinks for the following QMs:\
|
||||
"
|
||||
);
|
||||
$('#suggestions').append('<li>'+suspect_QMs.join('</li><li>')+</li>);*/
|
||||
|
||||
|
||||
/*end reccomendations stuff*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
4
urls.py
4
urls.py
@ -2,6 +2,7 @@ from django.conf.urls.defaults import *
|
||||
from django.conf import settings
|
||||
|
||||
from core.views import * # flat import
|
||||
from core.views_other import *
|
||||
from core.views_caves import *
|
||||
from core.views_survex import *
|
||||
from core.models import *
|
||||
@ -17,8 +18,9 @@ urlpatterns = patterns('',
|
||||
|
||||
url(r'^caves/?$', views_caves.caveindex, name="caveindex"),
|
||||
url(r'^people/?$', views_logbooks.personindex, name="personindex"),
|
||||
|
||||
|
||||
url(r'^newqmnumber/?$', views_other.ajax_QM_number, ),
|
||||
url(r'^lbo_suggestions/?$', logbook_entry_suggestions),
|
||||
#(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person),
|
||||
url(r'^person/(?P<first_name>[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"),
|
||||
#url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"),
|
||||
|
Loading…
Reference in New Issue
Block a user