Coverage for burials/models.py: 68%

218 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2024-06-10 15:48 +0000

1# -*- coding: utf-8 -*- 

2from django.db import models 

3from django.urls import reverse 

4from vocabs.models import SkosConcept 

5from places.models import Place 

6from bib.models import Book 

7 

8FULLYPARTLYEXCAVATED = ( 

9 ("fully excavated", "fully excavated"), 

10 ("partly excavated", "partly excavated"), 

11) 

12 

13BOOLEAN_CHOICES = ((None, "Unknown"), (True, "Yes"), (False, "No")) 

14 

15 

16class BurialSite(models.Model): 

17 name = models.CharField( 

18 max_length=255, blank=True, null=True, help_text="Please provide helptext" 

19 ) 

20 alternative_name = models.CharField( 

21 max_length=255, blank=True, null=True, help_text="helptext" 

22 ) 

23 location = models.ForeignKey( 

24 Place, on_delete=models.SET_NULL, blank=True, null=True, help_text="helptext" 

25 ) 

26 topography = models.ForeignKey( 

27 SkosConcept, 

28 on_delete=models.SET_NULL, 

29 blank=True, 

30 null=True, 

31 help_text="<a href='/vocabs/scheme/1' target='_blank'>See Topography Concept Schema</a>", 

32 related_name="skos_topography", 

33 ) 

34 exact_location = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

35 lat = models.FloatField(blank=True, null=True, verbose_name="latitude") 

36 lng = models.FloatField(blank=True, null=True, verbose_name="longitude") 

37 excavation = models.CharField( 

38 max_length=50, 

39 blank=True, 

40 null=True, 

41 choices=FULLYPARTLYEXCAVATED, 

42 help_text="helptext", 

43 ) 

44 distance_to_next_settlement = models.ForeignKey( 

45 SkosConcept, 

46 on_delete=models.SET_NULL, 

47 blank=True, 

48 null=True, 

49 help_text="<a href='/vocabs/scheme/2' target='_blank'>See Distance to next settlement Concept Schema</a>", 

50 related_name="skos_distance_to_next_settlement", 

51 ) 

52 type_of_burial_site = models.ForeignKey( 

53 SkosConcept, 

54 on_delete=models.SET_NULL, 

55 blank=True, 

56 null=True, 

57 help_text="<a href='/vocabs/scheme/3' target='_blank'>See Type of Burial site Concept Schema</a>", 

58 related_name="skos_type_of_burial_site", 

59 ) 

60 disturbance = models.TextField(blank=True, null=True, help_text="helptext") 

61 total_graves = models.CharField( 

62 max_length=255, 

63 blank=True, 

64 verbose_name="Total number of excavated graves", 

65 null=True, 

66 help_text="Total number of excavated graves", 

67 ) 

68 dating = models.ManyToManyField( 

69 SkosConcept, 

70 blank=True, 

71 help_text="<a href='/vocabs/scheme/4' target='_blank'>See Dating Concept Schema</a>", 

72 related_name="skos_dating", 

73 ) 

74 absolute_dating = models.CharField( 

75 max_length=255, blank=True, null=True, help_text="Please provide helptext" 

76 ) 

77 location_of_archaeological_material_and_contact_information = models.TextField( 

78 blank=True, null=True, help_text="helptext" 

79 ) 

80 reference = models.ManyToManyField( 

81 Book, blank=True, help_text="Please provide helptext" 

82 ) 

83 

84 def __str__(self): 

85 return "BurialSite: {}".format(self.name) 

86 

87 def get_absolute_url(self): 

88 return reverse("burials:burialsite_detail", kwargs={"pk": self.id}) 

89 

90 def get_classname(self): 

91 """Returns the name of the class as lowercase string""" 

92 class_name = str(self.__class__.__name__).lower() 

93 return class_name 

94 

95 

96class BurialGroup(models.Model): 

