blob: d068b857d02d166cd3d4d4eed397b72443f580b6 [file] [log] [blame]
# Copyright 2014 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Logic for signatures."""
import datetime
from google.appengine.ext import ndb
from melange.models import signature as signature_model
def getSignatureForProfileAndDocument(profile_key, document_key):
"""Returns a signature for the specified profile and document.
Args:
profile_key: ndb.Key of the profile.
document_key: ndb.Key of the document.
Returns:
signature_model.Signature entity or None if no signature exists for the
profile and the document.
"""
return signature_model.Signature.query(
signature_model.Signature.document == document_key,
signature_model.Signature.profile == profile_key).get()
@ndb.transactional(propagation=ndb.TransactionOptions.INDEPENDENT)
def createSignature(document_key, profile):
"""Creates a new signature for the specified document and the specified
profile.
Args:
document_key: ndb.Key of the document.
profile: profile_model.Profile entity.
Returns:
The newly created signature_model.Signature entity.
"""
signature = signature_model.Signature(
profile=profile.key, legal_name=profile.legal_name,
email=profile.contact.email, address=profile.residential_address,
document=document_key, signed_on=datetime.datetime.utcnow())
signature.put()
return signature