Exemplo n.º 1
0
    def post(self):

        from mysms import SMSAccount
        from accounts import Accounts, Organization

        #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
        vstrUserID = self.request.get('vstrUserID')
        vstrEmail = self.request.get('vstrEmail')
        vstrAccessToken = self.request.get('vstrAccessToken')

        findRequest = Accounts.query(Accounts.strUserID == vstrUserID)
        thisAccountList = findRequest.fetch()

        if len(thisAccountList) > 0:
            thisAccount = thisAccountList[0]
        else:
            findRequest = Accounts.query(Accounts.strEmail == vstrEmail)
            thisAccountList = findRequest.fetch()

            if len(thisAccountList) > 0:
                thisAccount = thisAccountList[0]
            else:
                thisAccount = Accounts()

        findRequest = SMSAccount.query(
            SMSAccount.strOrganizationID == thisAccount.strOrganizationID)
        thisSMSAccountList = findRequest.fetch()

        if len(thisSMSAccountList) > 0:
            thisSMSAccount = thisSMSAccountList[0]
        else:
            thisSMSAccount = SMSAccount()

        findRequest = Organization.query(
            Organization.strOrganizationID == thisAccount.strOrganizationID)
        thisOrgList = findRequest.fetch()

        if len(thisOrgList) > 0:
            thisOrg = thisOrgList[0]
        else:
            thisOrg = Organization()

        template = template_env.get_template(
            'templates/account/accountinfo.html')
        context = {
            'thisSMSAccount': thisSMSAccount,
            'thisAccount': thisAccount,
            'thisOrg': thisOrg
        }
        self.response.write(template.render(context))
Exemplo n.º 2
0
    def post(self):

        from mysms import SMSAccount
        from accounts import Accounts, Organization
        vstrUserID = self.request.get("vstrUserID")
        vstrUserEmail = self.request.get('vstrUserEmail')
        vstraccessToken = self.request.get('vstraccessToken')

        findRequest = Accounts.query(Accounts.strUserID == vstrUserID)
        thisAccountList = findRequest.fetch()

        if len(thisAccountList) > 0:
            thisAccount = thisAccountList[0]
        else:
            findRequest = Accounts.query(Accounts.strEmail == vstrUserEmail,
                                         Accounts.strVerified == True)
            thisAccountList = findRequest.fetch()

            if len(thisAccountList) > 0:
                thisAccount = thisAccountList[0]
            else:
                thisAccount = Accounts()

        findRequest = SMSAccount.query(
            SMSAccount.strOrganizationID == thisAccount.strOrganizationID)
        thisSMSAccountList = findRequest.fetch()

        if len(thisSMSAccountList) > 0:
            thisSMSAccount = thisSMSAccountList[0]
        else:
            thisSMSAccount = SMSAccount()

        findRequest = Organization.query(
            Organization.strOrganizationID == thisAccount.strOrganizationID)
        thisOrgList = findRequest.fetch()

        if len(thisOrgList) > 0:
            thisOrg = thisOrgList[0]
        else:
            thisOrg = Organization()

        template = template_env.get_template('templates/sms/sub/admin.html')
        context = {
            'thisSMSAccount': thisSMSAccount,
            'thisAccount': thisAccount,
            'thisOrg': thisOrg,
            'vstrUserID': vstrUserID
        }
        self.response.write(template.render(context))
Exemplo n.º 3
0
    def get(self):
        from mysms import SMSPortalVodacom, SMSPortalBudget, SMSAccount
        Guser = users.get_current_user
        if users.is_current_user_admin:

            findRequests = SMSPortalVodacom.query()
            thisSMSPortalVodacomList = findRequests.fetch()

            if len(thisSMSPortalVodacomList) > 0:
                thisVodacomPortal = thisSMSPortalVodacomList[0]
            else:
                thisVodacomPortal = SMSPortalVodacom()

            findRequests = SMSPortalBudget.query()
            thisBudgetPortalList = findRequests.fetch()

            if len(thisBudgetPortalList) > 0:
                thisBudgetPortal = thisBudgetPortalList[0]
            else:
                thisBudgetPortal = SMSPortalBudget()

            findRequests = SMSAccount.query()
            thisSMSAccountList = findRequests.fetch()

            template = template_env.get_template(
                'templates/dashboard/dashfiles/BulkSMS.html')
            context = {
                'thisBudgetPortal': thisBudgetPortal,
                'thisVodacomPortal': thisVodacomPortal,
                'thisSMSAccountList': thisSMSAccountList
            }
            self.response.write(template.render(context))
Exemplo n.º 4
0
    def get(self):
        from events import Birthdays
        from church import ChurchMember
        from mysms import SMSAccount


        findRequest = Birthdays.query()
        thisBirthDaysList = findRequest.fetch()

        thisDate = datetime.datetime.now()
        thisDate = thisDate.now()

        for thisBirthDay in thisBirthDaysList:
            if thisBirthDay.strAutoSend:
                findRequest = ChurchMember.query(ChurchMember.strChurchID == thisBirthDay.strChurchID)
                thisChurchMemberList = findRequest.fetch()

                for thisChurchMember in thisChurchMemberList:
                    if (thisChurchMember.strMonth == thisDate.month) and (thisChurchMember.strDay == thisDate.day) and (thisChurchMember.strCell <> None):
                        findRequest = SMSAccount.query(SMSAccount.strChurchID == thisChurchMember.strChurchID)
                        thisSMSAccountList = findRequest.fetch()

                        if len(thisSMSAccountList) > 0:
                            thisSMSAccount = thisSMSAccountList[0]
                            if (thisSMSAccount.strTotalSMS > 1):
                                if thisBirthDay.SendBirthdayWishes(strMessage=thisBirthDay.strBirthdayMessage,strCell=thisChurchMember.strCell,strPortal=thisSMSAccount.strUsePortal):
                                    if thisSMSAccount.strUsePortal == "Budget":
                                        thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1

                                    thisSMSAccount.put()
                                else:
                                    logging.info("Error sending birthday messages")
                            else:
                                pass
                                #TODO- Send a notification to the user indicating that their SMS Credits are insufficient and notifications can no loner be sent
                        else:
                            pass
                    else:
                        pass
            else:
                pass