97 burial_site = models.ForeignKey( 

98 BurialSite, 

99 on_delete=models.SET_NULL, 

100 blank=True, 

101 null=True, 

102 help_text="helptext", 

103 ) 

104 burial_group_id = models.CharField( 

105 max_length=255, 

106 blank=True, 

107 null=True, 

108 help_text="helptext", 

109 verbose_name="Burial group number", 

110 ) 

111 name = models.TextField(blank=True, null=True, help_text="helptext") 

112 burial_group_type = models.ForeignKey( 

113 SkosConcept, 

114 on_delete=models.SET_NULL, 

115 blank=True, 

116 null=True, 

117 help_text="<a href='/vocabs/scheme/5' target='_blank'>See Burial group type Concept Schema</a>", 

118 related_name="skos_type_of_burial_group", 

119 ) 

120 material = models.ForeignKey( 

121 SkosConcept, 

122 on_delete=models.SET_NULL, 

123 blank=True, 

124 null=True, 

125 help_text="<a href='/vocabs/scheme/6' target='_blank'>See Material Concept Schema</a>", 

126 related_name="skos_material_burialgroup", 

127 ) 

128 length = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

129 width = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

130 diameter = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

131 height = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

132 

133 def __str__(self): 

134 return "{} | BurialGroup: {}".format(self.burial_site, self.burial_group_id) 

135 

136 def get_absolute_url(self): 

137 return reverse("burials:burialgroup_detail", kwargs={"pk": self.id}) 

138 

139 def get_classname(self): 

140 """Returns the name of the class as lowercase string""" 

141 class_name = str(self.__class__.__name__).lower() 

142 return class_name 

143 

144 

145class Burial(models.Model): 

146 burial_site = models.ForeignKey( 

147 BurialSite, 

148 on_delete=models.SET_NULL, 

149 blank=True, 

150 null=True, 

151 help_text="helptext", 

152 ) 

153 burial_group = models.ForeignKey( 

154 BurialGroup, 

155 on_delete=models.SET_NULL, 

156 blank=True, 

157 null=True, 

158 help_text="helptext", 

159 ) 

160 burial_id = models.CharField( 

161 max_length=255, 

162 blank=True, 

163 null=True, 

164 help_text="helptext", 

165 verbose_name="Burial number", 

166 ) 

167 burial_type = models.ForeignKey( 

168 SkosConcept, 

169 on_delete=models.SET_NULL, 

170 blank=True, 

171 null=True, 

172 help_text="<a href='/vocabs/scheme/7' target='_blank'>See Burial type Concept Schema</a>", 

173 related_name="skos_burial_type", 

174 ) 

175 c14_dendro = models.BooleanField( 

176 null=True, 

177 blank=True, 

178 verbose_name="Absolute dating (C14/Dendro)", 

179 choices=BOOLEAN_CHOICES, 

180 ) 

181 absolute_age = models.CharField( 

182 max_length=255, blank=True, null=True, help_text="helptext" 

183 ) 

184 secondary_burial = models.BooleanField( 

185 null=True, blank=True, choices=BOOLEAN_CHOICES 

186 ) 

187 secondary_burial_text = models.TextField( 

188 blank=True, null=True, help_text="helptext" 

189 ) 

190 displaced = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

191 displaced_text = models.TextField(blank=True, null=True, help_text="helptext") 

192 extraordinary_burial = models.BooleanField( 

193 null=True, blank=True, choices=BOOLEAN_CHOICES 

194 ) 

195 extraordinary_burial_text = models.TextField( 

196 blank=True, null=True, help_text="helptext" 

197 ) 

198 inhumation_burial_type = models.TextField( 

199 blank=True, null=True, help_text="helptext" 

200 ) 

201 bi_ritual_burial_type = models.TextField( 

202 blank=True, 

203 null=True, 

204 help_text="helptext", 

205 verbose_name="Bi-ritual burial type", 

206 ) 

