Skip to content
Snippets Groups Projects
Commit 819d443d authored by Victor Löfgren's avatar Victor Löfgren
Browse files

Make data dict type

parent 039cfb63
No related branches found
No related tags found
2 merge requests!63Resolve "Add components",!62Resolve "Use data from database in editor"
......@@ -124,6 +124,6 @@ class ComponentSchema(BaseSchema):
y = ma.auto_field()
w = ma.auto_field()
h = ma.auto_field()
data = ma.auto_field() # TODO: Convert this to dict, or save as dict to begin with
data = ma.auto_field() # TODO: Convert this to dict
slide_id = ma.auto_field()
type_id = ma.auto_field()
......@@ -33,7 +33,7 @@ def db_add(func):
@db_add
def component(x, y, w, h, data, type_id, item_slide):
def component(x, y, w, h, data, item_slide, type_id):
return Component(x, y, w, h, data, item_slide.id, type_id)
......
import json
from app.core import bcrypt, db
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from sqlalchemy.orm import backref
from sqlalchemy.types import TypeDecorator
STRING_SIZE = 254
......@@ -183,6 +186,22 @@ class QuestionAnswer(db.Model):
self.team_id = team_id
class Dictionary(TypeDecorator):
impl = db.Text(1024)
def process_bind_param(self, value, dialect):
if value is not None:
value = json.dumps(value).replace("'", '"')
return value
def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
class Component(db.Model):
# __mapper_args__ = {"polymorphic_on": type, "polymorphic_identity": "component"}
id = db.Column(db.Integer, primary_key=True)
......@@ -190,16 +209,16 @@ class Component(db.Model):
y = db.Column(db.Integer, nullable=False, default=0)
w = db.Column(db.Integer, nullable=False, default=1)
h = db.Column(db.Integer, nullable=False, default=1)
data = db.Column(db.Text) # TODO: Don't save this as text
type_id = db.Column(db.Integer, db.ForeignKey("component_type.id"), nullable=False)
data = db.Column(Dictionary())
slide_id = db.Column(db.Integer, db.ForeignKey("slide.id"), nullable=False)
type_id = db.Column(db.Integer, db.ForeignKey("component_type.id"), nullable=False)
def __init__(self, x, y, w, h, data, slide_id, type_id):
self.x = x
self.y = y
self.w = w
self.h = h
self.data = str(data)
self.data = data
self.slide_id = slide_id
self.type_id = type_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment