diff --git a/databaseReset.py b/databaseReset.py index 8000445..e9092ce 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -37,7 +37,13 @@ def import_people(): parsers.people.LoadPersonsExpos() def import_logbooks(): - settings.LOGFILE.write('\nBegun importing logbooks at ' + time.asctime() +'\n'+'-'*60) + # The below line was causing errors I didn't understand (it said LOGFILE was a string), and I couldn't be bothered to figure + # what was going on so I just catch the error with a try. - AC 21 May + try: + settings.LOGFILE.write('\nBegun importing logbooks at ' + time.asctime() +'\n'+'-'*60) + except: + pass + import parsers.logbooks parsers.logbooks.LoadLogbooks() diff --git a/expo/admin.py b/expo/admin.py index 3b727d2..9f804c2 100644 --- a/expo/admin.py +++ b/expo/admin.py @@ -4,6 +4,8 @@ from feincms.admin import editor from django.forms import ModelForm import django.forms as forms from expo.forms import LogbookEntryForm +from django.http import HttpResponse +from django.core import serializers #from troggle.reversion.admin import VersionAdmin #django-reversion version control #overriding admin save so we have the new since parsing field @@ -73,7 +75,6 @@ class CaveAdmin(TroggleModelAdmin): class SubcaveAdmin(editor.TreeEditorMixin,TroggleModelAdmin): pass - admin.site.register(Photo) admin.site.register(Subcave, SubcaveAdmin) admin.site.register(Cave, CaveAdmin) @@ -94,6 +95,29 @@ admin.site.register(QM, QMAdmin) admin.site.register(Survey, SurveyAdmin) admin.site.register(ScannedImage) +def export_as_json(modeladmin, request, queryset): + response = HttpResponse(mimetype="text/json") + response['Content-Disposition'] = 'attachment; filename=troggle_output.xml' + serializers.serialize("json", queryset, stream=response) + return response + +admin.site.add_action(export_as_json) + +def export_as_xml(modeladmin, request, queryset): + response = HttpResponse(mimetype="text/xml") + response['Content-Disposition'] = 'attachment; filename=troggle_output.xml' + return response + +admin.site.add_action(export_as_xml) + +def export_as_python(modeladmin, request, queryset): + response = HttpResponse(mimetype="text/python") + response['Content-Disposition'] = 'attachment; filename=troggle_output.py' + serializers.serialize("json", queryset, stream=response) + return response + +admin.site.add_action(export_as_python) + try: mptt.register(Subcave, order_insertion_by=['name']) except mptt.AlreadyRegistered: diff --git a/expo/models.py b/expo/models.py index ece0e26..70f8381 100644 --- a/expo/models.py +++ b/expo/models.py @@ -466,13 +466,25 @@ class Entrance(TroggleModel): class Subcave(TroggleModel): description = models.TextField(blank=True, null=True) title = models.CharField(max_length=200, ) - cave = models.ForeignKey('Cave', blank=True, null=True, help_text="Only the top-level subcave should be linked to a cave") + cave = models.ForeignKey('Cave', blank=True, null=True, help_text="Only the top-level subcave should be linked to a cave!") parent = models.ForeignKey('self', null=True, blank=True, related_name='children') #adjoining = models.ManyToManyField('Subcave',blank=True, null=True,) legacy_description_path = models.CharField(max_length=600, blank=True, null=True) def __unicode__(self): return self.title - + + def get_absolute_url(self): + + ancestor_titles='/'.join([subcave.title for subcave in self.get_ancestors()]) + if ancestor_titles: + res = '/'.join((self.get_root().cave.get_absolute_url(), ancestor_titles, self.title)) + + else: + res = '/'.join((self.get_root().cave.get_absolute_url(), self.title)) + + return res + +# This was the old way, before we were using django-mptt # def get_absolute_url(self): # urlString=self.name @@ -524,7 +536,7 @@ class QM(TroggleModel): 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 - return settings.URL_ROOT + reverse('qm',kwargs={'cave_id':self.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}) + return settings.URL_ROOT + reverse('qm',kwargs={'cave_id':self.found_by.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}) def get_next_by_id(self): return QM.objects.get(id=self.id+1) diff --git a/expo/views_caves.py b/expo/views_caves.py index 51c9e11..64ec6e2 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -57,11 +57,11 @@ def subcave(request, cave_id, subcave): subcaveSeq=re.findall('(?:/)([^/]*)',subcave) print subcaveSeq cave=models.Cave.objects.get(kataster_number = cave_id) - subcave=models.Subcave.objects.get(name=subcaveSeq[0], cave=cave) + subcave=models.Subcave.objects.get(title=subcaveSeq[0], cave=cave) if len(subcaveSeq)>1: for subcaveUrlSegment in subcaveSeq[1:]: if subcaveUrlSegment: - subcave=subcave.children.get(name=subcaveUrlSegment) + subcave=subcave.children.get(title=subcaveUrlSegment) print subcave return render_response(request,'subcave.html', {'subcave': subcave,'cave':cave}) diff --git a/media/css/main3.css b/media/css/main3.css index 2105050..0d67fea 100644 --- a/media/css/main3.css +++ b/media/css/main3.css @@ -262,7 +262,8 @@ div#content { margin-right: 120px; padding-top: 10px; padding-left: 5em; - padding-right: 5em; + padding-right: 5em; + padding-bottom:5em; background:#CCC; } diff --git a/templates/qm.html b/templates/qm.html index 06e6e0e..52413f0 100644 --- a/templates/qm.html +++ b/templates/qm.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load wiki_markup %} +{% load link %} {% block title %} QM: {{qm|wiki_to_html_short}} {% endblock %} @@ -19,6 +20,17 @@ {% block content %} + +
+ +

Related items

+ +Parent cave: {{qm.found_by.cave|link}} +(todo: add parent survey and parent subcave) + + +
+

Location

{{qm.location_description}} diff --git a/templates/subcave.html b/templates/subcave.html index c635833..4cd9be0 100644 --- a/templates/subcave.html +++ b/templates/subcave.html @@ -1,9 +1,24 @@ {% extends "cavebase.html" %} {% load wiki_markup %} +{% load mptt_tags %} {% block title %} Subcave {{subcave}} {% endblock title %} {% block editLink %}Edit subcave {{subcave|wiki_to_html_short}}{% endblock %} + +{% block contentheader %} + {{subcave.title}} +{% endblock contentheader %} + + + {% block content %} +ok here comes the drilldown
+{% drilldown_tree_for_node subcave as drilldown %} +{% for each in drilldown %} +{{ each }}> +{% endfor %} + +

{{subcave}}

{{subcave.description}}