Example #1
0
    def post(self):
        Guser = users.get_current_user()
        if Guser:

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

            findRequest = Campaigns.query(
                Campaigns.strCampaignID == vstrCampaignID)
            thisCampaignList = findRequest.fetch()

            if len(thisCampaignList) > 0:
                thisCampaign = thisCampaignList[0]
            else:
                thisCampaign = Campaigns()

            if not (thisCampaign.strPromoted):
                findRequest = Constant.query(
                    Constant.strReference == Guser.user_id())
                thisConstantList = findRequest.fetch()
                if len(thisConstantList) > 0:
                    thisConstant = thisConstantList[0]
                else:
                    thisConstant = Constant()

                thisConstant.writeReference(strinput=Guser.user_id())
                thisConstant.put()

                findRequest = Profile.query(
                    Profile.strReference == Guser.user_id())
                thisProfileList = findRequest.fetch()
                if len(thisProfileList) > 0:
                    thisProfile = thisProfileList[0]
                else:
                    thisProfile = Profile()

                thisProfile.writeReference(strinput=Guser.user_id())

                if (thisProfile.strWallet > thisConstant.strPromotionCost):
                    thisProfile.strWallet = thisProfile.strWallet - thisConstant.strPromotionCost
                    thisCampaign.strPromoted = True
                    thisProfile.put()
                    thisCampaign.put()
                    self.response.write("Campaign Successfully Promoted")
                else:
                    self.response.write(
                        "Campaign cannot be promoted insufficient funds")
            else:
                self.response.write("Campaign Already Promoted")
Example #2
0
    def post(self):
        Guser = users.get_current_user()
        if Guser:
            vstrCampaignType = self.request.get('vstrCampaignType')
            vstrCampaignName = self.request.get('vstrCampaignName')
            vstrCampaignIntro = self.request.get('vstrCampaignIntro')
            vstrCampaignBody = self.request.get('vstrCampaignBody')
            vstrFundMe = self.request.get('vstrFundMe')

            findRequest = Constant.query(
                Constant.strReference == Guser.user_id())
            thisConstantList = findRequest.fetch()

            if len(thisConstantList) > 0:
                thisConstant = thisConstantList[0]
            else:
                thisConstant = Constant()

            findRequest = Campaigns.query(
                Campaigns.strReference == Guser.user_id())
            thisCampaignsList = findRequest.fetch()

            findRequest = Profile.query(
                Profile.strReference == Guser.user_id())
            thisProfileList = findRequest.fetch()

            if len(thisProfileList) > 0:
                thisProfile = thisProfileList[0]
            else:
                thisProfile = Profile()

            if (thisProfile.strWallet > thisConstant.strCampaignCost) or (
                    len(thisCampaignsList) <
                    thisConstant.strFreeCampaignAllowance):
                if len(thisCampaignsList
                       ) > thisConstant.strFreeCampaignAllowance:
                    thisProfile.strWallet = thisProfile.strWallet - thisConstant.strCampaignCost
                else:
                    pass
                try:
                    thisCampaign = Campaigns()
                    thisCampaign.writeReference(strinput=Guser.user_id())
                    thisCampaignID = str(Guser.user_id()) + str(
                        len(thisCampaignsList))

                    thisCampaign.writeCampaignID(strinput=thisCampaignID)
                    thisPublicURL = "/campaigns/public/" + thisCampaignID
                    thisPublicURL = thisConstant.strAppURL + thisPublicURL
                    thisCampaign.writeCampaignURL(strinput=thisPublicURL)
                    thisCampaign.writeCampaignName(strinput=vstrCampaignName)
                    if vstrCampaignType == "Personal":
                        thisCampaign.setBusinessCampaign(strinput=True)
                    else:
                        thisCampaign.setBusinessCampaign(strinput=False)

                    thisCampaign.writeCampaignIntro(strinput=vstrCampaignIntro)
                    thisCampaign.writeCampaignBody(strinput=vstrCampaignBody)
                    thisCampaign.writeFundMe(strinput=vstrFundMe)
                    # thisCampaign.setActive() Cannot set the campaign to active since this is a draft
                    StartDate = datetime.datetime.now()
                    StartDate = StartDate.date()
                    EndDate = datetime.date.today() + datetime.timedelta(+30)
                    thisCampaign.setStartDate(strinput=StartDate)
                    thisCampaign.setEndDate(strinput=EndDate)
                    thisInternalURL = "/campaigns/detail/" + thisCampaignID
                    thisCampaign.writeInternalURL(strinput=thisInternalURL)

                    thisCampaign.put()
                    self.response.write("Successfully created your Campaign")
                except:
                    self.response.write("Error Creating Campaign")
            else:
                self.response.write(
                    "Insufficient credit to create a new campaign")