diff options
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/models_finds.py | 12 | ||||
-rw-r--r-- | archaeological_finds/tests.py | 67 |
2 files changed, 73 insertions, 6 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index c7065166e..bab3dae9f 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -712,11 +712,15 @@ class FindBasket(Basket, MainItem, ValueGetter): ) def get_values(self, prefix='', no_values=False, filtr=None, **kwargs): + base_exclude = kwargs["exclude"][:] if "exclude" in kwargs else [] + base_exclude.append(prefix + "items") + kw = kwargs.copy() + kw["exclude"] = base_exclude values = super(FindBasket, self).get_values( - prefix=prefix, no_values=no_values, filtr=filtr, **kwargs) + prefix=prefix, no_values=no_values, filtr=filtr, **kw) if not filtr or prefix + "items" in filtr: values[prefix + "items"] = [ - item.get_values(no_values=True, filtr=None, **kwargs) + item.get_values(no_values=True, filtr=filtr, **kwargs) for item in self.items.distinct().all() ] return values @@ -1529,11 +1533,11 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, 'remarkabilities', 'communicabilities', 'preservation_to_considers', 'alterations', 'alteration_causes', "cultural_attributions" ] - GET_VALUES_EXTRA_TYPES = ( + GET_VALUES_EXTRA_TYPES = ValueGetter.GET_VALUES_EXCLUDE_FIELDS + [ 'material_types', 'object_types', 'integrities', 'remarkabilities', 'communicabilities', 'preservation_to_considers', 'alterations', 'alteration_causes' - ) + ] CACHED_LABELS = ['cached_label', 'cached_periods', 'cached_object_types', 'cached_materials'] objects = UUIDModelManager() diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 2ef551253..bede89b51 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -49,8 +49,7 @@ from archaeological_context_records.models import Period, Dating, \ ContextRecord, DatingType, DatingQuality from archaeological_finds import models, views from archaeological_warehouse.models import Warehouse, WarehouseType, \ - ContainerType, Container, WarehouseDivision, WarehouseDivisionLink, \ - ContainerLocalisation + ContainerType, Container, WarehouseDivisionLink from archaeological_operations.models import Operation, OperationType from ishtar_common import forms_common @@ -2579,3 +2578,67 @@ class LabelTest(FindInit, TestCase): self.templates.append(doc.template.path) else: self.assertFalse(doc.template.name, msg=msg) + + +class TemplateTest(FindInit, TestCase): + fixtures = FIND_FIXTURES + model = models.Find + + def setUp(self): + template = settings.ROOT_PATH + \ + '../archaeological_finds/tests/notices-panier.odt' + filename = template.split("/")[-1] + shutil.copy(template, + os.path.join(settings.MEDIA_ROOT, filename), + follow_symlinks=True) + self.template = os.path.join(settings.MEDIA_ROOT, filename) + self.templates = [self.template] + ope1 = self.create_operation()[0] + ope2 = self.create_operation()[1] + cr = self.create_context_record( + data={"label": "CR 1", "operation": ope1} + )[0] + cr2 = self.create_context_record( + data={"label": "CR 2", "operation": ope2} + )[1] + self.create_finds(data_base={"context_record": cr})[0] + self.create_finds(data_base={"context_record": cr2})[1] + self.basket = models.FindBasket.objects.create(label="Hophop") + self.basket.items.add(self.finds[0]) + self.basket.items.add(self.finds[1]) + wt, __ = WarehouseType.objects.get_or_create(label="WT", txt_idx="WT") + location = Warehouse.objects.create(name="Warehouse", warehouse_type=wt) + ct, __ = ContainerType.objects.get_or_create(label="CT", txt_idx="CT") + self.container = Container.objects.create( + location=location, + reference="Reférence", + container_type=ct + ) + + def test_label(self): + with open(self.template, 'rb') as tpl: + template = SimpleUploadedFile("template.odt", + tpl.read()) + model, __ = ImporterModel.objects.get_or_create( + klass='archaeological_finds.models.Find' + ) + q = DocumentTemplate.objects.filter(slug="test") + if q.count(): + q.all()[0].delete() + doc = DocumentTemplate.objects.create( + name="Test", + slug="test", + associated_model=model, + available=True, + template=template) + self.templates.append(doc.template.path) + doc = DocumentTemplate.objects.get(pk=doc.pk) + + result = doc.publish(self.basket) + if result: + self.templates.append(result) + + def tearDown(self): + for tpl in self.templates: + if os.path.exists(tpl): + os.remove(tpl) |