/
resources.py
66 lines (50 loc) · 2.05 KB
/
resources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from django.core.urlresolvers import reverse
from djangorestframework.resources import ModelResource
from endorsenet.models import Space, Context, Actor, Action, Endorsement, CommitEvent, ActionUpdateEvent
class SpaceResource(ModelResource):
"""
A Space is a container that can hold one or multiple Contexts.
"""
model = Space
def contexts(self, instance):
return reverse('contexts', kwargs={'space': instance.key})
class ContextResource(ModelResource):
"""
A Context holds one instance of an endorsenet and defines meta informations about the nodes of that network.
"""
model = Context
fields = ('action_name', 'actor_name')
def space(self, instance):
return reverse('space', kwargs={'key': instance.space.key})
def actors(self, instance):
return reverse('actors', kwargs={'context': instance.key})
def actions(self, instance):
return reverse('actions', kwargs={'context': instance.key})
def endorsements(self, instance):
return reverse('endorsements', kwargs={'context': instance.key})
class ActorResource(ModelResource):
"""
An Actor can be either an endorser (e.g. trustee) or an endorsee (e.g. borrower), or both.
"""
model = Actor
fields = ('external_id')
def context(self, instance):
return reverse('context', kwargs={'key': instance.context.key})
class ActionResource(ModelResource):
"""
An Action belongs to an Actor (and endorsee to be more specific) and can be endorsed by other Actors (i.e. endorsees).
Actions will usually end up with outcomes that then influence the scores in the graph.
"""
model = Action
fields = ('external_id', 'context', 'actor')
def context(self, instance):
return reverse('context', kwargs={'key': instance.context.key})
class EndorsementResource(ModelResource):
"""
An Endorsement is made by an Actor (endorser) to rate a particular subject.
A subject can be either another Actor (endorsee) or a particular Action.
"""
model = Endorsement
fields = ('external_id', 'subject', 'endorser', 'score')
def context(self, instance):
return reverse('context', kwargs={'key': instance.context.key})