-
Notifications
You must be signed in to change notification settings - Fork 10
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 #5 from nebula-contrib/4-django-support
- Loading branch information
Showing
4 changed files
with
111 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
try: | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class NebulaCarinaConfig(AppConfig): | ||
name = "nebula_carina" | ||
label = "nebula_carina" | ||
|
||
verbose_name = _("Nebula Carina") | ||
|
||
except ModuleNotFoundError: | ||
pass |
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 |
---|---|---|
@@ -1,21 +1,50 @@ | ||
from typing import Set, Optional | ||
|
||
from typing import Set, Optional, Union | ||
import typing | ||
from pydantic import BaseSettings | ||
|
||
|
||
class DatabaseSettings(BaseSettings): | ||
max_connection_pool_size: int = 10 | ||
servers: Set[str] = set() | ||
user_name: str | ||
password: str | ||
default_space: str = 'main' | ||
auto_create_default_space_with_vid_desc: Optional[str] | ||
try: | ||
# for django | ||
from django.conf import settings | ||
|
||
class DjangoCarinaDatabaseSettings(object): | ||
|
||
max_connection_pool_size: int = 10 | ||
servers: Set[str] = set() | ||
user_name: str | ||
password: str | ||
default_space: str = 'main' | ||
auto_create_default_space_with_vid_desc: Optional[str] | ||
|
||
model_paths: Set[str] = set() | ||
timezone_name: str = 'UTC' | ||
|
||
@staticmethod | ||
def is_optional(tp): | ||
return typing.get_origin(tp) is Union and type(None) in typing.get_args(tp) | ||
|
||
def __init__(self, **kwargs): | ||
for key, type_ in DjangoCarinaDatabaseSettings.__dict__['__annotations__'].items(): | ||
if not self.is_optional(type_) and not hasattr(DjangoCarinaDatabaseSettings, key): | ||
assert key in kwargs, f'Setting {key} is required but not provided in CARINA_SETTINGS.' | ||
key in kwargs and setattr(self, key, kwargs[key]) | ||
|
||
database_settings = DjangoCarinaDatabaseSettings(**settings.CARINA_SETTINGS) | ||
except ModuleNotFoundError: | ||
class DatabaseSettings(BaseSettings): | ||
|
||
max_connection_pool_size: int = 10 | ||
servers: Set[str] = set() | ||
user_name: str | ||
password: str | ||
default_space: str = 'main' | ||
auto_create_default_space_with_vid_desc: Optional[str] | ||
|
||
model_paths: Set[str] = set() | ||
timezone_name: str = 'UTC' | ||
model_paths: Set[str] = set() | ||
timezone_name: str = 'UTC' | ||
|
||
class Config: | ||
env_prefix = 'nebula_' | ||
class Config: | ||
env_prefix = 'nebula_' | ||
|
||
|
||
database_settings = DatabaseSettings() | ||
database_settings = DatabaseSettings() |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
setup( | ||
name='nebula-carina', | ||
version='0.2.0', | ||
version='0.2.1', | ||
author='Sword Elucidator', | ||
author_email='[email protected]', | ||
url='https://github.com/SwordElucidator/nebula-carina', | ||
|