diff --git a/core/admin.py b/core/admin.py index a8ce55f..59c93f2 100644 --- a/core/admin.py +++ b/core/admin.py @@ -74,11 +74,11 @@ class LogbookEntryAdmin(TroggleModelAdmin): } actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt') - def export_logbook_entries_as_html(modeladmin, request, queryset): + def export_logbook_entries_as_html(self, modeladmin, request, queryset): response=downloadLogbook(request=request, queryset=queryset, extension='html') return response - def export_logbook_entries_as_txt(modeladmin, request, queryset): + def export_logbook_entries_as_txt(self, modeladmin, request, queryset): response=downloadLogbook(request=request, queryset=queryset, extension='txt') return response @@ -141,14 +141,14 @@ admin.site.register(SurvexScanSingle) def export_as_json(modeladmin, request, queryset): - response = HttpResponse(mimetype="text/json") + response = HttpResponse(content_type="text/json") response['Content-Disposition'] = 'attachment; filename=troggle_output.json' serializers.serialize("json", queryset, stream=response) return response def export_as_xml(modeladmin, request, queryset): - response = HttpResponse(mimetype="text/xml") + response = HttpResponse(content_type="text/xml") response['Content-Disposition'] = 'attachment; filename=troggle_output.xml' serializers.serialize("xml", queryset, stream=response) return response diff --git a/core/forms.py b/core/forms.py index b091696..8265178 100644 --- a/core/forms.py +++ b/core/forms.py @@ -46,12 +46,12 @@ class EntranceForm(ModelForm): #underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) #notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) #references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) - other_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry - tag_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry - exact_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry - northing = forms.CharField(required=False) # Trying to change this to a singl;e line entry - easting = forms.CharField(required=False) # Trying to change this to a singl;e line entry - alt = forms.CharField(required=False) # Trying to change this to a singl;e line entry + other_station = forms.CharField(required=False) # Trying to change this to a single line entry + tag_station = forms.CharField(required=False) # Trying to change this to a single line entry + exact_station = forms.CharField(required=False) # Trying to change this to a single line entry + northing = forms.CharField(required=False) # Trying to change this to a single line entry + easting = forms.CharField(required=False) # Trying to change this to a single line entry + alt = forms.CharField(required=False) # Trying to change this to a single line entry class Meta: model = Entrance exclude = ("cached_primary_slug", "filename",) @@ -123,7 +123,7 @@ def getTripForm(expedition): html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) def clean(self): - print dir(self) + print(dir(self)) if self.cleaned_data.get("caveOrLocation") == "cave" and not self.cleaned_data.get("cave"): self._errors["cave"] = self.error_class(["This field is required"]) if self.cleaned_data.get("caveOrLocation") == "location" and not self.cleaned_data.get("location"): diff --git a/core/templatetags/survex_markup.py b/core/templatetags/survex_markup.py index 5b9aa36..d6ddd0e 100644 --- a/core/templatetags/survex_markup.py +++ b/core/templatetags/survex_markup.py @@ -47,6 +47,6 @@ def survex_to_html(value, autoescape=None): if autoescape: value = conditional_escape(value) for regex, sub in regexes: - print sub + print(sub) value = regex.sub(sub, value) return mark_safe(value) \ No newline at end of file diff --git a/core/views_caves.py b/core/views_caves.py index a785170..af76b1e 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -10,11 +10,10 @@ from troggle.helper import login_required_if_public from django.forms.models import modelformset_factory from django import forms from django.core.urlresolvers import reverse -from utils import render_with_context # see views_logbooks for explanation on this. from django.http import HttpResponse, HttpResponseRedirect from django.conf import settings import re, urlparse -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render import settings @@ -58,7 +57,7 @@ def caveindex(request): caves1626 = list(Cave.objects.filter(area__short_name = "1626")) caves1623.sort(caveCmp) caves1626.sort(caveCmp) - return render_with_context(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True}) + return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True}) def millenialcaves(request): #RW messing around area @@ -83,43 +82,43 @@ def cave3d(request, cave_id=''): def cave(request, cave_id='', offical_name=''): cave=getCave(cave_id) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id}) + return render(request,'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id}) else: - return render_with_context(request,'cave.html', {'settings': settings, 'cave': cave, 'cavepage': True, 'cave_id': cave_id}) + return render(request,'cave.html', {'settings': settings, 'cave': cave, 'cavepage': True, 'cave_id': cave_id}) def caveEntrance(request, slug): cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave}) + return render(request,'nonpublic.html', {'instance': cave}) else: - return render_with_context(request,'cave_entrances.html', {'cave': cave}) + return render(request,'cave_entrances.html', {'cave': cave}) def caveDescription(request, slug): cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave}) + return render(request,'nonpublic.html', {'instance': cave}) else: - return render_with_context(request,'cave_uground_description.html', {'cave': cave}) + return render(request,'cave_uground_description.html', {'cave': cave}) def caveQMs(request, slug): cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave}) + return render(request,'nonpublic.html', {'instance': cave}) else: - return render_with_context(request,'cave_qms.html', {'cave': cave}) + return render(request,'cave_qms.html', {'cave': cave}) def caveLogbook(request, slug): cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave}) + return render(request,'nonpublic.html', {'instance': cave}) else: - return render_with_context(request,'cave_logbook.html', {'cave': cave}) + return render(request,'cave_logbook.html', {'cave': cave}) def caveSlug(request, slug): cave = Cave.objects.get(caveslug__slug = slug) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug}) + return render(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug}) else: - return render_with_context(request,'cave.html', {'cave': cave, 'cave_editable': slug}) + return render(request,'cave.html', {'cave': cave, 'cave_editable': slug}) @login_required_if_public def edit_cave(request, slug=None): @@ -160,7 +159,7 @@ def edit_cave(request, slug=None): ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all()) versionControlForm = VersionControlCommentForm() - return render_with_context(request, + return render(request, 'editcave2.html', {'form': form, 'caveAndEntranceFormSet': ceFormSet, @@ -204,7 +203,7 @@ def editEntrance(request, caveslug, slug=None): entletter = EntranceLetterForm(request.POST) else: entletter = None - return render_with_context(request, + return render(request, 'editentrance.html', {'form': form, 'versionControlForm': versionControlForm, @@ -215,7 +214,7 @@ def qm(request,cave_id,qm_id,year,grade=None): year=int(year) try: qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) - return render_with_context(request,'qm.html',locals()) + return render(request,'qm.html',locals()) except QM.DoesNotExist: url=urlparse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id) @@ -228,16 +227,16 @@ def qm(request,cave_id,qm_id,year,grade=None): def ent(request, cave_id, ent_letter): cave = Cave.objects.filter(kataster_number = cave_id)[0] cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0] - return render_with_context(request,'entrance.html', {'cave': cave, + return render(request,'entrance.html', {'cave': cave, 'entrance': cave_and_ent.entrance, 'letter': cave_and_ent.entrance_letter,}) def entranceSlug(request, slug): entrance = Entrance.objects.get(entranceslug__slug = slug) if entrance.non_public and not request.user.is_authenticated(): - return render_with_context(request,'nonpublic.html', {'instance': entrance}) + return render(request,'nonpublic.html', {'instance': entrance}) else: - return render_with_context(request,'entranceslug.html', {'entrance': entrance}) + return render(request,'entranceslug.html', {'entrance': entrance}) def survexblock(request, survexpath): survexpath = re.sub("/", ".", survexpath) @@ -245,12 +244,12 @@ def survexblock(request, survexpath): survexblock = models.SurvexBlock.objects.get(survexpath=survexpath) #ftext = survexblock.filecontents() ftext = survexblock.text - return render_with_context(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, }) + return render(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, }) def surveyindex(request): surveys=Survey.objects.all() expeditions=Expedition.objects.order_by("-year") - return render_with_context(request,'survey.html',locals()) + return render(request,'survey.html',locals()) def survey(request,year,wallet_number): surveys=Survey.objects.all() @@ -263,19 +262,19 @@ def survey(request,year,wallet_number): planSketches=current_survey.scannedimage_set.filter(contents='plan') elevationSketches=current_survey.scannedimage_set.filter(contents='elevation') - return render_with_context(request,'survey.html', locals()) + return render(request,'survey.html', locals()) def cave_description(request, cavedescription_name): cave_description = get_object_or_404(CaveDescription, short_name = cavedescription_name) - return render_with_context(request,'cave_description.html', locals()) + return render(request,'cave_description.html', locals()) def get_entrances(request, caveslug): cave = Cave.objects.get(caveslug__slug = caveslug) - return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) + return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) def get_qms(request, caveslug): cave = Cave.objects.get(caveslug__slug = caveslug) - return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) + return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) areanames = [ #('', 'Location unclear'), @@ -313,7 +312,7 @@ def prospecting(request): caves = list(a.cave_set.all()) caves.sort(caveCmp) areas.append((name, a, caves)) - return render_with_context(request, 'prospecting.html', {"areas": areas}) + return render(request, 'prospecting.html', {"areas": areas}) # Parameters for big map and zoomed subarea maps: # big map first (zoom factor ignored) diff --git a/core/views_logbooks.py b/core/views_logbooks.py index ffd1243..b8069da 100644 --- a/core/views_logbooks.py +++ b/core/views_logbooks.py @@ -1,4 +1,4 @@ -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, render from troggle.core.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry, SurvexBlock import troggle.core.models as models import troggle.settings as settings @@ -9,7 +9,6 @@ from troggle.core.forms import getTripForm#, get_name, PersonForm from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect, HttpResponse from django.template import Context, loader -from utils import render_with_context import os.path import troggle.parsers.logbooks as logbookparsers from django.template.defaultfilters import slugify @@ -55,7 +54,7 @@ def personindex(request): if person.bisnotable(): notablepersons.append(person) - return render_with_context(request,'personindex.html', {'persons': persons, 'personss':personss, 'notablepersons':notablepersons, }) + return render(request,'personindex.html', {'persons': persons, 'personss':personss, 'notablepersons':notablepersons, }) def expedition(request, expeditionname): @@ -77,7 +76,7 @@ def expedition(request, expeditionname): if "reload" in request.GET: LoadLogbookForExpedition(this_expedition) - return render_with_context(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'settings':settings, 'dateditems': dateditems }) + return render(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'settings':settings, 'dateditems': dateditems }) def get_absolute_url(self): return ('expedition', (expedition.year)) @@ -102,7 +101,7 @@ def person(request, first_name='', last_name='', ): this_person.save() return HttpResponseRedirect(reverse('profiles_select_profile')) - return render_with_context(request,'person.html', {'person': this_person, }) + return render(request,'person.html', {'person': this_person, }) def GetPersonChronology(personexpedition): @@ -135,17 +134,17 @@ def personexpedition(request, first_name='', last_name='', year=''): this_expedition = Expedition.objects.get(year=year) personexpedition = person.personexpedition_set.get(expedition=this_expedition) personchronology = GetPersonChronology(personexpedition) - return render_with_context(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology}) + return render(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology}) def logbookentry(request, date, slug): this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug) if len(this_logbookentry)>1: - return render_with_context(request, 'object_list.html',{'object_list':this_logbookentry}) + return render(request, 'object_list.html',{'object_list':this_logbookentry}) else: this_logbookentry=this_logbookentry[0] - return render_with_context(request, 'logbookentry.html', {'logbookentry': this_logbookentry}) + return render(request, 'logbookentry.html', {'logbookentry': this_logbookentry}) def logbookSearch(request, extra): @@ -156,14 +155,14 @@ def logbookSearch(request, extra): entry_query = search.get_query(query_string, ['text','title',]) found_entries = LogbookEntry.objects.filter(entry_query) - return render_with_context(request,'logbooksearch.html', + return render(request,'logbooksearch.html', { 'query_string': query_string, 'found_entries': found_entries, }) #context_instance=RequestContext(request)) def personForm(request,pk): person=Person.objects.get(pk=pk) form=PersonForm(instance=person) - return render_with_context(request,'personform.html', {'form':form,}) + return render(request,'personform.html', {'form':form,}) def experimental(request): @@ -180,7 +179,7 @@ def experimental(request): survexlegs = models.SurvexLeg.objects.all() totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs]) - return render_with_context(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo }) + return render(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo }) @login_required_if_public def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None): @@ -239,7 +238,7 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None): tripForm = TripForm() # An unbound form personTripFormSet = PersonTripFormSet() - return render_with_context(request, 'newlogbookentry.html', { + return render(request, 'newlogbookentry.html', { 'tripForm': tripForm, 'personTripFormSet': personTripFormSet, @@ -261,8 +260,8 @@ def delLogbookEntry(lbe): def get_people(request, expeditionslug): exp = Expedition.objects.get(year = expeditionslug) - return render_with_context(request,'options.html', {"items": [(pe.slug, pe.name) for pe in exp.personexpedition_set.all()]}) + return render(request,'options.html', {"items": [(pe.slug, pe.name) for pe in exp.personexpedition_set.all()]}) def get_logbook_entries(request, expeditionslug): exp = Expedition.objects.get(year = expeditionslug) - return render_with_context(request,'options.html', {"items": [(le.slug, "%s - %s" % (le.date, le.title)) for le in exp.logbookentry_set.all()]}) + return render(request,'options.html', {"items": [(le.slug, "%s - %s" % (le.date, le.title)) for le in exp.logbookentry_set.all()]}) diff --git a/core/views_other.py b/core/views_other.py index 6a195b9..1297e7f 100644 --- a/core/views_other.py +++ b/core/views_other.py @@ -4,11 +4,11 @@ from django.conf import settings from django import forms from django.template import loader, Context from django.db.models import Q +from django.shortcuts import render import databaseReset import re from django.http import HttpResponse, HttpResponseRedirect from django.core.urlresolvers import reverse -from utils import render_with_context from troggle.core.models import * from troggle.helper import login_required_if_public @@ -21,18 +21,18 @@ def stats(request): statsDict['caveCount'] = int(Cave.objects.count()) statsDict['personCount'] = int(Person.objects.count()) statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count()) - return render_with_context(request,'statistics.html', statsDict) + return render(request,'statistics.html', statsDict) def frontpage(request): if request.user.is_authenticated(): - return render_with_context(request,'tasks.html') + return render(request,'tasks.html') expeditions = Expedition.objects.order_by("-year") logbookentry = LogbookEntry cave = Cave photo = DPhoto from django.contrib.admin.templatetags import log - return render_with_context(request,'frontpage.html', locals()) + return render(request,'frontpage.html', locals()) def todo(request): message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"}) @@ -45,7 +45,7 @@ def todo(request): expeditions = Expedition.objects.order_by("-year") totallogbookentries = LogbookEntry.objects.count() - return render_with_context(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message}) + return render(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message}) def controlPanel(request): @@ -64,11 +64,11 @@ def controlPanel(request): jobs_completed.append(item) else: if request.user.is_authenticated(): #The user is logged in, but is not a superuser. - return render_with_context(request,'controlPanel.html', {'caves':Cave.objects.all(),'error':'You must be a superuser to use that feature.'}) + return render(request,'controlPanel.html', {'caves':Cave.objects.all(),'error':'You must be a superuser to use that feature.'}) else: return HttpResponseRedirect(reverse('auth_login')) - return render_with_context(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed}) + return render(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed}) def downloadCavetab(request): from export import tocavetab @@ -201,7 +201,7 @@ def logbook_entry_suggestions(request): print('got 208') any_suggestions=True print('got 210') - return render_with_context(request,'suggestions.html', + return render(request,'suggestions.html', { 'unwiki_QMs':unwiki_QMs, 'any_suggestions':any_suggestions @@ -261,7 +261,7 @@ def newFile(request, pslug = None): # else: # fileform = UploadFileForm() # An unbound form - return render_with_context(request, 'editfile.html', { + return render(request, 'editfile.html', { 'fileForm': fileform, }) diff --git a/core/views_survex.py b/core/views_survex.py index 9fc334a..a0f4637 100644 --- a/core/views_survex.py +++ b/core/views_survex.py @@ -178,7 +178,7 @@ def svx(request, survex_file): def svxraw(request, survex_file): svx = open(os.path.join(settings.SURVEX_DATA, survex_file+".svx"), "rb") - return HttpResponse(svx, mimetype="text") + return HttpResponse(svx, content_type="text") # The cavern running function @@ -193,20 +193,20 @@ def threed(request, survex_file): process(survex_file) try: threed = open(settings.SURVEX_DATA + survex_file + ".3d", "rb") - return HttpResponse(threed, mimetype="model/3d") + return HttpResponse(threed, content_type="model/3d") except: log = open(settings.SURVEX_DATA + survex_file + ".log", "rb") - return HttpResponse(log, mimetype="text") + return HttpResponse(log, content_type="text") def log(request, survex_file): process(survex_file) log = open(settings.SURVEX_DATA + survex_file + ".log", "rb") - return HttpResponse(log, mimetype="text") + return HttpResponse(log, content_type="text") def err(request, survex_file): process(survex_file) err = open(settings.SURVEX_DATA + survex_file + ".err", "rb") - return HttpResponse(err, mimetype="text") + return HttpResponse(err, content_type="text") diff --git a/flatpages/views.py b/flatpages/views.py index 8bc25ba..6360393 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -1,6 +1,6 @@ import troggle.settings as settings from troggle.helper import login_required_if_public -from utils import render_with_context +from django.shortcuts import render from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.core.urlresolvers import reverse @@ -47,13 +47,13 @@ def flatpage(request, path): o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb") path = path + "index.htm" except IOError: - return render_with_context(request, 'pagenotfound.html', {'path': path}) + return render(request, 'pagenotfound.html', {'path': path}) else: try: filetobeopened = os.path.normpath(settings.EXPOWEB + path) o = open(filetobeopened, "rb") except IOError: - return render_with_context(request, 'pagenotfound.html', {'path': path}) + return render(request, 'pagenotfound.html', {'path': path}) if path.endswith(".htm") or path.endswith(".html"): html = o.read() @@ -75,7 +75,7 @@ def flatpage(request, path): if re.search(r"iso-8859-1", html): body = unicode(body, "iso-8859-1") body.strip - return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu}) + return render(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu}) else: return HttpResponse(o.read(), content_type=getmimetype(path)) @@ -160,7 +160,7 @@ def editflatpage(request, path): flatpageForm = FlatPageForm({"html": body, "title": title}) else: flatpageForm = FlatPageForm() - return render_with_context(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, }) + return render(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, }) class FlatPageForm(forms.Form): title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'})) diff --git a/templates/editcave2.html b/templates/editcave2.html index 85df6e7..03deeea 100644 --- a/templates/editcave2.html +++ b/templates/editcave2.html @@ -9,6 +9,7 @@ {% endblock %} {% block content %} +