Exemplo n.º 5
0
    def post(self):
        from mysms import SMSAccount
        from accounts import Accounts, UserRights, Organization

        vstrChoice = self.request.get('vstrChoice')

        if vstrChoice == "0":

            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')
            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = PresentCredits.query(
                    PresentCredits.strUserID == vstrUserID)
                CreditList = findRequest.fetch()

                findRequest = Affiliate.query(
                    Affiliate.strUserID == vstrUserID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]

                    findRequest = SMSMarket.query()
                    SMSMarketList = findRequest.fetch()

                    if len(SMSMarketList) > 0:
                        thisSMSMarket = SMSMarketList[0]
                    else:
                        thisSMSMarket = SMSMarket()

                    findRequest = TransactionHistory.query(
                        TransactionHistory.strUserID == vstrUserID)
                    thisTransactionList = findRequest.fetch()
                else:
                    thisAffiliate = Affiliate()
                    thisSMSMarket = SMSMarket()
                    thisTransactionList = []

                template = template_env.get_template(
                    'templates/affiliate/sub/credits.html')
                context = {
                    'CreditList': CreditList,
                    'thisAffiliate': thisAffiliate,
                    'thisSMSMarket': thisSMSMarket,
                    'thisTransactionList': thisTransactionList
                }
                self.response.write(template.render(context))

        elif vstrChoice == "1":

            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = Affiliate.query(
                    Affiliate.strUserID == vstrUserID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]
                else:
                    thisAffiliate = Affiliate()

                findRequest = MyAffiliates.query(
                    MyAffiliates.strUserID == vstrUserID)
                thisMyAffiliatesList = findRequest.fetch()

                template = template_env.get_template(
                    'templates/affiliate/sub/Accountdetails.html')
                context = {
                    'thisAffiliate': thisAffiliate,
                    'thisMyAffiliatesList': thisMyAffiliatesList
                }
                self.response.write(template.render(context))

        elif vstrChoice == "2":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                vstrAffiliateLink = self.request.get('vstrAffiliateLink')

                findRequest = Affiliate.query(
                    Affiliate.strAffiliateLink == vstrAffiliateLink)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    self.response.write("NO")
                else:
                    self.response.write("YES")

        elif vstrChoice == "3":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrAffiliateLink = self.request.get('vstrAffiliateLink')
            vstrPaymentMethod = self.request.get('vstrPaymentMethod')
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = Affiliate.query(
                    Affiliate.strAffiliateLink == vstrAffiliateLink)
                thisAffiliateLinkList = findRequest.fetch()

                if len(thisAffiliateLinkList) > 0:
                    thisLinkAffiliate = thisAffiliateLinkList[0]

                    findRequest = Affiliate.query(
                        Affiliate.strUserID == vstrUserID)
                    thisAffiliateList = findRequest.fetch()

                    if len(thisAffiliateList) > 0:
                        thisAffiliate = thisAffiliateList[0]

                        if thisLinkAffiliate.strUserID == thisAffiliate.strUserID:
                            thisAffiliate.writeAffiliateLink(
                                strinput=vstrAffiliateLink)
                            thisAffiliate.writePaymentMethod(
                                strinput=vstrPaymentMethod)
                            thisAffiliate.put()
                            self.response.write(
                                "Successfully updated Affiliate Account")
                        else:
                            self.response.write(
                                "you cannot change your Affiliate Link as the one you are choosing has already been used or you have already changed your affiliate link"
                            )
                    else:
                        self.response.write(
                            "Fatal Error your affiliate account isnt configured"
                        )
                else:
                    findRequest = Affiliate.query(
                        Affiliate.strUserID == vstrUserID)
                    thisAffiliateList = findRequest.fetch()

                    if len(thisAffiliateList) > 0:
                        thisAffiliate = thisAffiliateList[0]
                        thisAffiliate.writeAffiliateLink(
                            strinput=vstrAffiliateLink)
                        thisAffiliate.writePaymentMethod(
                            strinput=vstrPaymentMethod)
                        thisAffiliate.put()
                        self.response.write(
                            "Successfully updated Affiliate Account")
                    else:
                        self.response.write(
                            "Fatal Error Affiliate account not found")

        elif vstrChoice == "4":
            vstrSpendCredit = self.request.get('vstrSpendCredit')

            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = SMSAccount.query(
                    SMSAccount.strOrganizationID ==
                    thisMainAccount.strOrganizationID)
                thisSMSAccountList = findRequest.fetch()

                if len(thisSMSAccountList) > 0:
                    thisSMSAccount = thisSMSAccountList[0]

                    findRequest = Affiliate.query(
                        Affiliate.strUserID == vstrUserID)
                    thisAffiliateList = findRequest.fetch()

                    if len(thisAffiliateList) > 0:
                        thisAffiliate = thisAffiliateList[0]

                        if (not (vstrSpendCredit == None)) and (
                                thisAffiliate.strAvailableCredit >=
                                int(vstrSpendCredit)):

                            if thisSMSAccount.AddTotalSMS(
                                    strinput=vstrSpendCredit):
                                thisAffiliate.strAvailableCredit -= int(
                                    vstrSpendCredit)
                                thisSMSAccount.put()
                                thisAffiliate.put()
                                self.response.write(
                                    "Successfully bought SMS Credits for your organization main SMS Account"
                                )
                        else:
                            self.response.write(
                                "Spend Credit Error or not enough Available Credits"
                            )
                else:
                    self.response.write(
                        "SMS Account not found error Buying Credits")

        elif vstrChoice == "5":
            vstrWithdrawalAmount = self.request.get('vstrWithdrawalAmount')
            vstrSelectMethod = self.request.get('vstrSelectMethod')
            vstrWithDrawCredit = self.request.get('vstrWithDrawCredit')
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;

            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = Affiliate.query(
                    Affiliate.strUserID == thisMainAccount.strUserID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]

                    if thisAffiliate.strAvailableCredit <= int(
                            vstrWithDrawCredit):
                        thisAffiliate.strAvailableCredit -= int(
                            vstrWithDrawCredit)
                        thisWithDrawalRequest = WithdrawalRequests()
                        thisWithDrawalRequest.writeUserID(
                            strinput=thisMainAccount.strUserID)
                        vstrWithdrawalAmount = str(vstrWithdrawalAmount)
                        if not (vstrWithdrawalAmount == "0"):
                            vstrWithdrawalAmount = float(vstrWithdrawalAmount)
                            thisWithDrawalRequest.writeAmount(
                                strinput=vstrWithdrawalAmount)
                            strThisDateTime = datetime.datetime.now()
                            strThisDate = strThisDateTime.date()
                            strThisTime = strThisDateTime.time()
                            strThisProcessDate = strThisDateTime
                            strThisProcessDate += datetime.timedelta(days=3)
                            strThisProcessDate = strThisProcessDate.date()

                            thisWithDrawalRequest.writeDateCreated(
                                strinput=strThisDate)
                            thisWithDrawalRequest.writeTimeCreated(
                                strinput=strThisTime)
                            thisWithDrawalRequest.writeDateToProcess(
                                strinput=strThisProcessDate)
                            thisWithDrawalRequest.writeMethod(
                                strinput=vstrSelectMethod)
                            thisWithDrawalRequest.writeWithdrawalID(
                                strinput=thisWithDrawalRequest.
                                CreateWithDrawalID())
                            thisWithDrawalRequest.put()
                            thisAffiliate.put()
                            self.response.write(
                                "Successffully processed your withdrawal Requests your withdrawal can take up to three business days to be finalized"
                            )
                        else:
                            self.response.write(
                                "Cannot process withdrawal please check your withdrawal amount"
                            )
                    else:
                        self.response.write(
                            "You do not have enough credit to process this withdrawal request"
                        )
                else:
                    self.response.write("Error with your affiliate account")

        elif vstrChoice == "6":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;

            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = Affiliate.query(
                    Affiliate.strUserID == thisMainAccount.strUserID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]

                    findRequest = HitCounter.query(
                        HitCounter.strAffiliateLink ==
                        thisAffiliate.strAffiliateLink)
                    thisHitCountersList = findRequest.fetch()

                    if len(thisHitCountersList) > 0:
                        thisHitCounter = thisHitCountersList[0]
                    else:
                        thisHitCounter = HitCounter()

                    template = template_env.get_template(
                        'templates/affiliate/sub/statistics.html')
                    context = {'thisHitCounter': thisHitCounter}
                    self.response.write(template.render(context))

        elif vstrChoice == "7":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;

            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):
                findRequest = Affiliate.query(
                    Affiliate.strUserID == vstrUserID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]
                    findRequest = MyFacebook.query(
                        MyFacebook.strUserID == vstrUserID)
                    thisFacebookList = findRequest.fetch()

                    if len(thisFacebookList) > 0:
                        thisFacebook = thisFacebookList[0]
                    else:
                        thisFacebook = MyFacebook()
                        thisFacebook.writeAffiliateLink(
                            strinput=thisAffiliate.strAffiliateLink)
                        thisFacebook.writeUserID(strinput=vstrUserID)
                        thisFacebook.put()

                    template = template_env.get_template(
                        'templates/affiliate/sub/social.html')
                    context = {'thisSocial': thisFacebook}
                    self.response.write(template.render(context))

        elif vstrChoice == "8":
            vstrFacebook = self.request.get('vstrFacebook')
            vstrFacebookCodeSecret = self.request.get('vstrFacebookCodeSecret')
            vstrGroupIDs = self.request.get('vstrGroupIDs')
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')
            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                vstrGroupList = vstrGroupIDs.split(",")

                vstrGroupStr = ""

                for GroupID in vstrGroupList:
                    vstrGroupStr = vstrGroupStr + "," + GroupID

                findRequest = MyFacebook.query(
                    MyFacebook.strUserID == vstrUserID)
                thisFacebookList = findRequest.fetch()

                if len(thisFacebookList) > 0:
                    thisFacebook = thisFacebookList[0]
                else:
                    thisFacebook = MyFacebook()

                thisFacebook.writeUserID(strinput=vstrUserID)
                thisFacebook.writeFacebookAPI(strinput=vstrFacebook)
                thisFacebook.writeFacebookSecretCode(
                    strinput=vstrFacebookCodeSecret)
                thisFacebook.writeFacebookGroupIDList(strinput=vstrGroupStr)
                thisFacebook.put()
                self.response.write("Facebook Settings successfully saved")

        elif vstrChoice == "9":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
            vstrUserID = self.request.get('vstrUserID')
            vstrEmail = self.request.get('vstrEmail')
            vstrAccessToken = self.request.get('vstrAccessToken')

            thisMainAccount = VerifyAndReturnAccount(
                strUserID=vstrUserID, strAccessToken=vstrAccessToken)

            if (thisMainAccount != None) and (thisMainAccount.strEmail
                                              == vstrEmail):

                findRequest = Organization.query(
                    Organization.strOrganizationID ==
                    thisMainAccount.strOrganizationID)
                thisOrgList = findRequest.fetch()

                if len(thisOrgList) > 0:
                    thisOrg = thisOrgList[0]
                else:
                    thisOrg = Organization()

                findRequest = Affiliate.query(
                    Affiliate.strOrganizationID ==
                    thisMainAccount.strOrganizationID)
                thisAffiliateList = findRequest.fetch()

                if len(thisAffiliateList) > 0:
                    thisAffiliate = thisAffiliateList[0]
                else:
                    thisAffiliate = Affiliate()
                    thisAffiliate.writeUserID(strinput=vstrUserID)
                    thisAffiliate.writeOrganizationID(
                        strinput=thisMainAccount.strOrganizationID)
                    thisAffiliate.writeAffiliateLink(
                        thisAffiliate.CreateAffiliateLink())
                    thisAffiliate.put()

                template = template_env.get_template(
                    'templates/affiliate/sub/submenu.html')
                context = {'thisAffiliate': thisAffiliate, 'thisOrg': thisOrg}
                self.response.write(template.render(context))

        #Ipdate Twitter
        elif vstrChoice == "10":
            pass
