##// END OF EJS Templates
Delete global ID when deleting post. Cache model's content XML tag into global ID
neko259 -
r1520:ecaafe92 decentral
parent child Browse files
Show More
@@ -55,15 +55,19 b' class SyncManager:'
55 55
56 56 models = et.SubElement(response, TAG_MODELS)
57 57
58 # TODO Put global id's content into XML instad of manual serialization
59 58 for post in model_list:
60 59 model = et.SubElement(models, TAG_MODEL)
61 60 model.set(ATTR_NAME, 'post')
62 61
62 global_id = post.global_id
63
64 if global_id.content:
65 model.append(et.fromstring(global_id.content))
66 else:
63 67 content_tag = et.SubElement(model, TAG_CONTENT)
64 68
65 69 tag_id = et.SubElement(content_tag, TAG_ID)
66 post.global_id.to_xml_element(tag_id)
70 global_id.to_xml_element(tag_id)
67 71
68 72 title = et.SubElement(content_tag, TAG_TITLE)
69 73 title.text = post.title
@@ -100,17 +104,20 b' class SyncManager:'
100 104 attachments_tag, attachment_refs, file.file.file,
101 105 file.hash, file.file.url)
102 106
107 global_id.content = et.tostring(content_tag, ENCODING_UNICODE)
108 global_id.save()
109
103 110 signatures_tag = et.SubElement(model, TAG_SIGNATURES)
104 post_signatures = post.global_id.signature_set.all()
111 post_signatures = global_id.signature_set.all()
105 112 if post_signatures:
106 113 signatures = post_signatures
107 114 else:
108 key = KeyPair.objects.get(public_key=post.global_id.key)
115 key = KeyPair.objects.get(public_key=global_id.key)
109 116 signature = Signature(
110 117 key_type=key.key_type,
111 118 key=key.public_key,
112 signature=key.sign(et.tostring(content_tag, encoding=ENCODING_UNICODE)),
113 global_id=post.global_id,
119 signature=key.sign(global_id.content),
120 global_id=global_id,
114 121 )
115 122 signature.save()
116 123 signatures = [signature]
@@ -140,7 +147,7 b' class SyncManager:'
140 147 if exists:
141 148 print('Post with same ID already exists')
142 149 else:
143 global_id.content = et.to_string(tag_content,
150 global_id.content = et.tostring(tag_content,
144 151 ENCODING_UNICODE)
145 152 global_id.save()
146 153 for signature in signatures:
@@ -64,6 +64,12 b' class GlobalIdManager(models.Manager):'
64 64
65 65
66 66 class GlobalId(models.Model):
67 """
68 Global model ID and cache.
69 Key, key type and local ID make a single global identificator of the model.
70 Content is an XML cache of the model that can be passed along between nodes
71 without manual serialization each time.
72 """
67 73 class Meta:
68 74 app_label = 'boards'
69 75
@@ -79,3 +79,9 b' def update_thread_on_delete(instance, **'
79 79 thread = instance.get_thread()
80 80 thread.last_edit_time = timezone.now()
81 81 thread.save()
82
83
84 @receiver(post_delete, sender=Post)
85 def delete_global_id(instance, **kwargs):
86 if instance.global_id and instance.global_id.id:
87 instance.global_id.delete()
General Comments 0
You need to be logged in to leave comments. Login now