Example #1
0
    def save(self):
        self.forbid_if('redir' not in self.request.POST)
        redir = self.request.POST.get('redir')
        cust = self.request.ctx.customer
        lis = Listing.load(self.request.POST.get('listing_id'))
        if not lis:
            lis = Listing()
            lis.customer = cust
            lis.company = self.request.ctx.campaign.company
            lis.site = self.request.ctx.site
            # l.ip = util.self.request_ip()
            # g = Geo()
            # gip = g.by_ip(l.ip)
            # if gip and gip['latitude'] and gip['longitude']:
            #     l.latitude = gip['latitude'] if 'latitude' in gip else None
            #     l.longitude = gip['longitude'] if 'longitude' in gip else None
            #     l.city = gip['city'] if 'city' in gip else None
            #     l.state = gip['region_name'] if 'region_name' in gip else None
            #     l.zip = gip['postal_code'] if 'postal_code' in gip else None
            #     l.country = gip['country_code'] if 'country_code' in gip else None
            #     l.dma = gip['dma_code'] if 'dma_code' in gip else None
        # this overrides the original lat/lng settings if they are coming from
        # the POST instead of the geo ip.
        lis.bind(self.request.POST, True)
        lis.save()
        self.db_flush()

        # for key in self.request.POST.keys():
        #     if key.startswith('asset_'):
        #         ass = Asset.load(key[6:])
        #         ass.fk_type = 'Listing'
        #         ass.fk_id = lis.listing_id
        #         ass.save()

        Status.add(cust, lis, Status.find_event(self.enterprise_id, lis, 'OPEN'),
                   'Listing Created: %s' % self.request.POST.get('title'))
        self.flash('Listing: "%s" saved' % lis.title)
        return HTTPFound('%s?listing_id=%s&post=1' % (redir, lis.listing_id))