From d4ac28af18ef41661c299a1b9fc1f630cda6193c Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 15 May 2020 21:32:55 +0100 Subject: [PATCH] Remove PHOTOS_ROOT and DPhoto class --- core/admin.py | 13 +++++---- core/management/commands/reset_db.py | 8 ++++-- core/models.py | 37 ++++++++++++------------ core/models_survex.py | 6 ++++ core/templatetags/wiki_markup.py | 16 +++++------ core/views_logbooks.py | 2 +- core/views_other.py | 6 ++-- databaseReset.py | 4 +-- parsers/people.py | 43 ++++++++++++++-------------- pathreport.py | 2 +- settings.py | 2 +- templates/frontpage.html | 4 +-- urls.py | 9 +++--- 13 files changed, 83 insertions(+), 69 deletions(-) diff --git a/core/admin.py b/core/admin.py index 71bbd61..18fb404 100644 --- a/core/admin.py +++ b/core/admin.py @@ -50,10 +50,10 @@ class QMsFoundInline(admin.TabularInline): extra=1 -class PhotoInline(admin.TabularInline): - model = DPhoto - exclude = ['is_mugshot' ] - extra = 1 +# class PhotoInline(admin.TabularInline): + # model = DPhoto + # exclude = ['is_mugshot' ] + # extra = 1 class PersonTripInline(admin.TabularInline): @@ -67,7 +67,8 @@ class LogbookEntryAdmin(TroggleModelAdmin): prepopulated_fields = {'slug':("title",)} search_fields = ('title','expedition__year') date_heirarchy = ('date') - inlines = (PersonTripInline, PhotoInline, QMsFoundInline) +# inlines = (PersonTripInline, PhotoInline, QMsFoundInline) + inlines = (PersonTripInline, QMsFoundInline) class Media: css = { "all": ("css/troggleadmin.css",) @@ -116,7 +117,7 @@ class EntranceAdmin(TroggleModelAdmin): search_fields = ('caveandentrance__cave__kataster_number',) -admin.site.register(DPhoto) +#admin.site.register(DPhoto) admin.site.register(Cave, CaveAdmin) admin.site.register(Area) #admin.site.register(OtherCaveName) diff --git a/core/management/commands/reset_db.py b/core/management/commands/reset_db.py index e95ddd9..c55a0b1 100644 --- a/core/management/commands/reset_db.py +++ b/core/management/commands/reset_db.py @@ -11,6 +11,9 @@ from django.core.urlresolvers import reverse from troggle.core.models import Cave, Entrance import troggle.flatpages.models +"""Pretty much all of this is now replaced by databaseRest.py +I don't know why this still exists +""" databasename=settings.DATABASES['default']['NAME'] expouser=settings.EXPOUSER expouserpass=settings.EXPOUSERPASS @@ -89,9 +92,10 @@ class Command(BaseCommand): def make_dirs(obj): """Make directories that troggle requires""" + pass # should also deal with permissions here. - if not os.path.isdir(settings.PHOTOS_ROOT): - os.mkdir(settings.PHOTOS_ROOT) + #if not os.path.isdir(settings.PHOTOS_ROOT): + #os.mkdir(settings.PHOTOS_ROOT) def import_caves(obj): import parsers.caves diff --git a/core/models.py b/core/models.py index 0efe8c9..5b9f48c 100644 --- a/core/models.py +++ b/core/models.py @@ -780,31 +780,32 @@ class QM(TroggleModel): def wiki_link(self): return u"%s%s%s" % ('[[QM:',self.code(),']]') -photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL) -class DPhoto(TroggleImageModel): - caption = models.CharField(max_length=1000,blank=True,null=True) - contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True) - contains_person = models.ManyToManyField(Person,blank=True,null=True) - file = models.ImageField(storage=photoFileStorage, upload_to='.',) - is_mugshot = models.BooleanField(default=False) - contains_cave = models.ForeignKey(Cave,blank=True,null=True) - contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True) +#photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL) +#class DPhoto(TroggleImageModel): + #caption = models.CharField(max_length=1000,blank=True,null=True) + #contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True) + #contains_person = models.ManyToManyField(Person,blank=True,null=True) + # replace link to copied file with link to original file location + #file = models.ImageField(storage=photoFileStorage, upload_to='.',) + #is_mugshot = models.BooleanField(default=False) + #contains_cave = models.ForeignKey(Cave,blank=True,null=True) + #contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True) #nearest_survey_point = models.ForeignKey(SurveyStation,blank=True,null=True) - nearest_QM = models.ForeignKey(QM,blank=True,null=True) - lon_utm = models.FloatField(blank=True,null=True) - lat_utm = models.FloatField(blank=True,null=True) + #nearest_QM = models.ForeignKey(QM,blank=True,null=True) + #lon_utm = models.FloatField(blank=True,null=True) + #lat_utm = models.FloatField(blank=True,null=True) - class IKOptions: - spec_module = 'core.imagekit_specs' - cache_dir = 'thumbs' - image_field = 'file' + # class IKOptions: + # spec_module = 'core.imagekit_specs' + # cache_dir = 'thumbs' + # image_field = 'file' #content_type = models.ForeignKey(ContentType) #object_id = models.PositiveIntegerField() #location = generic.GenericForeignKey('content_type', 'object_id') - def __unicode__(self): - return self.caption + # def __unicode__(self): + # return self.caption scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL) def get_scan_path(instance, filename): diff --git a/core/models_survex.py b/core/models_survex.py index 3bae04c..448cea9 100644 --- a/core/models_survex.py +++ b/core/models_survex.py @@ -197,6 +197,9 @@ class SurvexScansFolder(models.Model): def get_absolute_url(self): return urlparse.urljoin(settings.URL_ROOT, reverse('surveyscansfolder', kwargs={"path":re.sub("#", "%23", self.walletname)})) + + def __unicode__(self): + return unicode(self.walletname) + " (Survey Scans Folder)" class SurvexScanSingle(models.Model): ffile = models.CharField(max_length=200) @@ -208,6 +211,9 @@ class SurvexScanSingle(models.Model): def get_absolute_url(self): return urlparse.urljoin(settings.URL_ROOT, reverse('surveyscansingle', kwargs={"path":re.sub("#", "%23", self.survexscansfolder.walletname), "file":self.name})) + + def __unicode__(self): + return "Survey Scan Image: " + unicode(self.name) + " in " + unicode(self.survexscansfolder) class TunnelFile(models.Model): diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py index 2640594..25c7103 100644 --- a/core/templatetags/wiki_markup.py +++ b/core/templatetags/wiki_markup.py @@ -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 troggle.core.models import QM, DPhoto, LogbookEntry, Cave +from troggle.core.models import QM, LogbookEntry, Cave import re, urlparse register = template.Library() @@ -120,13 +120,13 @@ def wiki_to_html_short(value, autoescape=None): except KeyError: linkText=None - try: - photo=DPhoto.objects.get(file=matchdict['photoName']) - if not linkText: - linkText=str(photo) - res=r'' + linkText + '' - except Photo.DoesNotExist: - res = r'make new photo' + # try: + # photo=DPhoto.objects.get(file=matchdict['photoName']) + # if not linkText: + # linkText=str(photo) + # res=r'' + linkText + '' + # except Photo.DoesNotExist: + # res = r'make new photo' return res def photoSrcRepl(matchobj): diff --git a/core/views_logbooks.py b/core/views_logbooks.py index 9891674..65453fa 100644 --- a/core/views_logbooks.py +++ b/core/views_logbooks.py @@ -184,7 +184,7 @@ def pathsreport(request): "MEDIA_ADMIN_DIR" : MEDIA_ADMIN_DIR, "MEDIA_ROOT" : MEDIA_ROOT, "MEDIA_URL" : MEDIA_URL, - "PHOTOS_ROOT" : PHOTOS_ROOT, + #"PHOTOS_ROOT" : PHOTOS_ROOT, "PHOTOS_URL" : PHOTOS_URL, "PYTHON_PATH" : PYTHON_PATH, "REPOS_ROOT_PATH" : REPOS_ROOT_PATH, diff --git a/core/views_other.py b/core/views_other.py index cc9782b..6adca9c 100644 --- a/core/views_other.py +++ b/core/views_other.py @@ -1,5 +1,5 @@ -from troggle.core.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, DPhoto, QM -#from troggle.core.forms import UploadFileForm +from troggle.core.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, QM +#from troggle.core.forms import UploadFileForm, DPhoto from django.conf import settings from django import forms from django.template import loader, Context @@ -30,7 +30,7 @@ def frontpage(request): expeditions = Expedition.objects.order_by("-year") logbookentry = LogbookEntry cave = Cave - photo = DPhoto + #photo = DPhoto from django.contrib.admin.templatetags import log return render(request,'frontpage.html', locals()) diff --git a/databaseReset.py b/databaseReset.py index 0b62479..f4b12d7 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -53,8 +53,8 @@ def dirsredirect(): """Make directories that troggle requires and sets up page redirects """ #should also deal with permissions here. - if not os.path.isdir(settings.PHOTOS_ROOT): - os.mkdir(settings.PHOTOS_ROOT) + #if not os.path.isdir(settings.PHOTOS_ROOT): + #os.mkdir(settings.PHOTOS_ROOT) for oldURL, newURL in [("indxal.htm", reverse("caveindex"))]: f = troggle.flatpages.models.Redirect(originalURL = oldURL, newURL = newURL) f.save() diff --git a/parsers/people.py b/parsers/people.py index cb9f79f..265dacc 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -7,34 +7,35 @@ from utils import save_carefully from HTMLParser import HTMLParser from unidecode import unidecode -def saveMugShot(mugShotPath, mugShotFilename, person): - if mugShotFilename.startswith(r'i/'): #if filename in cell has the directory attached (I think they all do), remove it - mugShotFilename=mugShotFilename[2:] - else: - mugShotFilename=mugShotFilename # just in case one doesn't +# def saveMugShot(mugShotPath, mugShotFilename, person): + # if mugShotFilename.startswith(r'i/'): #if filename in cell has the directory attached (I think they all do), remove it + # mugShotFilename=mugShotFilename[2:] + # else: + # mugShotFilename=mugShotFilename # just in case one doesn't - dummyObj=models.DPhoto(file=mugShotFilename) + # dummyObj=models.DPhoto(file=mugShotFilename) - #Put a copy of the file in the right place. mugShotObj.file.path is determined by the django filesystemstorage specified in models.py - if not os.path.exists(dummyObj.file.path): - shutil.copy(mugShotPath, dummyObj.file.path) + # #Put a copy of the file in the right place. mugShotObj.file.path is determined by the django filesystemstorage specified in models.py + # if not os.path.exists(dummyObj.file.path): + # shutil.copy(mugShotPath, dummyObj.file.path) - mugShotObj, created = save_carefully( - models.DPhoto, - lookupAttribs={'is_mugshot':True, 'file':mugShotFilename}, - nonLookupAttribs={'caption':"Mugshot for "+person.first_name+" "+person.last_name} - ) + # mugShotObj, created = save_carefully( + # models.DPhoto, + # lookupAttribs={'is_mugshot':True, 'file':mugShotFilename}, + # nonLookupAttribs={'caption':"Mugshot for "+person.first_name+" "+person.last_name} + # ) - if created: - mugShotObj.contains_person.add(person) - mugShotObj.save() + # if created: + # mugShotObj.contains_person.add(person) + # mugShotObj.save() def parseMugShotAndBlurb(personline, header, person): """create mugshot Photo instance""" mugShotFilename=personline[header["Mugshot"]] mugShotPath = os.path.join(settings.EXPOWEB, "folk", mugShotFilename) if mugShotPath[-3:]=='jpg': #if person just has an image, add it - saveMugShot(mugShotPath=mugShotPath, mugShotFilename=mugShotFilename, person=person) + #saveMugShot(mugShotPath=mugShotPath, mugShotFilename=mugShotFilename, person=person) + pass elif mugShotPath[-3:]=='htm': #if person has an html page, find the image(s) and add it. Also, add the text from the html page to the "blurb" field in his model instance. personPageOld=open(mugShotPath,'r').read() if not person.blurb: @@ -45,9 +46,9 @@ def parseMugShotAndBlurb(personline, header, person): person.blurb=re.search('.*

