[svn r8163] More work on survey images parser and virtual survey binder. Renamed expedition_year field of Survey model to expedition because this makes more sense.

This commit is contained in:
aaron 2009-01-16 20:50:23 +01:00
parent 246bb42545
commit 014f390100
5 changed files with 147 additions and 32 deletions

View File

@ -303,8 +303,8 @@ class Photo(models.Model):
scansFileStorage = FileSystemStorage(location=settings.SURVEYS, base_url=settings.SURVEYS_URL)
def get_scan_path(instance, filename):
year=instance.survey.expedition_year.year
number="%02d" % instance.survey.wallet_number + instance.survey.wallet_letter #using %02d string formatting because convention was 2009#01
year=instance.survey.expedition.year
number="%02d" % instance.survey.wallet_number + str(instance.survey.wallet_letter) #using %02d string formatting because convention was 2009#01
return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg')
class ScannedImage(models.Model):
@ -328,7 +328,7 @@ class ScannedImage(models.Model):
return get_scan_path(self,'')
class Survey(models.Model):
expedition_year = models.ForeignKey('Expedition')
expedition = models.ForeignKey('Expedition')
wallet_number = models.IntegerField(blank=True,null=True)
wallet_letter = models.CharField(max_length=1,blank=True,null=True)
comments = models.TextField(blank=True,null=True)
@ -344,5 +344,13 @@ class Survey(models.Model):
integrated_into_main_sketch_by = models.ForeignKey('Person' ,related_name='integrated_into_main_sketch_by', blank=True,null=True)
rendered_image = models.ImageField(upload_to='renderedSurveys',blank=True,null=True)
def __str__(self):
return self.expedition_year.year+"#"+"%02d" % self.wallet_number
return self.expedition.year+"#"+"%02d" % self.wallet_number
def notes(self):
return self.scannedimage_set.filter(contents='notes')
def plans(self):
return self.scannedimage_set.filter(contents='plan')
def elevations(self):
return self.scannedimage_set.filter(contents='elevation')

View File

@ -1,5 +1,5 @@
from django.shortcuts import render_to_response
from troggle.expo.models import Cave, CaveAndEntrance, Survey
from troggle.expo.models import Cave, CaveAndEntrance, Survey, Expedition
import troggle.settings as settings
from troggle.expo.forms import CaveForm
import search
@ -35,14 +35,22 @@ def caveSearch(request):
def surveyindex(request):
surveys=Survey.objects.all()
return render_to_response('survey.html',{'settings':settings,'surveys':surveys})
expeditions=Expedition.objects.all()
dictToPass=locals()
dictToPass.update({'settings':settings})
return render_to_response('survey.html',dictToPass)
def survey(request,survey_id):
def survey(request,year,wallet_number):
surveys=Survey.objects.all()
current_survey=Survey.objects.get(pk=survey_id)
notes=current_survey.scannedimage_set.filter(contents='notes')
planSketches=current_survey.scannedimage_set.filter(contents='plan')
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
expeditions=Expedition.objects.all()
current_expedition=Expedition.objects.filter(year=year)[0]
if wallet_number!='':
current_survey=Survey.objects.filter(expedition=current_expedition,wallet_number=wallet_number)[0]
notes=current_survey.scannedimage_set.filter(contents='notes')
planSketches=current_survey.scannedimage_set.filter(contents='plan')
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
dictToPass=locals()
dictToPass.update({'settings':settings})

View File

@ -31,7 +31,7 @@ for survey in surveyreader:
# print walletNumberLetter.groups()
surveyobj = models.Survey(
expedition_year = models.Expedition.objects.filter(year=survey[header['Year']])[0],
expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0],
wallet_number = walletNumberLetter.group('number'),
comments = survey[header['Comments']],
@ -58,20 +58,23 @@ def parseSurveyScans(year):
for scan in scanList:
try:
scanChopped=re.match(r'([a-zA-Z]*)(\d*)\.(png|jpg|JPG|PNG)',scan).groups()
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
scanType,scanNumber,scanFormat=scanChopped
except AttributeError:
print scan + " ignored"
print "Adding scans: " + scan + " ignored"
continue
if scanType == 'elev' or scanType == 'extend':
scanType = 'elevation'
if scanNumber=='':
scanNumber=1
if type(surveyNumber)==types.TupleType:
surveyNumber=surveyNumber[0]
try:
survey=models.Survey.objects.get_or_create(wallet_number=surveyNumber, expedition_year=year)[0]
survey=models.Survey.objects.get_or_create(wallet_number=surveyNumber, expedition=year)[0]
except models.Survey.MultipleObjectsReturned:
survey=models.Survey.objects.filter(wallet_number=surveyNumber, expedition_year=year)[0]
survey=models.Survey.objects.filter(wallet_number=surveyNumber, expedition=year)[0]
scanObj = models.ScannedImage(
file=os.path.join(year.year, surveyFolder, scan),
@ -79,7 +82,7 @@ def parseSurveyScans(year):
number_in_wallet=scanNumber,
survey=survey
)
print "Added scanned image at " + str(scanObj)
#print "Added scanned image at " + str(scanObj)
scanObj.save()
for year in models.Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then

