2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

Django 1.7 mostly working. Big refactor so probably bugs

This commit is contained in:
Sam Wenham 2018-04-15 16:28:13 +01:00
parent 2c2c815b25
commit 758259be4d
18 changed files with 82 additions and 60 deletions

View File

@ -4,7 +4,7 @@ from django.forms import ModelForm
import django.forms as forms import django.forms as forms
from django.http import HttpResponse from django.http import HttpResponse
from django.core import serializers from django.core import serializers
from core.views_other import downloadLogbook from troggle.core.views_other import downloadLogbook
#from troggle.reversion.admin import VersionAdmin #django-reversion version control #from troggle.reversion.admin import VersionAdmin #django-reversion version control
@ -12,8 +12,8 @@ class TroggleModelAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
"""overriding admin save to fill the new_since parsing_field""" """overriding admin save to fill the new_since parsing_field"""
obj.new_since_parsing=True obj.new_since_parsing=True
obj.save() obj.save()
class Media: class Media:
js = ('jquery/jquery.min.js','js/QM_helper.js') js = ('jquery/jquery.min.js','js/QM_helper.js')

View File

@ -1,5 +1,5 @@
from django.conf import settings from django.conf import settings
from core.models import Expedition from troggle.core.models import Expedition
def troggle_context(request): def troggle_context(request):
return { 'settings':settings, 'Expedition':Expedition } return { 'settings':settings, 'Expedition':Expedition }

View File

@ -15,7 +15,7 @@ from django.template import Context, loader
import settings import settings
getcontext().prec=2 #use 2 significant figures for decimal calculations getcontext().prec=2 #use 2 significant figures for decimal calculations
from models_survex import * from troggle.core.models_survex import *
def get_related_by_wikilinks(wiki_text): def get_related_by_wikilinks(wiki_text):
@ -55,7 +55,7 @@ class TroggleModel(models.Model):
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk)) return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
class Meta: class Meta:
abstract = True abstract = True
class TroggleImageModel(ImageModel): class TroggleImageModel(ImageModel):
new_since_parsing = models.BooleanField(default=False, editable=False) new_since_parsing = models.BooleanField(default=False, editable=False)
@ -68,7 +68,7 @@ class TroggleImageModel(ImageModel):
class Meta: class Meta:
abstract = True abstract = True
# #
# single Expedition, usually seen by year # single Expedition, usually seen by year
@ -140,7 +140,7 @@ class Person(TroggleModel):
return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name})) return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
class Meta: class Meta:
verbose_name_plural = "People" verbose_name_plural = "People"
class Meta: class Meta:
ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name') ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')

View File

@ -3,7 +3,7 @@ from django.utils.html import conditional_escape
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.conf import settings from django.conf import settings
from core.models import QM, DPhoto, LogbookEntry, Cave from troggle.core.models import QM, DPhoto, LogbookEntry, Cave
import re, urlparse import re, urlparse
register = template.Library() register = template.Library()

View File

@ -8,8 +8,8 @@ from django.db import connection
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import HttpResponse from django.http import HttpResponse
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from core.models import Cave, Entrance from troggle.core.models import Cave, Entrance
import flatpages.models import troggle.flatpages.models
databasename=settings.DATABASES['default']['NAME'] databasename=settings.DATABASES['default']['NAME']
expouser=settings.EXPOUSER expouser=settings.EXPOUSER

View File

@ -1,5 +1,5 @@
from django.db import models from django.db import models
from core.models import Cave, Entrance from troggle.core.models import Cave, Entrance
class Redirect(models.Model): class Redirect(models.Model):
originalURL = models.CharField(max_length=200, unique=True) originalURL = models.CharField(max_length=200, unique=True)

View File

@ -75,7 +75,7 @@ def flatpage(request, path):
body.strip body.strip
return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm")}) return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm")})
else: else:
return HttpResponse(o.read(), mimetype=getmimetype(path)) return HttpResponse(o.read(), content_type=getmimetype(path))
def getmimetype(path): def getmimetype(path):
if path.lower().endswith(".png"): return "image/png" if path.lower().endswith(".png"): return "image/png"

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import os, sys import os
import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

