diff --git a/djaosdb/__init__.py b/djaosdb/__init__.py index cac0d2672e149eca62d1604bfd51849faa961755..91cfae32d7f0a8e68e3b84ecdd57231199191015 100644 --- a/djaosdb/__init__.py +++ b/djaosdb/__init__.py @@ -1,10 +1 @@ -# This version of Djongo was made possible by -# the generous contributions from: -# -# * Zachary Sizemore -# * Wayne Van Son -# * Norman Niemer -# * Renz Ladia -# * thestick613 - -__version__ = '1.3.3' +__version__ = '0.1-dev' diff --git a/djaosdb/base.py b/djaosdb/base.py index 67bfd8aabc82c0d07f8ad44037142c48ebbd630b..f43deb8dcffecba40700a58c5e547a877825f4d1 100644 --- a/djaosdb/base.py +++ b/djaosdb/base.py @@ -14,30 +14,10 @@ from .features import DatabaseFeatures from .introspection import DatabaseIntrospection from .operations import DatabaseOperations from .schema import DatabaseSchemaEditor +from .caosdb_client import CaosDBClient +import caosdb -logger = getLogger(__name__) - - -class CachedCollections(set): - - def __init__(self, database): - self.db = database - super().__init__() - - def __contains__(self, item): - ans = super().__contains__(item) - if ans: - return ans - self.update(self.db.list_collection_names()) - return super().__contains__(item) - - -class DjongoClient: - - def __init__(self, database, enforce_schema=True): - self.enforce_schema = enforce_schema - self.cached_collections = CachedCollections(database) - +LOGGER = getLogger(__name__) class DatabaseWrapper(BaseDatabaseWrapper): """ @@ -51,28 +31,28 @@ class DatabaseWrapper(BaseDatabaseWrapper): 'BigAutoField': 'long', 'BinaryField': 'binData', 'BooleanField': 'bool', - 'CharField': 'string', - 'CommaSeparatedIntegerField': 'string', - 'DateField': 'date', - 'DateTimeField': 'date', + 'CharField': caosdb.TEXT, + 'CommaSeparatedIntegerField': caosdb.TEXT, + 'DateField': caosdb.DATETIME, + 'DateTimeField': caosdb.DATETIME, 'DecimalField': 'decimal', 'DurationField': 'long', - 'FileField': 'string', - 'FilePathField': 'string', + 'FileField': caosdb.TEXT, + 'FilePathField': caosdb.TEXT, 'FloatField': 'double', 'IntegerField': 'int', 'BigIntegerField': 'long', - 'IPAddressField': 'string', - 'GenericIPAddressField': 'string', + 'IPAddressField': caosdb.TEXT, + 'GenericIPAddressField': caosdb.TEXT, 'NullBooleanField': 'bool', 'OneToOneField': 'int', 'PositiveIntegerField': 'long', 'PositiveSmallIntegerField': 'int', - 'SlugField': 'string', + 'SlugField': caosdb.TEXT, 'SmallIntegerField': 'int', - 'TextField': 'string', - 'TimeField': 'date', - 'UUIDField': 'string', + 'TextField': caosdb.TEXT, + 'TimeField': caosdb.DATETIME, + 'UUIDField': caosdb.TEXT, 'GenericObjectIdField': 'objectId', 'ObjectIdField': 'objectId', 'EmbeddedField': 'object', @@ -130,11 +110,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): default values to blank fields. """ valid_settings = { - 'NAME': 'name', 'ENFORCE_SCHEMA': 'enforce_schema', } connection_params = { - 'name': 'djaosdb_test', 'enforce_schema': False } for setting_name, kwarg in valid_settings.items(): @@ -153,32 +131,33 @@ class DatabaseWrapper(BaseDatabaseWrapper): return connection_params def get_new_connection(self, connection_params): - """ - Receives a dictionary connection_params to setup + """Receives a dictionary connection_params to setup a connection to the database. Dictionary correct setup is made through the get_connection_params method. - """ - name = connection_params.pop('name') - es = connection_params.pop('enforce_schema') + Parameters + ---------- + connection_params : dict + Returns + ------- + connection : CaosDBClient + """ connection_params['document_class'] = OrderedDict # connection_params['tz_aware'] = True # To prevent leaving unclosed connections behind, # client_conn must be closed before a new connection # is created. - if self.client_connection is not None: - self.client_connection.close() - logger.debug('Existing CaosDBClient connection closed') + if self.connection is not None: + self.connection.close() + LOGGER.debug('Existing CaosDBClient connection closed') - self.client_connection = Database.connect(db=name, **connection_params) - logger.debug('New Database connection') + self.connection = CaosDBClient(**connection_params) + LOGGER.debug('New Database connection') - database = self.client_connection[name] - self.djaosdb_connection = DjongoClient(database, es) - return self.client_connection[name] + return self.connection def _set_autocommit(self, autocommit): """ @@ -199,7 +178,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): """ Returns an active connection cursor to the database. """ - return Cursor(self.client_connection, self.connection, self.djaosdb_connection) + return Cursor(self.connection) def _close(self): """ @@ -207,8 +186,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): """ if self.connection: with self.wrap_database_errors: - self.connection.client.close() - logger.debug('CaosDBClient connection closed') + self.connection.close() + LOGGER.debug('CaosDBClient connection closed') def _rollback(self): raise Error diff --git a/djaosdb/caosdb_client.py b/djaosdb/caosdb_client.py index d77411574bc72461a6f1ead71ccf04b144adc3b9..819b8c1d73669b23ea2a88d088e764d9e07023e5 100644 --- a/djaosdb/caosdb_client.py +++ b/djaosdb/caosdb_client.py @@ -1,7 +1,355 @@ +import caosdb from logging import getLogger +from .mockup_delegator import MockupDelegatorConnection logger = getLogger(__name__) -class CaosDBClient: + +class Result: + def __init__(self): + self.alive = True + + def close(self): + """close""" + pass + + def __next__(self): + """__next__""" + # TODO + raise StopIteration + + def __iter__(self): + """__iter__""" + # TODO + return self + +class FindResult(Result): + + def __init__(self, rows, columns): + self.alive = True + self._results = [] + + for row in rows: + self._results.append(dict(zip(columns, row))) + + def __iter__(self): + return iter(self._results) + +class InsertManyResult(Result): + def __init__(self, container): + super(InsertManyResult, self).__init__() + self.inserted_ids = [e.id for e in container] + + def __iter__(self): + return iter(self.inserted_ids) + +class CachedRecordTypes(set): + + def __init__(self, connection): + self.connection = connection + super().__init__() + + def __contains__(self, item): + ans = super().__contains__(item) + if ans: + return ans + self.update(self.connection.list_record_type_names()) + return super().__contains__(item) + +class CachedProperties(set): + + def __init__(self, connection): + self.connection = connection + super().__init__() + + def __contains__(self, item): + ans = super().__contains__(item) + if ans: + return ans + self.update(self.connection.list_property_names()) + return super().__contains__(item) + +class DefaultCaosDBClientDelegate: + def __init__(self, **kwargs): - logger.info("New CaosDBClient: {}".format(kwargs)) + self.cached_record_types = CachedRecordTypes(self) + self.cached_properties = CachedProperties(self) + self._connection = caosdb.configure_connection(**kwargs) + + def find(self, record_type, *args, **kwargs): + filter_clause = "" + if "filter" in kwargs: + fil = kwargs["filter"] + n = "" + if fil["negation"] is True: + n = "NOT " + p = fil["p"] + o = fil["o"] + v = fil["v"] + filter_clause = f'WITH {n}{p}{o}"{v}"' + + query = f'FIND RECORD "{record_type}"{filter_clause}' + res = caosdb.execute_query(query) + + projection = kwargs["projection"] + rows = res.get_property_values(*projection) + return FindResult(rows, projection) + + def list_record_type_names(self): + res = caosdb.execute_query("SELECT name FROM RECORDTYPE") + return [e.name for e in res if e.name is not None] + + def list_property_names(self): + res = caosdb.execute_query("SELECT name FROM PROPERTY") + return [e.name for e in res if e.name is not None] + + def create_record_type(self, name : str, properties : list): + c = caosdb.Container() + rt = caosdb.RecordType(name) + c.append(rt) + for p in properties: + name = p["name"] + datatype = p["datatype"] + if name not in self.cached_properties: + new_property = caosdb.Property(name=name, datatype=datatype) + c.append(new_property) + + rt.add_property(name=name, datatype=datatype) + + c.insert() + + def insert_many(self, record_type : str, records : list): + c = caosdb.Container() + for rec in records: + name, description = None, None + if "name" in rec: + name = rec["name"] + if "description" in rec: + description = rec["description"] + + new_rec = caosdb.Record(name=name, description=description) + new_rec.add_parent(record_type) + if "properties" in rec: + for prop in rec["properties"]: + new_rec.add_property(**prop) + c.append(new_rec) + c.insert() + return InsertManyResult(c) + +class CaosDBClient: + def __init__(self, enforce_schema=True, + delegate=DefaultCaosDBClientDelegate, **kwargs): + logger.info("New CaosDBClient: %s", kwargs) + self.enforce_schema = enforce_schema + self._delegate = delegate(**kwargs) + + @property + def cached_record_types(self): + return self._delegate.cached_record_types + + @property + def cached_properties(self): + return self._delegate.cached_properties + + def list_record_type_names(self): + """list_record_types + + List all record types names. + + Returns + ------- + record_types : list of str + """ + logger.debug("list_record_type_names") + return self._delegate.list_record_type_names() + + def close(self): + """close the connection to a CaosDB Server""" + logger.debug("close") + + def create_record_type(self, name : str, properties : list): + """create_record_type + + Parameters + ---------- + + name : str + name is the name of the new record type + properties : list of dict + properties is a list of {name: str, data_type: str} dicts. + + Returns + ------- + None + """ + logger.debug("create_record_type(%s, %s)", name, properties) + self._delegate.create_record_type(name, properties) + + def create_index(self, *args, **kwargs): + """create_index + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def update_one(self, *args, **kwargs): + """update_one + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def update_many(self, *args, **kwargs): + """update_many + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def drop_record_type(self, *args, **kwargs): + """drop_record_type + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def aggregate(self, *args, **kwargs): + """aggregate + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + logger.debug("aggregate(%s, %s)", args, kwargs) + return self._delegate.aggregate(*args, **kwargs) + + def insert_many(self, record_type : str, records : list): + """insert_many + + Parameters + ---------- + + record_type : str + name of the record type + records : list of dict + list of properties for the new records + + Returns + ------- + result : InsertManyResult + """ + logger.debug("insert_many(%s, %s)", record_type, records) + return self._delegate.insert_many(record_type, records) + + def update(self, *args, **kwargs): + """update + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def rename(self, *args, **kwargs): + """rename + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def delete_many(self, *args, **kwargs): + """delete_many + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def drop_index(self, *args, **kwargs): + """drop_index + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + """ + # TODO + raise Exception("NOT IMPLEMENTED") + + def find(self, *args, **kwargs): + """find + + Parameters + ---------- + + *args : + **kwargs : + + Returns + ------- + result : FindResult + """ + logger.debug("find(%s, %s)", args, kwargs) + return self._delegate.find(*args, **kwargs) diff --git a/djaosdb/cursor.py b/djaosdb/cursor.py index f5a4f4b8221ed2404077a08c7f30af05381efb75..08e910667a132f77cbb633fecaf8a4a38235cbe9 100644 --- a/djaosdb/cursor.py +++ b/djaosdb/cursor.py @@ -8,13 +8,8 @@ logger = getLogger(__name__) class Cursor: - def __init__(self, - client_conn, - db_conn, - connection_properties): - self.db_conn = db_conn - self.client_conn = client_conn - self.connection_properties = connection_properties + def __init__(self, connection): + self.connection = connection self.result = None def __exit__(self, exc_type, exc_val, exc_tb): @@ -31,7 +26,7 @@ class Cursor: pass try: - return getattr(self.db_conn, name) + return getattr(self.connection, name) except AttributeError: raise @@ -49,9 +44,7 @@ class Cursor: def execute(self, sql, params=None): try: self.result = Query( - self.client_conn, - self.db_conn, - self.connection_properties, + self.connection, sql, params) except Exception as e: diff --git a/djaosdb/database.py b/djaosdb/database.py index fffa9903028714d0d1a9e1f7351275c45773de14..e5f591d3f6161882bd739150abf7a89940b4145b 100644 --- a/djaosdb/database.py +++ b/djaosdb/database.py @@ -1,17 +1,6 @@ -from .caosdb_client import CaosDBClient from logging import getLogger logger = getLogger(__name__) -clients = {} - - -def connect(db, **kwargs): - try: - return clients[db] - except KeyError: - logger.debug('New CaosDBClient connection') - clients[db] = CaosDBClient(**kwargs, connect=False) - return clients[db] class Error(Exception): # NOQA: StandardError undefined on PY3 diff --git a/djaosdb/exceptions.py b/djaosdb/exceptions.py index 46a86566bd22c8906a17657967344364a5a56543..e31534dc1c9ce29eabf00aa57bd6a6afca373d0e 100644 --- a/djaosdb/exceptions.py +++ b/djaosdb/exceptions.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from typing import Sequence, Any -djaosdb_access_url = 'https://nesdis.github.io/djaosdb/sponsor/' +djaosdb_access_url = 'TODO' _printed_features = set() @@ -41,4 +41,4 @@ def print_warn(feature=None, message=None): message = ((message or f'This version of djaosdb does not support "{feature}" fully. ') + f'Visit {djaosdb_access_url}') print(message) - _printed_features.add(feature) \ No newline at end of file + _printed_features.add(feature) diff --git a/djaosdb/introspection.py b/djaosdb/introspection.py index 1066f1a028ac286115152c3739fb4f9c6a31ad9c..59ed3661f7d23f4b5d75f1f3341d46a19847655e 100644 --- a/djaosdb/introspection.py +++ b/djaosdb/introspection.py @@ -46,11 +46,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): # return sorted(cursor.m_cli_connection.collection_names(False)) def get_table_list(self, cursor): - return [ TableInfo(c, 't') - for c in cursor.db_conn.list_collection_names() - if c != '__schema__' + for c in cursor.connection.list_record_type_names() ] def get_constraints(self, cursor, table_name): diff --git a/djaosdb/mockup_delegator.py b/djaosdb/mockup_delegator.py new file mode 100644 index 0000000000000000000000000000000000000000..fd9ed2e0df4fa303860d6eb08634da22ba6ded44 --- /dev/null +++ b/djaosdb/mockup_delegator.py @@ -0,0 +1,32 @@ +class MockupDelegatorConnection(): + + def __init__(self): + pass + + def insert_many(self, table, *args, **kwargs): + from .caosdb_client import InsertManyResult + if "django_migrations" == table: + new_id = hash(args[0][0]["applied"]) + hash(args[0][0]["app"]) + result = InsertManyResult() + result.inserted_ids = [new_id] + return result + if "django_content_type" == table: + new_id = hash(args[0][0]["model"]) + hash(args[0][0]["app_label"]) + result = InsertManyResult() + result.inserted_ids = [new_id] + return result + + + return None + + def list_record_type_names(self): + return ["django_migrations", "django_content_type", "auth_permission"] + + def aggregate(self, *args, **kwargs): + from .caosdb_client import Result + if "auth_permission" == args[0]: + result = Result() + return result + + return None + diff --git a/djaosdb/sql2mongo/operators.py b/djaosdb/sql2mongo/operators.py index ed3637b9291c6cb90f34f86b1295f2ade477b55d..80f06266f180dab8311cc8f6f92c98712cafea45 100644 --- a/djaosdb/sql2mongo/operators.py +++ b/djaosdb/sql2mongo/operators.py @@ -526,18 +526,16 @@ class CmpOp(_Op): if self._field_ext: field += '.' + self._field_ext - if not self.is_negated: - return {field: {self._operator: self._constant}} - else: - return {field: {'$not': {self._operator: self._constant}}} + return {"negation": self.is_negated, "p": field, "o": + self._operator, "v": self._constant} OPERATOR_MAP = { - '=': '$eq', - '>': '$gt', - '<': '$lt', - '>=': '$gte', - '<=': '$lte', + '=': '=', + '>': '>', + '<': '<', + '>=': '>=', + '<=': '<=', } OPERATOR_PRECEDENCE = { 'IS': 8, diff --git a/djaosdb/sql2mongo/query.py b/djaosdb/sql2mongo/query.py index 9ed87019f5360cb6831bfcbe75e5e9e1dd3e1d6d..4c3705ed7021da15782451f4e298d73785071832 100644 --- a/djaosdb/sql2mongo/query.py +++ b/djaosdb/sql2mongo/query.py @@ -21,7 +21,6 @@ from sqlparse.sql import ( Where, Statement) -from ..caosdb_client import CaosDBClient from ..exceptions import SQLDecodeError, MigrationError, print_warn from .functions import SQLFunc from .sql_tokens import (SQLToken, SQLStatement, SQLIdentifier, @@ -58,13 +57,11 @@ class TokenAlias: class BaseQuery(abc.ABC): def __init__(self, - db: str, - connection_properties: 'base.DjongoClient', + connection: 'caosdb_client.CaosDBClient', statement: Statement, params: Sequence): self.statement = statement - self.db = db - self.connection_properties = connection_properties + self.connection = connection self.params = params self.token_alias = TokenAlias() self.nested_query: Optional[NestedInQueryConverter] = None @@ -244,7 +241,7 @@ class SelectQuery(DQLQuery): def _get_cursor(self): if self._needs_aggregation(): pipeline = self._make_pipeline() - cur = self.db[self.left_table].aggregate(pipeline) + cur = self.connection.aggregate(self.left_table, pipeline) logger.debug(f'Aggregation query: {pipeline}') else: kwargs = {} @@ -259,11 +256,11 @@ class SelectQuery(DQLQuery): if self.order: kwargs.update(self.order.to_mongo()) - + if self.offset: kwargs.update(self.offset.to_mongo()) - cur = self.db[self.left_table].find(**kwargs) + cur = self.connection.find(self.left_table, **kwargs) logger.debug(f'Find query: {kwargs}') return cur @@ -281,14 +278,14 @@ class SelectQuery(DQLQuery): try: ret.append(doc[selected.column]) except KeyError: - if self.connection_properties.enforce_schema: + if self.connection.enforce_schema: raise MigrationError(selected.column) ret.append(None) else: try: ret.append(doc[selected.table][selected.column]) except KeyError: - if self.connection_properties.enforce_schema: + if self.connection.enforce_schema: raise MigrationError(selected.column) ret.append(None) else: @@ -335,8 +332,8 @@ class UpdateQuery(DMLQuery): self.kwargs.update(self.set_columns.to_mongo()) def execute(self): - db = self.db - self.result = db[self.left_table].update_many(**self.kwargs) + db = self.connection + self.result = db.update_many(self.left_table, **self.kwargs) logger.debug(f'update_many: {self.result.modified_count}, matched: {self.result.matched_count}') @@ -352,13 +349,13 @@ class InsertQuery(DMLQuery): def _table(self, statement: SQLStatement): tok = statement.next() - collection = tok.get_name() - if collection not in self.connection_properties.cached_collections: - if self.connection_properties.enforce_schema: - raise MigrationError(f'Table {collection} does not exist in database') - self.connection_properties.cached_collections.add(collection) + record_type = tok.get_name() + if record_type not in self.connection.cached_record_types: + if self.connection.enforce_schema: + raise MigrationError(f'RecordType {record_type} does not exist.') + self.connection.cached_record_types.add(record_type) - self.left_table = collection + self.left_table = record_type def _columns(self, statement: SQLStatement): tok = statement.next() @@ -379,37 +376,20 @@ class InsertQuery(DMLQuery): raise SQLDecodeError def execute(self): - docs = [] + records = [] num = len(self._values) - auto = self.db['__schema__'].find_one_and_update( - { - 'name': self.left_table, - 'auto': { - '$exists': True - } - }, - {'$inc': {'auto.seq': num}}, - return_document=ReturnDocument.AFTER - ) - for i, val in enumerate(self._values): - ins = {} - if auto: - for name in auto['auto']['field_names']: - ins[name] = auto['auto']['seq'] - num + i + 1 + ins = {"properties": []} for _field, value in zip(self._cols, val): - if (auto and _field in auto['auto']['field_names'] - and value == 'DEFAULT'): - continue - ins[_field] = value - docs.append(ins) + if _field in ["name", "description"]: + ins[_field] = value + else: + ins["properties"].append({"value": value, "name": _field}) + records.append(ins) - res = self.db[self.left_table].insert_many(docs, ordered=False) - if auto: - self._result_ref.last_row_id = auto['auto']['seq'] - else: - self._result_ref.last_row_id = res.inserted_ids[-1] + res = self.connection.insert_many(self.left_table, records) + self._result_ref.last_row_id = res.inserted_ids[-1] logger.debug('inserted ids {}'.format(res.inserted_ids)) def parse(self): @@ -472,10 +452,11 @@ class AlterQuery(DDLQuery): if not column: # Rename table - self.execute = self._rename_collection + self.execute = self._rename_record_type def _rename_column(self): - self.db[self.left_table].update( + self.connection.update( + self.left_table, {}, { '$rename': { @@ -485,8 +466,8 @@ class AlterQuery(DDLQuery): multi=True ) - def _rename_collection(self): - self.db[self.left_table].rename(self._new_name) + def _rename_record_type(self): + self.connection.rename(self.left_table, self._new_name) def _alter(self, statement: SQLStatement): self.execute = lambda: None @@ -513,7 +494,7 @@ class AlterQuery(DDLQuery): print_warn(feature) def _flush(self): - self.db[self.left_table].delete_many({}) + self.connection.delete_many(self.left_table, {}) def _table(self, statement: SQLStatement): tok = statement.next() @@ -538,26 +519,20 @@ class AlterQuery(DDLQuery): raise SQLDecodeError def _drop_index(self): - self.db[self.left_table].drop_index(self._iden_name) + self.connection.drop_index(self.left_table, self._iden_name) def _drop_column(self): - self.db[self.left_table].update( - {}, - { - '$unset': { - self._iden_name: '' - } - }, - multi=True - ) - self.db['__schema__'].update( - {'name': self.left_table}, - { - '$unset': { - f'fields.{self._iden_name}': '' - } - } - ) + print_warn("DROP COLUMN") + # self.connection.update( + # self.left_table, + # {}, + # { + # '$unset': { + # self._iden_name: '' + # } + # }, + # multi=True + # ) def _add(self, statement: SQLStatement): for tok in statement: @@ -610,7 +585,8 @@ class AlterQuery(DDLQuery): err_sub_sql=statement) def _add_column(self): - self.db[self.left_table].update( + self.connection.update( + self.left_table, { '$or': [ {self._iden_name: {'$exists': False}}, @@ -624,7 +600,8 @@ class AlterQuery(DDLQuery): }, multi=True ) - self.db['__schema__'].update( + self.connection.update( + '__schema__', {'name': self.left_table}, { '$set': { @@ -636,15 +613,13 @@ class AlterQuery(DDLQuery): ) def _index(self): - self.db[self.left_table].create_index( + self.connection.create_index( + self.left_table, self.field_dir, name=self._iden_name) def _unique(self): - self.db[self.left_table].create_index( - self.field_dir, - unique=True, - name=self._iden_name) + print_warn("UNIQUE INDEX") def _fk(self): pass @@ -655,25 +630,9 @@ class CreateQuery(DDLQuery): def __init__(self, *args): super().__init__(*args) - def _create_table(self, statement): - if '__schema__' not in self.connection_properties.cached_collections: - self.db.create_collection('__schema__') - self.connection_properties.cached_collections.add('__schema__') - self.db['__schema__'].create_index('name', unique=True) - self.db['__schema__'].create_index('auto') - + def _create_record_type(self, statement): tok = statement.next() - table = SQLToken.token2sql(tok, self).table - try: - self.db.create_collection(table) - # except CollectionInvalid: - except CaosDBException as e: - if self.connection_properties.enforce_schema: - raise - else: - return - - logger.debug('Created table: {}'.format(table)) + record_type = SQLToken.token2sql(tok, self).table tok = statement.next() if not isinstance(tok, Parenthesis): @@ -684,61 +643,42 @@ class CreateQuery(DDLQuery): raise SQLDecodeError(f'Unexpected sql syntax' f' for column definition: {statement}') - _filter = { - 'name': table - } - _set = {} - push = {} - update = {} - + # collect properties + properties = [] for col in SQLColumnDef.sql2col_defs(tok.value): if isinstance(col, SQLColumnConstraint): print_warn('column CONSTRAINTS') else: field = col.name - if field == '_id': + if field in ['id', "name", "description"]: continue - _set[f'fields.{field}'] = { - 'type_code': col.data_type - } + properties.append({"name": field, + "datatype": col.data_type + }) if SQLColumnDef.autoincrement in col.col_constraints: - try: - push['auto.field_names']['$each'].append(field) - except KeyError: - push['auto.field_names'] = { - '$each': [field] - } - _set['auto.seq'] = 0 + print_warn("AUTO INCREMENT") if SQLColumnDef.primarykey in col.col_constraints: - self.db[table].create_index(field, unique=True, name='__primary_key__') + print_warn("PRIMARY KEY other than id") if SQLColumnDef.unique in col.col_constraints: - self.db[table].create_index(field, unique=True) + print_warn("UNIQUE INDEX") if (SQLColumnDef.not_null in col.col_constraints or SQLColumnDef.null in col.col_constraints): print_warn('NULL, NOT NULL column validation check') - if _set: - update['$set'] = _set - if push: - update['$push'] = push - if update: - self.db['__schema__'].update_one( - filter=_filter, - update=update, - upsert=True - ) + self.connection.create_record_type(record_type, properties) + logger.debug('Created record_type: {}'.format(record_type)) def parse(self): statement = SQLStatement(self.statement) statement.skip(2) tok = statement.next() if tok.match(tokens.Keyword, 'TABLE'): - self._create_table(statement) + self._create_record_type(statement) elif tok.match(tokens.Keyword, 'DATABASE'): pass else: @@ -766,7 +706,7 @@ class DeleteQuery(DMLQuery): kw.update(where.to_mongo()) def execute(self): - db_con = self.db + db_con = self.connection self.result = db_con[self.left_table].delete_many(**self.kw) logger.debug('delete_many: {}'.format(self.result.deleted_count)) @@ -777,16 +717,12 @@ class DeleteQuery(DMLQuery): class Query: def __init__(self, - client_connection: CaosDBClient, - db_connection: str, - connection_properties: 'base.DjongoClient', + connection: 'caosdb_client.CaosDBClient', sql: str, params: Optional[Sequence]): self._params = params - self.db = db_connection - self.cli_con = client_connection - self.connection_properties = connection_properties + self.connection = connection self._params_index_count = -1 self._sql = re.sub(r'%s', self._param_index, sql) self.last_row_id = None @@ -899,7 +835,7 @@ class Query: def _alter(self, sm): try: - query = AlterQuery(self.db, self.connection_properties, sm, self._params) + query = AlterQuery(self.connection, sm, self._params) except SQLDecodeError: logger.warning('Not implemented alter command for SQL {}'.format(self._sql)) raise @@ -908,7 +844,7 @@ class Query: return query def _create(self, sm): - query = CreateQuery(self.db, self.connection_properties, sm, self._params) + query = CreateQuery(self.connection, sm, self._params) query.execute() return query @@ -923,27 +859,27 @@ class Query: elif tok.match(tokens.Keyword, 'TABLE'): tok = statement.next() table_name = tok.get_name() - self.db.drop_collection(table_name) + self.connection.drop_record_type(table_name) else: raise SQLDecodeError('statement:{}'.format(sm)) def _update(self, sm): - query = UpdateQuery(self.db, self.connection_properties, sm, self._params) + query = UpdateQuery(self.connection, sm, self._params) query.execute() return query def _delete(self, sm): - query = DeleteQuery(self.db, self.connection_properties, sm, self._params) + query = DeleteQuery(self.connection, sm, self._params) query.execute() return query def _insert(self, sm): - query = InsertQuery(self, self.db, self.connection_properties, sm, self._params) + query = InsertQuery(self, self.connection, sm, self._params) query.execute() return query def _select(self, sm): - return SelectQuery(self.db, self.connection_properties, sm, self._params) + return SelectQuery(self.connection, sm, self._params) FUNC_MAP = { 'SELECT': _select, diff --git a/tests/djongo_tests/test_project/test_project/settings/__init__.py b/example/djaosdb_test/__init__.py similarity index 100% rename from tests/djongo_tests/test_project/test_project/settings/__init__.py rename to example/djaosdb_test/__init__.py diff --git a/example/djaosdb_test/settings.py b/example/djaosdb_test/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..30388c484b8928b0b486fac573e6a0db43b6d66a --- /dev/null +++ b/example/djaosdb_test/settings.py @@ -0,0 +1,165 @@ +""" +Django settings for djaosdb_test project. + +Generated by 'django-admin startproject' using Django 2.2.16. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'bvye0b*i%_m(ec_qmlc0(t#fy+&z&#-kzljb36yh&^hzjz(b+n' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "simple_test", + # 'django.contrib.admin', + # 'django.contrib.auth', + 'django.contrib.contenttypes', + # 'django.contrib.sessions', + # 'django.contrib.messages', + # 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + # 'django.middleware.security.SecurityMiddleware', + # 'django.contrib.sessions.middleware.SessionMiddleware', + # 'django.middleware.common.CommonMiddleware', + # 'django.middleware.csrf.CsrfViewMiddleware', + # 'django.contrib.auth.middleware.AuthenticationMiddleware', + # 'django.contrib.messages.middleware.MessageMiddleware', + # 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': "verbose", + }, + }, + 'formatters': { + 'verbose': { + 'format': '[{levelname}]({module}) {message}', + 'style': '{', + }, + }, + 'root': { + 'handlers': ['console'], + 'level': 'INFO', + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), + 'propagate': False, + }, + 'djaosdb': { + 'handlers': ['console'], + 'level': os.getenv('DJAOSDB_LOG_LEVEL', 'DEBUG'), + 'propagate': False, + } + }, +} + +ROOT_URLCONF = 'djaosdb_test.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + # 'OPTIONS': { + # 'context_processors': [ + # 'django.template.context_processors.debug', + # 'django.template.context_processors.request', + # 'django.contrib.auth.context_processors.auth', + # 'django.contrib.messages.context_processors.messages', + # ], + # }, + }, +] + +WSGI_APPLICATION = 'djaosdb_test.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'djaosdb', + 'CLIENT': { + 'url': 'https://localhost:10443', + 'password_method': "plain", + 'username': "admin", + "password": "caosdb", +# 'authSource': 'admin', + }, + 'ENFORCE_SCHEMA': True + }, + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + # } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +# AUTH_PASSWORD_VALIDATORS = [ + # { + # 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + # }, + # { + # 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + # }, + # { + # 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + # }, + # { + # 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + # }, +# ] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +# LANGUAGE_CODE = 'en-us' + +# TIME_ZONE = 'UTC' + +# USE_I18N = True + +# USE_L10N = True + +# USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +# STATIC_URL = '/static/' diff --git a/example/djaosdb_test/urls.py b/example/djaosdb_test/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..47e741158d6d991833d2d5ae811767898011a8b2 --- /dev/null +++ b/example/djaosdb_test/urls.py @@ -0,0 +1,21 @@ +"""djaosdb_test URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +#from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('simple_test/', include('simple_test.urls')), +] diff --git a/example/djaosdb_test/wsgi.py b/example/djaosdb_test/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..d823842976fbf397dd4186973258bdd33007d55d --- /dev/null +++ b/example/djaosdb_test/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djaosdb_test project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djaosdb_test.settings') + +application = get_wsgi_application() diff --git a/example/manage.py b/example/manage.py new file mode 100755 index 0000000000000000000000000000000000000000..1be2f33e49e67138ffc03d8f54a74d60dbc59fc5 --- /dev/null +++ b/example/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djaosdb_test.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/example/simple_test/__init__.py b/example/simple_test/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/example/simple_test/admin.py b/example/simple_test/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/example/simple_test/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/example/simple_test/apps.py b/example/simple_test/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..a1c4fbd1f2dcc3a571e485015c8a6f7ccdcbde62 --- /dev/null +++ b/example/simple_test/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SimpleTestConfig(AppConfig): + name = 'simple_test' diff --git a/example/simple_test/models.py b/example/simple_test/models.py new file mode 100644 index 0000000000000000000000000000000000000000..aeb697c15a785b284e37aac02a04f3c201c36a19 --- /dev/null +++ b/example/simple_test/models.py @@ -0,0 +1,10 @@ +from django.db import models + +class TestRecordType(models.Model): + id = models.CharField(primary_key=True, max_length=100, default=None) + name = models.CharField(max_length=100, default=None) + description = models.CharField(max_length=100, default=None) + prop1 = models.CharField(max_length=100, default=None) + + class Meta: + db_table = "TestRecordType" diff --git a/example/simple_test/templates/testrt/create.html b/example/simple_test/templates/testrt/create.html new file mode 100644 index 0000000000000000000000000000000000000000..256405a89e09ac3721b8ab59197c006fab230f3a --- /dev/null +++ b/example/simple_test/templates/testrt/create.html @@ -0,0 +1,4 @@ +<form method="post">{% csrf_token %} + {{ form.as_p }} + <input type="submit" value="Save"> +</form> diff --git a/example/simple_test/templates/testrt/detail.html b/example/simple_test/templates/testrt/detail.html new file mode 100644 index 0000000000000000000000000000000000000000..6feb3da55f85bb3daaf266e8dc104b81432a52d3 --- /dev/null +++ b/example/simple_test/templates/testrt/detail.html @@ -0,0 +1,7 @@ +<h1>TestRecordType</h1> +<dl> + <dt>id</dt><dd>{{ testrt.id }}</dd> + <dt>name</dt><dd>{{ testrt.name}}</dd> + <dt>description</dt><dd>{{ testrt.description }}</dd> + <dt>prop1</dt><dd>{{ testrt.prop1 }}</dd> +</dl> diff --git a/example/simple_test/tests.py b/example/simple_test/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/example/simple_test/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/example/simple_test/urls.py b/example/simple_test/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..d925a43b419a7fdf658f94298903005dd41ec640 --- /dev/null +++ b/example/simple_test/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from .views import ViewTestRT, CreateTestRT + +urlpatterns = [ + path("<int:pk>", ViewTestRT.as_view(), name="detail"), + path("create", CreateTestRT.as_view(), name="create"), +] diff --git a/example/simple_test/views.py b/example/simple_test/views.py new file mode 100644 index 0000000000000000000000000000000000000000..64bca1ddcd9d5fac29053d0232809fa2f7eea88e --- /dev/null +++ b/example/simple_test/views.py @@ -0,0 +1,14 @@ +from django.views.generic import DetailView +from django.views.generic.edit import CreateView + +from .models import TestRecordType + +class ViewTestRT(DetailView): + model = TestRecordType + template_name = 'testrt/detail.html' + context_object_name = "testrt" + +class CreateTestRT(CreateView): + model = TestRecordType + template_name = 'testrt/create.html' + fields = ["name", "description", "prop1"] diff --git a/setup.py b/setup.py index 8ac0cbd64896c3d70a257c98b28851529307fd43..ada86ff65e777b9fa10a8dfa19dc3ff63e8f75bb 100644 --- a/setup.py +++ b/setup.py @@ -81,9 +81,9 @@ def find_version(*file_paths): install_requires = [ - 'sqlparse==0.2.4', + 'sqlparse>=0.2.4', 'caosdb>=0.4.0', - 'django>=2.1,<=3.0.5', + 'django>=2.1', ] if sys.version_info.major == 3 and sys.version_info.minor < 7: diff --git a/tests/djongo_tests/test_project/djongo-test b/tests/djongo_tests/test_project/djongo-test deleted file mode 100644 index f8130afd9ed4b72044218c38a3b4775ef8e38c7d..0000000000000000000000000000000000000000 Binary files a/tests/djongo_tests/test_project/djongo-test and /dev/null differ diff --git a/tests/djongo_tests/test_project/manage.py b/tests/djongo_tests/test_project/manage.py index 2f01bb3d1a9fb9dcef2745a978114929dfccfe83..66550c0299707d5f3e3d46d4ffed89173b46c1af 100644 --- a/tests/djongo_tests/test_project/manage.py +++ b/tests/djongo_tests/test_project/manage.py @@ -5,7 +5,7 @@ import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings.settings_loaded") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") try: from django.core.management import execute_from_command_line except ImportError: diff --git a/tests/djongo_tests/test_project/simple/__init__.py b/tests/djongo_tests/test_project/simple/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/djongo_tests/test_project/simple/apps.py b/tests/djongo_tests/test_project/simple/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..d39220004017c5433e3bcef57d0f43c6747a58ea --- /dev/null +++ b/tests/djongo_tests/test_project/simple/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class XtestAppConfig(AppConfig): + name = 'xtest_app' diff --git a/tests/djongo_tests/test_project/simple/models/basic.py b/tests/djongo_tests/test_project/simple/models/basic.py new file mode 100644 index 0000000000000000000000000000000000000000..fe8538e253bb9e6a4571f5c05f7efdf10998038b --- /dev/null +++ b/tests/djongo_tests/test_project/simple/models/basic.py @@ -0,0 +1,8 @@ +from djaosdb import models + + +class TestRecordType(models.Model): + _id = models.ObjectIdField() + name = models.TextField() + description = models.TextField() + testProperty1 = models.TextField() diff --git a/tests/djongo_tests/test_project/test_project/settings/settings_loaded.py b/tests/djongo_tests/test_project/test_project/settings.py similarity index 65% rename from tests/djongo_tests/test_project/test_project/settings/settings_loaded.py rename to tests/djongo_tests/test_project/test_project/settings.py index 8a89f0939d44bc2e679093d5fd8baebe4e35c78f..05c2e3dcf27052c14978ef2726fa35db54841341 100644 --- a/tests/djongo_tests/test_project/test_project/settings/settings_loaded.py +++ b/tests/djongo_tests/test_project/test_project/settings.py @@ -15,26 +15,49 @@ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '5s(0&1x3(963q!xdyt1=$^(5om4(_=_39ys6=bnp7n-h8%7z+(' - # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': "verbose", + }, + }, + 'formatters': { + 'verbose': { + 'format': '[{levelname}]({module}) {message}', + 'style': '{', + }, + }, + 'root': { + 'handlers': ['console'], + 'level': 'INFO', + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), + 'propagate': False, + }, + }, +} + ALLOWED_HOSTS = ['localhost', '127.0.0.1'] DATABASES = { 'default': { 'ENGINE': 'djaosdb', - 'NAME': 'djaosdb-test', 'CLIENT': { 'host': 'localhost', 'port': 10443, - 'authSource': 'admin', +# 'authSource': 'admin', }, 'ENFORCE_SCHEMA': True }, @@ -42,25 +65,25 @@ DATABASES = { # Application definition INSTALLED_APPS = [ - 'xtest_app.apps.XtestAppConfig', - 'djaosdb.dynamic_formsets.apps.DynamicFormsetsConfig', - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', + 'simple.apps', +# 'djaosdb.dynamic_formsets.apps.DynamicFormsetsConfig', +# 'django.contrib.admin', +# 'django.contrib.auth', +# 'django.contrib.contenttypes', +# 'django.contrib.sessions', +# 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', +# 'django.middleware.security.SecurityMiddleware', +# 'django.contrib.sessions.middleware.SessionMiddleware', +# 'django.middleware.common.CommonMiddleware', +# 'django.middleware.csrf.CsrfViewMiddleware', +# 'django.contrib.auth.middleware.AuthenticationMiddleware', +# 'django.contrib.messages.middleware.MessageMiddleware', +# 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'test_project.urls.urls_loaded' diff --git a/tests/djongo_tests/test_project/test_project/settings/settings_lite.py b/tests/djongo_tests/test_project/test_project/settings/settings_lite.py deleted file mode 100644 index e0206772293f881e4c27fa94969054966e1e6fea..0000000000000000000000000000000000000000 --- a/tests/djongo_tests/test_project/test_project/settings/settings_lite.py +++ /dev/null @@ -1,130 +0,0 @@ -""" -Django settings for main_test_app project. - -Generated by 'django-admin startproject' using Django 1.11.2. - -For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ -""" - -import os, sys -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '5s(0&1x3(963q!xdyt1=$^(5om4(_=_39ys6=bnp7n-h8%7z+(' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['localhost','127.0.0.1'] - -DATABASES = { - 'default': { - 'ENGINE': 'djaosdb', - 'NAME': 'djaosdb-test', - 'ENFORCE_SCHEMA': False, - 'LOGGING': { - 'version': 1, - 'loggers': { - 'djaosdb': { - 'level': 'DEBUG', - 'propagate': False, - 'handlers': ['console'] - } - }, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - 'level': 'DEBUG', - 'stream': sys.stdout - } - } - } - }, -} -# Application definition - -INSTALLED_APPS = [ - 'xtest_app.apps.XtestAppConfig', -] - - -MIDDLEWARE = [ - # 'django.middleware.security.SecurityMiddleware', - # 'django.contrib.sessions.middleware.SessionMiddleware', - # 'django.middleware.common.CommonMiddleware', - # 'django.middleware.csrf.CsrfViewMiddleware', - # 'django.contrib.auth.middleware.AuthenticationMiddleware', - # 'django.contrib.messages.middleware.MessageMiddleware', - # 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'test_project.urls.urls_lite' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'test_project.wsgi.application' - - - -# Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ - -STATIC_URL = '/static/' - -STATIC_ROOT = os.path.join(BASE_DIR, 'static') \ No newline at end of file diff --git a/tests/djongo_tests/test_project/test_project/settings/settings_loaded_formsets.py b/tests/djongo_tests/test_project/test_project/settings/settings_loaded_formsets.py deleted file mode 100644 index 702ca94dc2aad14e7686a4dfdb194fa35ac4fe1a..0000000000000000000000000000000000000000 --- a/tests/djongo_tests/test_project/test_project/settings/settings_loaded_formsets.py +++ /dev/null @@ -1,125 +0,0 @@ -""" -Django settings for main_test_app project. - -Generated by 'django-admin startproject' using Django 1.11.2. - -For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '5s(0&1x3(963q!xdyt1=$^(5om4(_=_39ys6=bnp7n-h8%7z+(' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['localhost','127.0.0.1'] - -DATABASES = { - 'default': { - 'ENGINE': 'djaosdb', - 'NAME': 'djaosdb-test', - # 'USER': 'user', - # 'PASSWORD': 'passpass', - # 'AUTH_SOURCE': 'djaosdb-test', - 'ENFORCE_SCHEMA': True - - }, -} -# Application definition - -INSTALLED_APPS = [ - 'xtest_app.apps.XtestAppConfig', - 'djaosdb.dynamic_formsets.apps.DynamicFormsetsConfig', - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', -] - - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'test_project.urls.urls_loaded' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'test_project.wsgi.application' - - - -# Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ - -STATIC_URL = '/static/' - -STATIC_ROOT = os.path.join(BASE_DIR, 'static') \ No newline at end of file diff --git a/tests/djongo_tests/test_project/test_project/settings/settings_precheckin.py b/tests/djongo_tests/test_project/test_project/settings/settings_precheckin.py deleted file mode 100644 index c777dd07b44ffacfc66b78cde6a29a396a41624b..0000000000000000000000000000000000000000 --- a/tests/djongo_tests/test_project/test_project/settings/settings_precheckin.py +++ /dev/null @@ -1,121 +0,0 @@ -""" -Django settings for main_test_app project. - -Generated by 'django-admin startproject' using Django 1.11.2. - -For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '5s(0&1x3(963q!xdyt1=$^(5om4(_=_39ys6=bnp7n-h8%7z+(' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['localhost','127.0.0.1'] - -DATABASES = { - 'default': { - 'ENGINE': 'djaosdb', - 'NAME': 'djaosdb-test', - 'ENFORCE_SCHEMA': False - - }, -} -# Application definition - -INSTALLED_APPS = [ - 'xtest_app.apps.XtestAppConfig', - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', -] - - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'test_project.urls.urls_lite' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'test_project.wsgi.application' - - - -# Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ - -STATIC_URL = '/static/' - -STATIC_ROOT = os.path.join(BASE_DIR, 'static') \ No newline at end of file diff --git a/tests/djongo_tests/test_project/test_project/urls/urls_loaded.py b/tests/djongo_tests/test_project/test_project/urls/urls_loaded.py index 3c436e8df1f228abb4d65cbcc0665e8582b180b7..3713b705fe1fc10e0a6f622b51b6b4bce9eef39b 100644 --- a/tests/djongo_tests/test_project/test_project/urls/urls_loaded.py +++ b/tests/djongo_tests/test_project/test_project/urls/urls_loaded.py @@ -14,8 +14,8 @@ Including another URLconf 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url -from django.contrib import admin +#from django.contrib import admin urlpatterns = [ - url(r'^admin/', admin.site.urls), +# url(r'^admin/', admin.site.urls), ] diff --git a/tests/djongo_tests/test_project/xtest_app/admin.py b/tests/djongo_tests/test_project/xtest_app/admin.py index c2282aee205194c9009dc43214b01826d767d747..200dd0f5462bcd040f2381d4caf91542d76f63f5 100644 --- a/tests/djongo_tests/test_project/xtest_app/admin.py +++ b/tests/djongo_tests/test_project/xtest_app/admin.py @@ -1,15 +1,15 @@ -from django.contrib import admin +#from django.contrib import admin -from xtest_app.models.admin_tests import ArrayFieldEntry as ArrayEntry -from xtest_app.models.basic_field import BasicRelatedEntry, BasicAuthor, BasicBlog, EmbeddedFieldEntry as EmbeddedEntry +#from xtest_app.models.admin_tests import ArrayFieldEntry as ArrayEntry +#from xtest_app.models.basic_field import BasicRelatedEntry, BasicAuthor, BasicBlog, EmbeddedFieldEntry as EmbeddedEntry # from xtest_app.models.reference_field import ReferenceEntry, ReferenceAuthor -admin.site.register(BasicAuthor) -admin.site.register(BasicBlog) -admin.site.register(ArrayEntry) +#admin.site.register(BasicAuthor) +#admin.site.register(BasicBlog) +#admin.site.register(ArrayEntry) -admin.site.register(BasicRelatedEntry) +#admin.site.register(BasicRelatedEntry) # admin.site.register(EmbeddedEntry) # admin.site.register(EmbeddedDateEntry) # admin.site.register(ReferenceEntry)