From 45a1e17bd7ff8561feec44bd631201eae0487557 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 9 May 2015 22:02:24 -0400 Subject: [PATCH] Webapp: Django 1.6 and Python3 fixes --- gramps/webapp/grampsdb/models.py | 52 ++++++++++++++-------------- gramps/webapp/grampsdb/profile.py | 2 +- gramps/webapp/grampsdb/view/media.py | 4 +-- gramps/webapp/grampsdb/views.py | 30 ++++++++-------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/gramps/webapp/grampsdb/models.py b/gramps/webapp/grampsdb/models.py index 9fe3263e1..85d880f48 100644 --- a/gramps/webapp/grampsdb/models.py +++ b/gramps/webapp/grampsdb/models.py @@ -104,7 +104,7 @@ class mGrampsType(models.Model): name = models.CharField(max_length=40) - def __unicode__(self): + def __str__(self): return str(self.name) def get_default_type(self): @@ -408,7 +408,7 @@ class Config(models.Model): value_type = models.CharField('type of value', max_length=80) value = models.TextField('value') - def __unicode__(self): + def __str__(self): return str(self.setting) class Tag(models.Model): @@ -425,7 +425,7 @@ class Tag(models.Model): cache = models.TextField(blank=True, null=True) dji = None - def __unicode__(self): + def __str__(self): return str(self.name) def get_url(self): @@ -491,7 +491,7 @@ class PrimaryObject(models.Model): tags = models.ManyToManyField('Tag', blank=True, null=True) dji = None - def __unicode__(self): + def __str__(self): return "%s: %s" % (self.__class__.__name__, self.gramps_id) @@ -597,7 +597,7 @@ class Person(PrimaryObject): except: return "" - def __unicode__(self): + def __str__(self): return "%s [%s]" % (self.get_primary_name(), self.gramps_id) def get_selection_string(self): @@ -638,7 +638,7 @@ class Family(PrimaryObject): object_type=obj_type).order_by("order") 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" mother = self.mother.get_primary_name() if self.mother else "No mother" return "%s and %s" % (father, mother) @@ -651,7 +651,7 @@ class Citation(DateObject, PrimaryObject): content_type_field="object_type", object_id_field="object_id") - def __unicode__(self): + def __str__(self): return "[%s] (%s, %s) to %s" % (self.gramps_id, self.confidence, self.page, @@ -666,7 +666,7 @@ class Source(PrimaryObject): pubinfo = models.CharField("Pub. info.", 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, self.title) @@ -681,7 +681,7 @@ class Event(DateObject, PrimaryObject): content_type_field="object_type", object_id_field="object_id") - def __unicode__(self): + def __str__(self): return "[%s] (%s) %s" % (self.gramps_id, self.event_type, self.description) @@ -695,7 +695,7 @@ class Repository(PrimaryObject): object_id_field="object_id") #url_list = models.ManyToManyField('Url', null=True, blank=True) - def __unicode__(self): + def __str__(self): return "[%s] %s" % (self.gramps_id, self.name) # Others keys here: @@ -716,7 +716,7 @@ class Place(PrimaryObject): def get_selection_string(self): return "%s [%s]" % (self.title, self.gramps_id) - def __unicode__(self): + def __str__(self): return str(self.title) # Others keys here: @@ -732,7 +732,7 @@ class Media(DateObject, PrimaryObject): content_type_field="object_type", object_id_field="object_id") - def __unicode__(self): + def __str__(self): return str(self.desc) class Note(PrimaryObject): @@ -743,7 +743,7 @@ class Note(PrimaryObject): content_type_field="object_type", object_id_field="object_id") - def __unicode__(self): + def __str__(self): return str(self.gramps_id) #--------------------------------------------------------------------------- @@ -781,7 +781,7 @@ class Surname(models.Model): name = models.ForeignKey("Name") order = models.PositiveIntegerField() - def __unicode__(self): + def __str__(self): return str(self.surname) def get_url(self): @@ -812,7 +812,7 @@ class Name(DateObject, SecondaryObject): person = models.ForeignKey("Person") _sanitized = False - def __unicode__(self): + def __str__(self): try: surname = self.surname_set.get(primary=True) except: @@ -989,7 +989,7 @@ class Log(BaseRef): reason = models.TextField() # must be filled in cache = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): return "%s: %s on %s by %s" % (self.log_type, self.referenced_by, self.last_changed, @@ -1001,14 +1001,14 @@ class NoteRef(BaseRef): def get_reference_to(self): return self.ref_object - def __unicode__(self): + def __str__(self): return "NoteRef to " + str(self.ref_object) class EventRef(BaseRef): ref_object = models.ForeignKey('Event') role_type = models.ForeignKey('EventRoleType') - def __unicode__(self): + def __str__(self): return str(self.ref_object) def get_reference_to(self): @@ -1031,7 +1031,7 @@ class RepositoryRef(BaseRef): def get_reference_to(self): return self.ref_object - def __unicode__(self): + def __str__(self): return "RepositoryRef to " + str(self.ref_object) class PlaceRef(BaseRef, DateObject): @@ -1040,7 +1040,7 @@ class PlaceRef(BaseRef, DateObject): def get_reference_to(self): return self.ref_object - def __unicode__(self): + def __str__(self): return "PlaceRef to " + str(self.ref_object) class PersonRef(BaseRef): @@ -1050,13 +1050,13 @@ class PersonRef(BaseRef): def get_reference_to(self): return self.ref_object - def __unicode__(self): + def __str__(self): return "PersonRef to " + str(self.ref_object) class CitationRef(BaseRef): citation = models.ForeignKey('Citation') - def __unicode__(self): + def __str__(self): return "CitationRef to " + str(self.citation) def get_reference_to(self): @@ -1076,7 +1076,7 @@ class ChildRef(BaseRef): # FIXME: go to child reference return "/person/%s" % self.ref_object.handle - def __unicode__(self): + def __str__(self): return "ChildRef to " + str(self.ref_object) class MediaRef(BaseRef): @@ -1089,7 +1089,7 @@ class MediaRef(BaseRef): def get_reference_to(self): return self.ref_object - def __unicode__(self): + def __str__(self): return "MediaRef to " + str(self.ref_object) class Report(models.Model): @@ -1099,7 +1099,7 @@ class Report(models.Model): report_type = models.TextField(blank=True, null=True) options = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): return str(self.name) class Result(models.Model): @@ -1109,7 +1109,7 @@ class Result(models.Model): run_by = models.TextField('run by', blank=True, null=True) status = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): return str(self.name) TABLES = [ diff --git a/gramps/webapp/grampsdb/profile.py b/gramps/webapp/grampsdb/profile.py index b422fb40a..d5ee77202 100644 --- a/gramps/webapp/grampsdb/profile.py +++ b/gramps/webapp/grampsdb/profile.py @@ -37,7 +37,7 @@ class Profile(models.Model): user = models.OneToOneField(User, related_name="profile") theme_type = models.ForeignKey("ThemeType", default=1) # The default is a pk? - def __unicode__(self): + def __str__(self): return str(self.user) post_save.connect(save_profile, sender=User) diff --git a/gramps/webapp/grampsdb/view/media.py b/gramps/webapp/grampsdb/view/media.py index fa5c0720b..aecd4f014 100644 --- a/gramps/webapp/grampsdb/view/media.py +++ b/gramps/webapp/grampsdb/view/media.py @@ -99,7 +99,7 @@ def process_media(request, context, handle, act, add_to=None): # view, edit, sav # FIXME: This should be absolute: folder = Config.objects.get(setting="behavior.addmedia-image-dir").value # 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": image = Image.open("%s/%s" % (folder, media.path)) 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: folder = Config.objects.get(setting="behavior.addmedia-image-dir").value # 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 NEW_PIL or media_ext != "png": image = Image.open("%s/thumbnail/%s" % (folder, media.path)) diff --git a/gramps/webapp/grampsdb/views.py b/gramps/webapp/grampsdb/views.py index 643db7b39..073eae43d 100644 --- a/gramps/webapp/grampsdb/views.py +++ b/gramps/webapp/grampsdb/views.py @@ -180,8 +180,8 @@ def send_file(request, filename, mimetype): iterator for chunks of 8KB. """ from django.core.servers.basehttp import FileWrapper - wrapper = FileWrapper(file(filename)) - response = HttpResponse(wrapper, mimetype=mimetype) + wrapper = FileWrapper(open(filename, mode="rb")) + response = HttpResponse(wrapper, content_type=mimetype) path, base = os.path.split(filename) response['Content-Length'] = os.path.getsize(filename) response['Content-Disposition'] = 'attachment; filename=%s' % base @@ -267,8 +267,8 @@ def process_report_run(request, handle): if filename.endswith(".html"): # just give it, perhaps in a new tab from django.http import HttpResponse - response = HttpResponse(mimetype="text/html") - for line in open(filename): + response = HttpResponse(content_type="text/html") + for line in open(filename, mode="rb"): response.write(line) return response else: @@ -487,7 +487,7 @@ def action(request, view, handle, act, add_to=None): if request.GET["format"] == "json": item = db.get_event_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_event_detail.html' 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": item = db.get_family_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_family_detail.html' 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": item = db.get_media_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_media_detail.html' 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": item = db.get_note_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_note_detail.html' 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": person = db.get_person_from_handle(obj.handle) content = str(person.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_person_detail.html' 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": item = db.get_place_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_place_detail.html' 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": item = db.get_repository_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_repository_detail.html' 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": item = db.get_citation_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_citation_detail.html' 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": item = db.get_source_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_source_detail.html' 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": item = db.get_tag_from_handle(obj.handle) content = str(item.to_struct()) - response = HttpResponse(content, mimetype="application/json") + response = HttpResponse(content, content_type="application/json") return response view_template = 'view_tag_detail.html' 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)) if obj: 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")