View File

@ -27,6 +27,14 @@ body {
background: #DDDDDD;
padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
}
table {
border: thin solid silver;
border-collapse: collapse;
}
td {
padding:0px;
border: thin solid silver;
}
.twoColHybLtHdr #header h1 {
margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
@ -117,7 +125,7 @@ img.thumbnail {
/* the above proprietary zoom property gives IE the hasLayout it may need to avoid several bugs */
</style>
<![endif]-->
</head>
<script language="javascript">
mnuItmLst=document.getElementsByClassName("menuBarItem")
function highlight(div){
@ -148,11 +156,18 @@ img.thumbnail {
div.style.backgroundColor="#666666";
}
function redirect(surveyPK){
window.location = "{{ settings.URL_ROOT }}/survey/" + surveyPK
function redirect(){
window.location = "{{ settings.URL_ROOT }}/survey/" + document.getElementById("expeditionChooser").value + "%23" + document.getElementById("surveyChooser").value;
document.getElementById("progressTableContent").style.display='hidden'
}
function redirectYear(){
window.location = "{{ settings.URL_ROOT }}/survey/" + document.getElementById("expeditionChooser").value + "%23"
}
</script>
</head>
<body class="twoColHybLtHdr">
<div id="header">
<h1>CUCC Expo virtual survey binder</h1>
@ -162,20 +177,33 @@ img.thumbnail {
<h3>Survey Stages for {{ current_survey }}</h3>
<br />
<select id="surveyChooser" onchange="redirect(this.value)">
{% for survey in surveys %}
<option label="{{ survey }}" value="{{ survey.pk }}"
{% ifequal survey current_survey %}
<select id="expeditionChooser" onchange="redirectYear()">
{% for expedition in expeditions %}
<option label="{{ expedition }}" value="{{ expedition }}"
{% ifequal expedition current_expedition %}
selected
{% endifequal %} >
{{ survey }}
{{ expedition }}
</option>
{% endfor %}
</select>
<select id="surveyChooser" onchange="redirectSurvey()">
<option label="show all" value="">
{% for survey in current_expedition.survey_set.all %}
<option label="{{ survey }}" value="{{ survey.wallet_number }}"
{% ifequal survey current_survey %}
selected
{% endifequal %} >
{{ survey }}
</option>
{% endfor %}
<option label="add" value="add">
</select>
<div id="status">
<div id="notes" class="menuBarItem" onmouseover="highlight(this)" onmouseout="unhighlight(this)" onclick="choose(this)"> {% if notes %}&#10003;{% endif %}
scanned notes </div>
@ -192,8 +220,76 @@ img.thumbnail {
<!-- end #sidebar1 -->
</div>
<div id="mainContent">
<div id="notesContent" class="behind">
<h2>Scanned notes for {{ current_survey }}.</h2>
<div id="progressTableContent" class="behind" style="display:block;">
<h3>
Status of surveys from {{ current_expedition }}
</h3>
<table>
<tr>
<th>
</th>
{% for survey in current_expedition.survey_set.all %}
<th>
{{ survey.wallet_number }}
</th>
{% endfor %}
</tr>
<tr>
<td>
Notes
</td>
{% for survey in current_expedition.survey_set.all %}
<td>
{% if survey.notes %}
&#10003;
{% endif %}
</td>
{% endfor %}
</tr>
<tr>
<td>
Survex file
</td>
{% for survey in current_expedition.survey_set.all %}
<td>
{% if survey.survex_file %}
&#10003;
{% endif %}
</td>
{% endfor %}
</tr>
<tr>
<td>
Plans
</td>
{% for survey in current_expedition.survey_set.all %}
<td>
{% if survey.plans %}
&#10003;
{% endif %}
</td>
{% endfor %}
</tr>
<tr>
<td>
Elevations
</td>
{% for survey in current_expedition.survey_set.all %}
<td>
{% if survey.elevations %}
&#10003;
{% endif %}
</td>
{% endfor %}
</tr>
</table>
</div>
<div id="notesContent" class="behind">
<h3>Scanned notes for {{ current_survey }}.</h3>
{% for noteItem in notes %}
<div class="figure">
@ -222,12 +318,12 @@ img.thumbnail {
who entered by </div>
<div id="printedCentrelineContent" class="behind"> centreline </div>
<div id="scannedPassageSketchContent" class="behind">
<h2>Scanned plan sketch files for {{ current_survey }}.</h2>
<h3>Scanned plan sketch files for {{ current_survey }}.</h3>
{% for sketchItem in planSketches %}
<div class="figure">
<p>
<img src="{{ sketchItem.correctURL }}" class="thumbnail">
<img src="{{ sketchItem.correctURL }}" class="thumbnail" />
<p>
File at:
<a href="{{ sketchItem.correctUrl }}">

View File

@ -28,7 +28,7 @@ urlpatterns = patterns('',
(r'^statistics/?$', stats),
(r'^survey/?$', surveyindex),
(r'^survey/(?P<survey_id>.*)$', survey),
(r'^survey/(?P<year>\d\d\d\d)\#(?P<wallet_number>\d*)$', survey),
(r'^admin/doc/?', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root),