def post(self): """Create a new campaign.""" campaign_dict = self.get_request_json() validate_campaign_dict(campaign_dict) # get a list of platforms platforms_list = campaign_dict["platforms"] del campaign_dict["platforms"] # construct and store a new campaign campaign = Campaign(**campaign_dict) campaign.put() campaign_id = campaign.key.id() # construct and store platforms for campaign platforms = [] for platform_name in platforms_list: platform = Platform(name=platform_name, counter=0, campaign=campaign.key, id="%d-%s" % (campaign_id, platform_name)) platforms.append(platform) ndb.put_multi_async(platforms) # prepare response representation of the created campaign output = campaign_to_dict(campaign, platforms=platforms) # set the appropriate response headers self.response.location = self.uri_for("campaign-detail", campaign_id=campaign_id) self.response.status_int = 201 return output
def post(self, campaign_id): campaign = Campaign.get_by_key_name(campaign_id) if not campaign: campaign = Campaign(key_name = campaign_id, name = campaign_id, short_code = campaign_id) campaign.put() status_view = CampaignStatusView(campaign = campaign, response = self.response)
def post(self): user = users.get_current_user() if user: name = self.request.get('name') c = Campaign(name=name, owner=user) c.put() return self.redirect("/campaign/%s" % c.key().id()) else: return self.redirect(users.create_login_url(self.request.uri))
def post(self, campaign_id): campaign = Campaign.get_by_key_name(campaign_id) if not campaign: campaign = Campaign(key_name=campaign_id, name=campaign_id, short_code=campaign_id) campaign.put() status_view = CampaignStatusView(campaign=campaign, response=self.response)
def post(self): user = users.get_current_user() if user: name = self.request.get('name') c = Campaign(name=name,owner=user) c.put() return self.redirect("/campaign/%s" % c.key().id()) else: return self.redirect(users.create_login_url(self.request.uri))