##// END OF EJS Templates
Don't allow to import the same post twice
neko259 -
r1232:52a45386 decentral
parent child Browse files
Show More
@@ -102,15 +102,18 b' class SyncManager:'
102 print('Post with same ID already exists')
102 print('Post with same ID already exists')
103 except GlobalId.DoesNotExist:
103 except GlobalId.DoesNotExist:
104 global_id = GlobalId.from_xml_element(tag_id)
104 global_id = GlobalId.from_xml_element(tag_id)
105
106 if not GlobalId.objects.global_id_exists(global_id):
105 global_id.save()
107 global_id.save()
106
108
107 title = tag_content.find(TAG_TITLE).text
109 title = tag_content.find(TAG_TITLE).text
108 text = tag_content.find(TAG_TEXT).text
110 text = tag_content.find(TAG_TEXT).text
109 pub_time = tag_content.find(TAG_PUB_TIME).text
111 pub_time = tag_content.find(TAG_PUB_TIME).text
112
110 # TODO Check that the replied posts are already present
113 # TODO Check that the replied posts are already present
111 # before adding new ones
114 # before adding new ones
112
115
113 # TODO Pub time, thread, tags
116 # TODO thread, tags
114
117
115 # FIXME This prints are for testing purposes only, they must
118 # FIXME This prints are for testing purposes only, they must
116 # be removed after sync is implemented
119 # be removed after sync is implemented
@@ -37,6 +37,15 b' class GlobalIdManager(models.Manager):'
37
37
38 return et.tostring(request, 'unicode')
38 return et.tostring(request, 'unicode')
39
39
40 def global_id_exists(self, global_id):
41 """
42 Checks if the same global id already exists in the system.
43 """
44
45 return self.filter(key=global_id.key,
46 key_type=global_id.key_type,
47 local_id=global_id.local_id).exists()
48
40
49
41 class GlobalId(models.Model):
50 class GlobalId(models.Model):
42 class Meta:
51 class Meta:
@@ -54,3 +54,7 b' class SyncTest(TestCase):'
54 SyncManager().parse_response_get(response)
54 SyncManager().parse_response_get(response)
55 self.assertEqual(1, Post.objects.count(),
55 self.assertEqual(1, Post.objects.count(),
56 'Post was not created from XML response.')
56 'Post was not created from XML response.')
57
58 SyncManager().parse_response_get(response)
59 self.assertEqual(1, Post.objects.count(),
60 'The same post was imported twice.')
General Comments 0
You need to be logged in to leave comments. Login now