Webapp: Django 1.6 and Python3 fixes

This commit is contained in:
Doug Blank 2015-05-09 22:02:24 -04:00
parent 4e0927eba4
commit 45a1e17bd7
4 changed files with 44 additions and 44 deletions

View File

@ -104,7 +104,7 @@ class mGrampsType(models.Model):
name = models.CharField(max_length=40) name = models.CharField(max_length=40)
def __unicode__(self): def __str__(self):
return str(self.name) return str(self.name)
def get_default_type(self): def get_default_type(self):
@ -408,7 +408,7 @@ class Config(models.Model):
value_type = models.CharField('type of value', max_length=80) value_type = models.CharField('type of value', max_length=80)
value = models.TextField('value') value = models.TextField('value')
def __unicode__(self): def __str__(self):
return str(self.setting) return str(self.setting)
class Tag(models.Model): class Tag(models.Model):
@ -425,7 +425,7 @@ class Tag(models.Model):
cache = models.TextField(blank=True, null=True) cache = models.TextField(blank=True, null=True)
dji = None dji = None
def __unicode__(self): def __str__(self):
return str(self.name) return str(self.name)
def get_url(self): def get_url(self):
@ -491,7 +491,7 @@ class PrimaryObject(models.Model):
tags = models.ManyToManyField('Tag', blank=True, null=True) tags = models.ManyToManyField('Tag', blank=True, null=True)
dji = None dji = None
def __unicode__(self): def __str__(self):
return "%s: %s" % (self.__class__.__name__, return "%s: %s" % (self.__class__.__name__,
self.gramps_id) self.gramps_id)
@ -597,7 +597,7 @@ class Person(PrimaryObject):
except: except:
return "" return ""
def __unicode__(self): def __str__(self):
return "%s [%s]" % (self.get_primary_name(), self.gramps_id) return "%s [%s]" % (self.get_primary_name(), self.gramps_id)
def get_selection_string(self): def get_selection_string(self):
@ -638,7 +638,7 @@ class Family(PrimaryObject):
object_type=obj_type).order_by("order") object_type=obj_type).order_by("order")
return [childref.ref_object for childref in childrefs] return [childref.ref_object for childref in childrefs]
def __unicode__(self): def __str__(self):
father = self.father.get_primary_name() if self.father else "No father" father = self.father.get_primary_name() if self.father else "No father"
mother = self.mother.get_primary_name() if self.mother else "No mother" mother = self.mother.get_primary_name() if self.mother else "No mother"
return "%s and %s" % (father, mother) return "%s and %s" % (father, mother)
@ -651,7 +651,7 @@ class Citation(DateObject, PrimaryObject):
content_type_field="object_type", content_type_field="object_type",
object_id_field="object_id") object_id_field="object_id")
def __unicode__(self): def __str__(self):
return "[%s] (%s, %s) to %s" % (self.gramps_id, return "[%s] (%s, %s) to %s" % (self.gramps_id,
self.confidence, self.confidence,
self.page, self.page,
@ -666,7 +666,7 @@ class Source(PrimaryObject):
pubinfo = models.CharField("Pub. info.", max_length=50, blank=True, null=True) pubinfo = models.CharField("Pub. info.", max_length=50, blank=True, null=True)
abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True) abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True)
def __unicode__(self): def __str__(self):
return "[%s] %s" % (self.gramps_id, return "[%s] %s" % (self.gramps_id,
self.title) self.title)
@ -681,7 +681,7 @@ class Event(DateObject, PrimaryObject):
content_type_field="object_type", content_type_field="object_type",
object_id_field="object_id") object_id_field="object_id")
def __unicode__(self): def __str__(self):
return "[%s] (%s) %s" % (self.gramps_id, return "[%s] (%s) %s" % (self.gramps_id,
self.event_type, self.event_type,
self.description) self.description)
@ -695,7 +695,7 @@ class Repository(PrimaryObject):
object_id_field="object_id") object_id_field="object_id")
#url_list = models.ManyToManyField('Url', null=True, blank=True) #url_list = models.ManyToManyField('Url', null=True, blank=True)
def __unicode__(self): def __str__(self):
return "[%s] %s" % (self.gramps_id, self.name) return "[%s] %s" % (self.gramps_id, self.name)
# Others keys here: # Others keys here:
@ -716,7 +716,7 @@ class Place(PrimaryObject):
def get_selection_string(self): def get_selection_string(self):
return "%s [%s]" % (self.title, self.gramps_id) return "%s [%s]" % (self.title, self.gramps_id)
def __unicode__(self): def __str__(self):
return str(self.title) return str(self.title)
# Others keys here: # Others keys here:
@ -732,7 +732,7 @@ class Media(DateObject, PrimaryObject):
content_type_field="object_type", content_type_field="object_type",
object_id_field="object_id") object_id_field="object_id")
def __unicode__(self): def __str__(self):
return str(self.desc) return str(self.desc)
class Note(PrimaryObject): class Note(PrimaryObject):
@ -743,7 +743,7 @@ class Note(PrimaryObject):
content_type_field="object_type", content_type_field="object_type",
object_id_field="object_id") object_id_field="object_id")
def __unicode__(self): def __str__(self):
return str(self.gramps_id) return str(self.gramps_id)
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
@ -781,7 +781,7 @@ class Surname(models.Model):
name = models.ForeignKey("Name") name = models.ForeignKey("Name")
order = models.PositiveIntegerField() order = models.PositiveIntegerField()
def __unicode__(self): def __str__(self):
return str(self.surname) return str(self.surname)
def get_url(self): def get_url(self):
@ -812,7 +812,7 @@ class Name(DateObject, SecondaryObject):
person = models.ForeignKey("Person") person = models.ForeignKey("Person")
_sanitized = False _sanitized = False
def __unicode__(self): def __str__(self):
try: try:
surname = self.surname_set.get(primary=True) surname = self.surname_set.get(primary=True)
except: except:
@ -989,7 +989,7 @@ class Log(BaseRef):
reason = models.TextField() # must be filled in reason = models.TextField() # must be filled in
cache = models.TextField(blank=True, null=True) cache = models.TextField(blank=True, null=True)
def __unicode__(self): def __str__(self):
return "%s: %s on %s by %s" % (self.log_type, return "%s: %s on %s by %s" % (self.log_type,
self.referenced_by, self.referenced_by,
self.last_changed, self.last_changed,
@ -1001,14 +1001,14 @@ class NoteRef(BaseRef):
def get_reference_to(self): def get_reference_to(self):
return self.ref_object return self.ref_object
def __unicode__(self): def __str__(self):
return "NoteRef to " + str(self.ref_object) return "NoteRef to " + str(self.ref_object)
class EventRef(BaseRef): class EventRef(BaseRef):
ref_object = models.ForeignKey('Event') ref_object = models.ForeignKey('Event')
role_type = models.ForeignKey('EventRoleType') role_type = models.ForeignKey('EventRoleType')
def __unicode__(self): def __str__(self):
return str(self.ref_object) return str(self.ref_object)
def get_reference_to(self): def get_reference_to(self):
@ -1031,7 +1031,7 @@ class RepositoryRef(BaseRef):
def get_reference_to(self): def get_reference_to(self):
return self.ref_object return self.ref_object
def __unicode__(self): def __str__(self):
return "RepositoryRef to " + str(self.ref_object) return "RepositoryRef to " + str(self.ref_object)
class PlaceRef(BaseRef, DateObject): class PlaceRef(BaseRef, DateObject):
@ -1040,7 +1040,7 @@ class PlaceRef(BaseRef, DateObject):
def get_reference_to(self): def get_reference_to(self):
return self.ref_object return self.ref_object
def __unicode__(self): def __str__(self):
return "PlaceRef to " + str(self.ref_object) return "PlaceRef to " + str(self.ref_object)
class PersonRef(BaseRef): class PersonRef(BaseRef):
@ -1050,13 +1050,13 @@ class PersonRef(BaseRef):
def get_reference_to(self): def get_reference_to(self):
return self.ref_object return self.ref_object
def __unicode__(self): def __str__(self):
return "PersonRef to " + str(self.ref_object) return "PersonRef to " + str(self.ref_object)
class CitationRef(BaseRef): class CitationRef(BaseRef):
citation = models.ForeignKey('Citation') citation = models.ForeignKey('Citation')
def __unicode__(self): def __str__(self):
return "CitationRef to " + str(self.citation) return "CitationRef to " + str(self.citation)
def get_reference_to(self): def get_reference_to(self):
@ -1076,7 +1076,7 @@ class ChildRef(BaseRef):
# FIXME: go to child reference # FIXME: go to child reference
return "/person/%s" % self.ref_object.handle return "/person/%s" % self.ref_object.handle
def __unicode__(self): def __str__(self):
return "ChildRef to " + str(self.ref_object) return "ChildRef to " + str(self.ref_object)
class MediaRef(BaseRef): class MediaRef(BaseRef):
@ -1089,7 +1089,7 @@ class MediaRef(BaseRef):
def get_reference_to(self): def get_reference_to(self):
return self.ref_object return self.ref_object
def __unicode__(self): def __str__(self):
return "MediaRef to " + str(self.ref_object) return "MediaRef to " + str(self.ref_object)
class Report(models.Model): class Report(models.Model):
@ -1099,7 +1099,7 @@ class Report(models.Model):
report_type = models.TextField(blank=True, null=True) report_type = models.TextField(blank=True, null=True)
options = models.TextField(blank=True, null=True) options = models.TextField(blank=True, null=True)
def __unicode__(self): def __str__(self):
return str(self.name) return str(self.name)
class Result(models.Model): class Result(models.Model):
@ -1109,7 +1109,7 @@ class Result(models.Model):
run_by = models.TextField('run by', blank=True, null=True) run_by = models.TextField('run by', blank=True, null=True)
status = models.TextField(blank=True, null=True) status = models.TextField(blank=True, null=True)
def __unicode__(self): def __str__(self):
return str(self.name) return str(self.name)
TABLES = [ TABLES = [

View File

@ -37,7 +37,7 @@ class Profile(models.Model):
user = models.OneToOneField(User, related_name="profile") user = models.OneToOneField(User, related_name="profile")
theme_type = models.ForeignKey("ThemeType", default=1) # The default is a pk? theme_type = models.ForeignKey("ThemeType", default=1) # The default is a pk?
def __unicode__(self): def __str__(self):
return str(self.user) return str(self.user)
post_save.connect(save_profile, sender=User) post_save.connect(save_profile, sender=User)

View File

@ -99,7 +99,7 @@ def process_media(request, context, handle, act, add_to=None): # view, edit, sav
# FIXME: This should be absolute: # FIXME: This should be absolute:
folder = Config.objects.get(setting="behavior.addmedia-image-dir").value folder = Config.objects.get(setting="behavior.addmedia-image-dir").value
# FIXME: media.path should not have any .. for security # FIXME: media.path should not have any .. for security
response = HttpResponse(mimetype=media.mime) response = HttpResponse(content_type=media.mime)
if NEW_PIL or media_ext != "png": if NEW_PIL or media_ext != "png":
image = Image.open("%s/%s" % (folder, media.path)) image = Image.open("%s/%s" % (folder, media.path))
image.save(response, media_ext) image.save(response, media_ext)
@ -116,7 +116,7 @@ def process_media(request, context, handle, act, add_to=None): # view, edit, sav
# FIXME: This should be absolute: # FIXME: This should be absolute:
folder = Config.objects.get(setting="behavior.addmedia-image-dir").value folder = Config.objects.get(setting="behavior.addmedia-image-dir").value
# FIXME: media.path should not have any .. for security # FIXME: media.path should not have any .. for security
response = HttpResponse(mimetype=media.mime) response = HttpResponse(content_type=media.mime)
if os.path.exists("%s/thumbnail/%s" % (folder, media.path)): if os.path.exists("%s/thumbnail/%s" % (folder, media.path)):
if NEW_PIL or media_ext != "png": if NEW_PIL or media_ext != "png":
image = Image.open("%s/thumbnail/%s" % (folder, media.path)) image = Image.open("%s/thumbnail/%s" % (folder, media.path))

View File

@ -180,8 +180,8 @@ def send_file(request, filename, mimetype):
iterator for chunks of 8KB. iterator for chunks of 8KB.
""" """
from django.core.servers.basehttp import FileWrapper from django.core.servers.basehttp import FileWrapper
wrapper = FileWrapper(file(filename)) wrapper = FileWrapper(open(filename, mode="rb"))
response = HttpResponse(wrapper, mimetype=mimetype) response = HttpResponse(wrapper, content_type=mimetype)
path, base = os.path.split(filename) path, base = os.path.split(filename)
response['Content-Length'] = os.path.getsize(filename) response['Content-Length'] = os.path.getsize(filename)
response['Content-Disposition'] = 'attachment; filename=%s' % base response['Content-Disposition'] = 'attachment; filename=%s' % base
@ -267,8 +267,8 @@ def process_report_run(request, handle):
if filename.endswith(".html"): if filename.endswith(".html"):
# just give it, perhaps in a new tab # just give it, perhaps in a new tab
from django.http import HttpResponse from django.http import HttpResponse
response = HttpResponse(mimetype="text/html") response = HttpResponse(content_type="text/html")
for line in open(filename): for line in open(filename, mode="rb"):
response.write(line) response.write(line)
return response return response
else: else:
@ -487,7 +487,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_event_from_handle(obj.handle) item = db.get_event_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_event_detail.html' view_template = 'view_event_detail.html'
rd = process_event(request, context, handle, act, add_to) rd = process_event(request, context, handle, act, add_to)
@ -503,7 +503,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_family_from_handle(obj.handle) item = db.get_family_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_family_detail.html' view_template = 'view_family_detail.html'
rd = process_family(request, context, handle, act, add_to) rd = process_family(request, context, handle, act, add_to)
@ -519,7 +519,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_media_from_handle(obj.handle) item = db.get_media_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_media_detail.html' view_template = 'view_media_detail.html'
rd = process_media(request, context, handle, act, add_to) rd = process_media(request, context, handle, act, add_to)
@ -535,7 +535,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_note_from_handle(obj.handle) item = db.get_note_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_note_detail.html' view_template = 'view_note_detail.html'
rd = process_note(request, context, handle, act, add_to) rd = process_note(request, context, handle, act, add_to)
@ -551,7 +551,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
person = db.get_person_from_handle(obj.handle) person = db.get_person_from_handle(obj.handle)
content = str(person.to_struct()) content = str(person.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_person_detail.html' view_template = 'view_person_detail.html'
rd = process_person(request, context, handle, act, add_to) rd = process_person(request, context, handle, act, add_to)
@ -567,7 +567,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_place_from_handle(obj.handle) item = db.get_place_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_place_detail.html' view_template = 'view_place_detail.html'
rd = process_place(request, context, handle, act, add_to) rd = process_place(request, context, handle, act, add_to)
@ -583,7 +583,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_repository_from_handle(obj.handle) item = db.get_repository_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_repository_detail.html' view_template = 'view_repository_detail.html'
rd = process_repository(request, context, handle, act, add_to) rd = process_repository(request, context, handle, act, add_to)
@ -599,7 +599,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_citation_from_handle(obj.handle) item = db.get_citation_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_citation_detail.html' view_template = 'view_citation_detail.html'
rd = process_citation(request, context, handle, act, add_to) rd = process_citation(request, context, handle, act, add_to)
@ -615,7 +615,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_source_from_handle(obj.handle) item = db.get_source_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_source_detail.html' view_template = 'view_source_detail.html'
rd = process_source(request, context, handle, act, add_to) rd = process_source(request, context, handle, act, add_to)
@ -631,7 +631,7 @@ def action(request, view, handle, act, add_to=None):
if request.GET["format"] == "json": if request.GET["format"] == "json":
item = db.get_tag_from_handle(obj.handle) item = db.get_tag_from_handle(obj.handle)
content = str(item.to_struct()) content = str(item.to_struct())
response = HttpResponse(content, mimetype="application/json") response = HttpResponse(content, content_type="application/json")
return response return response
view_template = 'view_tag_detail.html' view_template = 'view_tag_detail.html'
rd = process_tag(request, context, handle, act, add_to) rd = process_tag(request, context, handle, act, add_to)
@ -1589,4 +1589,4 @@ def process_json_request(request):
obj = db.get_from_name_and_handle(class_type.__name__, eval(handle_expr)) obj = db.get_from_name_and_handle(class_type.__name__, eval(handle_expr))
if obj: if obj:
response_data["results"].append(obj.to_struct()) response_data["results"].append(obj.to_struct())
return HttpResponse(simplejson.dumps(response_data), mimetype="application/json") return HttpResponse(simplejson.dumps(response_data), content_type="application/json")