Coverage for src/crawler/models.py: 86%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2025-01-15 14:09 +0000

1from django.db import models 

2from ptf.models import Collection, Publisher 

3 

4 

5class SourceManager(models.Manager): 

6 def get_by_natural_key(self, name): 

7 return self.get(name=name) 

8 

9 

10class Source(models.Model): 

11 object_id = models.PositiveIntegerField(null=True) 

12 domain = models.CharField(max_length=150, null=True) 

13 website = models.CharField(max_length=250, null=True) 

14 name = models.CharField(max_length=300) 

15 create_xissue = models.BooleanField(blank=True, null=True) 

16 periode_href = models.CharField(max_length=250, blank=True, null=True) 

17 article_href = models.CharField(max_length=150, null=True, blank=True) 

18 pdf_href = models.CharField(max_length=250, blank=True) 

19 objects = SourceManager() 

20 

21 def natural_key(self): 

22 return (self.name,) 

23 

24 def __str__(self): 

25 return f"{self.name}" 

26 

27 class Meta: 

28 ordering = ["name"] 

29 

30 

31class PeriodeManager(models.Manager): 

32 def get_by_natural_key(self, title): 

33 return self.get(title=title) 

34 

35 

36class Periode(models.Model): 

37 collection = models.ForeignKey( 

38 Collection, null=True, related_name="periods", on_delete=models.CASCADE 

39 ) 

40 source = models.ForeignKey( 

41 Source, blank=True, null=True, related_name="source", on_delete=models.CASCADE 

42 ) 

43 title = models.CharField(max_length=250, default="title") 

44 issue_href = models.CharField(max_length=150, null=True, blank=True) 

45 collection_href = models.CharField(max_length=300, null=True, blank=True) 

46 doi_href = models.CharField(max_length=90, blank=True) 

47 published = models.BooleanField(blank=True, null=True) 

48 begin = models.IntegerField(("Début"), blank=True, null=True) 

49 end = models.IntegerField(("Fin"), blank=True, null=True) 

50 first_issue = models.IntegerField(("premier numéro"), blank=True, null=True) 

51 last_issue = models.IntegerField(("dernier numéro"), blank=True, null=True) 

52 

53 publisher = models.ForeignKey( 

54 Publisher, blank=True, null=True, related_name="publisher_col", on_delete=models.PROTECT 

55 ) 

56 wall = models.IntegerField(default=5) 

57 objects = PeriodeManager() 

58 

59 def natural_key(self): 

60 return (self.title, self.collection) 

61 

62 def __str__(self): 

63 return f"{self.collection}"