Exemplo n.º 6
0
    def get(self):

        from dashboard import AppRequests,BlueITMarketingAdminStaff
        from mysms import SMSAccount,SMSPortalVodacom,SMSPortalBudget

        findRequests = AppRequests.query(AppRequests.strRequestAccepted == False,AppRequests.strNotificationSent == False)
        thisAppRequestList = findRequests.fetch()

        findRequests = BlueITMarketingAdminStaff.query(BlueITMarketingAdminStaff.strPosition == "Admin",BlueITMarketingAdminStaff.strPosition == "Marketing")
        thisBlueStaffList = findRequests.fetch()

        strTotalRequests = len(thisAppRequestList)

        findRequests = SMSPortalVodacom.query()
        thisVodaPortalList = findRequests.fetch()

        if len(thisVodaPortalList) > 0:
            thisVoda = thisVodaPortalList[0]
        else:
            thisVoda = SMSPortalVodacom()


        findRequests = SMSPortalBudget.query()
        thisBudgetPortalList = findRequests.fetch()

        if len(thisBudgetPortalList) > 0:
            thisBudget = thisBudgetPortalList[0]
        else:
            thisBudget = SMSPortalBudget()

        strMessage = "Church Admin" + "%0A"
        strNotifications = "System Notifications" + "%0A"
        NewClients  ="New Clients : " + str(strTotalRequests) + "%0A"
        Vodacom_Credit ="Vodacom Credit : " + str(thisVoda.strAvailableCredit) + "%0A"
        Budget_Credit = "Budget Credit : " + str(thisBudget.CheckCredits())

        strMessage = strMessage + strNotifications + NewClients  + Vodacom_Credit + Budget_Credit




        thisAdminStaff = BlueITMarketingAdminStaff()
        findRequests = SMSAccount.query(SMSAccount.strChurchID == thisAdminStaff.strStaffID)
        thisSMSAccountList = findRequests.fetch()

        if len(thisSMSAccountList) > 0:
            thisSMSAccount = thisSMSAccountList[0]
        else:
            thisSMSAccount = SMSAccount()

        ReceipientList = []

        if len(thisBlueStaffList) > 0:
            for thisStaff in thisBlueStaffList:
                ReceipientList.append(thisStaff.strCell)

        if "0790471559" in ReceipientList:
            pass
        else:
            ReceipientList.append("0790471559")


        if thisSMSAccount.strUsePortal == "Vodacom":
            findRequests = SMSPortalVodacom.query()
            thisVodaPortalList = findRequests.fetch()

            if len(thisVodaPortalList) > 0:
                Voda = thisVodaPortalList[0]
            else:
                Voda = SMSPortalVodacom()
                Voda.put()

            if Voda.CronSendMessages(strCellNumberList=ReceipientList,strMessage=strMessage,strAccountID=thisAdminStaff.strStaffID):
                logging.info("Successfully sent system messages")
            else:
                logging.info("Error sending system messages")

        elif thisSMSAccount.strUsePortal == "Budget":

            for thisNumber in ReceipientList:
                thisBudget.SendCronMessage(strCell=thisNumber,strMessage=strMessage)
                thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1
            thisSMSAccount.put()
