Skip to content

Commit

Permalink
Merge branch 'hotfix/1.12.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Feb 13, 2015
2 parents 3edb838 + 8a9e1d4 commit e78b8f0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
31 changes: 30 additions & 1 deletion app/detective/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from app.detective import utils
from app.detective.exceptions import UnavailableImage
from app.detective.permissions import create_permissions, remove_permissions
from app.detective.parser import schema
from app.detective.parser import schema, json

from django import forms
from django.conf import settings
Expand Down Expand Up @@ -472,6 +472,35 @@ def get_rules(self):
if func: rules = func()
return rules

@staticmethod
def field_type_sanitized(field):
matches = json.VirtualApp.TYPEMATCHES
field_type = field.get("type", None)
field_match = matches.get(field_type, None)
# We find a match
if not field_match is None:
# Update the type attribute
field_type = field_match
# Special behavior for richtext that can be deduce from the field rules
if field_type == "string" and field.get("rules", {}).get("is_rich", False):
# Switch to 'richtext' type
field_type = 'richtext'
return field_type

@property
def ontology_sanitized(self):
ontology = self.ontology_as_json or []
for model in ontology:
# Sanitizes model's fields
for field in model.get('fields', []):
# The sanitize function return the field type
field["type"] = self.field_type_sanitized(field)
# Sanitizes relationship's fields
for rel_field in field.get('fields', []):
rel_field["type"] = self.field_type_sanitized(rel_field)
return ontology


class TopicToken(models.Model):
topic = models.ForeignKey(Topic, help_text="The topic this token is related to.")
token = models.CharField(editable=False, max_length=32, help_text="Title of your article.", db_index=True)
Expand Down
9 changes: 9 additions & 0 deletions app/detective/parser/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class VirtualApp:
"float" : "StringProperty"
}

TYPEMATCHES = {
"date" : "datetime",
"time" : "datetime",
"datetimestamp": "datetime",
"bool" : "boolean",
"char" : "string",
"int" : "integer"
}

def __init__(self, module, app_label, ontology):
# Add dictionary of pending rules that
# will be added once the model is created
Expand Down
6 changes: 5 additions & 1 deletion app/detective/topics/common/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ def dehydrate(self, bundle):
bundle.data["is_uploading"] = True
return bundle


def dehydrate_ontology_as_json(self, bundle):
return bundle.obj.ontology_sanitized

def get_skeleton(self, bundle):
# workaround to avoid SQL lazyness, store topic skeleton in bundle obj.
topic_skeleton = getattr(bundle, 'skeleton', None)
Expand Down Expand Up @@ -657,4 +661,4 @@ def hydrate(self, bundle):
bundle.data['user'] = bundle.request.user
else:
raise Unauthorized()
return bundle
return bundle

0 comments on commit e78b8f0

Please sign in to comment.