##// END OF EJS Templates
Added id-type attribute to attachments to specify a type of hash (currently only md5). Added management command to delete global id caches
neko259 -
r1560:bf42cc40 default
parent child Browse files
Show More
@@ -0,0 +1,20 b''
1 from django.core.management import BaseCommand
2 from django.db import transaction
3
4 from boards.models import GlobalId
5
6 __author__ = 'neko259'
7
8
9 class Command(BaseCommand):
10 help = 'Removes local global ID cache'
11
12 @transaction.atomic
13 def handle(self, *args, **options):
14 count = 0
15 for global_id in GlobalId.objects.all():
16 if global_id.is_local() and global_id.content is not None:
17 global_id.content = None
18 global_id.save()
19 count += 1
20 print('Invalidated {} caches.'.format(count))
@@ -3,8 +3,8 b" STATUS_BUMPLIMIT = 'bumplimit'"
3 STATUS_ARCHIVE = 'archived'
3 STATUS_ARCHIVE = 'archived'
4
4
5
5
6 from boards.models.sync_key import KeyPair
6 from boards.models.signature import GlobalId, Signature
7 from boards.models.signature import GlobalId, Signature
7 from boards.models.sync_key import KeyPair
8 from boards.models.image import PostImage
8 from boards.models.image import PostImage
9 from boards.models.attachment import Attachment
9 from boards.models.attachment import Attachment
10 from boards.models.thread import Thread
10 from boards.models.thread import Thread
@@ -43,6 +43,9 b" ATTR_MIMETYPE = 'mimetype'"
43 ATTR_KEY = 'key'
43 ATTR_KEY = 'key'
44 ATTR_REF = 'ref'
44 ATTR_REF = 'ref'
45 ATTR_URL = 'url'
45 ATTR_URL = 'url'
46 ATTR_ID_TYPE = 'id-type'
47
48 ID_TYPE_MD5 = 'md5'
46
49
47 STATUS_SUCCESS = 'success'
50 STATUS_SUCCESS = 'success'
48
51
@@ -269,6 +272,7 b' class SyncManager:'
269 mimetype = get_file_mimetype(file)
272 mimetype = get_file_mimetype(file)
270 attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT)
273 attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT)
271 attachment.set(ATTR_MIMETYPE, mimetype)
274 attachment.set(ATTR_MIMETYPE, mimetype)
275 attachment.set(ATTR_ID_TYPE, ID_TYPE_MD5)
272 attachment.text = hash
276 attachment.text = hash
273
277
274 attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF)
278 attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF)
@@ -1,5 +1,6 b''
1 import xml.etree.ElementTree as et
1 import xml.etree.ElementTree as et
2 from django.db import models
2 from django.db import models
3 from boards.models import KeyPair
3
4
4
5
5 TAG_MODEL = 'model'
6 TAG_MODEL = 'model'
@@ -124,6 +125,11 b' class GlobalId(models.Model):'
124 key_type=element.get(ATTR_KEY_TYPE),
125 key_type=element.get(ATTR_KEY_TYPE),
125 local_id=int(element.get(ATTR_LOCAL_ID))), False
126 local_id=int(element.get(ATTR_LOCAL_ID))), False
126
127
128 def is_local(self):
129 """Checks fo the ID is local model's"""
130 return KeyPair.objects.filter(
131 key_type=self.key_type, public_key=self.key).exists()
132
127
133
128 class Signature(models.Model):
134 class Signature(models.Model):
129 class Meta:
135 class Meta:
General Comments 0
You need to be logged in to leave comments. Login now