def post(self):
        logging.info("saving user rights and settings")

        strIsEmployee = self.request.get('vstrIsEmployee')

        strAccessEmployeeAdmin = self.request.get('vstrAccessEmployeeAdmin')
        strSearchCoverPolicy = self.request.get('vstrSearchCoverPolicy')
        strEditCoverPolicy = self.request.get('vstrEditCoverPolicy')
        strSearchFuneralService = self.request.get('vstrSearchFuneralService')
        strEditFuneralServices = self.request.get('vstrEditFuneralServices')
        strSearchLeadsForm = self.request.get('vstrSearchLeadsForm')
        strEditLeadsForm  = self.request.get('vstrEditLeadsForm')

        Rights = UserRights()
        logging.info(msg=strIsEmployee)

        URL = str(self.request.url)
        URLList = URL.split("/")
        strReference = URLList[len(URLList)-1]


        findRequest = UserRights.query(UserRights.strReference == strReference)
        RightsList = findRequest.fetch()

        if len(RightsList) > 0:
            Rights = RightsList[0]

        if strIsEmployee == "YES":
            Rights.setEmployeeUserRights()
            logging.info(msg="Is employee")

        if strAccessEmployeeAdmin == "YES":
            Rights.bolEmployeesAdminFormReadAccess = True
        else:
            Rights.bolEmployeesAdminFormReadAccess = False

        if strSearchCoverPolicy == "YES":
            Rights.bolEmployeesFuneralCoverFormReadAccess =True
        else:
            Rights.bolEmployeesFuneralCoverFormReadAccess = False

        if strEditCoverPolicy == "YES":
            Rights.bolEmployeesFuneralCoverFormWriteAccess = True
        else:
            Rights.bolEmployeesFuneralCoverFormWriteAccess = False

        if strSearchFuneralService == "YES":
            Rights.bolEmployeesFuneralServicesFormReadAccess = True
        else:
            Rights.bolEmployeesFuneralServicesFormReadAccess = False

        if strEditFuneralServices == "YES":
            Rights.bolEmployeesFuneralServicesFormWriteAccess = True
        else:
            Rights.bolEmployeesFuneralServicesFormWriteAccess = False

        if strSearchLeadsForm == "YES":
            Rights.bolEmployeesLeadsFormReadAccess = True
        else:
            Rights.bolEmployeesLeadsFormReadAccess = False

        if strEditLeadsForm == "YES":
            Rights.bolEmployeesLeadsFormWriteAccess = True
        else:
            Rights.bolEmployeesLeadsFormWriteAccess = False

        URL = str(self.request.url)
        URLlist = URL.split("/")

        strReference = URLlist[len(URLlist) - 1]

        Rights.writeReference(strinput=strReference)

        Rights.put()


        template = template_env.get_template('templates/dynamic/admin/rightsresponse.html')
        context = {'vstrIsEmployee': strIsEmployee,'vstrAccessEmployeeAdmin': strAccessEmployeeAdmin, 'vstrSearchCoverPolicy': strSearchCoverPolicy,
                   'vstrEditCoverPolicy': strEditCoverPolicy, 'vstrSearchFuneralService': strSearchFuneralService,
                   'vstrEditFuneralServices': strEditFuneralServices, 'vstrSearchLeadsForm': strSearchLeadsForm,
                   'vstrEditLeadsForm': strEditLeadsForm}
        self.response.write(template.render(context))
    def post(self):
        Guser = users.get_current_user()

        if Guser:
            strFirstnames = self.request.get('vstrFirstnames')
            strSurname = self.request.get('vstrSurname')
            strIDNumber = self.request.get('vstrIDNumber')
            strEmployeeCode = self.request.get('vstrEmployeeCode')
            strBranchCode = self.request.get('vstrBranchCode')

            URL = str(self.request.url)

            URLList = URL.split("/")
            strReference = URLList[len(URLList) - 1]

            findRequest = EmploymentDetails.query(EmploymentDetails.strReference == strReference)
            EmployeeList = findRequest.fetch()

            Employee = EmploymentDetails()

            if len(EmployeeList) > 0:
                Employee = EmployeeList[0]
            else:
                pass

            Employee.writeReference(strinput=strReference)
            Employee.writeEmployeeCode(strinput=strEmployeeCode)
            Employee.writeBranchWorking(strinput=strBranchCode)
            Employee.writeIDNumber(strinput=strIDNumber)
            Employee.writeSurname(strinput=strSurname)
            Employee.writeNames(strinput=strFirstnames)

            Employee.put()

            FindRequest = EmployeeRegRequest.query(EmployeeRegRequest.strReference == strReference)
            EmployeeReqList = FindRequest.fetch()

            findRequest = UserRights.query(UserRights.strReference == strReference)
            UserRightsList =findRequest.fetch()
            UserRight = UserRights()

            if len(UserRightsList) > 0:
                UserRight = UserRightsList[0]

            UserRight.writeReference(strinput=strReference)
            UserRight.writeEmployeeCode(strinput=strEmployeeCode)
            UserRight.put()


            if len(EmployeeReqList) > 0:
                EmployeeReq = EmployeeReqList[0]
                try:
                    EmployeeReq.key.delete()
                except:
                    pass
            else:
                pass


            template = template_env.get_template('templates/dynamic/admin/personalsresponse.html')
            context = {'vstrFirstnames': strFirstnames, 'vstrSurname': strSurname,'vstrIDNumber':strIDNumber,
                       'vstrEmployeeCode': strEmployeeCode,'vstrReference': strReference,'vstrBranchCode':strBranchCode}

            self.response.write(template.render(context))
    def get(self):
        Guser = users.get_current_user()
        logging.info(msg=" User Rights Called")

        if Guser:
            findRequest = BranchDetails.query()
            branchList = findRequest.fetch()

            URLList = str(self.request.url)

            URLList = URLList.split("/")

            strReference = URLList[len(URLList) - 1]

            findRequest = EmploymentDetails.query(EmploymentDetails.strReference == strReference)
            ThisEmployeeList = findRequest.fetch()

            ThisEmployee = EmploymentDetails()

            if len(ThisEmployeeList) > 0:
                ThisEmployee = ThisEmployeeList[0]
                strUsername = ThisEmployee.readSurname()
                strReference = ThisEmployee.readReference()
                strIDNumber = ThisEmployee.readIDNumber()
                strEmployeeBranch = ThisEmployee.readBranchWorking()
                strFirstname = ThisEmployee.readNames()
                strSurname = ThisEmployee.readSurname()
                strEmployeeCode = ThisEmployee.readEmployeeCode()

                ThisUserRights = UserRights()

                findRequest = UserRights.query(UserRights.strReference == strReference)
                ThisUserRightsList = findRequest.fetch()
                if len(ThisUserRightsList) > 0:
                    ThisUserRights = ThisUserRightsList[0]


                if ThisUserRights.bolIsEmployee:
                    vstrIsEmployee = "YES"
                else:
                    vstrIsEmployee = "NO"

                if ThisUserRights.bolAccessToEmployeesAdminForm:
                    vstrAccessEmployeeAdmin = "YES"
                else:
                    vstrAccessEmployeeAdmin = "NO"

                if ThisUserRights.bolEmployeesFuneralCoverFormReadAccess:
                    vstrSearchCoverPolicy = "YES"
                else:
                    vstrSearchCoverPolicy = "NO"

                if ThisUserRights.bolEmployeesFuneralCoverFormWriteAccess:
                    vstrEditCoverPolicy = "YES"
                else:
                    vstrEditCoverPolicy = "NO"


                if ThisUserRights.bolEmployeesFuneralServicesFormReadAccess:
                    vstrSearchFuneralService = "YES"
                else:
                    vstrSearchFuneralService = "NO"

                if ThisUserRights.bolEmployeesFuneralServicesFormWriteAccess:
                    vstrEditFuneralServices = "YES"
                else:
                    vstrEditFuneralServices = "NO"

                if ThisUserRights.bolEmployeesLeadsFormReadAccess:
                    vstrSearchLeadsForm = "YES"
                else:
                    vstrSearchLeadsForm = "NO"
                if ThisUserRights.bolEmployeesLeadsFormWriteAccess:
                    vstrEditLeadsForm = "YES"
                else:
                    vstrEditLeadsForm = "NO"

                ThisUserRights.writeEmployeeCode(strinput=strEmployeeCode)
                ThisUserRights.writeReference(strinput=strReference)
                ThisUserRights.put()

                template = template_env.get_template('templates/dynamic/admin/thisuserights.html')
                context = {'vstrUsername':strUsername,'vstrReference': strReference, 'vstrIDNumber': strIDNumber,
                           'branches': branchList,'vstrEmployeeBranch': strEmployeeBranch,'vstrEmployeeCode':strEmployeeCode,  'vstrFirstnames': strFirstname,
                           'vstrSurname': strSurname,'vstrIsEmployee': vstrIsEmployee,'vstrAccessEmployeeAdmin':vstrAccessEmployeeAdmin,
                           'vstrSearchCoverPolicy':vstrSearchCoverPolicy,'vstrEditCoverPolicy':vstrEditCoverPolicy,'vstrSearchFuneralService':vstrSearchFuneralService,
                               'vstrEditFuneralServices':vstrEditFuneralServices,'vstrSearchLeadsForm':vstrSearchLeadsForm,
                               'vstrEditLeadsForm':vstrEditLeadsForm}
                self.response.write(template.render(context))

            else:

                findRequest = EmployeeRegRequest.query(EmployeeRegRequest.strReference == strReference)
                EmployeeList = findRequest.fetch()

                EmployeeReq = EmployeeRegRequest()

                if len(EmployeeList) > 0:
                    EmployeeReq = EmployeeList[0]
                    strUsername = EmployeeReq.readEmail()
                    strReference = EmployeeReq.readReference()
                    strIDNumber = EmployeeReq.readIDNumber()
                    strFirstname = ""
                    strSurname = ""
                    strEmployeeBranch = ""


                    findRequest = EmploymentDetails.query()
                    EmployeeListed = findRequest.fetch()

                    NextCode = len(EmployeeListed)
                    NextCode = "E" + str(NextCode)
                    strEmployeeCode = NextCode

                    CodeList = []
                    CodeList.append(NextCode)
                    template = template_env.get_template('templates/dynamic/admin/thisuserights.html')
                    context = {'vstrUsername':strUsername,'vstrReference': strReference, 'vstrIDNumber': strIDNumber,
                               'branches': branchList,'vstrEmployeeBranch': strEmployeeBranch, 'vstrEmployeeCode':strEmployeeCode,
                               'vstrFirstnames': strFirstname,
                               'vstrSurname': strSurname}
                    self.response.write(template.render(context))

                else:
                    pass







        else:
            pass