#-*-coding: utf-8 -*-

from pollandsurvey import model
from surveyobject import JsontoObject
from tgext.pyutilservice import Utility, extraLog
from tg import expose, flash, require, url, lurl, request, redirect, tmpl_context,validate,response 

import logging;
log = logging.getLogger(__name__);
__all__ = ['InvitationService']
class InvitationService(object):
    def __init__(self, mymodel=None):
        self.utility = Utility();
        if mymodel is None:
            self.mymodel = model
        self.mymodel = mymodel       
        
    def createInvitation(self, InvitationObject=None):        
        createInvitation = InvitationObject.CreateInvitation
        user =  request.identity['user'];        
        createInvitation.user_id=user.user_id
        if(not self.utility.setIfEmpty(InvitationObject.id_question_invitation)):
            createInvitation.id_question_invitation=None
            createInvitation.save()
        else :            
            createInvitation.updateall()        
    
    def DeleteInvitation(self, InvitationData=None):
        invitation = model.Invitation.getId(InvitationData.id_question_invitation);
        if invitation :
            invitation.active = 0 
            