207 construction = models.ForeignKey( 

208 SkosConcept, 

209 on_delete=models.SET_NULL, 

210 blank=True, 

211 null=True, 

212 help_text="<a href='/vocabs/scheme/8' target='_blank'>See Burial construction Concept Schema</a>", 

213 related_name="skos_burial_construction", 

214 ) 

215 arrangement = models.ForeignKey( 

216 SkosConcept, 

217 on_delete=models.SET_NULL, 

218 blank=True, 

219 null=True, 

220 help_text="<a href='/vocabs/scheme/9' target='_blank'>See Burial arrangement Concept Schema</a>", 

221 related_name="skos_burial_arrangement", 

222 ) 

223 cover = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

224 cover_type = models.ForeignKey( 

225 SkosConcept, 

226 on_delete=models.SET_NULL, 

227 blank=True, 

228 null=True, 

229 help_text="<a href='/vocabs/scheme/10' target='_blank'>See Cover type Concept Schema</a>", 

230 related_name="skos_type_of_burial_cover", 

231 ) 

232 grave_pit_form = models.ForeignKey( 

233 SkosConcept, 

234 on_delete=models.SET_NULL, 

235 blank=True, 

236 null=True, 

237 help_text="<a href='/vocabs/scheme/11' target='_blank'>See Grave pit form Concept Schema</a>", 

238 related_name="skos_form_of_the_grave_pit", 

239 ) 

240 grave_pit_orientation = models.ForeignKey( 

241 SkosConcept, 

242 on_delete=models.SET_NULL, 

243 blank=True, 

244 null=True, 

245 help_text="<a href='/vocabs/scheme/12' target='_blank'>See Grave pit orientation Concept Schema</a>", 

246 related_name="skos_orientation_of_the_grave_pit", 

247 ) 

248 length = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

249 width = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

250 diameter = models.CharField(max_length=255, blank=True, null=True, help_text="cm") 

251 height = models.CharField( 

252 max_length=255, blank=True, null=True, help_text="cm", verbose_name="Depth" 

253 ) 

254 filling_objects = models.ManyToManyField( 

255 SkosConcept, 

256 blank=True, 

257 help_text="<a href='/vocabs/scheme/26' target='_blank'>See Burial filling objects Concept Schema</a>", 

258 related_name="skos_filling_object", 

259 ) 

260 intentionally_deposited = models.BooleanField( 

261 null=True, blank=True, choices=BOOLEAN_CHOICES 

262 ) 

263 filling = models.ForeignKey( 

264 SkosConcept, 

265 on_delete=models.SET_NULL, 

266 blank=True, 

267 null=True, 

268 help_text="<a href='/vocabs/scheme/27' target='_blank'>See Burial filling type Concept Schema</a>", 

269 related_name="skos_filling", 

270 ) 

271 post_holes = models.TextField(blank=True, null=True, help_text="helptext") 

272 surface_identification_mark = models.TextField( 

273 blank=True, null=True, help_text="helptext" 

274 ) 

275 erdgraebchen = models.TextField(blank=True, null=True, help_text="helptext") 

276 other_features = models.TextField(blank=True, null=True, help_text="helptext") 

277 

278 def __str__(self): 

279 if self.burial_group is None: 

280 return "{} | Burial: {}".format(self.burial_site, self.burial_id) 

281 else: 

282 return " {} | Burial: {}".format(self.burial_group, self.burial_id) 

283 

284 def get_absolute_url(self): 

285 return reverse("burials:burial_detail", kwargs={"pk": self.id}) 

286 

287 @property 

288 def related_gravegoods(self): 

289 goods = [] 

290 for x in GraveGood.objects.filter(burial=self.id): 

291 try: 

292 goods.append( 

293 [ 

294 x.name.skos_broader.all()[0].pref_label, 

295 x.name.pref_label, 

296 x.amount_countable, 

297 ] 

298 ) 

299 except: # noqa 

300 goods.append([x]) 

301 return goods 

302 

303 @property 

304 def amount_related_gravegoods(self): 

305 goods = [] 

306 for x in GraveGood.objects.filter(burial=self.id): 

