Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.43'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Dec 27, 2018
2 parents 28c7426 + 5bcbad0 commit 9fa3e1c
Show file tree
Hide file tree
Showing 49 changed files with 457 additions and 566 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
omit =
*/wsgi.py
setup.py
*/navbars.py
manage.py
*/config_utils/*
*/migrations/*
*/mommy_*
venv/*
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The mixin:

* sets the id fields to a ``UUIDField`` instead of an integer;
* adds audit fields through ``BaseModel`` (user_created, user_modified, date_created, etc);
* adds ``UrlMixin``, ``DeviceModelMixin``
* adds ``UrlModelMixin``, ``DeviceModelMixin``

Most models require an audit trail. If so, add the ``HistoricalRecord`` model manager.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.42
0.2.43
5 changes: 4 additions & 1 deletion edc_base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from .constants import BASE_MODEL_UPDATE_FIELDS, BASE_UUID_MODEL_UPDATE_FIELDS
from .constants import DEFAULT_BASE_FIELDS
from .utils import get_utcnow, convert_php_dateformat, get_dob, get_uuid
from .model_validators import CellNumber, TelephoneNumber
from .model_validators import datetime_not_future, datetime_is_future
from .model_validators import date_not_future, date_is_future
from .utils import formatted_datetime, to_utc
from .utils import get_utcnow, convert_php_dateformat, get_dob, get_uuid
File renamed without changes.
3 changes: 2 additions & 1 deletion edc_base/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BASE_MODEL_UPDATE_FIELDS = [
'user_created', 'user_modified', 'hostname_created', 'hostname_modified']
'modified', 'user_modified', 'hostname_modified']

BASE_UUID_MODEL_UPDATE_FIELDS = ['revision', ]

DEFAULT_BASE_FIELDS = [
Expand Down
20 changes: 0 additions & 20 deletions edc_base/freeze.py

This file was deleted.

20 changes: 10 additions & 10 deletions edc_base/logging.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

verbose_formatter = {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'}

file_handler = {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': None,
'formatter': 'verbose'
}
#
# verbose_formatter = {
# 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'}
#
# file_handler = {
# 'level': 'DEBUG',
# 'class': 'logging.FileHandler',
# 'filename': None,
# 'formatter': 'verbose'
# }
1 change: 0 additions & 1 deletion edc_base/model_managers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .historical_records import HistoricalRecords
from .history_manager_mixin import HistoryManagerMixin
15 changes: 8 additions & 7 deletions edc_base/model_managers/historical_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ class HistoricalRecords(SimpleHistoricalRecords):
model_cls = SerializableModel

def __init__(self, **kwargs):
"""Defaults use of UUIDField instead of AutoField.
"""Defaults use of UUIDField instead of AutoField and
serializable base.
"""
kwargs.update(bases=(self.model_cls, ))
kwargs.update(history_id_field=models.UUIDField(default=uuid.uuid4))
super().__init__(**kwargs)

def get_extra_fields(self, model, fields):
"""Overridden to add natural key.
"""
extra_fields = super().get_extra_fields(model, fields)
extra_fields.update({'natural_key': lambda x: (x.history_id, )})
return extra_fields
# def get_extra_fields(self, model, fields):
# """Overridden to add natural key.
# """
# extra_fields = super().get_extra_fields(model, fields)
# extra_fields.update({'natural_key': lambda x: (x.history_id, )})
# return extra_fields
11 changes: 0 additions & 11 deletions edc_base/model_managers/history_manager_mixin.py

This file was deleted.

3 changes: 1 addition & 2 deletions edc_base/model_mixins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
from .address_mixin import AddressMixin
from .base_model import BaseModel
from .base_uuid_model import BaseUuidModel
from .form_as_json_model_mixin import FormAsJSONModelMixin
from .report_status_model_mixin import ReportStatusModelMixin
from .url_mixin import UrlMixin
from .url_model_mixin import UrlModelMixin, UrlModelMixinNoReverseMatch
14 changes: 8 additions & 6 deletions edc_base/model_mixins/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from ..constants import BASE_MODEL_UPDATE_FIELDS
from ..utils import get_utcnow
from .url_mixin import UrlMixin
from .url_model_mixin import UrlModelMixin


class BaseModel(UrlMixin, models.Model):
class BaseModel(UrlModelMixin, models.Model):

"""Base model class for all models. Adds created and modified'
values for user, date and hostname (computer).
Expand Down Expand Up @@ -58,13 +58,15 @@ def save(self, *args, **kwargs):
# don't allow update_fields to bypass these audit fields
update_fields = kwargs.get(
'update_fields', None) + BASE_MODEL_UPDATE_FIELDS
kwargs.update({'update_fields': update_fields})
except TypeError:
pass
else:
kwargs.update({'update_fields': update_fields})
dte_modified = get_utcnow()
if not self.id:
self.created = get_utcnow()
self.modified = get_utcnow()
self.hostname_created = self.hostname_created[:60]
self.created = dte_modified
self.hostname_created = self.hostname_created[:60]
self.modified = dte_modified
self.hostname_modified = self.hostname_modified[:50]
super().save(*args, **kwargs)

Expand Down
22 changes: 0 additions & 22 deletions edc_base/model_mixins/form_as_json_model_mixin.py

This file was deleted.

16 changes: 9 additions & 7 deletions edc_base/model_mixins/report_status_model_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from edc_constants.constants import CLOSED
# from edc_constants.constants import CLOSED, OPEN

from ..choices import REPORT_STATUS
from ..model_validators.date import datetime_not_future
Expand All @@ -18,12 +18,14 @@ class ReportStatusModelMixin(models.Model):
validators=[datetime_not_future],
verbose_name=('Date and time report closed.'))

@property
def status(self):
if self.report_status == CLOSED:
return 'Closed'
else:
return 'Open'
# @property
# def status(self):
# if self.report_status == CLOSED:
# return 'Closed'
# elif self.report_status == OPEN:
# return 'Open'
# else:
# return self.report_status

class Meta:
abstract = True
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from django.urls.exceptions import NoReverseMatch


class UrlMixinNoReverseMatch(Exception):
class UrlModelMixinNoReverseMatch(Exception):
pass


class UrlMixin(models.Model):
class UrlModelMixin(models.Model):

ADMIN_SITE_NAME = None # default is '{app_label}_admin'

Expand All @@ -20,7 +20,7 @@ def get_absolute_url(self):
else:
absolute_url = reverse(self.admin_url_name)
except NoReverseMatch as e:
raise UrlMixinNoReverseMatch(
raise UrlModelMixinNoReverseMatch(
f'Tried {self.admin_url_name}. Got {e}. '
f'Perhaps define AppConfig.admin_site_name or '
f'directly on model.ADMIN_SITE_NAME that refers to your '
Expand All @@ -32,10 +32,7 @@ def admin_url_name(self):
"""Returns the django admin add or change url name
(includes namespace).
"""
if self.id:
mode = 'change'
else:
mode = 'add'
mode = 'change' if self.id else 'add'
return (f'{self.admin_site_name}:'
f'{self._meta.app_label}_{self._meta.object_name.lower()}_{mode}')

Expand Down
10 changes: 2 additions & 8 deletions edc_base/model_validators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from .consent_age import MinConsentAgeValidator, MaxConsentAgeValidator
from .date import datetime_not_future, date_not_future, datetime_is_future, date_is_future
from .dob import dob_not_future, dob_not_today
from .eligibility import (
eligible_if_yes, eligible_if_yes_or_declined, eligible_if_no,
eligible_if_unknown, eligible_if_female, eligible_if_male, eligible_if_negative,
eligible_if_positive, eligible_not_positive)
from .date import datetime_not_future, date_not_future
from .date import datetime_is_future, date_is_future
from .phone import CellNumber, TelephoneNumber
from .compare_numbers import CompareNumbersValidator
43 changes: 0 additions & 43 deletions edc_base/model_validators/compare_numbers.py

This file was deleted.

26 changes: 0 additions & 26 deletions edc_base/model_validators/consent_age.py

This file was deleted.

1 change: 0 additions & 1 deletion edc_base/model_validators/date.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import timedelta

from django.core.exceptions import ValidationError

from ..utils import get_utcnow
Expand Down
30 changes: 0 additions & 30 deletions edc_base/model_validators/dob.py

This file was deleted.

Loading

0 comments on commit 9fa3e1c

Please sign in to comment.