Exemplo n.º 7
0
    def get(self):
        from meetings import Meeting,Attendees
        from mysms import SMSAccount,SMSPortalVodacom,SMSPortalBudget

        thisDate = datetime.datetime.now()
        UpComingDate = thisDate - timedelta(days=1)
        findRequest = Meeting.query(Meeting.strDateMeetingSchedule == thisDate)
        thisTodaysMeetingList = findRequest.fetch()

        for thisMeeting in thisTodaysMeetingList:

            if thisMeeting.strTodaysNotificationSent == False:
                findRequest = SMSAccount.query(SMSAccount.strChurchID == thisMeeting.strChurchID)
                thisSMSAccountList = findRequest.fetch()

                if len(thisSMSAccountList) > 0:
                    thisSMSAccount = thisSMSAccountList[0]

                    strMessage = "Meeting Reminder" + "%0A"
                    Subject = thisMeeting.strSubjectOfMeeting + "%0A"
                    Venue =  thisMeeting.strMeetingVenue + "%0A"
                    Facilitator = thisMeeting.strFacilitatorName + " " +   thisMeeting.strFacilitatorSurname + "%0A"
                    Cell =  thisMeeting.strFacilitatorCell + "%0A"
                    Time = thisMeeting.strTimeMeetingScheduled + "%0A"
                    ThanksMessage = " Thank You " +  "%0A" + "Church Admin Team"
                    strMessage = strMessage + Subject + Venue + Facilitator + Cell + Time + ThanksMessage

                    findRequest = Attendees.query(Attendees.strMeetingID == thisMeeting.strMeetingID)
                    thisAttendeesList = findRequest.fetch()

                    ReceipientList = []
                    for thisAttendee in thisAttendeesList:
                        if thisAttendee.strCell <> None:
                            ReceipientList.append(thisAttendee.strCell)

                    ReceipientList.append(thisMeeting.strFacilitatorCell)

                    if thisSMSAccount.strTotalSMS >= len(ReceipientList):

                        if thisSMSAccount.strUsePortal == "Vodacom":

                            findRequests = SMSPortalVodacom.query()
                            thisVodaPortalList = findRequests.fetch()

                            if len(thisVodaPortalList) > 0:
                                thisVoda = thisVodaPortalList()
                            else:
                                thisVoda = SMSPortalVodacom()
                                thisVoda.put()


                            if thisVoda.CronSendMessages(strCellNumberList=ReceipientList, strMessage=strMessage,strAccountID=thisSMSAccount.strChurchID):
                                logging.info("Meeting Reminder Messages successfully sent")
                            else:
                                logging.info("Failure sending Meeting Reminder messages")

                            # thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - len(ReceipientList)
                            # Vodacom Portal Subtracts its own credits

                        elif thisSMSAccount.strUsePortal == "Budget":
                            findRequest = SMSPortalBudget.query()
                            thisPortalList = findRequest.fetch()

                            if len(thisPortalList) > 0:
                                thisPortal = thisPortalList[0]
                            else:
                                thisPortal = SMSPortalBudget()

                            for thisCell in ReceipientList:
                                findRequest = Attendees.query(Attendees.strChurchID == thisSMSAccount.strChurchID,Attendees.strCell == thisCell)
                                thisAttendeeList = findRequest.fetch()

                                if len(thisAttendeeList) > 0:
                                    thisAttendee = thisAttendeeList[0]
                                else:
                                    thisAttendee = Attendees()

                                strRef = thisPortal.SendCronMessage(strMessage=strMessage,strCell=thisCell)
                                if not(strRef == None):
                                    thisAttendee.writeRef(strinput=strRef)
                                    thisAttendee.put()
                                    thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1

                        thisSMSAccount.put()


                thisMeeting.strTodaysNotificationSent = True
                thisMeeting.put()


        #TODO-Upcoming Meetings Reminder

        findRequest = Meeting.query(Meeting.strDateMeetingSchedule == UpComingDate)
        thisUpcomingMeetingsList = findRequest.fetch()

        for thisMeeting in thisUpcomingMeetingsList:

            if thisMeeting.strUpcomingNotificationSent == False:
                findRequest = SMSAccount.query(SMSAccount.strChurchID == thisMeeting.strChurchID)
                thisSMSAccountList = findRequest.fetch()

                if len(thisSMSAccountList) > 0:
                    thisSMSAccount = thisSMSAccountList[0]

                    strMessage = "Upcoming Meeting Reminder" + "%0A"
                    Subject = thisMeeting.strSubjectOfMeeting + "%0A"
                    Venue =  thisMeeting.strMeetingVenue + "%0A"
                    Facilitator = thisMeeting.strFacilitatorName + " " +   thisMeeting.strFacilitatorSurname + "%0A"
                    Cell =  thisMeeting.strFacilitatorCell + "%0A"
                    Date = thisMeeting.strDateMeetingSchedule + "%0A"
                    Time = thisMeeting.strTimeMeetingScheduled + "%0A"
                    ThanksMessage = " Thank You " +  "%0A" + "Church Admin Team"
                    strMessage = strMessage + Subject + Venue + Facilitator + Cell + Date + Time + ThanksMessage

                    findRequest = Attendees.query(Attendees.strMeetingID == thisMeeting.strMeetingID)
                    thisAttendeesList = findRequest.fetch()

                    ReceipientList = []
                    for thisAttendee in thisAttendeesList:
                        if thisAttendee.strCell != None:
                            ReceipientList.append(thisAttendee.strCell)

                    ReceipientList.append(thisMeeting.strFacilitatorCell)

                    if thisSMSAccount.strUsePortal == "Vodacom":
                        findRequests = SMSPortalVodacom.query()
                        thisVodaPortalList = findRequests.fetch()

                        if len(thisVodaPortalList) > 0:
                            thisVoda = thisVodaPortalList()
                        else:
                            thisVoda = SMSPortalVodacom()
                            thisVoda.put()


                        if thisVoda.CronSendMessages(strCellNumberList=ReceipientList,strMessage=strMessage,strAccountID=thisSMSAccount.strChurchID):
                            logging.info("Upcoming Meeting Reminders Sent")
                        else:
                            logging.info("Upcoming Meeting Reminders Not Sent")
                            #TODO- Notify the user via SMS to buy more credits and his meeting notifications will no longer be sent

                    elif thisSMSAccount.strUsePortal == "Budget":
                        findRequest = SMSPortalBudget.query()
                        thisPortalList = findRequest.fetch()

                        if len(thisPortalList) > 0:
                            thisPortal = thisPortalList[0]
                        else:
                            thisPortal = SMSPortalBudget()

                        for thisCell in ReceipientList:
                            findRequest = Attendees.query(Attendees.strChurchID == thisSMSAccount.strChurchID,Attendees.strCell == thisCell)
                            thisAttendeeList = findRequest.fetch()

                            if len(thisAttendeeList) > 0:
                                thisAttendee = thisAttendeeList[0]
                            else:
                                thisAttendee = Attendees()

                            strRef = thisPortal.SendCronMessage(strMessage=strMessage,strCell=thisCell)
                            if not(strRef == None):
                                thisAttendee.writeRef(strinput=strRef)
                                thisAttendee.put()
                                thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1

                    thisSMSAccount.put()

                    thisMeeting.strUpcomingNotificationSent = True
                    thisMeeting.put()
