-
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 branch 'dabih-release' into devfix-simple-postgresql
- Loading branch information
Showing
22 changed files
with
351 additions
and
273 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
from django.conf import settings | ||
from django.db import models | ||
|
||
from chemreg.common.utils import get_current_user_pk | ||
|
||
|
||
class CommonInfo(models.Model): | ||
"""Common information to be applied to all models. | ||
Attributes: | ||
created_at (datetime.datetime): When the model was created. | ||
created_by (chemreg.user.models.User): Who created this model. | ||
updated_at (datetime.datetime): When the model was updated. | ||
updated_by (chemreg.user.models.User): Who updated this model. | ||
""" | ||
|
||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
created_at = models.DateTimeField(auto_now_add=True, editable=False) | ||
created_by = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, | ||
default=get_current_user_pk, | ||
editable=False, | ||
related_name="%(class)s_created_by_set", | ||
null=True, | ||
on_delete=models.PROTECT, | ||
) | ||
updated_at = models.DateTimeField(auto_now=True, editable=False) | ||
updated_by = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, | ||
editable=False, | ||
related_name="%(class)s_updated_by_set", | ||
null=True, | ||
on_delete=models.PROTECT, | ||
) | ||
|
||
class Meta: | ||
abstract = True | ||
ordering = ["pk"] |
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,17 @@ | ||
from django.db.models.signals import pre_save | ||
from django.dispatch import receiver | ||
|
||
from chemreg.common.models import CommonInfo | ||
from chemreg.common.utils import get_current_user_pk | ||
|
||
|
||
@receiver(pre_save) | ||
def set_updated_by(sender, instance, **kwargs): | ||
"""Signal to set the `CommonInfo.updated_by`. | ||
Arguments: | ||
sender: the model class. | ||
instance: the model instance. | ||
""" | ||
if isinstance(instance, CommonInfo): | ||
instance.updated_by_id = get_current_user_pk() |
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 @@ | ||
from crum import get_current_user | ||
|
||
|
||
def get_current_user_pk(): | ||
"""Retrieve the current user's primary key. | ||
Returns: | ||
The primary key of the current request's user. | ||
""" | ||
current_user = get_current_user() | ||
if not current_user: | ||
return None | ||
return current_user.pk |
This file was deleted.
Oops, something went wrong.
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,228 @@ | ||
# Generated by Django 3.0.3 on 2020-03-25 17:38 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
import computed_property.fields | ||
|
||
import chemreg.common.utils | ||
import chemreg.compound.models | ||
import chemreg.compound.utils | ||
import chemreg.compound.validators | ||
|
||
|
||
def fwd_create_illdefined_querystructuretype(apps, schema_editor): | ||
QueryStructureType = apps.get_model("compound", "QueryStructureType") | ||
db_alias = schema_editor.connection.alias | ||
QueryStructureType.objects.using(db_alias).create( | ||
name="ill-defined", | ||
label="Ill defined", | ||
short_description="Ill defined", | ||
long_description="Ill defined", | ||
) | ||
|
||
|
||
def rev_create_illdefined_querystructuretype(apps, schema_editor): | ||
QueryStructureType = apps.get_model("compound", "QueryStructureType") | ||
db_alias = schema_editor.connection.alias | ||
QueryStructureType.objects.using(db_alias).filter(name="ill-defined").delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
("contenttypes", "0002_remove_content_type_name"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="BaseCompound", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"cid", | ||
models.CharField( | ||
default=chemreg.compound.utils.build_cid, | ||
max_length=50, | ||
unique=True, | ||
validators=[ | ||
chemreg.compound.validators.validate_cid_regex, | ||
chemreg.compound.validators.validate_cid_checksum, | ||
], | ||
), | ||
), | ||
("structure", models.TextField()), | ||
( | ||
"created_by", | ||
models.ForeignKey( | ||
default=chemreg.common.utils.get_current_user_pk, | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="basecompound_created_by_set", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"polymorphic_ctype", | ||
models.ForeignKey( | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="polymorphic_compound.basecompound_set+", | ||
to="contenttypes.ContentType", | ||
), | ||
), | ||
( | ||
"updated_by", | ||
models.ForeignKey( | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="basecompound_updated_by_set", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={"ordering": ["pk"], "abstract": False,}, | ||
), | ||
migrations.CreateModel( | ||
name="DefinedCompound", | ||
fields=[ | ||
( | ||
"basecompound_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="compound.BaseCompound", | ||
), | ||
), | ||
( | ||
"inchikey", | ||
computed_property.fields.ComputedCharField( | ||
compute_from="_inchikey", editable=False, max_length=29 | ||
), | ||
), | ||
], | ||
options={"ordering": ["pk"], "abstract": False,}, | ||
bases=("compound.basecompound",), | ||
), | ||
migrations.CreateModel( | ||
name="QueryStructureType", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"name", | ||
models.SlugField( | ||
help_text="Query structure type name", | ||
max_length=49, | ||
unique=True, | ||
verbose_name="name", | ||
), | ||
), | ||
( | ||
"label", | ||
models.CharField( | ||
help_text="Query structure type label", | ||
max_length=99, | ||
unique=True, | ||
verbose_name="label", | ||
), | ||
), | ||
( | ||
"short_description", | ||
models.CharField( | ||
help_text="Query structure type short description", | ||
max_length=499, | ||
verbose_name="short description", | ||
), | ||
), | ||
( | ||
"long_description", | ||
models.TextField( | ||
help_text="Query structure type long description", | ||
verbose_name="long description", | ||
), | ||
), | ||
( | ||
"created_by", | ||
models.ForeignKey( | ||
default=chemreg.common.utils.get_current_user_pk, | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="querystructuretype_created_by_set", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"updated_by", | ||
models.ForeignKey( | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="querystructuretype_updated_by_set", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={"ordering": ["pk"], "abstract": False,}, | ||
), | ||
migrations.RunPython( | ||
fwd_create_illdefined_querystructuretype, | ||
rev_create_illdefined_querystructuretype, | ||
), | ||
migrations.CreateModel( | ||
name="IllDefinedCompound", | ||
fields=[ | ||
( | ||
"basecompound_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="compound.BaseCompound", | ||
), | ||
), | ||
( | ||
"query_structure_type", | ||
models.ForeignKey( | ||
default=chemreg.compound.models.get_illdefined_qst, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="compound.QueryStructureType", | ||
), | ||
), | ||
], | ||
options={"verbose_name": "ill-defined compound",}, | ||
bases=("compound.basecompound",), | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.