Exemple #1
0
 def test_create_new(self):
     listing_id = self._create_new()
     cust = Customer.find(TEST_CUSTOMER_EMAIL, Campaign.load(self.site.default_campaign_id))
     listings = Listing.find_by_customer(cust)
     assert len(listings) == 1
     assert str(listings[0].listing_id) == listing_id
     Listing.find_last_n_assets(10)
     self._delete_new(listing_id)
Exemple #2
0
 def test_remove(self):
     listing_id = self._create_new()
     R = self.get('/crm/listing/remove/%s' % listing_id)
     assert R.status_int == 200
     lis = Listing.load(listing_id)
     self.assertNotEqual(lis.delete_dt, None)
     self._delete_new(listing_id)
Exemple #3
0
 def remove(self):
     lis = Listing.load(self.request.matchdict.get('listing_id'))
     cust = self.request.ctx.customer
     self.forbid_if(not lis or not cust or lis.customer.customer_id != cust.customer_id or cust.campaign.company.enterprise_id != self.enterprise_id)
     lis.soft_delete()
     Status.add(cust, lis, Status.find_event(self.enterprise_id, lis, 'CLOSED'),
                'Listing Deleted: %s' % self.request.POST.get('title'))
     return 'True'
Exemple #4
0
 def upload_asset(self):
     """ KB: [2011-03-23]: Take this file and hash its name up to put it in a sensible directory. """
     listing_id = self.request.matchdict.get('listing_id')
     listing_hash = self.request.matchdict.get('hash')
     lis = Listing.load(listing_id)
     self.forbid_if(not lis or lis.hash != listing_hash)
     ass = Asset.create_new(lis, self.enterprise_id, self.request)
     Status.add(lis.customer, lis, Status.find_event(self.enterprise_id, lis, 'ASSET_UPLOAD'), ass.name)
     return str(ass.id)
Exemple #5
0
 def json(self):
     listing_id = self.request.matchdict.get('listing_id')
     if not listing_id:
         listing_id = self.request.GET.get('listing_id')
     self.forbid_if(not listing_id)
     cust = self.request.ctx.customer
     listing = Listing.load(listing_id)
     self.forbid_if(not listing or not cust or listing.customer.customer_id != cust.customer_id or cust.campaign.company.enterprise_id != self.enterprise_id)
     return {
         'listing' : listing
         }
Exemple #6
0
 def test_upload_asset(self):
     listing_id = self._create_new()
     # http://stackoverflow.com/questions/2488978/nose-tests-file-uploads
     listing = Listing.load(listing_id)
     assert listing is not None
     files = [("Filedata", "testfile.txt", "testfile.txt contents")]
     R = self.app.post('/crm/listing/upload/%s/%s' % (listing_id, listing.hash),
                       upload_files=files)
     assert R.status_int == 200
     asset_id = R.body
     ass = Asset.load(asset_id)
     assert ass.web_path is not None
     assert str(ass.id) in ass.web_path
     assert ass.exists
     assert ass is not None
     assert ass.get_listing().listing_id == listing.listing_id
     listings = Listing.find_all_pending_approval(self.site.company.enterprise_id)
     assert len(listings) > 0
     assert listings[0].listing_id == listing.listing_id
     self._delete_new(listing_id)
Exemple #7
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))
Exemple #8
0
 def _delete_new(self, listing_id):
     Listing.full_delete(listing_id)
     self.commit()
Exemple #9
0
 def get_listing(self):
     # KB: [2012-09-27]: if this is applicable you'll know it.
     # otherwise it will barf.
     from pvscore.model.crm.listing import Listing
     return Listing.load(self.fk_id)