Exemplo n.º 8
0
    def get(self):
        from mysms import MessageSchedule, Messages, SMSContacts, Groups, SMSAccount, SMSPortalVodacom, DeliveryReport,SMSPortalBudget
        from church import ChurchMember
        Today = datetime.datetime.now()
        thisDate = Today.date()
        thisTime = Today.time()

        findRequest = MessageSchedule.query(MessageSchedule.strStatus == "Scheduled",
                                            MessageSchedule.strStartDate == thisDate,
                                            MessageSchedule.strStartTime >= thisTime)
        thisMessageScheduleList = findRequest.fetch()

        for thisSchedule in thisMessageScheduleList:
            findRequest = Messages.query(Messages.strMessageID == thisSchedule.strMessageID,
                                         Messages.strSubmitted == False)
            thisMessageList = findRequest.fetch()

            if len(thisMessageList) > 0:
                thisMessage = thisMessageList[0]
            else:
                thisMessage = Messages()

            findRequest = Groups.query(Groups.strGroupID == thisMessage.strGroupID)
            thisGroupList = findRequest.fetch()

            if len(thisGroupList) > 0:
                thisGroup = thisGroupList[0]
            else:
                thisGroup = Groups()

            findRequest = SMSAccount.query(SMSAccount.strChurchID == thisGroup.strChurchID)
            thisSMSAccountList = findRequest.fetch()

            if len(thisSMSAccountList) > 0:
                thisSMSAccount = thisSMSAccountList[0]
            else:
                thisSMSAccount = SMSAccount()
                thisSMSAccount.writeChurchID(strinput=thisGroup.strChurchID)
                thisSMSAccount.put()

            findRequest = SMSContacts.query(SMSContacts.strGroupID == thisMessage.strGroupID)
            thisContactsList = findRequest.fetch()

            ReceipientList = []
            for thisContact in thisContactsList:
                if thisContact.strCellNumber != None:
                    ReceipientList.append(thisContact.strCellNumber)

            if thisSchedule.strNotifyOnStart == True:
                findRequest = ChurchMember.query(ChurchMember.strMemberID == thisSchedule.strMemberID)
                thisChurchMemberList = findRequest.fetch()

                if len(thisChurchMemberList) > 0:
                    thisChurchMember = thisChurchMemberList[0]
                    if thisChurchMember.strCell in ReceipientList:
                        pass
                    else:
                        ReceipientList.append(thisChurchMember.strCell)

            if thisSMSAccount.strTotalSMS >= len(ReceipientList):
                if thisSMSAccount.strUsePortal == "Vodacom":
                    findRequest = SMSPortalVodacom.query()
                    thisVodaList = findRequest.fetch()

                    if len(thisVodaList) > 0:
                        thisVoda = thisVodaList[0]
                    else:
                        thisVoda = SMSPortalVodacom()
                        thisVoda.put()

                    if thisVoda.CronSendMessages(strCellNumberList=ReceipientList, strMessage=thisMessage.strMessage,
                                                 strAccountID=thisSMSAccount.strChurchID):
                        thisSchedule.writeStatus(strinput="Completed")
                        thisSchedule.put()
                        thisMessage.writeDateSubmitted(strinput=thisDate)
                        thisMessage.writeTimeSubmitted(strinput=thisTime)
                        thisMessage.writeSubmitted(strinput=True)
                        thisMessage.put()
                        for StrCell in ReceipientList:
                            #TODO- Investigate if Vodacom uses cell number for reference to obtain response
                            thisDeliveryReport = DeliveryReport()
                            thisDeliveryReport.writeMessageID(strinput=thisMessage.strMessageID)
                            thisDeliveryReport.writeGroupID(strinput=thisMessage.strGroupID)
                            thisDeliveryReport.writeCell(strinput=StrCell)
                            thisDeliveryReport.writeDate(strinput=thisDate)
                            thisDeliveryReport.writeTime(strinput=thisTime)
                            thisDeliveryReport.writeDelivered(strinput=True)
                            thisDeliveryReport.put()
                        logging.info("Bulk SMS Schedule executed")

                        # thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - len(ReceipientList)
                        # Vodacom Portal Subtracts its own Credits


                elif thisSMSAccount.strUsePortal == "Budget":
                    findRequest = SMSPortalBudget.query()
                    thisPortalList = findRequest.fetch()

                    if len(thisPortalList) > 0:
                        thisPortal = thisPortalList[0]
                    else:
                        thisPortal = SMSPortalBudget()

                    for thisCell in ReceipientList:
                        strRef = thisPortal.SendCronMessage(strMessage=thisMessage.strMessage,strCell=thisCell)
                        if not(strRef == None):
                            thisDeliveryReport = DeliveryReport()
                            thisDeliveryReport.writeMessageID(strinput=thisMessage.strMessageID)
                            thisDeliveryReport.writeGroupID(strinput=thisMessage.strGroupID)
                            thisDeliveryReport.writeCell(strinput=thisCell)
                            thisDeliveryReport.writeRef(strinput=strRef)
                            thisDeliveryReport.writeDate(strinput=thisDate)
                            thisDeliveryReport.writeTime(strinput=thisTime)
                            thisDeliveryReport.writeDelivered(strinput=True)
                            thisDeliveryReport.put()
                            thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1
                        else:
                            thisDeliveryReport = DeliveryReport()
                            thisDeliveryReport.writeMessageID(strinput=thisMessage.strMessageID)
                            thisDeliveryReport.writeGroupID(strinput=thisMessage.strGroupID)
                            thisDeliveryReport.writeCell(strinput=thisCell)
                            thisDeliveryReport.writeRef(strinput="")
                            thisDeliveryReport.writeDate(strinput=thisDate)
                            thisDeliveryReport.writeTime(strinput=thisTime)
                            thisDeliveryReport.writeDelivered(strinput=False)
                            thisDeliveryReport.put()


                    thisMessage.writeDateSubmitted(strinput=thisDate)
                    thisMessage.writeTimeSubmitted(strinput=thisTime)
                    thisMessage.writeSubmitted(strinput=True)
                    thisMessage.put()



                            #TODO- Include Budget Sending Capability to enable the Messages to be sent on schedule

                thisSMSAccount.put()
    def post(self):

        Guser = users.get_current_user()
        from church import ChurchMember, UserRights
        if Guser:

            findRequests = ChurchMember.query(
                ChurchMember.strMemberID == Guser.user_id())
            thisChurchMemberList = findRequests.fetch()

            if len(thisChurchMemberList) > 0:
                thisChurchMember = thisChurchMemberList[0]
            else:
                thisChurchMember = ChurchMember()

            findRequests = UserRights.query(
                UserRights.strMemberID == Guser.user_id())
            thisUserRightsList = findRequests.fetch()

            if len(thisUserRightsList) > 0:
                thisUserRight = thisUserRightsList[0]
            else:
                thisUserRight = UserRights()

            if thisUserRight.strAdminUser or thisUserRight.strSuperUser:
                vstrChoice = self.request.get('vstrChoice')

                if vstrChoice == "0":
                    vstrCell = self.request.get('vstrCell')

                    findRequests = Contacts.query(
                        Contacts.strCell == vstrCell,
                        Contacts.strChurchID == thisChurchMember.strChurchID)
                    thisContactList = findRequests.fetch()

                    if len(thisContactList) > 0:
                        thisContact = thisContactList[0]
                    else:
                        thisContact = Contacts()

                    findRequests = Notes.query(
                        Notes.strContactID == thisContact.strContactID)
                    thisNotesList = findRequests.fetch()

                    findRequests = PostalAddress.query(
                        PostalAddress.strContactID == thisContact.strContactID)
                    thisPostalAddressList = findRequests.fetch()

                    if len(thisPostalAddressList) > 0:
                        thisPostalAddress = thisPostalAddressList[0]
                    else:
                        thisPostalAddress = PostalAddress()
                        thisPostalAddress.writeContactID(
                            strinput=thisContact.strContactID)
                        thisPostalAddress.writeChurchID(
                            strinput=thisContact.strChurchID)
                        thisPostalAddress.put()

                    findRequests = PhysicalAddress.query(
                        PhysicalAddress.strContactID ==
                        thisContact.strContactID)
                    thisPhysicalAddressList = findRequests.fetch()

                    if len(thisPhysicalAddressList) > 0:
                        thisPhysicalAddress = thisPhysicalAddressList[0]
                    else:
                        thisPhysicalAddress = PhysicalAddress()
                        thisPhysicalAddress.writeContactID(
                            strinput=thisContact.strContactID)
                        thisPhysicalAddress.writeChurchID(
                            strinput=thisContact.strChurchID)
                        thisPhysicalAddress.put()

                    template = template_env.get_template(
                        'templates/contacts/sub/manage.html')
                    context = {
                        'thisContact': thisContact,
                        'thisNotesList': thisNotesList,
                        'thisPostalAddress': thisPostalAddress,
                        'thisPhysicalAddress': thisPhysicalAddress
                    }
                    self.response.write(template.render(context))

                elif vstrChoice == "1":

                    vstrContactID = self.request.get('vstrContactID')
                    vstrPostalCode = self.request.get('vstrPostalCode')
                    vstrCountry = self.request.get('vstrCountry')
                    vstrProvince = self.request.get('vstrProvince')
                    vstrCityTown = self.request.get('vstrCityTown')
                    vstrBox = self.request.get('vstrBox')

                    findRequests = PostalAddress.query(
                        PostalAddress.strContactID == vstrContactID)
                    thisPostalAddressList = findRequests.fetch()

                    if len(thisPostalAddressList) > 0:
                        thisPostalAddress = thisPostalAddressList[0]
                    else:
                        thisPostalAddress = PostalAddress()

                    thisPostalAddress.writeChurchID(
                        strinput=thisChurchMember.strChurchID)
                    thisPostalAddress.writeContactID(strinput=vstrContactID)
                    thisPostalAddress.writeBox(strinput=vstrBox)
                    thisPostalAddress.writeCityTown(strinput=vstrCityTown)
                    thisPostalAddress.writeProvince(strinput=vstrProvince)
                    thisPostalAddress.writeCountry(strinput=vstrCountry)
                    thisPostalAddress.writePostalCode(strinput=vstrPostalCode)
                    thisPostalAddress.put()

                    self.response.write("Postal Address updated successfully")

                elif vstrChoice == "2":
                    vstrSubject = self.request.get('vstrSubject')
                    vstrNotes = self.request.get('vstrNotes')
                    vstrContactID = self.request.get('vstrContactID')

                    findRequests = Notes.query(
                        Notes.strContactID == vstrContactID,
                        Notes.strSubject == vstrSubject,
                        Notes.strNotes == vstrNotes)
                    thisNotesList = findRequests.fetch()

                    if len(thisNotesList) > 0:
                        thisNote = thisNotesList[0]
                    else:
                        thisNote = Notes()

                    thisNote.writeContactID(strinput=vstrContactID)
                    thisNote.writeChurchID(
                        strinput=thisChurchMember.strChurchID)
                    thisDate = datetime.datetime.now()
                    thisDate = thisDate.date()
                    thisNote.writeDateTaken(strinput=thisDate)
                    thisTime = datetime.datetime.now()
                    thisTime = thisTime.time()
                    thisTime = datetime.time(hour=thisTime.hour,
                                             minute=thisTime.minute,
                                             second=thisTime.second)
                    thisNote.writeTimeTaken(strinput=thisTime)
                    thisNote.writeSubject(strinput=vstrSubject)
                    thisNote.writeNotes(strinput=vstrNotes)
                    thisNote.put()

                    self.response.write("Note successfully uploaded")

                elif vstrChoice == "3":
                    vstrContactID = self.request.get('vstrContactID')
                    vstrStandNumber = self.request.get('vstrStandNumber')
                    vstrStreetName = self.request.get('vstrStreetName')
                    vstrPhyCityTown = self.request.get('vstrPhyCityTown')
                    vstrPhyProvince = self.request.get('vstrPhyProvince')
                    vstrPhyCountry = self.request.get('vstrPhyCountry')
                    vstrPhyPostalCode = self.request.get('vstrPhyPostalCode')

                    findRequests = PhysicalAddress.query(
                        PhysicalAddress.strContactID == vstrContactID)
                    thisPhysicalAddressList = findRequests.fetch()

                    if len(thisPhysicalAddressList) > 0:
                        thisPhysicalAddress = thisPhysicalAddressList[0]
                    else:
                        thisPhysicalAddress = PhysicalAddress()

                    thisPhysicalAddress.writeContactID(strinput=vstrContactID)
                    thisPhysicalAddress.writeChurchID(
                        strinput=thisChurchMember.strChurchID)
                    thisPhysicalAddress.writeStandNumber(
                        strinput=vstrStandNumber)
                    thisPhysicalAddress.writeStreetName(
                        strinput=vstrStreetName)
                    thisPhysicalAddress.writeCityTown(strinput=vstrPhyCityTown)
                    thisPhysicalAddress.writeProvince(strinput=vstrPhyProvince)
                    thisPhysicalAddress.writeCountry(strinput=vstrPhyCountry)
                    thisPhysicalAddress.writePostalCode(
                        strinput=vstrPhyPostalCode)

                    thisPhysicalAddress.put()

                    self.response.write(
                        "Physical Address successfully updated")

                elif vstrChoice == "4":
                    vstrCell = self.request.get('vstrCell')

                    findRequests = Contacts.query(
                        Contacts.strChurchID == thisChurchMember.strChurchID,
                        Contacts.strCell == vstrCell)
                    thisContactList = findRequests.fetch()

                    if len(thisContactList) > 0:
                        thisContact = thisContactList[0]
                    else:
                        thisContact = Contacts()

                    findRequests = SMSInBox.query(
                        SMSInBox.strContactID == thisContact.strContactID)
                    thisInBoxMessagesList = findRequests.fetch()

                    findRequests = SMSOutBox.query(
                        SMSOutBox.strContactID == thisContact.strContactID)
                    thisSMSOutBoxList = findRequests.fetch()

                    template = template_env.get_template(
                        'templates/contacts/sub/sms.html')
                    context = {
                        'thisInBoxMessagesList': thisInBoxMessagesList,
                        'thisSMSOutBoxList': thisSMSOutBoxList,
                        'thisContact': thisContact
                    }
                    self.response.write(template.render(context))

                elif vstrChoice == "5":
                    from mysms import SMSAccount, SMSPortalVodacom, SMSPortalBudget, DeliveryReport
                    vstrMessage = self.request.get('vstrMessage')
                    vstrContactID = self.request.get('vstrContactID')
                    vstrCell = self.request.get('vstrCell')

                    findRequest = SMSAccount.query(
                        SMSAccount.strChurchID == thisChurchMember.strChurchID)
                    thisSMSAccountList = findRequest.fetch()
                    if len(thisSMSAccountList) > 0:
                        thisSMSAccount = thisSMSAccountList[0]
                    else:
                        thisSMSAccount = SMSAccount()

                    if thisSMSAccount.strUsePortal == "Vodacom":

                        findRequest = SMSPortalVodacom.query()
                        thisPortalList = findRequest.fetch()

                        if len(thisPortalList) > 0:
                            thisPortal = thisPortalList[0]
                        else:
                            thisPortal = SMSPortalVodacom()

                        i = 0

                        message = mail.EmailMessage()
                        message.sender = thisPortal.strSenderAddress
                        message.to = thisPortal.strEmailAddress
                        message.subject = vstrCell
                        message.body = vstrMessage
                        message.send()
                        thisPortal.strAvailableCredit = thisPortal.strAvailableCredit - 1

                        thisDeliveryReport = DeliveryReport()
                        thisDeliveryReport.writeGroupID(vstrContactID)
                        thisDeliveryReport.writeCell(vstrCell)
                        thisDeliveryReport.writeDelivered(strinput=True)
                        thisDate = datetime.datetime.now()
                        strThisDate = thisDate.date()
                        strThisTime = thisDate.time()
                        strThisTime = datetime.time(hour=strThisTime.hour,
                                                    minute=strThisTime.minute,
                                                    second=strThisTime.second)
                        thisDeliveryReport.writeDate(strinput=strThisDate)
                        thisDeliveryReport.writeTime(strinput=strThisTime)
                        thisDeliveryReport.writeMessageID(strinput=vstrMessage)
                        thisDeliveryReport.put()
                        thisPortal.put()

                        thisSMSAccount.strTotalSMS = thisSMSAccount.strTotalSMS - 1
                        thisSMSAccount.put()

                        thisOutBox = SMSOutBox()
                        thisOutBox.writeMessage(strinput=vstrMessage)
                        thisOutBox.writeContactID(strinput=vstrContactID)
                        thisOutBox.writeMessageID(
                            strinput=thisOutBox.CreateMessageID())
                        thisOutBox.writeDateSent(strinput=strThisDate)
                        thisOutBox.writeTimeSent(strinput=strThisTime)
                        thisOutBox.put()

                        self.response.write("SMS Successfully sent")

                elif vstrChoice == "6":
                    vstrCell = self.request.get('vstrCell')

                    findRequest = Contacts.query(Contacts.strCell == vstrCell)
                    thisContactList = findRequest.fetch()

                    if len(thisContactList) > 0:
                        thisContact = thisContactList[0]
                    else:
                        thisContact = Contacts()

                    findRequest = EmailInBox.query(
                        EmailInBox.strContactID == thisContact.strContactID)
                    thisEmailInboxList = findRequest.fetch()

                    findRequest = EmailOutBox.query(
                        EmailOutBox.strContactID == thisContact.strContactID)
                    thisEmailOutBoxList = findRequest.fetch()

                    template = template_env.get_template(
                        'templates/contacts/sub/email.html')
                    context = {
                        'vstrCell': vstrCell,
                        'thisEmailInboxList': thisEmailInboxList,
                        'thisEmailOutBoxList': thisEmailOutBoxList
                    }
                    self.response.write(template.render(context))

                elif vstrChoice == "7":

                    vstrCell = self.request.get('vstrCell')
                    vstrSubject = self.request.get('vstrSubject')
                    vstrMessage = self.request.get('vstrMessage')

                    findRequest = Contacts.query(Contacts.strCell == vstrCell)
                    thisContactList = findRequest.fetch()

                    if len(thisContactList) > 0:
                        thisContact = thisContactList[0]
                    else:
                        thisContact = Contacts()

                    findRequest = EmailOutBox.query(
                        EmailOutBox.strSubject == vstrSubject,
                        EmailOutBox.strMessage == vstrMessage)
                    thisEmailOutBoxList = findRequest.fetch()

                    if len(thisEmailOutBoxList) > 0:
                        thisEmailOutBox = thisEmailOutBoxList[0]
                    else:
                        thisEmailOutBox = EmailOutBox()

                    thisEmailOutBox.writeContactID(
                        strinput=thisContact.strContactID)
                    thisEmailOutBox.writeMessageID(
                        strinput=thisEmailOutBox.CreateMessageID())
                    thisEmailOutBox.writeMessage(strinput=vstrMessage)
                    thisDate = datetime.datetime.now()
                    thisDate = thisDate.date()
                    thisTime = datetime.datetime.now()
                    thisTime = datetime.time(hour=thisTime.hour,
                                             minute=thisTime.minute,
                                             second=thisTime.second)
                    if thisEmailOutBox.sendEmail():
                        thisEmailOutBox.writeIsSent(strinput=True)
                        thisEmailOutBox.writeTimeSent(strinput=thisTime)
                        thisEmailOutBox.writeDateSent(strinput=thisDate)

                        thisEmailOutBox.put()
                        self.response.write("Successfully sent an Email")
                    else:
                        self.response.write("Error Sending Email")
