mirror of
https://github.com/yweber/lodel2.git
synced 2026-07-24 23:13:28 +02:00
ME : renommage et import
This commit is contained in:
parent
59f75eddbd
commit
a86ff9ee97
7 changed files with 107 additions and 21 deletions
|
|
@ -5,32 +5,40 @@
|
|||
@see EmClass, EmType, EmFieldGroup, EmField
|
||||
"""
|
||||
|
||||
from component import EmComponent
|
||||
from EditorialModel.components import EmComponent, EmComponentNotExistError
|
||||
import EditorialModel.classtypes
|
||||
from Database.sqlwrapper import SqlWrapper
|
||||
|
||||
class EmClass(EmComponent)
|
||||
def __init(id_or_name):
|
||||
class EmClass(EmComponent):
|
||||
def __init__(self, id_or_name):
|
||||
self.table = 'em_class'
|
||||
pass
|
||||
super(EmClass, self).__init__(id_or_name)
|
||||
|
||||
""" create a new class
|
||||
@param name str: name of the new class
|
||||
@param class_type EmClasstype: type of the class
|
||||
"""
|
||||
@staticmethod
|
||||
def create(self, name, class_type):
|
||||
pass
|
||||
def create(name, class_type):
|
||||
#try:
|
||||
exists = EmClass(name)
|
||||
#except EmComponentNotExistError:
|
||||
#print ("bin")
|
||||
#pass
|
||||
print (name, class_type)
|
||||
pass
|
||||
|
||||
""" retrieve list of the field_groups of this class
|
||||
@return field_groups [EmFieldGroup]:
|
||||
"""
|
||||
def field_groups():
|
||||
pass
|
||||
pass
|
||||
|
||||
""" retrieve list of fields
|
||||
@return fields [EmField]:
|
||||
"""
|
||||
def fields():
|
||||
pass
|
||||
pass
|
||||
|
||||
""" retrieve list of type of this class
|
||||
@return types [EmType]:
|
||||
|
|
@ -42,7 +50,7 @@ class EmClass(EmComponent)
|
|||
@param t EmType: type to link
|
||||
@return success bool: done or not
|
||||
"""
|
||||
def link_type(t <EmType>):
|
||||
def link_type(t):
|
||||
pass
|
||||
|
||||
""" retrieve list of EmType that are linked to this class
|
||||
55
EditorialModel/classtypes.py
Normal file
55
EditorialModel/classtypes.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
representation of the classTypes (sic…)
|
||||
"""
|
||||
|
||||
class EmNature(object):
|
||||
PARENT = 'parent'
|
||||
TRANSLATION = 'translation'
|
||||
IDENTITY = 'identity'
|
||||
|
||||
class EmClassType(object):
|
||||
|
||||
entity = {
|
||||
'name' : 'entity',
|
||||
'hierarchy' : [
|
||||
{
|
||||
'nature' : EmNature.PARENT,
|
||||
'attach' : 'type',
|
||||
'editable' : True,
|
||||
},
|
||||
{
|
||||
'nature' : EmNature.TRANSLATION,
|
||||
'attach' : 'type',
|
||||
'editable' : True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
entry = {
|
||||
'name' : 'entry',
|
||||
'hierarchy' : [
|
||||
{
|
||||
'nature' : EmNature.PARENT,
|
||||
'attach' : 'type',
|
||||
'editable' : True,
|
||||
},
|
||||
{
|
||||
'nature' : EmNature.TRANSLATION,
|
||||
'attach' : 'type',
|
||||
'editable' : True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
person = {
|
||||
'name' : 'person',
|
||||
'hierarchy' : [
|
||||
{
|
||||
'nature' : EmNature.IDENTITY,
|
||||
'attach' : 'classtype',
|
||||
'editable' : False,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -6,7 +6,10 @@
|
|||
"""
|
||||
|
||||
from Lodel.utils.mlstring import MlString
|
||||
from Database.sqlwrapper import SqlWrapper
|
||||
from Database.sqlobject import SqlObject
|
||||
import logging
|
||||
import sqlalchemy as sql
|
||||
|
||||
logger = logging.getLogger('Lodel2.EditorialModel')
|
||||
|
||||
|
|
@ -17,11 +20,13 @@ class EmComponent(object):
|
|||
@exception TypeError
|
||||
"""
|
||||
def __init__(self, id_or_name):
|
||||
SqlWrapper.start()
|
||||
if self is EmComponent:
|
||||
raise EnvironmentError('Abstract class')
|
||||
if type(id_or_name) is int:
|
||||
self.id = id_or_name
|
||||
elif type(id_or_name) is str:
|
||||
self.id = None
|
||||
self.name = id_or_name
|
||||
self.populate()
|
||||
else:
|
||||
|
|
@ -30,12 +35,28 @@ class EmComponent(object):
|
|||
""" Lookup in the database properties of the object to populate the properties
|
||||
"""
|
||||
def populate(self):
|
||||
if self.id is None:
|
||||
where = "name = " + db.quote(self.name)
|
||||
else:
|
||||
where = "id = " + self.id
|
||||
dbo = SqlObject(self.table)
|
||||
|
||||
t = dbo.table
|
||||
|
||||
req = dbo.sel
|
||||
print(t.c.__dict__)
|
||||
|
||||
if self.id is None:
|
||||
req.where(t.c.name == self.name)
|
||||
else:
|
||||
req.where(dbo.col.id == self.id)
|
||||
|
||||
sqlresult = dbo.rexec(req)
|
||||
print (sqlresult)
|
||||
|
||||
# Transformation du résultat en une liste de dictionnaires
|
||||
records = sqlresult.fetchall()
|
||||
print (records)
|
||||
|
||||
for record in records:
|
||||
selected_lines.append(dict(zip(record.keys(), record)))
|
||||
|
||||
row = db.query('*', self.table, where)
|
||||
if not row:
|
||||
# could have two possible Error message for id and for name
|
||||
raise EmComponentNotExistError("Bad id_or_name: could not find the component")
|
||||
|
|
@ -89,3 +110,6 @@ class EmComponent(object):
|
|||
"""
|
||||
def get_string(self, lang):
|
||||
pass
|
||||
|
||||
class EmComponentNotExistError(Exception):
|
||||
pass
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from component import EmComponent
|
||||
|
||||
from EditorialModel.components import EmComponent
|
||||
|
||||
class EmFieldGroup(EmComponent):
|
||||
""" Represents groups of EmField
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from component import EmComponent
|
||||
from EditorialModel.components import EmComponent
|
||||
|
||||
"""Represent one data for a lodel2 document"""
|
||||
class EmField(EmComponent):
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#from django.test import TestCase
|
||||
from unittest import TestCase
|
||||
from EditorialModel.lib.component import EmComponent
|
||||
from EditorialModel.component import EmComponent
|
||||
|
||||
class ComponentTestCase(TestCase):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from component import EmComponent
|
||||
from EditorialModel.components import EmComponent
|
||||
|
||||
class EmType(EmComponent):
|
||||
""" Represents type of documents
|
||||
|
||||
|
||||
A type is a specialisation of a class, it can select optional field,
|
||||
they have hooks, are organized in hierarchy and linked to other
|
||||
EmType with special fields called relation_to_type fields
|
||||
@see EmComponent
|
||||
"""
|
||||
|
||||
|
||||
def __init__(id_or_name):
|
||||
""" Instanciate an EmType with data fetched from db
|
||||
@param id_or_name str|int: Identify the EmType by name or by global_id
|
||||
Loading…
Add table
Add a link
Reference in a new issue