View File

@ -2,7 +2,7 @@
import csv import csv
from django.conf import settings from django.conf import settings
from core.models import QM, LogbookEntry, Cave from troggle.core.models import QM, LogbookEntry, Cave
from datetime import * from datetime import *
from utils import save_carefully from utils import save_carefully
import re, os import re, os
@ -87,7 +87,7 @@ def parseCaveQMs(cave,inputFile):
continue continue
def parse_KH_QMs(kh, inputFile): def parse_KH_QMs(kh, inputFile):
"""import QMs from the 1623-161 (Kaninchenhöhle) html pages """import QMs from the 1623-161 (Kaninchenh<EFBFBD>hle) html pages
""" """
khQMs=open(settings.EXPOWEB+inputFile,'r') khQMs=open(settings.EXPOWEB+inputFile,'r')
khQMs=khQMs.readlines() khQMs=khQMs.readlines()

View File

@ -4,7 +4,7 @@ from django.conf import settings
import csv, time, re, os, logging import csv, time, re, os, logging
from utils import save_carefully from utils import save_carefully
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import flatpages.models import troggle.flatpages.models
##format of CAVETAB2.CSV is ##format of CAVETAB2.CSV is
KatasterNumber = 0 KatasterNumber = 0

View File

@ -1,7 +1,7 @@
#.-*- coding: utf-8 -*- #.-*- coding: utf-8 -*-
from django.conf import settings from django.conf import settings
import core.models as models import troggle.core.models as models
from parsers.people import GetPersonExpeditionNameLookup from parsers.people import GetPersonExpeditionNameLookup
from parsers.cavetab import GetCaveLookup from parsers.cavetab import GetCaveLookup

View File

@ -1,7 +1,7 @@
#.-*- coding: utf-8 -*- #.-*- coding: utf-8 -*-
from django.conf import settings from django.conf import settings
import core.models as models import troggle.core.models as models
import csv, re, datetime, os, shutil import csv, re, datetime, os, shutil
from utils import save_carefully from utils import save_carefully

View File

@ -6,7 +6,7 @@ import sys, os
import os, re, logging import os, re, logging
from django.conf import settings from django.conf import settings
from core.models import Subcave, Cave from troggle.core.models import Subcave, Cave
from utils import save_carefully from utils import save_carefully
def getLinksInCaveDescription(cave): def getLinksInCaveDescription(cave):

View File

@ -3,7 +3,7 @@ import sys, os, types, logging, stat
#from troggle import * #from troggle import *
#os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings' #os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
import settings import settings
from core.models import * from troggle.core.models import *
from PIL import Image from PIL import Image
#import settings #import settings
#import core.models as models #import core.models as models

View File

@ -7,7 +7,13 @@ site-specific user profile model specified in the
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import SiteProfileNotAvailable #from django.contrib.auth.models import SiteProfileNotAvailable
try:
from django.contrib.auth.models import SiteProfileNotAvailable
except ImportError: # django >= 1.7
SiteProfileNotAvailable = type('SiteProfileNotAvailable', (Exception,), {})
from django.db.models import get_model from django.db.models import get_model

View File

@ -14,31 +14,31 @@ from django.template import RequestContext
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django import forms from django import forms
from core.models import Person from troggle.core.models import Person
from profiles import utils from profiles import utils
from django.conf import settings from django.conf import settings
class SelectPersonForm(forms.Form): #This and the select_profile view class SelectPersonForm(forms.Form): #This and the select_profile view
person = forms.ModelChoiceField(queryset=Person.objects.all()) person = forms.ModelChoiceField(queryset=Person.objects.all())
def select_profile(request): def select_profile(request):
if request.method == 'POST': if request.method == 'POST':
form = SelectPersonForm(request.POST) form = SelectPersonForm(request.POST)
if form.is_valid(): if form.is_valid():
profile_obj=form.cleaned_data['person'] profile_obj=form.cleaned_data['person']
profile_obj.user=request.user profile_obj.user=request.user
profile_obj.save() profile_obj.save()
return HttpResponseRedirect(profile_obj.get_absolute_url()) return HttpResponseRedirect(profile_obj.get_absolute_url())
else: else:
form = SelectPersonForm() form = SelectPersonForm()
context = RequestContext(request) context = RequestContext(request)
return render_to_response('profiles/select_profile.html', { return render_to_response('profiles/select_profile.html', {
'form':form,}, 'form':form,},
context_instance=context context_instance=context
) )
def create_profile(request, form_class=None, success_url=None, def create_profile(request, form_class=None, success_url=None,

View File

@ -2,11 +2,16 @@ from localsettings import * #inital localsettings call so that urljoins work
import os import os
import urlparse import urlparse
import django import django
# Django settings for troggle project.
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Django settings for troggle project.
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = []
ADMINS = ( ADMINS = (
# ('Your Name', 'your_email@domain.com'), # ('Your Name', 'your_email@domain.com'),
) )
@ -30,6 +35,7 @@ SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not # If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery. # to load the internationalization machinery.
USE_I18N = True USE_I18N = True
USE_L10N = True
FIX_PERMISSIONS = [] FIX_PERMISSIONS = []
NOTABLECAVESHREFS = [ "161", "204", "258", "76", "107", "264" ] NOTABLECAVESHREFS = [ "161", "204", "258", "76", "107", "264" ]
@ -69,23 +75,6 @@ TEMPLATE_CONTEXT_PROCESSORS = ( authmodule, "core.context.troggle_context", )
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = '/'
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'troggle.middleware.SmartAppendSlashMiddleware'
)
ROOT_URLCONF = 'troggle.urls'
ACCOUNT_ACTIVATION_DAYS=3
AUTH_PROFILE_MODULE = 'core.person'
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
@ -94,9 +83,11 @@ INSTALLED_APPS = (
'django.contrib.sites', 'django.contrib.sites',
'django.contrib.redirects', 'django.contrib.redirects',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles',
#'troggle.photologue', #'troggle.photologue',
#'troggle.reversion', #'troggle.reversion',
#'django_evolution', #'django_evolution',
'tinymce',
'registration', 'registration',
'troggle.profiles', 'troggle.profiles',
'troggle.core', 'troggle.core',
@ -104,9 +95,32 @@ INSTALLED_APPS = (
'troggle.imagekit', 'troggle.imagekit',
) )
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'troggle.middleware.SmartAppendSlashMiddleware'
)
ROOT_URLCONF = 'troggle.urls'
WSGI_APPLICATION = 'troggle.wsgi.application'
ACCOUNT_ACTIVATION_DAYS=3
AUTH_PROFILE_MODULE = 'core.person'
QM_PATTERN="\[\[\s*[Qq][Mm]:([ABC]?)(\d{4})-(\d*)-(\d*)\]\]" QM_PATTERN="\[\[\s*[Qq][Mm]:([ABC]?)(\d{4})-(\d*)-(\d*)\]\]"
TINYMCE_JS_URL = 'http://debug.example.org/tiny_mce/tiny_mce_src.js' TINYMCE_JS_URL = 'http://debug.example.org/tiny_mce/tiny_mce_src.js'
#TINYMCE_JS_URL = os.path.join(MEDIA_URL, "tinybibble_mce.js")
TINYMCE_DEFAULT_CONFIG = { TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,spellchecker,paste,searchreplace", 'plugins': "table,spellchecker,paste,searchreplace",
'theme': "advanced", 'theme': "advanced",

View File

@ -1,14 +1,14 @@
from django.conf import settings from django.conf import settings
import random, re, logging import random, re, logging
from core.models import CaveDescription from troggle.core.models import CaveDescription
def weighted_choice(lst): def weighted_choice(lst):
n = random.uniform(0,1) n = random.uniform(0,1)
for item, weight in lst: for item, weight in lst:
if n < weight: if n < weight:
break break
n = n - weight n = n - weight
return item return item
def randomLogbookSentence(): def randomLogbookSentence():
from troggle.core.models import LogbookEntry from troggle.core.models import LogbookEntry