307 if x.amount_countable: 

308 goods.append(x.amount_countable) 

309 return sum(goods) 

310 

311 @property 

312 def amount_related_deadbodyremains(self): 

313 deadbodyremains = [] 

314 for x in DeadBodyRemains.objects.filter(burial=self.id): 

315 if x.amount_countable: 

316 deadbodyremains.append(x.amount_countable) 

317 return sum(deadbodyremains) 

318 

319 @property 

320 def amount_related_organic(self): 

321 organic = [] 

322 for x in AnimalRemains.objects.filter(burial=self.id): 

323 if x.amount_countable: 

324 organic.append(x.amount_countable) 

325 return sum(organic) 

326 

327 def get_classname(self): 

328 """Returns the name of the class as lowercase string""" 

329 class_name = str(self.__class__.__name__).lower() 

330 return class_name 

331 

332 

333class Urn(models.Model): 

334 burial = models.ForeignKey( 

335 Burial, on_delete=models.SET_NULL, blank=True, null=True, help_text="helptext" 

336 ) 

337 basic_shape = models.ForeignKey( 

338 SkosConcept, 

339 on_delete=models.SET_NULL, 

340 blank=True, 

341 null=True, 

342 help_text="<a href='/vocabs/scheme/13' target='_blank'>See Basic shape of urn Concept Schema</a>", 

343 related_name="skos_basic_shape_of_urn", 

344 ) 

345 urn_type = models.TextField(blank=True, null=True, help_text="helptext") 

346 variation = models.TextField(blank=True, null=True, help_text="helptext") 

347 urn_id = models.TextField( 

348 blank=True, null=True, help_text="helptext", verbose_name="Urn Inventory Number" 

349 ) 

350 urncover_exists = models.BooleanField( 

351 null=True, blank=True, verbose_name="Urn Cover", choices=BOOLEAN_CHOICES 

352 ) 

353 

354 def __str__(self): 

355 return "{}- ID {} {}".format(self.urn_id, self.id, self.burial) 

356 

357 def get_absolute_url(self): 

358 return reverse("burials:urn_detail", kwargs={"pk": self.id}) 

359 

360 def get_classname(self): 

361 """Returns the name of the class as lowercase string""" 

362 class_name = str(self.__class__.__name__).lower() 

363 return class_name 

364 

365 @property 

366 def related_gravegoods(self): 

367 goods = [] 

368 for x in GraveGood.objects.filter(urn=self.id): 

369 goods.append( 

370 [ 

371 x.name.skos_broader.all()[0].pref_label, 

372 x.name.pref_label, 

373 x.amount_countable, 

374 ] 

375 ) 

376 return goods 

377 

378 

379class UrnCover(models.Model): 

380 basic_shape = models.ForeignKey( 

381 SkosConcept, 

382 on_delete=models.SET_NULL, 

383 blank=True, 

384 null=True, 

385 help_text="<a href='/vocabs/scheme/14' target='_blank'>See Basic shape of urn cover Concept Schema</a>", 

386 related_name="skos_basic_shape_of_urn_cover", 

387 ) 

388 upside_down = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

389 fragment = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

390 cover_id = models.TextField( 

391 blank=True, 

392 null=True, 

393 help_text="helptext", 

394 verbose_name="Urn cover inventory number", 

395 ) 

396 urn = models.ForeignKey( 

397 Urn, on_delete=models.SET_NULL, blank=True, null=True, help_text="helptext" 

398 ) 

399 

400 def __str__(self): 

401 return "{}-{}-{}".format(self.urn, self.cover_id, self.id) 

402 

403 def get_absolute_url(self): 

404 return reverse("burials:urncover_detail", kwargs={"pk": self.id}) 

405 

406 def get_classname(self): 

407 """Returns the name of the class as lowercase string""" 

408 class_name = str(self.__class__.__name__).lower() 

409 return class_name 

410 

411 

412class CrematedRemainsBaseClass(models.Model): 

