Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jørn Åne de Jong
Pyramid CRUD
Commits
2ed0840f
Commit
2ed0840f
authored
Nov 14, 2014
by
yorn
Browse files
Add LaaS datamodel
parent
caa6935c
Changes
4
Hide whitespace changes
Inline
Side-by-side
crud/models.py
View file @
2ed0840f
...
...
@@ -2,7 +2,11 @@ from sqlalchemy import (
Column
,
Index
,
Integer
,
Text
,
String
,
Interval
,
ForeignKey
,
Enum
,
orm
,
)
from
sqlalchemy.ext.declarative
import
declarative_base
...
...
@@ -18,10 +22,47 @@ DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base
=
declarative_base
()
class
MyModel
(
Base
):
__tablename__
=
'models'
class
Organisation
(
Base
):
__tablename__
=
'organisation'
id
=
Column
(
Integer
,
primary_key
=
True
,
info
=
{
'label'
:
'ID'
})
identifier
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Identifier'
})
realm
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Realm'
})
Index
(
'organisation_identifier'
,
Organisation
.
identifier
,
unique
=
True
)
class
LogService
(
Base
):
__tablename__
=
'log_service'
id
=
Column
(
Integer
,
primary_key
=
True
,
info
=
{
'label'
:
'ID'
})
organisation_id
=
Column
(
Integer
,
ForeignKey
(
'organisation.id'
),
nullable
=
False
,
info
=
{
'label'
:
'organisation'
})
organisation
=
orm
.
relationship
(
Organisation
)
name
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'name'
})
duration
=
Column
(
Interval
,
nullable
=
False
,
info
=
{
'label'
:
'duration'
})
Index
(
'log_service_organisation'
,
LogService
.
organisation_id
)
Index
(
'logservice_unique'
,
LogService
.
organisation_id
,
LogService
.
name
,
unique
=
True
)
class
LogType
(
Base
):
__tablename__
=
'log_type'
id
=
Column
(
Integer
,
primary_key
=
True
,
info
=
{
'label'
:
'ID'
})
organisation_id
=
Column
(
Integer
,
ForeignKey
(
'organisation.id'
),
info
=
{
'label'
:
'Organisation'
})
organisation
=
orm
.
relationship
(
Organisation
)
name
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Name'
})
pattern
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Pattern'
})
ts_pattern
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Timestamp Pattern'
})
ts_field
=
Column
(
String
,
nullable
=
False
,
info
=
{
'label'
:
'Timestamp Field'
})
tags
=
Column
(
String
)
Index
(
'log_name'
,
LogType
.
name
,
unique
=
True
,
mysql_length
=
255
)
class
LogAccessor
(
Base
):
__tablename__
=
'log_accessor'
id
=
Column
(
Integer
,
primary_key
=
True
)
name
=
Column
(
Text
)
value
=
Column
(
Integer
)
log_type_id
=
Column
(
Integer
,
ForeignKey
(
'log_type.id'
)
)
os
=
Column
(
Enum
(
'*nix'
,
'windows'
,
name
=
"operating_system"
),
nullable
=
False
)
Index
(
'my_index'
,
MyModel
.
name
,
unique
=
True
,
mysql_length
=
255
)
class
Access
(
Base
):
__tablename__
=
'access'
id
=
Column
(
Integer
,
primary_key
=
True
)
log_service_id
=
Column
(
Integer
,
ForeignKey
(
'log_service.id'
),
nullable
=
False
)
value
=
Column
(
String
,
nullable
=
False
)
type
=
Column
(
Enum
(
'eduPersonPrincipalName'
,
'norEduOrgUnitUniqueIdentifier'
,
name
=
"access_type"
),
nullable
=
False
)
Index
(
'access_log_service_id'
,
Access
.
log_service_id
,
unique
=
True
)
Index
(
'access_unique'
,
Access
.
log_service_id
,
Access
.
value
,
Access
.
type
,
unique
=
True
)
crud/scripts/initializedb.py
View file @
2ed0840f
...
...
@@ -13,7 +13,6 @@ from pyramid.scripts.common import parse_vars
from
..models
import
(
DBSession
,
MyModel
,
Base
,
)
...
...
@@ -35,6 +34,3 @@ def main(argv=sys.argv):
engine
=
engine_from_config
(
settings
,
'sqlalchemy.'
)
DBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
create_all
(
engine
)
with
transaction
.
manager
:
model
=
MyModel
(
name
=
'one'
,
value
=
1
)
DBSession
.
add
(
model
)
crud/tests.py
View file @
2ed0840f
...
...
@@ -13,13 +13,9 @@ class TestMyViewSuccessCondition(unittest.TestCase):
engine
=
create_engine
(
'sqlite://'
)
from
.models
import
(
Base
,
MyModel
,
)
DBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
create_all
(
engine
)
with
transaction
.
manager
:
model
=
MyModel
(
name
=
'one'
,
value
=
55
)
DBSession
.
add
(
model
)
def
tearDown
(
self
):
DBSession
.
remove
()
...
...
@@ -40,7 +36,6 @@ class TestMyViewFailureCondition(unittest.TestCase):
engine
=
create_engine
(
'sqlite://'
)
from
.models
import
(
Base
,
MyModel
,
)
DBSession
.
configure
(
bind
=
engine
)
...
...
crud/views.py
View file @
2ed0840f
...
...
@@ -7,15 +7,35 @@ from sqlalchemy.exc import DBAPIError
from
.models
import
(
DBSession
,
MyModel
,
LogService
,
LogType
,
Organisation
,
)
class
MyModel
Form
(
CSRFModelForm
):
class
LogService
Form
(
CSRFModelForm
):
class
Meta
:
model
=
MyModel
model
=
LogService
class
MyModelView
(
CRUDView
):
Form
=
MyModelForm
url_path
=
'/mymodel'
class
LogServiceView
(
CRUDView
):
Form
=
LogServiceForm
url_path
=
'/services/'
list_display
=
(
'id'
,
'name'
,
'duration'
,
'organisation_id'
,)
class
LogTypeForm
(
CSRFModelForm
):
class
Meta
:
model
=
LogType
class
LogTypeView
(
CRUDView
):
Form
=
LogTypeForm
url_path
=
'/types/'
list_display
=
(
'id'
,
'name'
,
'pattern'
,
'ts_pattern'
,
'ts_field'
,
'organisation_id'
,)
class
OrganisationForm
(
CSRFModelForm
):
class
Meta
:
model
=
Organisation
class
OrganisationView
(
CRUDView
):
Form
=
OrganisationForm
url_path
=
'/orgs/'
list_display
=
(
'id'
,
'identifier'
,
'realm'
,)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment