-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tarsil/feature/support_for_edgy
Support for Edgy
- Loading branch information
Showing
32 changed files
with
804 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from edgy import Database, Registry | ||
from esmerald import Esmerald, EsmeraldAPISettings, Include | ||
from esmerald.config.jwt import JWTConfig | ||
from esmerald.contrib.auth.edgy.base_user import AbstractUser | ||
|
||
from esmerald_admin import Admin | ||
from esmerald_admin.backends.edgy.email import EmailAdminAuth | ||
|
||
database = Database("sqlite:///db.sqlite") | ||
registry = Registry(database=database) | ||
|
||
|
||
class AppSettings(EsmeraldAPISettings): | ||
@property | ||
def jwt_config(self) -> JWTConfig: | ||
return JWTConfig(signing_key=self.secret_key) | ||
|
||
|
||
class User(AbstractUser): | ||
"""Inherits from the user base""" | ||
|
||
class Meta: | ||
registry = registry | ||
|
||
|
||
# You can use the `settings_config` directly or ESMERALD_SETTINGS_MODULE | ||
settings = AppSettings() | ||
|
||
|
||
def get_application(): | ||
""" | ||
This is optional. The function is only used for organisation purposes. | ||
""" | ||
|
||
app = Esmerald( | ||
routes=[Include(namespace="linezap.urls")], | ||
on_startup=[database.connect], | ||
on_shutdown=[database.disconnect], | ||
settings_config=settings, | ||
) | ||
|
||
# EmailAdminAuth or UsernameAdminAuth | ||
auth_backend = EmailAdminAuth( | ||
secret_key=settings.secret_key, auth_model=User, config=settings.jwt_config | ||
) | ||
Admin(app, registry.engine, authentication_backend=auth_backend) | ||
|
||
return app | ||
|
||
|
||
app = get_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from edgy import Database, Registry | ||
from esmerald import Request | ||
from esmerald.contrib.auth.edgy.base_user import AbstractUser | ||
|
||
from esmerald_admin import ModelView | ||
|
||
database = Database("sqlite:///db.sqlite") | ||
registry = Registry(database=database) | ||
|
||
|
||
class User(AbstractUser): | ||
"""Inherits from the user base""" | ||
|
||
class Meta: | ||
registry = registry | ||
|
||
|
||
# Use the declarative from Saffier | ||
UserDeclarative = User.declarative() | ||
|
||
|
||
class UserAdmin(ModelView, model=UserDeclarative): | ||
def is_visible(self, request: Request) -> bool: | ||
# Check incoming request | ||
# For example request.session if using AuthenticationBackend | ||
return True | ||
|
||
def has_permission(self, request: Request) -> bool: | ||
# Check incoming request | ||
# For example request.session if using AuthenticationBackend | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import edgy | ||
from edgy import Database, Registry | ||
from esmerald.contrib.auth.edgy.base_user import AbstractUser | ||
|
||
database = Database("sqlite:///db.sqlite") | ||
registry = Registry(database=database) | ||
|
||
|
||
class BaseModel(edgy.Model): | ||
class Meta: | ||
abstract = True | ||
registry = registry | ||
|
||
|
||
class User(BaseModel, AbstractUser): | ||
"""Inherits from the user base""" | ||
|
||
... | ||
|
||
|
||
# Create the tables | ||
await registry.create_all() |
Oops, something went wrong.