| author | ymh <ymh.work@gmail.com> |
| Sun, 14 Jul 2024 21:04:58 +0200 | |
| changeset 662 | df0060476f35 |
| parent 626 | 112912309726 |
| permissions | -rw-r--r-- |
| 662 | 1 |
# -*- coding: utf-8 -*- |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
2 |
''' |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
3 |
Created on Jul 17, 2014 |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
4 |
Reworked in December, 2015 |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
5 |
|
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
6 |
@author: tc, nd |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
7 |
''' |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
8 |
import uuid, logging, json, datetime |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
9 |
from django.conf import settings |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
10 |
from django.db import models, transaction |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
11 |
from django.core.exceptions import ValidationError |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
12 |
from django.utils import timezone, dateparse |
|
611
f0f07e2b841f
serverside: translation + timestamp handling + logging
durandn
parents:
610
diff
changeset
|
13 |
from django.utils.translation import ugettext_lazy as _ |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
14 |
|
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
15 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
16 |
|
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
17 |
logger = logging.getLogger(__name__) |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
18 |
auth_user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
19 |
|
|
626
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
20 |
# Copy the content of a révision. |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
21 |
# This will return a map (not a serialized) to allow further treatment |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
22 |
# This changes the ids of the project, nodes, views and edges but NOT users |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
23 |
# |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
24 |
def content_copy(content_str): #TODO: ??? Extract this in another class, like a RevisionManager ??? |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
25 |
node_ids_map = {} |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
26 |
content = json.loads(content_str) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
27 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
28 |
content['id'] = str(uuid.uuid4()) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
29 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
30 |
#nodes |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
31 |
for node in content.get('nodes', []): |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
32 |
id_key = 'id' if 'id' in node else '_id' |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
33 |
node_ids_map[node[id_key]] = node['id'] = str(uuid.uuid4()) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
34 |
node.pop('_id', None) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
35 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
36 |
for edge in content.get('edges', []): |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
37 |
edge['id'] = str(uuid.uuid4()) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
38 |
edge.pop('_id', None) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
39 |
edge['from'] = node_ids_map[edge['from']] |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
40 |
edge['to'] = node_ids_map[edge['to']] |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
41 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
42 |
for view in content.get('views', []): |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
43 |
view['id'] = str(uuid.uuid4()) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
44 |
view.pop('_id', None) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
45 |
view['hidden_nodes'] = [ node_ids_map[n] for n in view.get('hidden_nodes', [])] |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
46 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
47 |
for user in content.get('users', []): |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
48 |
if '_id' in user: |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
49 |
user['id'] = user.pop('_id') |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
50 |
|
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
51 |
return content |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
52 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
53 |
class Workspace(models.Model): |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
54 |
|
|
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
55 |
workspace_guid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, blank=False, null=False) |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
56 |
title = models.CharField(max_length=1024, null=True) |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
57 |
creator = models.ForeignKey(auth_user_model, blank=True, null=True, related_name="workspace_creator") |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
58 |
creation_date = models.DateTimeField(auto_now_add=True) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
59 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
60 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
61 |
def renkan_count(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
62 |
return self.renkans.all().count() |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
63 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
64 |
class Meta: |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
65 |
app_label = 'renkanmanager' |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
66 |
permissions = ( |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
67 |
('view_workspace', 'Can view workspace'), |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
68 |
) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
69 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
70 |
|
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
71 |
class RenkanManager(models.Manager): |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
72 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
73 |
@transaction.atomic |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
74 |
def create_renkan(self, creator, title='', content='', source_revision=None, workspace = None): |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
75 |
new_renkan = Renkan() |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
76 |
new_renkan.creator = creator |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
77 |
new_renkan_workspace_guid = None |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
78 |
new_renkan_title = title |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
79 |
new_renkan_content = content |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
80 |
if workspace is not None: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
81 |
new_renkan.workspace = workspace |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
82 |
new_renkan_workspace_guid = workspace.workspace_guid |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
83 |
if source_revision is not None: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
84 |
new_renkan.source_revision = source_revision |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
85 |
if not title: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
86 |
new_renkan_title = source_revision.title |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
87 |
new_renkan_content = source_revision.content |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
88 |
new_renkan.save() |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
89 |
creation_date = timezone.now() |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
90 |
initial_revision = Revision(parent_renkan=new_renkan) |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
91 |
initial_revision.title = new_renkan_title if new_renkan_title else "Untitled Renkan" |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
92 |
initial_revision.creation_date = creation_date |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
93 |
initial_revision.modification_date = creation_date |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
94 |
initial_revision.creator = creator |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
95 |
initial_revision.last_updated_by = creator |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
96 |
if new_renkan_content: |
|
626
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
97 |
new_renkan_content_dict = content_copy(new_renkan.validate_json_content(new_renkan_content)) |
|
112912309726
ensure that we change the ids of elements when copying/creating a new renkan
ymh <ymh.work@gmail.com>
parents:
621
diff
changeset
|
98 |
new_renkan_content_dict["id"] = str(new_renkan.renkan_guid) |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
99 |
new_renkan_content_dict["created"] = str(creation_date) |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
100 |
new_renkan_content_dict["updated"] = str(creation_date) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
101 |
else: |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
102 |
new_renkan_content_dict = { |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
103 |
"id": str(new_renkan.renkan_guid), |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
104 |
"title": initial_revision.title, |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
105 |
"description": "", |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
106 |
"created": str(creation_date), |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
107 |
"updated": str(creation_date), |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
108 |
"edges": [], |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
109 |
"nodes": [], |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
110 |
"users": [], |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
111 |
"space_id": str(new_renkan_workspace_guid), |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
112 |
"views": [] |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
113 |
} |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
114 |
initial_revision.content = json.dumps(new_renkan_content_dict) |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
115 |
initial_revision.save() |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
116 |
return new_renkan |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
117 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
118 |
class Renkan(models.Model): |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
119 |
|
|
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
120 |
renkan_guid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, blank=False, null=False) |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
121 |
workspace = models.ForeignKey('renkanmanager.Workspace', null=True, blank=True, on_delete=models.CASCADE, related_name="renkans") |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
122 |
current_revision = models.ForeignKey('renkanmanager.Revision', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
123 |
source_revision = models.ForeignKey('renkanmanager.Revision', null=True, blank=True, on_delete=models.SET_NULL, related_name='copies') |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
124 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
125 |
creator = models.ForeignKey(auth_user_model, blank=True, null=True, related_name="renkan_creator") |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
126 |
creation_date = models.DateTimeField(auto_now_add=True) |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
127 |
state = models.IntegerField(default=1) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
128 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
129 |
objects = RenkanManager() |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
130 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
131 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
132 |
def revision_count(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
133 |
return self.revisions.all().count() |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
134 |
|
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
135 |
@property |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
136 |
def workspace_guid(self): |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
137 |
return self.workspace and self.workspace.workspace_guid |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
138 |
|
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
139 |
@property |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
140 |
def current_revision_guid(self): |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
141 |
return self.current_revision and self.current_revision.revision_guid |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
142 |
|
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
143 |
@property |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
144 |
def source_revision_guid(self): |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
145 |
return self.source_revision and self.source_revision.revision_guid |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
146 |
|
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
147 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
148 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
149 |
def is_copy(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
150 |
return bool(self.source_revision) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
151 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
152 |
# Current revision title |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
153 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
154 |
def title(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
155 |
return self.current_revision and self.current_revision.title or '' |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
156 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
157 |
# Current revision content |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
158 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
159 |
def content(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
160 |
return self.current_revision and self.current_revision.content or '' |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
161 |
|
|
611
f0f07e2b841f
serverside: translation + timestamp handling + logging
durandn
parents:
610
diff
changeset
|
162 |
def __str__(self): |
| 621 | 163 |
return str(self.renkan_guid) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
164 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
165 |
@transaction.atomic |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
166 |
def save_renkan(self, updator, timestamp="", title="", content="", create_new_revision=False): |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
167 |
""" |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
168 |
Saves over current revision or saves a new revision entirely. |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
169 |
Timestamp must be the current revision modification_date. |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
170 |
""" |
|
618
3051b847c124
validation_timestamp and create_new_revision are not part of the data. move them to query parameters
ymh <ymh.work@gmail.com>
parents:
616
diff
changeset
|
171 |
if (not timestamp) or ((self.current_revision is not None) and timestamp != self.current_revision.modification_date): |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
172 |
logger.error("SAVING RENKAN: provided timestamp is %r, which isn't current revision modification_date %r", timestamp, self.current_revision.modification_date) |
|
611
f0f07e2b841f
serverside: translation + timestamp handling + logging
durandn
parents:
610
diff
changeset
|
173 |
raise ValidationError(_("Cannot save, provided timestamp is invalid")) |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
174 |
else: |
|
618
3051b847c124
validation_timestamp and create_new_revision are not part of the data. move them to query parameters
ymh <ymh.work@gmail.com>
parents:
616
diff
changeset
|
175 |
dt_timestamp = timestamp |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
176 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
177 |
if create_new_revision: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
178 |
revision_to_update = Revision(parent_renkan=self) |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
179 |
revision_to_update.creator = updator |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
180 |
else: |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
181 |
revision_to_update = Revision.objects.select_for_update().get(id=self.current_revision.id) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
182 |
|
|
610
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
183 |
updated_content = self.validate_json_content(content) if content else current_revision.content |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
184 |
updated_content_dict = json.loads(updated_content) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
185 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
186 |
# If title is passed as arg to the method, update the title in the json |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
187 |
if title: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
188 |
updated_title = title |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
189 |
updated_content_dict["title"] = title |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
190 |
# If it is not, we use the one in the json instead |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
191 |
else: |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
192 |
updated_title = updated_content_dict["title"] |
|
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
193 |
|
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
194 |
revision_to_update.modification_date = timezone.now() |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
195 |
updated_content_dict["updated"] = str(revision_to_update.modification_date) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
196 |
updated_content = json.dumps(updated_content_dict) |
|
609
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
197 |
revision_to_update.title = updated_title |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
198 |
revision_to_update.content = updated_content |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
199 |
if dt_timestamp == revision_to_update.modification_date: |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
200 |
revision_to_update.modification_date += datetime.resolution |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
201 |
revision_to_update.last_updated_by = updator |
|
854a027c80ff
models refactoring to use ForeignKey fields + associated migrations
durandn
parents:
589
diff
changeset
|
202 |
revision_to_update.save() |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
203 |
self.save() |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
204 |
|
|
610
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
205 |
def validate_json_content(self, content): |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
206 |
""" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
207 |
Checks that the json content is valid (keys and structures), raise a ValidationError if format is wrong or value is wrong (for ids), |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
208 |
if a key is missing, autocompletes with the empty default value |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
209 |
|
|
610
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
210 |
Returns the validated json string |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
211 |
""" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
212 |
try: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
213 |
content_to_validate_dict = json.loads(content) |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
214 |
except ValueError: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
215 |
raise ValidationError("Provided content to create Renkan is not a JSON-serializable") |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
216 |
if "id" not in content_to_validate_dict or content_to_validate_dict["id"] == "" : |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
217 |
content_to_validate_dict["id"] = str(self.renkan_guid) |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
218 |
if "title" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
219 |
content_to_validate_dict["title"] = "" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
220 |
if "description" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
221 |
content_to_validate_dict["description"] = "" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
222 |
if "created" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
223 |
content_to_validate_dict["description"] = "" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
224 |
if "updated" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
225 |
content_to_validate_dict["description"] = "" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
226 |
expected_workspace_id = str(self.workspace.workspace_guid) if self.workspace is not None else "" |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
227 |
if "space_id" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
228 |
content_to_validate_dict["space_id"] = expected_workspace_id |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
229 |
if "nodes" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
230 |
content_to_validate_dict["nodes"] = [] |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
231 |
if "edges" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
232 |
content_to_validate_dict["edges"] = [] |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
233 |
if "views" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
234 |
content_to_validate_dict["views"] = [] |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
235 |
if "users" not in content_to_validate_dict: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
236 |
content_to_validate_dict["users"] = [] |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
237 |
|
|
610
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
238 |
if type(content_to_validate_dict["nodes"]) is not list: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
239 |
raise ValidationError("Provided content has an invalid 'nodes' key: not a list") |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
240 |
if type(content_to_validate_dict["edges"]) is not list: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
241 |
raise ValidationError("Provided content has an invalid 'edges' key: not a list") |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
242 |
if type(content_to_validate_dict["views"]) is not list: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
243 |
raise ValidationError("Provided content has an invalid 'views' key: not a list") |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
244 |
if type(content_to_validate_dict["users"]) is not list: |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
245 |
raise ValidationError("Provided content has an invalid 'users' key: not a list") |
|
b9edc1c1538a
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents:
609
diff
changeset
|
246 |
return json.dumps(content_to_validate_dict) |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
247 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
248 |
class Meta: |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
249 |
app_label = 'renkanmanager' |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
250 |
permissions = ( |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
251 |
('view_renkan', 'Can view renkan'), |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
252 |
) |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
253 |
|
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
254 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
255 |
class Revision(models.Model): |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
256 |
|
|
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
257 |
revision_guid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, blank=False, null=False) |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
258 |
parent_renkan = models.ForeignKey('renkanmanager.Renkan', on_delete=models.CASCADE, related_name="revisions") |
|
588
95536fa18d0d
Minor adjustements to properly interact with Renkan client
durandn
parents:
587
diff
changeset
|
259 |
title = models.CharField(max_length=1024, null=True, blank=True) |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
260 |
content = models.TextField(blank=True, null=True) |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
261 |
creator = models.ForeignKey(auth_user_model, blank=True, null=True, related_name="revision_creator") |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
262 |
last_updated_by = models.ForeignKey(auth_user_model, blank=True, null=True, related_name="revision_last_updated_by") |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
263 |
creation_date = models.DateTimeField(auto_now_add=True, editable=False) |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
264 |
modification_date = models.DateTimeField() |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
265 |
|
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
266 |
@property |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
267 |
def parent_renkan_guid(self): |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
268 |
return self.parent_renkan and self.parent_renkan.renkan_guid |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
269 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
270 |
@property |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
271 |
def is_current_revision(self): |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
272 |
return self == self.parent_renkan.current_revision |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
273 |
|
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
274 |
class Meta: |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
275 |
app_label = 'renkanmanager' |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
276 |
ordering = ['-modification_date'] |
|
587
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
277 |
permissions = ( |
|
fb0041aa74d3
transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff
changeset
|
278 |
('view_revision', 'Can view revision'), |
|
614
23416a833ca8
Change guid fields to more optimal type + migration
ymh <ymh.work@gmail.com>
parents:
611
diff
changeset
|
279 |
) |
|
615
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
280 |
|
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
281 |
def __str__(self): |
|
f3875fbe206a
redo foreign key for renkanmanager, optimize property access, correct unit tests
ymh <ymh.work@gmail.com>
parents:
614
diff
changeset
|
282 |
return str(self.revision_guid) |