Skip to content

Commit

Permalink
Merge pull request #53 from mekanix/feature/specific-model
Browse files Browse the repository at this point in the history
Try import of specific DB type model first
  • Loading branch information
mekanix authored Mar 29, 2020
2 parents 5b5d04a + c542388 commit 34c046f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions freenit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys
from importlib import import_module

import freenit.schemas.user
from flask import Flask, send_file
from flask_collect import Collect
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from flask_security import Security

import freenit.schemas.user
from freenit.schemas.paging import PageOutSchema

from . import cli
Expand All @@ -19,8 +20,14 @@ def sqlinit(app):
from .db import db
db.init_app(app)
app.db = db
User = import_module(f"{app.config['NAME']}.models.user").User
role_module = import_module(f"{app.config['NAME']}.models.role")
try:
User = import_module(f"{app.config['NAME']}.models.sql.user").User
except ModuleNotFoundError:
User = import_module(f"{app.config['NAME']}.models.user").User
try:
role_module = import_module(f"{app.config['NAME']}.models.role")
except ModuleNotFoundError:
role_module = import_module(f"{app.config['NAME']}.models.sql.role")
Role = role_module.Role
UserRoles = role_module.UserRoles
app.user_datastore = PeeweeUserDatastore(
Expand All @@ -35,8 +42,14 @@ def mongoinit(app):
from flask_security import MongoEngineUserDatastore
from flask_mongoengine import MongoEngine
app.db = MongoEngine(app)
User = import_module(f"{app.config['NAME']}.models.user").User
Role = import_module(f"{app.config['NAME']}.models.role").Role
try:
User = import_module(f"{app.config['NAME']}.models.user").User
except ModuleNotFoundError:
User = import_module(f"{app.config['NAME']}.models.mongo.user").User
try:
Role = import_module(f"{app.config['NAME']}.models.role").Role
except ModuleNotFoundError:
Role = import_module(f"{app.config['NAME']}.models.mongo.role").Role
app.user_datastore = MongoEngineUserDatastore(app.db, User, Role)


Expand Down
3 changes: 2 additions & 1 deletion freenit/schemas/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from marshmallow import Schema
from marshmallow import EXCLUDE, Schema

from ..fields.objectid import ID

Expand All @@ -9,3 +9,4 @@ class BaseSchema(Schema):
class Meta:
strict = True
ordered = True
unknown = EXCLUDE
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='freenit',
version='0.1.3',
version='0.1.4',
description='REST API framework based on Flask-Smorest',
long_description=README,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 34c046f

Please sign in to comment.