##// 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 models = et.SubElement(response, TAG_MODELS)
56 models = et.SubElement(response, TAG_MODELS)
57
57
58 # TODO Put global id's content into XML instad of manual serialization
59 for post in model_list:
58 for post in model_list:
60 model = et.SubElement(models, TAG_MODEL)
59 model = et.SubElement(models, TAG_MODEL)
61 model.set(ATTR_NAME, 'post')
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 content_tag = et.SubElement(model, TAG_CONTENT)
67 content_tag = et.SubElement(model, TAG_CONTENT)
64
68
65 tag_id = et.SubElement(content_tag, TAG_ID)
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 title = et.SubElement(content_tag, TAG_TITLE)
72 title = et.SubElement(content_tag, TAG_TITLE)
69 title.text = post.title
73 title.text = post.title
@@ -100,17 +104,20 b' class SyncManager:'
100 attachments_tag, attachment_refs, file.file.file,
104 attachments_tag, attachment_refs, file.file.file,
101 file.hash, file.file.url)
105 file.hash, file.file.url)
102
106
107 global_id.content = et.tostring(content_tag, ENCODING_UNICODE)
108 global_id.save()
109
103 signatures_tag = et.SubElement(model, TAG_SIGNATURES)
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 if post_signatures:
112 if post_signatures:
106 signatures = post_signatures
113 signatures = post_signatures
107 else:
114 else:
108 key = KeyPair.objects.get(public_key=post.global_id.key)
115 key = KeyPair.objects.get(public_key=global_id.key)
109 signature = Signature(
116 signature = Signature(
110 key_type=key.key_type,
117 key_type=key.key_type,
111 key=key.public_key,
118 key=key.public_key,
112 signature=key.sign(et.tostring(content_tag, encoding=ENCODING_UNICODE)),
119 signature=key.sign(global_id.content),
113 global_id=post.global_id,
120 global_id=global_id,
114 )
121 )
115 signature.save()
122 signature.save()
116 signatures = [signature]
123 signatures = [signature]
@@ -140,7 +147,7 b' class SyncManager:'
140 if exists:
147 if exists:
141 print('Post with same ID already exists')
148 print('Post with same ID already exists')
142 else:
149 else:
143 global_id.content = et.to_string(tag_content,
150 global_id.content = et.tostring(tag_content,
144 ENCODING_UNICODE)
151 ENCODING_UNICODE)
145 global_id.save()
152 global_id.save()
146 for signature in signatures:
153 for signature in signatures:
@@ -64,6 +64,12 b' class GlobalIdManager(models.Manager):'
64
64
65
65
66 class GlobalId(models.Model):
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 class Meta:
73 class Meta:
68 app_label = 'boards'
74 app_label = 'boards'
69
75
@@ -79,3 +79,9 b' def update_thread_on_delete(instance, **'
79 thread = instance.get_thread()
79 thread = instance.get_thread()
80 thread.last_edit_time = timezone.now()
80 thread.last_edit_time = timezone.now()
81 thread.save()
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