mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Refactoring: enable formatting with autopep8
This commit is contained in:
parent
9e4f7ca2f2
commit
18c09ecd93
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
|
@ -4,6 +4,7 @@
|
||||||
".pytest_cache/": true
|
".pytest_cache/": true
|
||||||
},
|
},
|
||||||
"typescript.tsdk": "rsconcept/frontend/node_modules/typescript/lib",
|
"typescript.tsdk": "rsconcept/frontend/node_modules/typescript/lib",
|
||||||
|
"eslint.workingDirectories": ["rsconcept/frontend"],
|
||||||
"isort.args": [
|
"isort.args": [
|
||||||
"--line-length",
|
"--line-length",
|
||||||
"100",
|
"100",
|
||||||
|
@ -12,10 +13,16 @@
|
||||||
"--project",
|
"--project",
|
||||||
"apps"
|
"apps"
|
||||||
],
|
],
|
||||||
"eslint.workingDirectories": ["rsconcept/frontend"],
|
"autopep8.args": [
|
||||||
|
"--max-line-length",
|
||||||
|
"120",
|
||||||
|
"--aggressive",
|
||||||
|
"--ignore",
|
||||||
|
"E303"
|
||||||
|
],
|
||||||
"[python]": {
|
"[python]": {
|
||||||
"editor.formatOnSave": false,
|
|
||||||
"editor.defaultFormatter": "ms-python.autopep8",
|
"editor.defaultFormatter": "ms-python.autopep8",
|
||||||
|
"editor.formatOnSave": true,
|
||||||
"editor.tabSize": 4,
|
"editor.tabSize": 4,
|
||||||
"editor.insertSpaces": true,
|
"editor.insertSpaces": true,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
|
|
|
@ -7,6 +7,7 @@ ItemType = TypeVar("ItemType")
|
||||||
|
|
||||||
class Graph(Generic[ItemType]):
|
class Graph(Generic[ItemType]):
|
||||||
''' Directed graph. '''
|
''' Directed graph. '''
|
||||||
|
|
||||||
def __init__(self, graph: Optional[dict[ItemType, list[ItemType]]] = None):
|
def __init__(self, graph: Optional[dict[ItemType, list[ItemType]]] = None):
|
||||||
if graph is None:
|
if graph is None:
|
||||||
self.outputs: dict[ItemType, list[ItemType]] = {}
|
self.outputs: dict[ItemType, list[ItemType]] = {}
|
||||||
|
|
|
@ -1,41 +1,54 @@
|
||||||
''' Utility: Text messages. '''
|
''' Utility: Text messages. '''
|
||||||
# pylint: skip-file
|
# pylint: skip-file
|
||||||
|
|
||||||
|
|
||||||
def constituentaNotOwned(title: str):
|
def constituentaNotOwned(title: str):
|
||||||
return f'Конституента не принадлежит схеме: {title}'
|
return f'Конституента не принадлежит схеме: {title}'
|
||||||
|
|
||||||
|
|
||||||
def substitutionNotInList():
|
def substitutionNotInList():
|
||||||
return 'Отождествляемая конституента отсутствует в списке'
|
return 'Отождествляемая конституента отсутствует в списке'
|
||||||
|
|
||||||
|
|
||||||
def schemaNotOwned():
|
def schemaNotOwned():
|
||||||
return 'Нет доступа к схеме'
|
return 'Нет доступа к схеме'
|
||||||
|
|
||||||
|
|
||||||
def renameTrivial(name: str):
|
def renameTrivial(name: str):
|
||||||
return f'Имя должно отличаться от текущего: {name}'
|
return f'Имя должно отличаться от текущего: {name}'
|
||||||
|
|
||||||
|
|
||||||
def substituteTrivial(name: str):
|
def substituteTrivial(name: str):
|
||||||
return f'Отождествление конституенты с собой не корректно: {name}'
|
return f'Отождествление конституенты с собой не корректно: {name}'
|
||||||
|
|
||||||
|
|
||||||
def substituteDouble(name: str):
|
def substituteDouble(name: str):
|
||||||
return f'Повторное отождествление: {name}'
|
return f'Повторное отождествление: {name}'
|
||||||
|
|
||||||
|
|
||||||
def aliasTaken(name: str):
|
def aliasTaken(name: str):
|
||||||
return f'Имя уже используется: {name}'
|
return f'Имя уже используется: {name}'
|
||||||
|
|
||||||
|
|
||||||
def pyconceptFailure():
|
def pyconceptFailure():
|
||||||
return 'Invalid data response from pyconcept'
|
return 'Invalid data response from pyconcept'
|
||||||
|
|
||||||
|
|
||||||
def typificationInvalidStr():
|
def typificationInvalidStr():
|
||||||
return 'Invalid typification string'
|
return 'Invalid typification string'
|
||||||
|
|
||||||
|
|
||||||
def libraryTypeUnexpected():
|
def libraryTypeUnexpected():
|
||||||
return 'Attempting to use invalid adaptor for non-RSForm item'
|
return 'Attempting to use invalid adaptor for non-RSForm item'
|
||||||
|
|
||||||
|
|
||||||
def exteorFileVersionNotSupported():
|
def exteorFileVersionNotSupported():
|
||||||
return 'Некорректный формат файла Экстеор. Сохраните файл в новой версии'
|
return 'Некорректный формат файла Экстеор. Сохраните файл в новой версии'
|
||||||
|
|
||||||
|
|
||||||
def invalidPosition():
|
def invalidPosition():
|
||||||
return 'Invalid position: should be positive integer'
|
return 'Invalid position: should be positive integer'
|
||||||
|
|
||||||
|
|
||||||
def constituentaNoStructure():
|
def constituentaNoStructure():
|
||||||
return 'Указанная конституента не обладает теоретико-множественной типизацией'
|
return 'Указанная конституента не обладает теоретико-множественной типизацией'
|
||||||
|
|
|
@ -29,6 +29,7 @@ _INSERT_LAST: int = -1
|
||||||
|
|
||||||
class RSForm:
|
class RSForm:
|
||||||
''' RSForm is math form of conceptual schema. '''
|
''' RSForm is math form of conceptual schema. '''
|
||||||
|
|
||||||
def __init__(self, item: LibraryItem):
|
def __init__(self, item: LibraryItem):
|
||||||
if item.item_type != LibraryItemType.RSFORM:
|
if item.item_type != LibraryItemType.RSFORM:
|
||||||
raise ValueError(msg.libraryTypeUnexpected())
|
raise ValueError(msg.libraryTypeUnexpected())
|
||||||
|
@ -426,20 +427,21 @@ class RSForm:
|
||||||
|
|
||||||
class SemanticInfo:
|
class SemanticInfo:
|
||||||
''' Semantic information derived from constituents. '''
|
''' Semantic information derived from constituents. '''
|
||||||
|
|
||||||
def __init__(self, schema: RSForm):
|
def __init__(self, schema: RSForm):
|
||||||
self._graph = schema._graph_formal()
|
self._graph = schema._graph_formal()
|
||||||
self._items = list(
|
self._items = list(
|
||||||
schema.constituents() \
|
schema.constituents()
|
||||||
.only('id', 'alias', 'cst_type', 'definition_formal') \
|
.only('id', 'alias', 'cst_type', 'definition_formal')
|
||||||
.order_by('order')
|
.order_by('order')
|
||||||
)
|
)
|
||||||
self._cst_by_alias = {cst.alias: cst for cst in self._items}
|
self._cst_by_alias = {cst.alias: cst for cst in self._items}
|
||||||
self._cst_by_ID = {cst.id: cst for cst in self._items}
|
self._cst_by_ID = {cst.id: cst for cst in self._items}
|
||||||
self.info = {
|
self.info = {
|
||||||
cst.id: {
|
cst.id: {
|
||||||
'is_simple' : False, \
|
'is_simple': False,
|
||||||
'is_template' : False, \
|
'is_template': False,
|
||||||
'parent' : cst.id, \
|
'parent': cst.id,
|
||||||
'children': []
|
'children': []
|
||||||
}
|
}
|
||||||
for cst in self._items
|
for cst in self._items
|
||||||
|
@ -483,7 +485,7 @@ class SemanticInfo:
|
||||||
|
|
||||||
dependencies = self._graph.inputs[target.id]
|
dependencies = self._graph.inputs[target.id]
|
||||||
has_complex_dependency = any(
|
has_complex_dependency = any(
|
||||||
self.is_template(cst_id) and \
|
self.is_template(cst_id) and
|
||||||
not self.is_simple_expression(cst_id) for cst_id in dependencies
|
not self.is_simple_expression(cst_id) for cst_id in dependencies
|
||||||
)
|
)
|
||||||
if has_complex_dependency:
|
if has_complex_dependency:
|
||||||
|
@ -551,12 +553,13 @@ class SemanticInfo:
|
||||||
|
|
||||||
class _OrderManager:
|
class _OrderManager:
|
||||||
''' Ordering helper class '''
|
''' Ordering helper class '''
|
||||||
|
|
||||||
def __init__(self, schema: RSForm):
|
def __init__(self, schema: RSForm):
|
||||||
self._semantic = schema.semantic()
|
self._semantic = schema.semantic()
|
||||||
self._graph = schema._graph_formal()
|
self._graph = schema._graph_formal()
|
||||||
self._items = list(
|
self._items = list(
|
||||||
schema.constituents() \
|
schema.constituents()
|
||||||
.only('id', 'order', 'alias', 'cst_type', 'definition_formal') \
|
.only('id', 'order', 'alias', 'cst_type', 'definition_formal')
|
||||||
.order_by('order')
|
.order_by('order')
|
||||||
)
|
)
|
||||||
self._cst_by_ID = {cst.id: cst for cst in self._items}
|
self._cst_by_ID = {cst.id: cst for cst in self._items}
|
||||||
|
@ -579,8 +582,8 @@ class _OrderManager:
|
||||||
result = [cst for cst in self._items if cst.cst_type == CstType.BASE]
|
result = [cst for cst in self._items if cst.cst_type == CstType.BASE]
|
||||||
result = result + [cst for cst in self._items if cst.cst_type == CstType.CONSTANT]
|
result = result + [cst for cst in self._items if cst.cst_type == CstType.CONSTANT]
|
||||||
kernel = [
|
kernel = [
|
||||||
cst.id for cst in self._items if \
|
cst.id for cst in self._items if
|
||||||
cst.cst_type in [CstType.STRUCTURED, CstType.AXIOM] or \
|
cst.cst_type in [CstType.STRUCTURED, CstType.AXIOM] or
|
||||||
self._cst_by_ID[self._semantic.parent(cst.id)].cst_type == CstType.STRUCTURED
|
self._cst_by_ID[self._semantic.parent(cst.id)].cst_type == CstType.STRUCTURED
|
||||||
]
|
]
|
||||||
kernel = kernel + self._graph.expand_inputs(kernel)
|
kernel = kernel + self._graph.expand_inputs(kernel)
|
||||||
|
@ -604,7 +607,6 @@ class _OrderManager:
|
||||||
result.append(child)
|
result.append(child)
|
||||||
self._items = result
|
self._items = result
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def _save_order(self) -> None:
|
def _save_order(self) -> None:
|
||||||
order = 1
|
order = 1
|
||||||
|
|
|
@ -150,7 +150,7 @@ def generate_structure(alias: str, expression: str, parse: dict) -> list:
|
||||||
parent_type = ast[parent_index]['typeID']
|
parent_type = ast[parent_index]['typeID']
|
||||||
parent_text = generated[parent_index]['text']
|
parent_text = generated[parent_index]['text']
|
||||||
parent_is_boolean = generated[parent_index]['is_boolean']
|
parent_is_boolean = generated[parent_index]['is_boolean']
|
||||||
assert(parent_type in [TokenType.BOOLEAN, TokenType.DECART])
|
assert parent_type in [TokenType.BOOLEAN, TokenType.DECART]
|
||||||
|
|
||||||
if parent_is_boolean:
|
if parent_is_boolean:
|
||||||
if parent_type == TokenType.BOOLEAN:
|
if parent_type == TokenType.BOOLEAN:
|
||||||
|
|
|
@ -65,6 +65,7 @@ class ErrorDescriptionSerializer(serializers.Serializer):
|
||||||
child=serializers.CharField()
|
child=serializers.CharField()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NodeDataSerializer(serializers.Serializer):
|
class NodeDataSerializer(serializers.Serializer):
|
||||||
''' Serializer: Node data. '''
|
''' Serializer: Node data. '''
|
||||||
dataType = serializers.CharField()
|
dataType = serializers.CharField()
|
||||||
|
|
|
@ -12,6 +12,7 @@ _TRS_VERSION_MIN = 16
|
||||||
_TRS_VERSION = 16
|
_TRS_VERSION = 16
|
||||||
_TRS_HEADER = 'Exteor 4.8.13.1000 - 30/05/2022'
|
_TRS_HEADER = 'Exteor 4.8.13.1000 - 30/05/2022'
|
||||||
|
|
||||||
|
|
||||||
class FileSerializer(serializers.Serializer):
|
class FileSerializer(serializers.Serializer):
|
||||||
''' Serializer: File input. '''
|
''' Serializer: File input. '''
|
||||||
file = serializers.FileField(allow_empty_file=False)
|
file = serializers.FileField(allow_empty_file=False)
|
||||||
|
@ -25,6 +26,7 @@ class RSFormUploadSerializer(serializers.Serializer):
|
||||||
|
|
||||||
class RSFormTRSSerializer(serializers.Serializer):
|
class RSFormTRSSerializer(serializers.Serializer):
|
||||||
''' Serializer: TRS file production and loading for RSForm. '''
|
''' Serializer: TRS file production and loading for RSForm. '''
|
||||||
|
|
||||||
def to_representation(self, instance: RSForm) -> dict:
|
def to_representation(self, instance: RSForm) -> dict:
|
||||||
result = self._prepare_json_rsform(instance)
|
result = self._prepare_json_rsform(instance)
|
||||||
items = instance.constituents().order_by('order')
|
items = instance.constituents().order_by('order')
|
||||||
|
|
|
@ -10,6 +10,7 @@ from ..models import RSForm
|
||||||
|
|
||||||
class PyConceptAdapter:
|
class PyConceptAdapter:
|
||||||
''' RSForm adapter for interacting with pyconcept module. '''
|
''' RSForm adapter for interacting with pyconcept module. '''
|
||||||
|
|
||||||
def __init__(self, data: Union[RSForm, dict]):
|
def __init__(self, data: Union[RSForm, dict]):
|
||||||
try:
|
try:
|
||||||
if 'items' in cast(dict, data):
|
if 'items' in cast(dict, data):
|
||||||
|
|
|
@ -14,6 +14,7 @@ class NewCstResponse(serializers.Serializer):
|
||||||
new_cst = serializers.IntegerField()
|
new_cst = serializers.IntegerField()
|
||||||
schema = RSFormParseSerializer()
|
schema = RSFormParseSerializer()
|
||||||
|
|
||||||
|
|
||||||
class NewMultiCstResponse(serializers.Serializer):
|
class NewMultiCstResponse(serializers.Serializer):
|
||||||
''' Serializer: Create multiple cst response. '''
|
''' Serializer: Create multiple cst response. '''
|
||||||
cst_list = serializers.ListField(
|
cst_list = serializers.ListField(
|
||||||
|
@ -21,6 +22,7 @@ class NewMultiCstResponse(serializers.Serializer):
|
||||||
)
|
)
|
||||||
schema = RSFormParseSerializer()
|
schema = RSFormParseSerializer()
|
||||||
|
|
||||||
|
|
||||||
class NewVersionResponse(serializers.Serializer):
|
class NewVersionResponse(serializers.Serializer):
|
||||||
''' Serializer: Create cst response. '''
|
''' Serializer: Create cst response. '''
|
||||||
version = serializers.IntegerField()
|
version = serializers.IntegerField()
|
||||||
|
|
|
@ -8,6 +8,7 @@ from apps.rsform.models import Constituenta, CstType, LibraryItem, LibraryItemTy
|
||||||
|
|
||||||
class TestConstituenta(TestCase):
|
class TestConstituenta(TestCase):
|
||||||
''' Testing Constituenta model. '''
|
''' Testing Constituenta model. '''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.schema1 = LibraryItem.objects.create(item_type=LibraryItemType.RSFORM, title='Test1')
|
self.schema1 = LibraryItem.objects.create(item_type=LibraryItemType.RSFORM, title='Test1')
|
||||||
self.schema2 = LibraryItem.objects.create(item_type=LibraryItemType.RSFORM, title='Test2')
|
self.schema2 = LibraryItem.objects.create(item_type=LibraryItemType.RSFORM, title='Test2')
|
||||||
|
|
|
@ -6,6 +6,7 @@ from apps.rsform.models import LibraryItem, LibraryItemType, Subscription, User
|
||||||
|
|
||||||
class TestLibraryItem(TestCase):
|
class TestLibraryItem(TestCase):
|
||||||
''' Testing LibraryItem model. '''
|
''' Testing LibraryItem model. '''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user1 = User.objects.create(username='User1')
|
self.user1 = User.objects.create(username='User1')
|
||||||
self.user2 = User.objects.create(username='User2')
|
self.user2 = User.objects.create(username='User2')
|
||||||
|
|
|
@ -7,6 +7,7 @@ from apps.rsform.models import Constituenta, CstType, RSForm, User
|
||||||
|
|
||||||
class TestRSForm(TestCase):
|
class TestRSForm(TestCase):
|
||||||
''' Testing RSForm wrapper. '''
|
''' Testing RSForm wrapper. '''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user1 = User.objects.create(username='User1')
|
self.user1 = User.objects.create(username='User1')
|
||||||
self.user2 = User.objects.create(username='User2')
|
self.user2 = User.objects.create(username='User2')
|
||||||
|
|
|
@ -8,7 +8,6 @@ from apps.rsform.utils import apply_pattern, fix_old_references
|
||||||
class TestUtils(unittest.TestCase):
|
class TestUtils(unittest.TestCase):
|
||||||
''' Test various utility functions. '''
|
''' Test various utility functions. '''
|
||||||
|
|
||||||
|
|
||||||
def test_apply_mapping_patter(self):
|
def test_apply_mapping_patter(self):
|
||||||
mapping = {'X101': 'X20'}
|
mapping = {'X101': 'X20'}
|
||||||
pattern = re.compile(r'(X[0-9]+)')
|
pattern = re.compile(r'(X[0-9]+)')
|
||||||
|
|
|
@ -15,6 +15,7 @@ _REF_OLD_PATTERN = re.compile(r'@{([^0-9\-][^\}\|\{]*?)\|([^\}\|\{]*?)\|([^\}\|\
|
||||||
|
|
||||||
class ObjectOwnerOrAdmin(BasePermission):
|
class ObjectOwnerOrAdmin(BasePermission):
|
||||||
''' Permission for object ownership restriction '''
|
''' Permission for object ownership restriction '''
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
def has_object_permission(self, request, view, obj):
|
||||||
if request.user == obj.owner:
|
if request.user == obj.owner:
|
||||||
return True
|
return True
|
||||||
|
@ -25,6 +26,7 @@ class ObjectOwnerOrAdmin(BasePermission):
|
||||||
|
|
||||||
class IsClaimable(IsAuthenticated):
|
class IsClaimable(IsAuthenticated):
|
||||||
''' Permission for object ownership restriction '''
|
''' Permission for object ownership restriction '''
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
def has_object_permission(self, request, view, obj):
|
||||||
if not super().has_permission(request, view):
|
if not super().has_permission(request, view):
|
||||||
return False
|
return False
|
||||||
|
@ -33,6 +35,7 @@ class IsClaimable(IsAuthenticated):
|
||||||
|
|
||||||
class SchemaOwnerOrAdmin(BasePermission):
|
class SchemaOwnerOrAdmin(BasePermission):
|
||||||
''' Permission for object ownership restriction '''
|
''' Permission for object ownership restriction '''
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
def has_object_permission(self, request, view, obj):
|
||||||
if request.user == obj.schema.owner:
|
if request.user == obj.schema.owner:
|
||||||
return True
|
return True
|
||||||
|
@ -43,6 +46,7 @@ class SchemaOwnerOrAdmin(BasePermission):
|
||||||
|
|
||||||
class ItemOwnerOrAdmin(BasePermission):
|
class ItemOwnerOrAdmin(BasePermission):
|
||||||
''' Permission for object ownership restriction '''
|
''' Permission for object ownership restriction '''
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
def has_object_permission(self, request, view, obj):
|
||||||
if request.user == obj.item.owner:
|
if request.user == obj.item.owner:
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
''' Utility: Text messages. '''
|
''' Utility: Text messages. '''
|
||||||
# pylint: skip-file
|
# pylint: skip-file
|
||||||
|
|
||||||
|
|
||||||
def passwordAuthFailed():
|
def passwordAuthFailed():
|
||||||
return 'Неизвестное сочетание имени пользователя и пароля'
|
return 'Неизвестное сочетание имени пользователя и пароля'
|
||||||
|
|
||||||
|
|
||||||
def passwordsNotMatch():
|
def passwordsNotMatch():
|
||||||
return 'Введенные пароли не совпадают'
|
return 'Введенные пароли не совпадают'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
''' Models: User profile and Authentification. '''
|
''' Models: User profile and Authorization. '''
|
||||||
|
|
||||||
# Note: using User import to isolate original
|
# Note: using User import to isolate original
|
||||||
# pylint: disable=unused-import,ungrouped-imports
|
# pylint: disable=unused-import,ungrouped-imports
|
||||||
|
|
|
@ -23,6 +23,7 @@ def _get_secret(key: str, default):
|
||||||
return f.read()
|
return f.read()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
_TRUE_VARIANTS = [True, 'True', '1']
|
_TRUE_VARIANTS = [True, 'True', '1']
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user