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

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

9 6
__all__ = ['ActivityStream']
10

11

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

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

21 6
    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 6
    actor = models.ForeignKey(settings.AUTH_USER_MODEL,
30
                              null=True,
31
                              on_delete=models.SET_NULL,
32
                              related_name='activity_stream')
33 6
    operation = models.CharField(max_length=13, choices=OPERATION_CHOICES)
34 6
    timestamp = models.DateTimeField(auto_now_add=True)
35 6
    changes = models.TextField(blank=True)
36

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

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

48 6
    setting = JSONField(blank=True)
49

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

53 6
    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 6
        try:
57 6
            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