datatracker/ietf/nomcom/fields.py
Emilio Jiménez 29064193a3 * Add feedback view by nominee
* Refactor EncryptedTextField
 * Add feedback model managers 
 * Add templatetag to get person from author email
See #973
 - Legacy-Id: 5574
2013-03-16 15:43:32 +00:00

27 lines
766 B
Python

from django.conf import settings
from django.db import models
from ietf.utils.pipe import pipe
class EncryptedException(Exception):
pass
class EncryptedTextField(models.TextField):
def pre_save(self, instance, add):
if add:
comments = getattr(instance, 'comments')
nomcom = getattr(instance, 'nomcom')
cert_file = nomcom.public_key.path
code, out, error = pipe("%s smime -encrypt -in /dev/stdin %s" % (settings.OPENSSL_COMMAND,
cert_file), comments)
if not error:
instance.comments = out
return out
else:
raise EncryptedException(error)
else:
return instance.comments