cleanup use of python-ox api
This commit is contained in:
parent
5aac6ebe22
commit
69b1e6c7b2
10 changed files with 25 additions and 25 deletions
|
@ -44,10 +44,10 @@ def get_matches(obj, model, layer_type):
|
||||||
has_type = 'has%ss' % layer_type.capitalize()
|
has_type = 'has%ss' % layer_type.capitalize()
|
||||||
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])]
|
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])]
|
||||||
if contains:
|
if contains:
|
||||||
name = ox.decodeHtml(obj.name)
|
name = ox.decode_html(obj.name)
|
||||||
q = Q(findvalue__icontains=" " + name)|Q(findvalue__istartswith=name)
|
q = Q(findvalue__icontains=" " + name)|Q(findvalue__istartswith=name)
|
||||||
for name in obj.alternativeNames:
|
for name in obj.alternativeNames:
|
||||||
name = ox.decodeHtml(name)
|
name = ox.decode_html(name)
|
||||||
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
||||||
contains_matches = q&Q(layer__in=contains)
|
contains_matches = q&Q(layer__in=contains)
|
||||||
if f:
|
if f:
|
||||||
|
@ -59,11 +59,11 @@ def get_matches(obj, model, layer_type):
|
||||||
for a in Annotation.objects.filter(f):
|
for a in Annotation.objects.filter(f):
|
||||||
value = a.findvalue.lower()
|
value = a.findvalue.lower()
|
||||||
for name in super_matches:
|
for name in super_matches:
|
||||||
name = ox.decodeHtml(name)
|
name = ox.decode_html(name)
|
||||||
value = value.replace(name.lower(), '')
|
value = value.replace(name.lower(), '')
|
||||||
for name in [obj.name] + list(obj.alternativeNames):
|
for name in [obj.name] + list(obj.alternativeNames):
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
name = ox.decodeHtml(name)
|
name = ox.decode_html(name)
|
||||||
if name in value and (exact or re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name).findall(value)):
|
if name in value and (exact or re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name).findall(value)):
|
||||||
matches.append(a.id)
|
matches.append(a.id)
|
||||||
break
|
break
|
||||||
|
@ -130,7 +130,7 @@ class Annotation(models.Model):
|
||||||
layer = self.get_layer()
|
layer = self.get_layer()
|
||||||
if self.value:
|
if self.value:
|
||||||
self.value = utils.cleanup_value(self.value, layer['type'])
|
self.value = utils.cleanup_value(self.value, layer['type'])
|
||||||
self.findvalue = ox.decodeHtml(ox.stripTags(self.value).strip()).replace('\n', ' ')
|
self.findvalue = ox.decode_html(ox.strip_tags(self.value).strip()).replace('\n', ' ')
|
||||||
sortvalue = sort_string(self.findvalue)
|
sortvalue = sort_string(self.findvalue)
|
||||||
if sortvalue:
|
if sortvalue:
|
||||||
self.sortvalue = sortvalue[:900]
|
self.sortvalue = sortvalue[:900]
|
||||||
|
|
|
@ -26,7 +26,7 @@ def update_matching_events(id):
|
||||||
if a.findvalue:
|
if a.findvalue:
|
||||||
names = {}
|
names = {}
|
||||||
for n in Event.objects.all().values('id', 'name', 'alternativeNames'):
|
for n in Event.objects.all().values('id', 'name', 'alternativeNames'):
|
||||||
names[n['id']] = [ox.decodeHtml(x) for x in [n['name']] + json.loads(n['alternativeNames'])]
|
names[n['id']] = [ox.decode_html(x) for x in [n['name']] + json.loads(n['alternativeNames'])]
|
||||||
|
|
||||||
value = a.findvalue.lower()
|
value = a.findvalue.lower()
|
||||||
update = []
|
update = []
|
||||||
|
@ -56,7 +56,7 @@ def update_matching_places(id):
|
||||||
if a.findvalue:
|
if a.findvalue:
|
||||||
names = {}
|
names = {}
|
||||||
for n in Place.objects.all().values('id', 'name', 'alternativeNames'):
|
for n in Place.objects.all().values('id', 'name', 'alternativeNames'):
|
||||||
names[n['id']] = [ox.decodeHtml(x) for x in [n['name']] + json.loads(n['alternativeNames'])]
|
names[n['id']] = [ox.decode_html(x) for x in [n['name']] + json.loads(n['alternativeNames'])]
|
||||||
value = a.findvalue.lower()
|
value = a.findvalue.lower()
|
||||||
update = []
|
update = []
|
||||||
for i in names:
|
for i in names:
|
||||||
|
|
|
@ -5,7 +5,7 @@ import ox
|
||||||
def cleanup_value(value, layer_type):
|
def cleanup_value(value, layer_type):
|
||||||
#FIXME: what about other types? location etc
|
#FIXME: what about other types? location etc
|
||||||
if layer_type == 'text':
|
if layer_type == 'text':
|
||||||
value = ox.parse_html(value)
|
value = ox.sanitize_html(value)
|
||||||
else:
|
else:
|
||||||
value = ox.escape_html(value)
|
value = ox.escape_html(value)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -139,7 +139,7 @@ def editPage(request):
|
||||||
page, created = models.Page.objects.get_or_create(name=data['name'])
|
page, created = models.Page.objects.get_or_create(name=data['name'])
|
||||||
if not created:
|
if not created:
|
||||||
page.log()
|
page.log()
|
||||||
page.text = ox.parse_html(data['text'])
|
page.text = ox.sanitize_html(data['text'])
|
||||||
page.save()
|
page.save()
|
||||||
response = json_response({'name': page.name, 'text': page.text})
|
response = json_response({'name': page.name, 'text': page.text})
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -31,7 +31,7 @@ def addEvent(request):
|
||||||
exists = False
|
exists = False
|
||||||
names = [data['name']] + data.get('alternativeNames', [])
|
names = [data['name']] + data.get('alternativeNames', [])
|
||||||
for name in names:
|
for name in names:
|
||||||
name = ox.decodeHtml(name)
|
name = ox.decode_html(name)
|
||||||
if models.Event.objects.filter(defined=True,
|
if models.Event.objects.filter(defined=True,
|
||||||
name_find__icontains=u'|%s|'%name).count() != 0:
|
name_find__icontains=u'|%s|'%name).count() != 0:
|
||||||
exists = True
|
exists = True
|
||||||
|
|
|
@ -227,7 +227,7 @@ class Item(models.Model):
|
||||||
if not description:
|
if not description:
|
||||||
description = ''
|
description = ''
|
||||||
d, created = Description.objects.get_or_create(key=k, value=value)
|
d, created = Description.objects.get_or_create(key=k, value=value)
|
||||||
d.description = ox.parse_html(description)
|
d.description = ox.sanitize_html(description)
|
||||||
d.save()
|
d.save()
|
||||||
for key in data:
|
for key in data:
|
||||||
if data[key] == None:
|
if data[key] == None:
|
||||||
|
@ -237,9 +237,9 @@ class Item(models.Model):
|
||||||
k = filter(lambda i: i['id'] == key, settings.CONFIG['itemKeys'])
|
k = filter(lambda i: i['id'] == key, settings.CONFIG['itemKeys'])
|
||||||
ktype = k and k[0].get('type') or ''
|
ktype = k and k[0].get('type') or ''
|
||||||
if ktype == 'text':
|
if ktype == 'text':
|
||||||
self.data[key] = ox.parse_html(data[key])
|
self.data[key] = ox.sanitize_html(data[key])
|
||||||
elif ktype == '[text]':
|
elif ktype == '[text]':
|
||||||
self.data[key] = [ox.parse_html(t) for t in data[key]]
|
self.data[key] = [ox.sanitize_html(t) for t in data[key]]
|
||||||
elif ktype == '[string]':
|
elif ktype == '[string]':
|
||||||
self.data[key] = [ox.escape_html(t) for t in data[key]]
|
self.data[key] = [ox.escape_html(t) for t in data[key]]
|
||||||
elif isinstance(data[key], basestring):
|
elif isinstance(data[key], basestring):
|
||||||
|
@ -579,7 +579,7 @@ class Item(models.Model):
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
value = value and 'true' or 'false'
|
value = value and 'true' or 'false'
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
value = ox.decodeHtml(ox.stripTags(value.strip()))
|
value = ox.decode_html(ox.strip_tags(value.strip()))
|
||||||
f.value = value
|
f.value = value
|
||||||
f.save()
|
f.save()
|
||||||
else:
|
else:
|
||||||
|
@ -660,7 +660,7 @@ class Item(models.Model):
|
||||||
if not value:
|
if not value:
|
||||||
value = None
|
value = None
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
value = ox.decodeHtml(value.lower())
|
value = ox.decode_html(value.lower())
|
||||||
setattr(s, name, value)
|
setattr(s, name, value)
|
||||||
|
|
||||||
base_keys = (
|
base_keys = (
|
||||||
|
@ -809,7 +809,7 @@ class Item(models.Model):
|
||||||
def update_layer_facet(self, key):
|
def update_layer_facet(self, key):
|
||||||
current_values = [a['value']
|
current_values = [a['value']
|
||||||
for a in self.annotations.filter(layer=key).distinct().values('value')]
|
for a in self.annotations.filter(layer=key).distinct().values('value')]
|
||||||
current_values = [ox.decodeHtml(v) for v in current_values]
|
current_values = [ox.decode_html(v) for v in current_values]
|
||||||
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
||||||
removed_values = filter(lambda i: i not in current_values, saved_values)
|
removed_values = filter(lambda i: i not in current_values, saved_values)
|
||||||
if removed_values:
|
if removed_values:
|
||||||
|
@ -854,7 +854,7 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
current_values = [unicode(current_values)]
|
current_values = [unicode(current_values)]
|
||||||
current_values = list(set(current_values))
|
current_values = list(set(current_values))
|
||||||
current_values = [ox.decodeHtml(v) for v in current_values]
|
current_values = [ox.decode_html(v) for v in current_values]
|
||||||
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]
|
||||||
removed_values = filter(lambda i: i not in current_values, saved_values)
|
removed_values = filter(lambda i: i not in current_values, saved_values)
|
||||||
if removed_values:
|
if removed_values:
|
||||||
|
|
|
@ -434,7 +434,7 @@ def edit(request):
|
||||||
response = json_response(status=200, text='ok')
|
response = json_response(status=200, text='ok')
|
||||||
if 'notes' in data:
|
if 'notes' in data:
|
||||||
if request.user.get_profile().capability('canEditMetadata'):
|
if request.user.get_profile().capability('canEditMetadata'):
|
||||||
item.notes = ox.parse_html(data['notes'])
|
item.notes = ox.sanitize_html(data['notes'])
|
||||||
del data['notes']
|
del data['notes']
|
||||||
if 'rightslevel' in data:
|
if 'rightslevel' in data:
|
||||||
item.level = int(data['rightslevel'])
|
item.level = int(data['rightslevel'])
|
||||||
|
@ -1131,7 +1131,7 @@ def item(request, id):
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = value = ', '.join(value)
|
value = value = ', '.join(value)
|
||||||
if value:
|
if value:
|
||||||
ctx[key] = ox.stripTags(value)
|
ctx[key] = ox.strip_tags(value)
|
||||||
|
|
||||||
context = RequestContext(request, ctx)
|
context = RequestContext(request, ctx)
|
||||||
return render_to_response(template, context)
|
return render_to_response(template, context)
|
||||||
|
|
|
@ -243,7 +243,7 @@ def addList(request):
|
||||||
value = list.status
|
value = list.status
|
||||||
list.status = value
|
list.status = value
|
||||||
if 'description' in data:
|
if 'description' in data:
|
||||||
list.description = ox.parse_html(data['description'])
|
list.description = ox.sanitize_html(data['description'])
|
||||||
if 'view' in data:
|
if 'view' in data:
|
||||||
list.view = data['view']
|
list.view = data['view']
|
||||||
if 'sort' in data:
|
if 'sort' in data:
|
||||||
|
@ -363,7 +363,7 @@ def editList(request):
|
||||||
name = data['name'] + ' [%d]' % num
|
name = data['name'] + ' [%d]' % num
|
||||||
list.name = name
|
list.name = name
|
||||||
elif key == 'description':
|
elif key == 'description':
|
||||||
list.description = ox.parse_html(data['description'])
|
list.description = ox.sanitize_html(data['description'])
|
||||||
|
|
||||||
if 'position' in data:
|
if 'position' in data:
|
||||||
pos, created = models.Position.objects.get_or_create(list=list, user=request.user)
|
pos, created = models.Position.objects.get_or_create(list=list, user=request.user)
|
||||||
|
|
|
@ -55,7 +55,7 @@ def addPlace(request):
|
||||||
for n in data.get('alternativeNames', [])]
|
for n in data.get('alternativeNames', [])]
|
||||||
name = ox.escape_html(name)
|
name = ox.escape_html(name)
|
||||||
for n in names:
|
for n in names:
|
||||||
n = ox.decodeHtml(name)
|
n = ox.decode_html(name)
|
||||||
if models.Place.objects.filter(defined=True,
|
if models.Place.objects.filter(defined=True,
|
||||||
name_find__icontains=u'|%s|'%n).count() != 0:
|
name_find__icontains=u'|%s|'%n).count() != 0:
|
||||||
exists = True
|
exists = True
|
||||||
|
@ -117,7 +117,7 @@ def editPlace(request):
|
||||||
if alternative_names:
|
if alternative_names:
|
||||||
data['alternativeNames'] = alternative_names
|
data['alternativeNames'] = alternative_names
|
||||||
for name in names + alternative_names:
|
for name in names + alternative_names:
|
||||||
name = ox.decodeHtml(name)
|
name = ox.decode_html(name)
|
||||||
if models.Place.objects.filter(defined=True,
|
if models.Place.objects.filter(defined=True,
|
||||||
name_find__icontains=u'|%s|'%name).exclude(id=place.id).count() != 0:
|
name_find__icontains=u'|%s|'%name).exclude(id=place.id).count() != 0:
|
||||||
conflict = True
|
conflict = True
|
||||||
|
|
|
@ -643,8 +643,8 @@ def contact(request):
|
||||||
'footer': settings.CONFIG['site']['email']['footer'],
|
'footer': settings.CONFIG['site']['email']['footer'],
|
||||||
'url': request.build_absolute_uri('/'),
|
'url': request.build_absolute_uri('/'),
|
||||||
})
|
})
|
||||||
subject = ox.decodeHtml(subject)
|
subject = ox.decode_html(subject)
|
||||||
message = ox.decodeHtml(template.render(context))
|
message = ox.decode_html(template.render(context))
|
||||||
response = json_response(text='message sent')
|
response = json_response(text='message sent')
|
||||||
try:
|
try:
|
||||||
send_mail(u'%s Contact - %s' % (settings.SITENAME, subject), message, email_from, email_to)
|
send_mail(u'%s Contact - %s' % (settings.SITENAME, subject), message, email_from, email_to)
|
||||||
|
|
Loading…
Reference in a new issue