Exemplo n.º 10
0
    def post(self):
        from mysms import SMSPortalVodacom, SMSPortalBudget, SMSAccount
        Guser = users.get_current_user
        if users.is_current_user_admin:
            vstrChoice = self.request.get('vstrChoice')

            if vstrChoice == "0":
                vstrSenderAddress = self.request.get('vstrSenderAddress')
                vstrEmailAddress = self.request.get('vstrEmailAddress')
                vstrCSVEmail = self.request.get('vstrCSVEmail')
                vstrSMSSizeLimit = self.request.get('vstrSMSSizeLimit')
                vstrBuyRate = self.request.get('vstrBuyRate')
                vstrSellRate = self.request.get('vstrSellRate')
                vstrAvailableCredit = self.request.get('vstrAvailableCredit')
                vstrPortalLogin = self.request.get('vstrPortalLogin')
                vstrPortalPassword = self.request.get('vstrPortalPassword')
                vstrPortalAddress = self.request.get('vstrPortalAddress')
                vstrSystemCredit = self.request.get('vstrSystemCredit')

                findRequest = SMSPortalVodacom.query()
                thisVodacomPortalList = findRequest.fetch()
                if len(thisVodacomPortalList) > 0:
                    thisVodacomPortal = thisVodacomPortalList[0]
                else:
                    thisVodacomPortal = SMSPortalVodacom()

                thisVodacomPortal.writeSystemCredit(strinput=vstrSystemCredit)
                thisVodacomPortal.writeCSVEmail(strinput=vstrCSVEmail)
                thisVodacomPortal.writeEmailAddress(strinput=vstrEmailAddress)
                thisVodacomPortal.writeSMSSixeLimit(strinput=vstrSMSSizeLimit)
                thisVodacomPortal.writeAvailableCredit(
                    strinput=vstrAvailableCredit)
                thisVodacomPortal.writeSellRate(strinput=vstrSellRate)
                thisVodacomPortal.writePortalAddress(
                    strinput=vstrPortalAddress)
                thisVodacomPortal.writeSenderAddress(
                    strinput=vstrSenderAddress)
                thisVodacomPortal.writeBuyRate(strinput=vstrBuyRate)
                thisVodacomPortal.writePortaLogin(strinput=vstrPortalLogin)
                thisVodacomPortal.writePassword(strinput=vstrPortalPassword)

                thisVodacomPortal.put()

                self.response.write(
                    "Successfully updated vodacom SMS portal settings")
            elif vstrChoice == "1":
                vstrChurchID = self.request.get('vstrChurchID')
                vstrAdditionalCredit = self.request.get('vstrAdditionalCredit')

                findRequest = SMSAccount.query(
                    SMSAccount.strChurchID == vstrChurchID)
                thisSMSAccountList = findRequest.fetch()

                if len(thisSMSAccountList) > 0 and (int(vstrAdditionalCredit) >
                                                    0):
                    thisSMSAccount = thisSMSAccountList[0]

                    thisSMSAccount.writeChurchID(strinput=vstrChurchID)
                    thisSMSAccount.AddTotalSMS(strinput=vstrAdditionalCredit)
                    thisSMSAccount.put()
                    self.response.write(
                        "Successfully added new credit amount please refresh your browser to see new values"
                    )
                else:
                    self.response.write("Error Crediting Account")