413 """An abstract class for Grave Goods and living remains""" 

414 

415 burial = models.ForeignKey( 

416 Burial, on_delete=models.SET_NULL, blank=True, null=True, help_text="helptext" 

417 ) 

418 urn = models.ForeignKey( 

419 Urn, on_delete=models.SET_NULL, blank=True, null=True, help_text="helptext" 

420 ) 

421 amount_countable = models.IntegerField(null=True, blank=True, help_text="helptext") 

422 comment = models.TextField(blank=True, null=True, help_text="helptext") 

423 secondary_depostition = models.BooleanField( 

424 null=True, blank=True, choices=BOOLEAN_CHOICES 

425 ) 

426 

427 class Meta: 

428 abstract = True 

429 

430 

431class GraveGood(CrematedRemainsBaseClass): 

432 name = models.ForeignKey( 

433 SkosConcept, 

434 on_delete=models.SET_NULL, 

435 blank=True, 

436 null=True, 

437 help_text="<a href='/vocabs/scheme/28' target='_blank'>See Grave good object Concept Schema</a>", 

438 related_name="skos_name_gravegood", 

439 verbose_name="Type", 

440 ) 

441 material = models.ForeignKey( 

442 SkosConcept, 

443 on_delete=models.SET_NULL, 

444 blank=True, 

445 null=True, 

446 help_text="<a href='/vocabs/scheme/6' target='_blank'>See Material Concept Schema</a>", 

447 related_name="skos_material", 

448 ) 

449 condition = models.ForeignKey( 

450 SkosConcept, 

451 on_delete=models.SET_NULL, 

452 blank=True, 

453 null=True, 

454 help_text="<a href='/vocabs/scheme/16' target='_blank'>See Condition Concept Schema</a>", 

455 related_name="skos_condition", 

456 ) 

457 position = models.ForeignKey( 

458 SkosConcept, 

459 on_delete=models.SET_NULL, 

460 blank=True, 

461 null=True, 

462 help_text="<a href='/vocabs/scheme/17' target='_blank'>See Position Concept Schema</a>", 

463 related_name="skos_gravegood_position", 

464 ) 

465 

466 def __str__(self): 

467 return "type: {} | material: {} | amount: {}".format( 

468 self.name, self.material, self.amount_countable 

469 ) 

470 

471 def get_absolute_url(self): 

472 return reverse("burials:gravegood_detail", kwargs={"pk": self.id}) 

473 

474 def get_classname(self): 

475 """Returns the name of the class as lowercase string""" 

476 class_name = str(self.__class__.__name__).lower() 

477 return class_name 

478 

479 

480class GraveGoodOther(CrematedRemainsBaseClass): 

481 food = models.BooleanField(null=True, blank=True, choices=BOOLEAN_CHOICES) 

482 other_organic_grave_good = models.BooleanField( 

483 null=True, blank=True, choices=BOOLEAN_CHOICES 

484 ) 

485 other_organic_grave_good_text = models.TextField( 

486 blank=True, null=True, help_text="helptext" 

487 ) 

488 position = models.ForeignKey( 

489 SkosConcept, 

490 on_delete=models.SET_NULL, 

491 blank=True, 

492 null=True, 

493 help_text="<a href='/vocabs/scheme/17' target='_blank'>See Position Concept Schema</a>", 

494 related_name="skos_gravegoodother_position", 

495 ) 

496 

497 def __str__(self): 

498 if self.food is True and ( 

499 self.other_organic_grave_good is False 

500 or self.other_organic_grave_good is None # noqa: 

501 ): 

502 return "food ID {}".format(self.id) 

503 elif self.other_organic_grave_good is True and ( 

504 self.food is False or self.food is None 

505 ): 

506 return "other ID {}".format(self.id) 

507 elif self.other_organic_grave_good is True and self.food is True: 

508 return "food and other ID {}".format(self.id) 

509 else: 

510 return "ID {}".format(self.id) 

511 

512 def get_absolute_url(self): 

513 return reverse("burials:gravegoodother_detail", kwargs={"pk": self.id}) 

514 

515 def get_classname(self): 

516 """Returns the name of the class as lowercase string""" 

517 class_name = str(self.__class__.__name__).lower() 

518 return class_name 

519 

520 

521class DeadBodyRemains(CrematedRemainsBaseClass): 

522 age = models.ForeignKey( 

523 SkosConcept, 

524 on_delete=models.SET_NULL, 

525 blank=True, 

526 null=True, 

527 help_text="<a href='/vocabs/scheme/23' target='_blank'>See Age Concept Schema</a>", 

528 related_name="skos_age", 

529 ) 

530 gender = models.ForeignKey( 

531 SkosConcept, 

532 on_delete=models.SET_NULL, 

533 blank=True, 

534 null=True, 

535 help_text="<a href='/vocabs/scheme/24' target='_blank'>See Gender Concept Schema</a>", 

536 related_name="skos_gender", 

537 ) 

538 temperature = models.ForeignKey( 

539 SkosConcept, 

540 on_delete=models.SET_NULL, 

541 blank=True, 

542 null=True, 

543 help_text="<a href='/vocabs/scheme/25' target='_blank'>See Cremation temperature Concept Schema</a>", 

544 related_name="skos_temperature", 

545 ) 

546 weight = models.TextField(blank=True, null=True, help_text="in gram") 

547 pathology = models.TextField(blank=True, null=True, help_text="helptext") 

548 total_weight = models.TextField( 

549 blank=True, 

550 null=True, 

551 help_text="in gram", 

552 verbose_name="Total weight of Human Remains", 

553 ) 

554 position = models.ForeignKey( 

555 SkosConcept, 

556 on_delete=models.SET_NULL, 

557 blank=True, 

558 null=True, 

559 help_text="<a href='/vocabs/scheme/17' target='_blank'>See Position Concept Schema</a>", 

560 related_name="skos_deadbodyremains_position", 

561 ) 

562 

563 def __str__(self): 

564 return "age: {} | gender: {} | amount: {}".format( 

565 self.age, self.gender, self.amount_countable 

566 ) 

567 

568 def get_absolute_url(self): 

569 return reverse("burials:deadbodyremains_detail", kwargs={"pk": self.id}) 

570 

571 def get_classname(self): 

572 """Returns the name of the class as lowercase string""" 

573 class_name = str(self.__class__.__name__).lower() 

574 return class_name 

575 

576 

577class AnimalRemains(CrematedRemainsBaseClass): 

578 species = models.ForeignKey( 

579 SkosConcept, 

580 on_delete=models.SET_NULL, 

581 blank=True, 

582 null=True, 

583 help_text="<a href='/vocabs/scheme/29' target='_blank'>See Species Concept Schema</a>", 

584 related_name="skos_species", 

585 ) 

586 age = models.CharField(max_length=255, blank=True, null=True, help_text="helptext") 

587 sex = models.CharField(max_length=255, blank=True, null=True, help_text="helptext") 

588 weight = models.CharField( 

589 max_length=255, blank=True, null=True, help_text="helptext" 

590 ) 

591 position = models.ForeignKey( 

592 SkosConcept, 

593 on_delete=models.SET_NULL, 

594 blank=True, 

595 null=True, 

596 help_text="<a href='/vocabs/scheme/17' target='_blank'>See Position Concept Schema</a>", 

597 related_name="skos_animalsremains_position", 

598 ) 

599 

600 def __str__(self): 

601 return "species: {} | age: {} | sex: {} | amount: {}".format( 

602 self.species, self.age, self.sex, self.amount_countable 

603 ) 

604 

605 def get_absolute_url(self): 

606 return reverse("burials:animalremains_detail", kwargs={"pk": self.id}) 

607 

608 def get_classname(self): 

609 """Returns the name of the class as lowercase string""" 

610 class_name = str(self.__class__.__name__).lower() 

611 return class_name