-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwombatdb.py
140 lines (115 loc) · 4.43 KB
/
wombatdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#author: Pronoy Chopra
#imports
from flask import Flask
from flaskext.sqlalchemy import SQLAlchemy
import wombat_config.config_file
from os.path import splitext
from backend.functions import Base
#initialising the flask application
app = Flask(__name__)
func = Base()
#app.config.from_object(wombat_config.config_file)
#configuration from the SQLALCHEMY_DATABASE_URI variable which is essentially
#the creation of database using sqlite
#can be put in a separate config and be imported
app.config['SQLALCHEMY_DATABASE_URI'] = wombat_config.config_file.DB_URI
#flask extension initialized
db = SQLAlchemy(app)
#Define models here:
class WorkSpaces(db.Model):
__tablename__ = 'workspaces'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), default=u'Unnamed Workspace')
class Collection(db.Model):
__tablename__ = 'collections'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), default=u'Unnamed collection')
#collections = db.relationship('Collection',backref = 'asset', lazy ='dynamic')
def __init__(self,name,tags):
self.name= name
self.tags= tags
class Asset(db.Model):
# __bind_key__='assets'
__tablename__ = 'assets'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text, default=u'Unnamed Asset')
used_by = db.Column(db.Integer, db.ForeignKey('collections.id'))
def __init__(self,name,tags):
self.name = name
self.tags = tags
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
email = db.Column(db.Text)
password = db.Column(db.Text)
#users can't login until the field is active
active = db.Column(db.Boolean)
#hashvalue for uses with email activation
hashvalue = db.Column(db.Text)
def __init__(self,email,password,active=False,hashvalue=None):
self.email = email
self.password = password
self.active = active
self.hashvalue = hashvalue
class UserData(db.Model):
__tablename__ = 'user_data'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
nick = db.Column(db.String(255))
vcs_user = db.Column(db.String(255))
vcs_pass = db.Column(db.String(255))
user_id = db.Column(db.String(255),db.ForeignKey('users.id'))
def __init__(self,name=None, nick=None,vcs_user=None,vcs_pass=None):
self.name = name
self.nick = nick
self.vcs_user = vcs_user
self.vcs_pass = vcs_pass
class Dir(db.Model):
__tablename__ = 'dirs'
path = db.Column(db.String(255), primary_key=True)
name = db.Column(db.String(255))
root = db.Column(db.String(255))
rev_id = db.Column(db.Integer, db.ForeignKey('revisions.id'))
in_dir = db.Column(db.String(255), db.ForeignKey('dirs.path'))
#dirs = db.relationship('DIR',backref='files',lazy='dynamic')
def __init__(self,path,name,root):
self.path = path
self.name = name
self.root = root
class Revision(db.Model):
__tablename__ = 'revisions'
id = db.Column(db.Integer,primary_key=True)
name = db.Column(db.String(255), default='')
log = db.Column(db.Text, default = u'No log message')
author = db.Column(db.String(255), default = u'Unknown Author')
date = db.Column(db.DateTime)
#revisions = db.relationship('Revision',backref='dirs',lazy='dynamic')
def __init__(self,name,log,author,date):
self.id = id
self.name = name
self.log = log
self.author = author
self.date = date
class File(db.Model):
path = db.Column(db.String(255), primary_key=True)
name = db.Column(db.String(255))
size = db.Column(db.Integer)
root = db.Column(db.String(255))
ext = db.Column(db.String(20))
type = db.Column(db.String(20),default=u'other')
as_thumbnail = db.Column(db.Boolean,default=False)
in_dir = db.Column(db.String(255),db.ForeignKey('dirs.path'))
rev_id = db.Column(db.Integer, db.ForeignKey('revisions.id'))
used_by = db.Column(db.Integer, db.ForeignKey('assets.id'))
def __init__(self,path,name,size,root):
self.path = path
self.name = name
self.size = size
self.root = root
dummy, self.ext = splitext(name)
self.ext = self.ext.lower()
self.type = unicode(func.getType(name))
#create the database by db.create_all()
#if database is present, it won't be overwritten
def init_db():
db.create_all()