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

44 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-20 09:03 +0000

1from django.db import models 

2 

3from ptf.models import Collection 

4from ptf.models import Publisher 

5 

6 

7class SourceManager(models.Manager): 

8 def get_by_natural_key(self, name): 

9 return self.get(name=name) 

10 

11 

12class Source(models.Model): 

13 object_id = models.PositiveIntegerField(null=True) 

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

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

16 name = models.CharField(max_length=300) 

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

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

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

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

21 objects = SourceManager() 

22 

23 def natural_key(self): 

24 return (self.name,) 

25 

26 def __str__(self): 

27 return f"{self.name}" 

28 

29 class Meta: 

30 ordering = ["name"] 

31 

32 

33class PeriodeManager(models.Manager): 

34 def get_by_natural_key(self, title): 

35 return self.get(title=title) 

36 

37 

38class Periode(models.Model): 

39 collection = models.ForeignKey( 

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

41 ) 

42 source = models.ForeignKey( 

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

44 ) 

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

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

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

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

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

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

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

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

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

54 

55 publisher = models.ForeignKey( 

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

57 ) 

58 wall = models.IntegerField(default=5) 

59 objects = PeriodeManager() 

60 

61 def natural_key(self): 

62 return (self.title, self.collection) 

63 

64 def __str__(self): 

65 return f"{self.collection}"