Welcome

-This is Troggle, the information portal for Cambridge University Caving Club's Expeditions to Austria. +This is Troggle, the online system for Cambridge University Caving Club's Expeditions to Austria.

@@ -46,7 +46,7 @@ Here you will find information about the {{expedition.objects.count}} expedition

-If you are an expedition member, please sign up using the link to the top right and begin editing. +If you are an expedition member, please sign up using the link to the top right.

{% endblock content %} diff --git a/urls.py b/urls.py index 281e189..410c391 100644 --- a/urls.py +++ b/urls.py @@ -48,7 +48,7 @@ actualurlpatterns = patterns('', url(r'^newfile', views_other.newFile, name="newFile"), url(r'^getEntrances/(?P.*)', views_caves.get_entrances, name = "get_entrances"), - url(r'^getQMs/(?P.*)', views_caves.get_qms, name = "get_qms"), + url(r'^getQMs/(?P.*)', views_caves.get_qms, name = "get_qms"), # no template "get_qms"? url(r'^getPeople/(?P.*)', views_logbooks.get_people, name = "get_people"), url(r'^getLogBookEntries/(?P.*)', views_logbooks.get_logbook_entries, name = "get_logbook_entries"), @@ -58,7 +58,7 @@ actualurlpatterns = patterns('', url(r'^caveslug/([^/]+)/?$', views_caves.caveSlug, name="caveSlug"), url(r'^cave/entrance/([^/]+)/?$', views_caves.caveEntrance), url(r'^cave/description/([^/]+)/?$', views_caves.caveDescription), - url(r'^cave/qms/([^/]+)/?$', views_caves.caveQMs), + url(r'^cave/qms/([^/]+)/?$', views_caves.caveQMs), # blank page url(r'^cave/logbook/([^/]+)/?$', views_caves.caveLogbook), url(r'^entrance/(?P[^/]+)/(?P[^/]+)/edit/', views_caves.editEntrance, name = "editentrance"), url(r'^entrance/new/(?P[^/]+)/', views_caves.editEntrance, name = "newentrance"), @@ -87,6 +87,7 @@ actualurlpatterns = patterns('', url(r'^survey/?$', surveyindex, name="survey"), url(r'^survey/(?P\d\d\d\d)\#(?P\d*)$', survey, name="survey"), +# Is all this lot out of date ? Maybe the logbooks work? url(r'^controlpanel/?$', views_other.controlPanel, name="controlpanel"), url(r'^CAVETAB2\.CSV/?$', views_other.downloadCavetab, name="downloadcavetab"), url(r'^Surveys\.csv/?$', views_other.downloadSurveys, name="downloadsurveys"), @@ -147,8 +148,8 @@ actualurlpatterns = patterns('', #url(r'^tunneldatainfo/(?P.+?\.xml)$', view_surveys.tunnelfileinfo, name="tunnelfileinfo"), - (r'^photos/(?P.*)$', 'django.views.static.serve', - {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}), + #(r'^photos/(?P.*)$', 'django.views.static.serve', + #{'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}), url(r'^prospecting/(?P[^.]+).png$', prospecting_image, name="prospecting_image"),