def _remember_site(request): if 'site_id' in request.session: request.ctx.site = Site.load(request.session['site_id']) else: #if '__sid' in request.params: # request.ctx.site = Site.find_by_host(request.params['__sid']) #else: request.ctx.site = Site.find_by_host(request.host) if request.ctx.site: request.session['site_id'] = request.ctx.site.site_id if request.ctx.site: return True
def _edit_impl(self): site_id = self.request.matchdict.get('site_id') self.session['last_site_id'] = site_id if site_id: site = Site.load(site_id) self.forbid_if(not site or str(site.company.enterprise_id) != str(self.enterprise_id)) else: site = Site() return { 'site' : site, 'shipping_methods' : Site.get_shipping_methods(), 'tax_methods' : Site.get_tax_methods(), 'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'), 'campaigns' : util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name') }
def wrap(func_self, *args, **kwargs): orig_site = func_self.site func_self.site = Site.find_by_host(self.domain) try: return original_func(func_self, *args, **kwargs) finally: func_self.site = orig_site
def list(self): site = Site.load(self.request.matchdict.get('site_id')) self.forbid_if(not site or str(site.company.enterprise_id) != str(self.enterprise_id)) return { 'site' : site, 'contents' : Content.find_by_site(site) }
def provision(self): ent = Enterprise() ent.bind(self.request.POST, True, 'ent') ent.save() ent.flush() comp = Company() comp.bind(self.request.POST, True, 'cmp') comp.enterprise_id = ent.enterprise_id comp.save() comp.flush() campaign = Campaign() campaign.name = comp.name + ' Default' campaign.company_id = comp.company_id campaign.save() campaign.flush() comp.default_campaign_id = campaign.campaign_id comp.save() comp.flush() user = Users() user.bind(self.request.POST, True, 'u') user.password = Users.encode_password('password') user.enterprise_id = ent.enterprise_id user.type = 'Admin' user.save() user.flush() site = Site() site.bind(self.request.POST, True, 'st') site.company = comp site.description = comp.name + ' Site' site.creator = user #site.template = Template.find_by_name('default') site.save() site.flush() return { 'enterprise' : ent, 'company' : comp, 'campaign' : campaign, 'user' : user, 'site' : site, 'done' : True }
def invalidate_caches(self, **kwargs): from pvscore.model.cms.site import Site invalidate(self, 'Company.find_all_all') invalidate(self, 'Company.find_all', self.enterprise_id) invalidate(self, 'Company.find_by_name', self.name) invalidate(self, 'Company.default_campaign', self.company_id) for i in Site.find_all(self.enterprise_id): i.invalidate_caches()
def save(self): site = Site.load(self.request.POST.get('site_id')) if not site: site = Site() site.user_created = self.request.ctx.user.user_id else: self.forbid_if(site.company.enterprise_id != self.enterprise_id) site.bind(self.request.POST, True) site.save() site.flush() #if not os.path.isdir(site.site_full_directory): # site.create_dir_structure() self.flash('Successfully saved %s.' % (site.domain)) return HTTPFound('/cms/site/edit/%s' % site.site_id)
def file_save(self): site = Site.load(self.request.matchdict.get('site_id')) self.forbid_if(site.company.enterprise_id != self.enterprise_id) asset = Asset.create_new(site, self.enterprise_id, self.request) asset.bind(self.request.POST, True) asset.save() asset.flush() self.flash('Saved image %s' % asset.name) return HTTPFound('/cms/content/file/edit/%s/%s' % (site.site_id, asset.id))
def _file_edit_impl(self): site = Site.load(self.request.matchdict.get('site_id')) self.forbid_if(site.company.enterprise_id != self.enterprise_id) asset_id = self.request.matchdict.get('asset_id') if asset_id: asset = Asset.load(asset_id) self.forbid_if(not asset or str(asset.enterprise_id) != str(self.enterprise_id)) else: asset = Asset() return { 'site' : site, 'asset' : asset }
def _edit_impl(self): site_id = self.request.matchdict.get('site_id') site = Site.load(site_id) self.forbid_if(not site or str(site.company.enterprise_id) != str(self.enterprise_id)) content_id = self.request.matchdict.get('content_id') if content_id: content = Content.load(content_id) self.forbid_if(not content or str(content.site.company.enterprise_id) != str(self.enterprise_id) or str(content.site_id) != str(site_id)) else: content = Content() content.site_id = site_id return { 'site' : site, 'content' : content, 'companies' : util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name'), 'campaigns' : util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name') }
def _create_new(self): R = self.get('/cms/site/new') assert R.status_int == 200 R.mustcontain('New Site') f = R.forms['frm_site'] self.assertEqual(f['site_id'].value, '') f.set('domain', 'testsite.com') f.set('domain_alias0', 'testsite0.com') f.set('seo_title', 'Test Site') f.set('robots_txt', """User-agent: * Disallow: /cms/cart/add/*""") R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_site'] R.mustcontain('Edit Site') site_id = f['site_id'].value self.assertNotEqual(f['site_id'].value, '') site = Site.load(site_id) log.debug(site) return site_id
def _delete_new(self, site_id): site = Site.load(site_id) self.assertNotEqual(site, None) site.delete() self.commit()
def list(self): return { 'sites' : Site.find_all(self.enterprise_id) }
def setUp(self): self.settings = paste.deploy.appconfig('config:unittest.ini', relative_to='.') app = self.init_app(self.settings) self.app = TestApp(app) self.site = Site.find_by_host(self.get_host())
def file_list(self): site = Site.load(self.request.matchdict.get('site_id')) self.forbid_if(site.company.enterprise_id != self.enterprise_id) return { 'contents' : Asset.find_for_object(site) }