1 3
from cyborgbackup.api.versioning import reverse
2 3
from cyborgbackup.main.fields import JSONField
3

4
# Django
5 3
from django.db import models
6 3
from django.conf import settings
7 3
from django.utils.translation import ugettext_lazy as _
8

9 3
__all__ = ['ActivityStream']
10

11

12 3
class ActivityStream(models.Model):
13
    '''
14
    Model used to describe activity stream (audit) events
15
    '''
16

17 3
    class Meta:
18 3
        app_label = 'main'
19 3
        ordering = ('pk',)
20

21 3
    OPERATION_CHOICES = [
22
        ('create', _('Entity Created')),
23
        ('update', _("Entity Updated")),
24
        ('delete', _("Entity Deleted")),
25
        ('associate', _("Entity Associated with another Entity")),
26
        ('disassociate', _("Entity was Disassociated with another Entity"))
27
    ]
28

29 3
    actor = models.ForeignKey(settings.AUTH_USER_MODEL,
30
                              null=True,
31
                              on_delete=models.SET_NULL,
32
                              related_name='activity_stream')
33 3
    operation = models.CharField(max_length=13, choices=OPERATION_CHOICES)
34 3
    timestamp = models.DateTimeField(auto_now_add=True)
35 3
    changes = models.TextField(blank=True)
36

37 3
    object_relationship_type = models.TextField(blank=True)
38 3
    object1 = models.TextField()
39 3
    object2 = models.TextField()
40

41 3
    user = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
42 3
    job = models.ManyToManyField("Job", blank=True)
43 3
    client = models.ManyToManyField("Client", blank=True)
44 3
    schedule = models.ManyToManyField("Schedule", blank=True)
45 3
    policy = models.ManyToManyField("Policy", blank=True)
46 3
    repository = models.ManyToManyField("Repository", blank=True)
47

48 3
    setting = JSONField(blank=True)
49

50 3
    def get_absolute_url(self, request=None):
51 0
        return reverse('api:activity_stream_detail', kwargs={'pk': self.pk}, request=request)
52

53 3
    def save(self, *args, **kwargs):
54
        # For compatibility with Django 1.4.x, attempt to handle any calls to
55
        # save that pass update_fields.
56 3
        try:
57 3
            super(ActivityStream, self).save(*args, **kwargs)
58 0
        except TypeError:
59 0
            if 'update_fields' not in kwargs:
60 0
                raise
61 0
            kwargs.pop('update_fields')
62 0
            super(ActivityStream, self).save(*args, **kwargs)

Read our documentation on viewing source code .

Loading