Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/migrations/0007_auto_20160805_1304.py Fri Aug 05 15:19:47 2016 +0200
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-08-05 13:04
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('iconolab', '0006_metacategory_triggers_notifications'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='tag',
+ name='label_slug',
+ field=models.SlugField(blank=True, null=True),
+ ),
+ migrations.AlterField(
+ model_name='tag',
+ name='label',
+ field=models.CharField(blank=True, max_length=255, null=True),
+ ),
+ ]
--- a/src/iconolab/models.py Fri Aug 05 14:48:52 2016 +0200
+++ b/src/iconolab/models.py Fri Aug 05 15:19:47 2016 +0200
@@ -10,7 +10,8 @@
class Tag(models.Model):
- label = models.SlugField(blank=True, null=True)
+ label = models.CharField(max_length=255, blank=True, null=True)
+ label_slug = models.SlugField(blank=True, null=True)
link = models.URLField(unique=True)
description = models.CharField(max_length=255, blank=True, null=True)
collection = models.ForeignKey('Collection', blank=True, null=True)
@@ -214,6 +215,7 @@
if new_revision.state == AnnotationRevision.ACCEPTED:
self.current_revision = new_revision
self.save()
+ print(new_revision)
iconolab_signals.revision_created.send(sender=AnnotationRevision, instance=new_revision)
return new_revision
@@ -300,6 +302,7 @@
else:
tag_obj = Tag.objects.create(
label = tag_string,
+ label_slug = slugify(tag_string),
description = "",
link = settings.INTERNAL_TAGS_URL+'/'+slugify(tag_string),
collection = self.annotation.image.item.collection
@@ -326,6 +329,7 @@
}
)
except:
+ # dbpedia is down, will be handled with database label
pass
try:
results = json.loads(dbpedia_resp.text).get("results", {})
@@ -333,11 +337,10 @@
# if error with json, results is empty
results = {}
variable_bindings = results.get("bindings", None)
+ label_data = {}
if variable_bindings:
- label_json = variable_bindings.pop()
- else:
- label_json = {"l": {"value": "ERROR_LABEL"}}
- return label_json.get("l").get("value")
+ label_data = variable_bindings.pop()
+ return label_data.get("l", {"value": False}).get("value")
final_list = []
for tagging_info in self.tagginginfo_set.select_related("tag").all():
@@ -359,6 +362,11 @@
try:
(source, fetch_label) = next(item for item in externaL_repos_fetch_dict.items() if tag_link.startswith(item[0]))
tag_label = fetch_label(tag_link, "fr", source)
+ if not tag_label: # Error happened and we got False as a fetch return
+ tag_label = tagging_info.tag.label
+ else:
+ tagging_info.tag.label = tag_label
+ tagging_info.tag.save()
final_list.append({
"tag_label": tag_label,
"tag_link": tag_link,
--- a/src/iconolab/signals/handlers.py Fri Aug 05 14:48:52 2016 +0200
+++ b/src/iconolab/signals/handlers.py Fri Aug 05 15:19:47 2016 +0200
@@ -12,12 +12,13 @@
def increment_stats_on_new_revision(sender, instance, **kwargs):
from iconolab.models import AnnotationRevision
if sender == AnnotationRevision:
+ print(instance)
# Annotation stats
annotation = instance.annotation
annotation.stats.submitted_revisions_count += 1
if instance.state in [AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]:
annotation.stats.accepted_revisions_count += 1
- if instance.state == AnnotationRevision.ACCEPTED and instance.merge_parent_revision.state == AnnotationRevision.STUDIED:
+ if instance.state == AnnotationRevision.ACCEPTED and instance.merge_parent_revision is not None and instance.merge_parent_revision.state == AnnotationRevision.STUDIED:
annotation.stats.awaiting_revisions_count -= 1
if instance.state in [AnnotationRevision.AWAITING]:
annotation.stats.awaiting_revisions_count += 1