Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added roles and models #1

Open
wants to merge 3 commits into
base: temp-models
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from src import api, db, ma, create_app, configs, bp, security, admin

config = os.environ.get('PYTH_SRVR')
config = os.environ.get('PYTH_SRVR', 'default')

config = configs.get(config, 'default')
config = configs.get(config)

extensions = [api, db, ma, security, admin]
bps = [bp]
Expand Down
192 changes: 96 additions & 96 deletions web/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
alembic==0.8.8
aniso8601==1.2.0
backports.shutil-get-terminal-size==1.0.0
base58==0.2.4
bcrypt==3.1.1
blinker==1.4
boto3==1.4.1
botocore==1.4.72
cffi==1.9.1
click==6.6
coverage==4.2
decorator==4.0.10
docutils==0.12
entrypoints==0.2.2
et-xmlfile==1.0.1
Flask==0.11.1
Flask-Admin==1.4.2
Flask-Cors==3.0.2
Flask-Excel==0.0.5
Flask-Login==0.3.2
Flask-Mail==0.9.1
flask-marshmallow==0.7.0
Flask-Migrate==2.0.0
Flask-Principal==0.4.0
Flask-RESTful==0.3.5
Flask-Script==2.0.5
Flask-Security==1.7.5
Flask-SQLAlchemy==2.1
Flask-Testing==0.6.1
Flask-WTF==0.13.1
future==0.16.0
futures==3.0.5
gunicorn==19.6.0
hjson==2.0.2
ipykernel==4.5.0
ipython==5.1.0
ipython-genutils==0.1.0
ipywidgets==5.2.2
itsdangerous==0.24
jdcal==1.3
Jinja2==2.8
jmespath==0.9.0
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.4.0
jupyter-console==5.0.0
jupyter-core==4.2.0
kappa==0.6.0
lambda-packages==0.10.0
Mako==1.0.5
MarkupSafe==0.23
marshmallow==2.10.3
marshmallow-sqlalchemy==0.12.0
mistune==0.7.3
nbconvert==4.2.0
nbformat==4.1.0
notebook==4.2.3
openpyxl==2.4.0
passlib==1.6.5
pexpect==4.2.1
pickleshare==0.7.4
placebo==0.8.1
prompt-toolkit==1.0.8
psycopg2==2.6.2
ptyprocess==0.5.1
py==1.4.31
pycparser==2.17
pycrypto==2.6.1
pycryptodome==3.4.3
pyexcel==0.3.3
pyexcel-io==0.2.3
pyexcel-webio==0.0.8
Pygments==2.1.3
pytest==3.0.3
python-dateutil==2.6.0
python-editor==1.0.1
python-slugify==1.2.1
pytz==2016.7
PyYAML==3.12
pyzmq==16.0.0
qtconsole==4.2.1
requests==2.11.1
s3transfer==0.1.9
simplegeneric==0.8.1
six==1.10.0
SQLAlchemy==1.1.3
terminado==0.6
texttable==0.8.7
tornado==4.4.2
traitlets==4.3.1
troposphere==1.8.2
Unidecode==0.4.19
wcwidth==0.1.7
Werkzeug==0.11.11
widgetsnbextension==1.2.6
WTForms==2.1
alembic>=0.8.8
aniso8601>=1.2.0
backports.shutil-get-terminal-size>=1.0.0
base58>=0.2.4
bcrypt>=3.1.1
blinker>=1.4
boto3>=1.4.1
botocore>=1.4.72
cffi>=1.9.1
click>=6.6
coverage>=4.2
decorator>=4.0.10
docutils>=0.12
entrypoints>=0.2.2
et-xmlfile>=1.0.1
Flask>=0.11.1
Flask-Admin>=1.4.2
Flask-Cors>=3.0.2
Flask-Excel>=0.0.5
Flask-Login>=0.3.2
Flask-Mail>=0.9.1
flask-marshmallow>=0.7.0
Flask-Migrate>=2.0.0
Flask-Principal>=0.4.0
Flask-RESTful>=0.3.5
Flask-Script>=2.0.5
Flask-Security>=1.7.5
Flask-SQLAlchemy>=2.1
Flask-Testing>=0.6.1
Flask-WTF>=0.13.1
future>=0.16.0
futures>=3.0.5
gunicorn>=19.6.0
hjson>=2.0.2
ipykernel>=4.5.0
ipython>=5.1.0
ipython-genutils>=0.1.0
ipywidgets>=5.2.2
itsdangerous>=0.24
jdcal>=1.3
Jinja2>=2.8
jmespath>=0.9.0
jsonschema>=2.5.1
jupyter>=1.0.0
jupyter-client>=4.4.0
jupyter-console>=5.0.0
jupyter-core>=4.2.0
kappa>=0.6.0
lambda-packages>=0.10.0
Mako>=1.0.5
MarkupSafe>=0.23
marshmallow>=2.10.3
marshmallow-sqlalchemy>=0.12.0
mistune>=0.7.3
nbconvert>=4.2.0
nbformat>=4.1.0
notebook>=4.2.3
openpyxl>=2.4.0
passlib>=1.6.5
pexpect>=4.2.1
pickleshare>=0.7.4
placebo>=0.8.1
prompt-toolkit>=1.0.8
psycopg2>=2.6.2
ptyprocess>=0.5.1
py>=1.4.31
pycparser>=2.17
pycrypto>=2.6.1
pycryptodome>=3.4.3
pyexcel>=0.3.3
pyexcel-io>=0.2.3
pyexcel-webio>=0.0.8
Pygments>=2.1.3
pytest>=3.0.3
python-dateutil>=2.6.0
python-editor>=1.0.1
python-slugify>=1.2.1
pytz>=2016.7
PyYAML>=3.12
pyzmq>=16.0.0
qtconsole>=4.2.1
requests>=2.11.1
s3transfer>=0.1.9
simplegeneric>=0.8.1
six>=1.10.0
SQLAlchemy>=1.1.3
terminado>=0.6
texttable>=0.8.7
tornado>=4.4.2
traitlets>=4.3.1
troposphere>=1.8.2
Unidecode>=0.4.19
wcwidth>=0.1.7
Werkzeug>=0.11.11
widgetsnbextension>=1.2.6
WTForms>=2.1
-e git://github.com/saurabh1e/flask_admin_impexp.git@master#egg=flask_admin_impexp
38 changes: 38 additions & 0 deletions web/src/temp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from flask_security import RoleMixin, UserMixin
from sqlalchemy import UniqueConstraint

