コード例 #1
0
def process_batch(key, batch_info, iv):
    """Loops through items in a batch and processes them."""
    batch_info = pickle.loads(decrypt(key, batch_info, iv.decode('hex')))
    success = True


    if 'dependencies' in batch_info:
        dependencies = serializers.deserialize('json', batch_info['dependencies'])
        for dep in dependencies:
            dep.save()

    if 'update' in batch_info:
        updates = serializers.deserialize('json', batch_info['update'])
        for item in updates:
            with reversion.create_revision():
                item.save()

    if 'deletions' in batch_info:
        deletions = json.loads(batch_info['deletions'])
        for deletion in deletions:
            app_label, model_label, object_id = deletion
            ct = ContentType.objects.get_by_natural_key(app_label, model_label)
            for result in ct.model_class().objects.filter(pk=object_id):
                with reversion.create_revision():
                    result.delete()
                    
    return success
コード例 #2
0
ファイル: tests.py プロジェクト: luisibanez/django-nudge
 def test_encryption(self):
     """
     Tests that encryption and decryption are sane
     """
     message=u"Hello, Nudge Encryption!"
     key=generate_key()
     encrypted, iv = encrypt(key.decode('hex'), message)
     decrypted= decrypt(key.decode('hex'), encrypted, iv)
     self.assertEqual(message, decrypted.strip())
コード例 #3
0
 def test_encryption(self):
     """
     Tests that encryption and decryption are sane
     """
     message = u"Hello, Nudge Encryption!"
     key = generate_key()
     encrypted, iv = encrypt(key.decode('hex'), message)
     decrypted = decrypt(key.decode('hex'), encrypted, iv)
     self.assertEqual(message, decrypted.strip())