From b344d57200efb44dd95155d69d4b4c9c45937951 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Oct 2016 11:11:44 +0200 Subject: Change default logging conf --- example_project/settings.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'example_project') diff --git a/example_project/settings.py b/example_project/settings.py index 128befe5a..9c4d5c9c3 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -155,6 +155,12 @@ INSTALLED_APPS = [ LOGFILE = '' +default_handler = { + 'handlers': ['logfile'], + 'level': 'INFO', + 'propogate': False +} + LOGGING = { 'version': 1, 'disable_existing_loggers': False, @@ -178,24 +184,24 @@ LOGGING = { }, }, 'loggers': { - # Again, default Django configuration to email unhandled exceptions 'django.request': { - 'handlers': ['mail_admins'], + 'handlers': ['mail_admins', 'logfile'], 'level': 'ERROR', 'propagate': True, }, - # Might as well log any errors anywhere else in Django 'django': { 'handlers': ['logfile'], 'level': 'ERROR', 'propagate': False, }, - # Your own app - this assumes all your logger names start with "myapp." - 'chimere': { - 'handlers': ['logfile'], - 'level': 'WARNING', # Or maybe INFO or DEBUG - 'propogate': False - }, + 'ishtar_pdl': default_handler, + 'ishtar_common': default_handler, + 'archaeological_files_pdl': default_handler, + 'archaeological_files': default_handler, + 'archaeological_operations': default_handler, + 'archaeological_context_records': default_handler, + 'archaeological_warehouse': default_handler, + 'archaeological_finds': default_handler, }, } @@ -243,6 +249,11 @@ INTERNAL_IPS = ('127.0.0.1',) JQUERY_URL = STATIC_URL + "js/jquery.min.js" JQUERY_UI_URL = STATIC_URL + "js/jquery-ui/" +if DEBUG: + # make all loggers use the console + for logger in LOGGING['loggers']: + LOGGING['loggers'][logger]['handlers'] += ['console'] + if DJANGO_EXTENSIONS: INSTALLED_APPS.append('django_extensions') -- cgit v1.2.3 From 606e7a781722b671f98135f72149f7b290f320bd Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Oct 2016 14:11:54 +0200 Subject: Use spatialite for tests --- example_project/settings.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'example_project') diff --git a/example_project/settings.py b/example_project/settings.py index 9c4d5c9c3..104569e29 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -235,6 +235,8 @@ except ImportError, e: if 'test' in sys.argv: SOUTH_TESTS_MIGRATE = False + DATABASES['default']['ENGINE'] = \ + 'django.contrib.gis.db.backends.spatialite' PROJECT_SLUG = locals().get('PROJECT_SLUG', 'default') -- cgit v1.2.3 From 6b2730288641ff0206fca8b2c0cbff1b1e442b1f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Oct 2016 14:22:55 +0200 Subject: Make the use of spatialite for tests not mandatory --- example_project/local_settings.py.gitlab-ci | 1 + example_project/settings.py | 3 +++ 2 files changed, 4 insertions(+) (limited to 'example_project') diff --git a/example_project/local_settings.py.gitlab-ci b/example_project/local_settings.py.gitlab-ci index 7f4bcefa1..81196b4a0 100644 --- a/example_project/local_settings.py.gitlab-ci +++ b/example_project/local_settings.py.gitlab-ci @@ -12,3 +12,4 @@ DATABASES = { LOGFILE = '/tmp/ishtar.log' PROJECT_SLUG = "CI-instance" +USE_SPATIALITE_FOR_TESTS = False diff --git a/example_project/settings.py b/example_project/settings.py index 104569e29..26119451a 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -10,6 +10,7 @@ DEBUG_TOOLBAR = False TEMPLATE_DEBUG = DEBUG SQL_DEBUG = False DJANGO_EXTENSIONS = False +USE_SPATIALITE_FOR_TESTS = True if "test" in sys.argv: sys.path.insert(0, '..') @@ -235,6 +236,8 @@ except ImportError, e: if 'test' in sys.argv: SOUTH_TESTS_MIGRATE = False + +if USE_SPATIALITE_FOR_TESTS: DATABASES['default']['ENGINE'] = \ 'django.contrib.gis.db.backends.spatialite' -- cgit v1.2.3 From 328de388cf7c8cd213752c01dfadc2a19e8acb6f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Oct 2016 19:21:41 +0200 Subject: Too many lazy evaluations and nobody do the job! Fixed. --- archaeological_files/forms.py | 6 +++--- archaeological_files_pdl/forms.py | 22 +++++++++++----------- example_project/settings.py | 6 +++--- ishtar_common/forms.py | 23 ++++++++++++++++++++--- ishtar_common/models.py | 13 +++++-------- ishtar_common/widgets.py | 1 - 6 files changed, 42 insertions(+), 29 deletions(-) (limited to 'example_project') diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 04badfc10..42a645171 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -28,9 +28,9 @@ from django.core import validators from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe -from ishtar_common.models import Person, PersonType, Organization, \ - OrganizationType, valid_id, Department, person_type_pks_lazy, \ - person_type_pk_lazy, organization_type_pk_lazy, organization_type_pks_lazy +from ishtar_common.models import Person, Organization, \ + valid_id, Department, person_type_pks_lazy, \ + person_type_pk_lazy, organization_type_pks_lazy from archaeological_operations.models import ActType, AdministrativeAct, \ OperationType import models diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index 5c92f689a..cf241aa18 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -26,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.models import Person, Town, Department, valid_id, \ person_type_pk_lazy, person_type_pks_lazy, organization_type_pks_lazy, \ - organization_type_pk_lazy, organization_type_lazy, person_type_lazy + organization_type_pk_lazy from archaeological_files import models from ishtar_common.forms import get_now, reverse_lazy, ManageOldType @@ -132,10 +132,10 @@ class FileFormResearchAddress(forms.Form): class PersonOrgaForm(forms.Form): PERSON_FIELD = 'TO BE DEFINED' - PERSON_TYPE = person_type_lazy('general_contractor') + PERSON_TYPE_PK = person_type_pk_lazy('general_contractor') PERSON_LABEL = "" ORGA_FIELD = 'TO BE DEFINED' - ORGA_TYPE = organization_type_lazy('general_contractor') + ORGA_TYPE_PK = organization_type_pk_lazy('general_contractor') ORGA_LABEL = "" def _media(self): @@ -202,10 +202,10 @@ class PersonOrgaForm(forms.Form): initial=initial.get(self.PERSON_FIELD, None), widget=widgets.JQueryPersonOrganization( reverse_lazy('autocomplete-person', - args=[self.PERSON_TYPE.pk]), + args=[self.PERSON_TYPE_PK]), reverse_lazy('person_create'), model=Person, - limit={'person_types': [self.PERSON_TYPE.pk], + limit={'person_types': [self.PERSON_TYPE_PK], 'attached_to__isnull': True}, js_template='ishtar/blocks/JQueryNaturalPerson.js', new=True), @@ -217,10 +217,10 @@ class PersonOrgaForm(forms.Form): initial=initial.get(self.ORGA_FIELD, None), widget=widgets.JQueryPersonOrganization( reverse_lazy('autocomplete-organization', - args=[self.ORGA_TYPE.pk]), + args=[self.ORGA_TYPE_PK]), reverse_lazy('organization_create'), model=models.Organization, - limit={'organization_type': [self.ORGA_TYPE.pk]}, + limit={'organization_type': [self.ORGA_TYPE_PK]}, js_template='ishtar/blocks/JQueryCorporationPerson.js', new=True), validators=[valid_id(models.Organization)]) @@ -267,10 +267,10 @@ class FileFormGeneralContractor(PersonOrgaForm): ) PERSON_FIELD = 'general_contractor' - PERSON_TYPE = person_type_lazy('general_contractor') + PERSON_TYPE_PK = person_type_pk_lazy('general_contractor') PERSON_LABEL = _(u"General contractor") ORGA_FIELD = 'corporation_general_contractor' - ORGA_TYPE = organization_type_lazy('general_contractor') + ORGA_TYPE_PK = organization_type_pk_lazy('general_contractor') ORGA_LABEL = _(u"General contractor") def __init__(self, *args, **kwargs): @@ -331,10 +331,10 @@ class FileFormGeneralContractor(PersonOrgaForm): initial=initial.get(self.PERSON_FIELD, None), widget=widgets.JQueryPersonOrganization( reverse_lazy('autocomplete-person', - args=[self.PERSON_TYPE.pk]), + args=[self.PERSON_TYPE_PK]), reverse_lazy('person_create'), model=Person, - limit={'person_types': [self.PERSON_TYPE.pk], + limit={'person_types': [self.PERSON_TYPE_PK], 'attached_to__isnull': True}, js_template='ishtar/blocks/JQueryNaturalPerson.js', new=True), diff --git a/example_project/settings.py b/example_project/settings.py index 26119451a..ef52d932a 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -237,9 +237,9 @@ except ImportError, e: if 'test' in sys.argv: SOUTH_TESTS_MIGRATE = False -if USE_SPATIALITE_FOR_TESTS: - DATABASES['default']['ENGINE'] = \ - 'django.contrib.gis.db.backends.spatialite' + if USE_SPATIALITE_FOR_TESTS: + DATABASES['default']['ENGINE'] = \ + 'django.contrib.gis.db.backends.spatialite' PROJECT_SLUG = locals().get('PROJECT_SLUG', 'default') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index b0e8cb43c..043b03f61 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -31,6 +31,10 @@ from django.utils import formats from django.utils.functional import lazy from django.utils.translation import ugettext_lazy as _ +import models +import widgets + + # from formwizard.forms import NamedUrlSessionFormWizard @@ -44,10 +48,23 @@ class NamedUrlSessionFormWizard(forms.Form): def rindex(self, idx): return self.url_name.rindex(idx) -import models -import widgets -reverse_lazy = lazy(reverse, unicode) +def my_reverse(*args, **kwargs): + """ + Custom reverse method in order to evaluate lazy args + """ + if 'args' in kwargs: + my_args = [] + for arg in kwargs['args']: + if callable(arg): + my_args.append(unicode(arg())) + else: + my_args.append(unicode(arg)) + kwargs['args'] = my_args + return reverse(*args, **kwargs) + + +reverse_lazy = lazy(my_reverse, unicode) regexp_name = re.compile(r"^[,:/\w\-'\"() \&\[\]@]+$", re.UNICODE) name_validator = validators.RegexValidator( diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 814387bb4..c0888ec06 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -67,7 +67,6 @@ from ishtar_common.data_importer import Importer, ImportFormater, \ def post_save_user(sender, **kwargs): user = kwargs['instance'] - ishtaruser = None try: q = IshtarUser.objects.filter(username=user.username) if not q.count(): @@ -360,9 +359,9 @@ class GeneralType(Cached, models.Model): :param slug: textual id - :return: the id of the item + :return: id of the item (string) """ - return cls.get_or_create(slug).pk + return unicode(cls.get_or_create(slug).pk) @classmethod def get_or_create_pks(cls, slugs): @@ -377,7 +376,7 @@ class GeneralType(Cached, models.Model): items = [] for slug in slugs: items.append(str(cls.get_or_create(slug).pk)) - return "_".join(items) + return u"_".join(items) @classmethod def get_help(cls, dct={}, exclude=[]): @@ -1580,8 +1579,7 @@ class OrganizationType(GeneralType): post_save.connect(post_save_cache, sender=OrganizationType) post_delete.connect(post_save_cache, sender=OrganizationType) -organization_type_lazy = lazy(OrganizationType.get_or_create, OrganizationType) -organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, int) +organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, unicode) organization_type_pks_lazy = lazy(OrganizationType.get_or_create_pks, unicode) IMPORTER_CLASSES = {} @@ -2374,8 +2372,7 @@ class PersonType(GeneralType): post_save.connect(post_save_cache, sender=PersonType) post_delete.connect(post_save_cache, sender=PersonType) -person_type_lazy = lazy(PersonType.get_or_create_pk, PersonType) -person_type_pk_lazy = lazy(PersonType.get_or_create_pk, int) +person_type_pk_lazy = lazy(PersonType.get_or_create_pk, unicode) person_type_pks_lazy = lazy(PersonType.get_or_create_pks, unicode) diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index d3a2c975e..1183836bc 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -431,7 +431,6 @@ class JQueryPersonOrganization(forms.TextInput): @classmethod def encode_source(cls, source): - encoded_src = '' if isinstance(source, list): encoded_src = JSONEncoder().encode(source) elif isinstance(source, str) \ -- cgit v1.2.3 From f296333a87085ee0e04a0f4fbfc207c112f17bce Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Oct 2016 20:26:31 +0200 Subject: Force regeneration of cached labels when add M2M or changing ids --- archaeological_context_records/models.py | 1 + archaeological_files/models.py | 5 +++-- archaeological_files/tests.py | 14 ++++++++++++++ archaeological_finds/models.py | 4 ++++ example_project/settings.py | 3 +++ ishtar_common/wizards.py | 4 +++- 6 files changed, 28 insertions(+), 3 deletions(-) (limited to 'example_project') diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 7df766f2f..3f4dc1598 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -364,6 +364,7 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 623eb1dee..1d8317b31 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -521,6 +521,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned @@ -536,9 +537,9 @@ post_save.connect(cached_label_changed, sender=File) class FileByDepartment(models.Model): - ''' + """ Database view for dashboard - ''' + """ file = models.ForeignKey(File, verbose_name=_(u"File")) department = models.ForeignKey(Department, verbose_name=_(u"Department"), blank=True, null=True) diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index dfaa1fb09..4a09e1caa 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -86,6 +86,20 @@ class FileTest(TestCase, FileInit): u"{}-{}".format(self.item.year, self.item.numeric_reference)) + def testCachedLabel(self): + lbls = ['No town', self.item.external_id, + self.item.internal_reference] + lbl = settings.JOINT.join(lbls) + self.assertEqual(self.item.cached_label, lbl) + default_town = Town.objects.create(name="Paris", numero_insee='75001') + self.item.towns.add(default_town) + # manually done inside wizards + self.item._cached_label_checked = False + self.item.save() + lbls[0] = "Paris" + lbl = settings.JOINT.join(lbls) + self.assertEqual(self.item.cached_label, lbl) + def testAddAndGetHistorized(self): """ Test correct new version and correct access to history diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 5799d0e9a..aa5eacc30 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -269,6 +269,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return returned @@ -653,6 +654,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.auto_external_id = True self.external_id = external_id if updated: + self._cached_label_checked = False self.save() return @@ -671,6 +673,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.index = q.aggregate(Max('index'))['index__max'] + 1 else: self.index = 1 + self._cached_label_checked = False self.save() for base_find in self.base_finds.filter( context_record__operation__pk__isnull=False).all(): @@ -689,6 +692,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): modified = True if modified: base_find.skip_history_when_saving = True + base_find._cached_label_checked = False base_find.save() # if not base_find.material_index: # idx = BaseFind.objects\ diff --git a/example_project/settings.py b/example_project/settings.py index ef52d932a..a191b83b3 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -288,3 +288,6 @@ if SQL_DEBUG: 'level': 'DEBUG', 'handlers': ['console'], } + +if 'test' in sys.argv: + PROJECT_SLUG += "-test" diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index c8467ca61..c065459f6 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -553,6 +553,7 @@ class Wizard(NamedUrlWizardView): getattr(obj, k).add(adds[k]) # necessary to manage interaction between models like # material_index management for baseitems + obj._cached_label_checked = False obj.save() m2m_items = {} # clear @@ -618,6 +619,7 @@ class Wizard(NamedUrlWizardView): related_model.add(value) # necessary to manage interaction between models like # material_index management for baseitems + obj._cached_label_checked = False obj.save() # make the new object a default if self.current_obj_slug: @@ -715,7 +717,7 @@ class Wizard(NamedUrlWizardView): # and self.form_initialized: # for k in init[0]: # data[step + '-' + unicode(total_field) + '-' + k] = \ - # init[0][k] + # init[0][k] data = data or None form = super(Wizard, self).get_form(step, data, files) -- cgit v1.2.3