models.py 5.5 KB
Newer Older
1
from django.conf import settings
2
from django.contrib.auth import get_user_model
3
from django.db import models
4
from django.utils.datetime_safe import date
5

6
from djangoldp.models import Model
7

8

9
class Skill(Model):
10
    title = models.CharField(max_length=255, blank=True, null=True)
11
    obligatoire = models.CharField(max_length=255)
12
    slug = models.SlugField(blank=True, null=True, unique=True)
13 14 15 16
    date = models.DateTimeField(auto_now_add=True, blank=True)

    def recent_jobs(self):
        return self.joboffer_set.filter(date__gte=date.today())
17

18
    class Meta:
19 20 21
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']
22
        serializer_fields = ["@id", "title", "recent_jobs"]
23 24 25 26
        lookup_field = 'slug'


class JobOffer(Model):
27
    title = models.CharField(max_length=255, blank=True, null=True)
28
    skills = models.ManyToManyField(Skill, blank=True)
29
    slug = models.SlugField(blank=True, null=True, unique=True)
30 31 32 33
    date = models.DateTimeField(auto_now_add=True, blank=True)

    def recent_skills(self):
        return self.skills.filter(date__gte=date.today())
34

35 36 37
    def some_skill(self):
        return self.skills.all().first()

38
    class Meta:
39
        anonymous_perms = ['view']
40 41
        authenticated_perms = ['inherit', 'change', 'add']
        owner_perms = ['inherit', 'delete', 'control']
42
        nested_fields = ["skills"]
43
        serializer_fields = ["@id", "title", "skills", "recent_skills", "resources", "slug", "some_skill"]
44
        container_path = "job-offers/"
45
        lookup_field = 'slug'
46

47

48
class Conversation(models.Model):
49
    description = models.CharField(max_length=255, blank=True, null=True)
50
    author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
51
    peer_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="peers_conv")
52

53 54 55 56 57
    class Meta:
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']

58

59 60 61 62 63 64 65 66 67
class Resource(Model):
    joboffers = models.ManyToManyField(JobOffer, blank=True, related_name='resources')

    class Meta:
        anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control']
        authenticated_perms = ['inherit']
        owner_perms = ['inherit']
        serializer_fields = ["@id", "joboffers"]
        nested_fields = ["joboffers"]
68
        depth = 1
69 70


71 72 73 74
class UserProfile(Model):
    description = models.CharField(max_length=255, blank=True, null=True)
    user = models.OneToOneField(settings.AUTH_USER_MODEL)

75
    class Meta:
76 77 78
        anonymous_perms = ['view']
        authenticated_perms = ['inherit']
        owner_perms = ['inherit', 'change', 'control']
79 80
        depth = 1

81

82 83
class Message(models.Model):
    text = models.CharField(max_length=255, blank=True, null=True)
84
    conversation = models.ForeignKey(Conversation, on_delete=models.DO_NOTHING)
85
    author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
86

87 88 89 90 91
    class Meta:
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']

92

93 94
class Dummy(models.Model):
    some = models.CharField(max_length=255, blank=True, null=True)
95
    slug = models.SlugField(blank=True, null=True, unique=True)
96

97 98 99 100 101
    class Meta:
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']

102

103
class LDPDummy(Model):
104 105
    some = models.CharField(max_length=255, blank=True, null=True)

106 107 108 109 110
    class Meta:
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']

111 112 113

class Invoice(Model):
    title = models.CharField(max_length=255, blank=True, null=True)
114 115
    date = models.DateField(blank=True, null=True)

116 117
    class Meta:
        depth = 2
118 119 120
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']
121 122
        nested_fields = ["batches"]

123 124 125 126 127 128 129

class Batch(Model):
    invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, related_name='batches')
    title = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        serializer_fields = ['@id', 'title', 'invoice', 'tasks']
130 131 132
        anonymous_perms = ['view', 'add']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']
133
        nested_fields = ["tasks", 'invoice']
134
        depth = 1
135 136 137 138 139 140 141 142


class Task(models.Model):
    batch = models.ForeignKey(Batch, on_delete=models.CASCADE, related_name='tasks')
    title = models.CharField(max_length=255)

    class Meta:
        serializer_fields = ['@id', 'title', 'batch']
143 144 145
        anonymous_perms = ['view']
        authenticated_perms = ['inherit', 'add']
        owner_perms = ['inherit', 'change', 'delete', 'control']
146 147 148 149 150


class Post(Model):
    content = models.CharField(max_length=255)
    author = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
151 152
    peer_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="peers_post")

153 154
    class Meta:
        auto_author = 'author'
155 156 157
        anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control']
        authenticated_perms = ['inherit']
        owner_perms = ['inherit']
158 159


160 161
get_user_model()._meta.serializer_fields = ['@id', 'username', 'first_name', 'last_name', 'email', 'userprofile',
                                            'conversation_set', ]