from src import db, BaseMixin, ReprMixin


class Order(db.Model):

id = db.Column(db.Integer, primary_key=True)
inline_items = db.relationship('InlineItem', back_populates='order', uselist=True, lazy='dynamic')

transaction_id = db.Column(db.Integer, db.ForeignKey('transaction.id'), nullable=False)
admin_id = db.Column(db.ForeignKey('user.id'), nullable=False)
vendor_id = db.Column(db.ForeignKey('user.id'), nullable=False)

admin = db.relationship('AdminRole', backref='order', foreign_keys=[admin_id])
vendor = db.relationship('VendorRole', backref='order', foreign_keys=[vendor_id])


class InlineItem(db.Model):

id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False)
unique_id = db.Column(db.String(64), nullable=False, unique=True)
order_id = db.Column(db.ForeignKey('order.id'), nullable=False, back_populates='inline_items')
transfer_id = db.Column(db.ForeignKey('transfer.id'), nullable=False, back_populates='inline_items')


class Transfer(db.Model):

id = db.Column(db.Integer, primary_key=True)
amount = db.Column(db.Integer, nullable=False)
admin_id = db.Column(db.ForeignKey('user.id'), nullable=False)
client_id = db.Column(db.ForeignKey('user.id'), nullable=False)

inline_items = db.relationship('InlineItem', uselist=True, lazy='dynamic')
admin = db.relationship('AdminRole', backref='order', foreign_keys=[admin_id])
client = db.relationship('VendorRole', backref='order', foreign_keys=[client_id])
56 changes: 56 additions & 0 deletions web/src/temp/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from src.utils import ModelResource, operators as ops, AssociationModelResource
from .schemas import Order, OrderSchema, InlineItem, InlineItemSchema, Transfer, TransferSchema


class OrderResource(ModelResource):

model = Order
schema = OrderSchema

def has_read_permission(self, qs):
return qs

def has_change_permission(self, obj):
return True

def has_delete_permission(self, obj):
return True

def has_add_permission(self, obj):
return True


class InlineItemResource(ModelResource):

model = InlineItem
schema = InlineItemSchema

def has_read_permission(self, qs):
return qs

def has_change_permission(self, obj):
return True

def has_delete_permission(self, obj):
return True

def has_add_permission(self, obj):
return True


class TransferResource(ModelResource):

model = Transfer
schema = TransferSchema

def has_read_permission(self, qs):
return qs

def has_change_permission(self, obj):
return True

def has_delete_permission(self, obj):
return True

def has_add_permission(self, obj):
return True
40 changes: 40 additions & 0 deletions web/src/temp/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from src import ma, BaseSchema
from .models import Order, InlineItem, Transfer


class OrderSchema(BaseSchema):

class Meta:
model = Order

id = ma.Integer()
transaction_id = ma.Integer()
admin_id = ma.Integer()
vendor_id = ma.Integer()

roles = ma.Nested('RoleSchema', many=True)


class InlineItemSchema(BaseSchema):

class Meta:
model = InlineItem

id = ma.Integer()
name = ma.String(required=True)
unique_id = ma.Integer(unique=True)
order_id = ma.Integer()
transfer_id = ma.Integer()


class TransferSchema(BaseSchema):

class Meta:
model = Transfer

id = ma.Integer()
amount = ma.Integer()
admin_id = ma.Integer()
client_id = ma.Integer()

roles = ma.Nested('RoleSchema', many=True)
28 changes: 28 additions & 0 deletions web/src/temp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from src.utils import BaseView, AssociationView
from .resources import OrderResource, InlineItemResource, TransferResource
from src import api


@api.register()
class OrderView(BaseView):

@classmethod
def get_resource(cls):
return OrderResource


@api.register()
class InlineItemView(BaseView):

@classmethod
def get_resource(cls):
return InlineItemResource


@api.register()
class TransferView(BaseView):

@classmethod
def get_resource(cls):
return TransferResource

2 changes: 1 addition & 1 deletion web/src/utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def index(self):
return redirect(url_for('security.login'))
return super(MyAdminIndexView, self).index()

admin = Admin(name="Test App", template_mode='bootstrap3', index_view=MyAdminIndexView(url='/test/v1/admin'))
admin = Admin(name="Test App", template_mode='bootstrap3', index_view=MyAdminIndexView(url='/api/v1/admin'))
2 changes: 1 addition & 1 deletion web/src/utils/blue_prints.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from flask import Blueprint

bp = Blueprint('test', __name__, url_prefix='/test/v1')
bp = Blueprint('api', __name__, url_prefix='/api/v1')
2 changes: 1 addition & 1 deletion web/src/utils/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def save_resource(self):
.dump(objects, many=True).data}, 201

@abstractmethod
def has_read_permission(self, qs) -> Type(db.Model):
def has_read_permission(self, qs) -> type(db.Model):
return qs

@abstractmethod
Expand Down
Loading