From 014f390100ec864a26caebca295b7e3a8b90c3c7 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 16 Jan 2009 20:50:23 +0100 Subject: [PATCH] [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. --- troggle/expo/models.py | 18 +++-- troggle/expo/views_caves.py | 22 ++++-- troggle/parsers/surveys.py | 15 +++-- troggle/templates/survey.html | 122 ++++++++++++++++++++++++++++++---- troggle/urls.py | 2 +- 5 files changed, 147 insertions(+), 32 deletions(-) diff --git a/troggle/expo/models.py b/troggle/expo/models.py index e58489cfd..4bbf4216b 100644 --- a/troggle/expo/models.py +++ b/troggle/expo/models.py @@ -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 - \ No newline at end of file + 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') \ No newline at end of file diff --git a/troggle/expo/views_caves.py b/troggle/expo/views_caves.py index 8d0a4f44c..045dbcf5a 100644 --- a/troggle/expo/views_caves.py +++ b/troggle/expo/views_caves.py @@ -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}) diff --git a/troggle/parsers/surveys.py b/troggle/parsers/surveys.py index 22b1767d1..cd9781be6 100644 --- a/troggle/parsers/surveys.py +++ b/troggle/parsers/surveys.py @@ -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 diff --git a/troggle/templates/survey.html b/troggle/templates/survey.html index e4998f3d0..b611d78a8 100644 --- a/troggle/templates/survey.html +++ b/troggle/templates/survey.html @@ -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 */ - + +