예제 #1
0
    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
            }
예제 #2
0
    def save(self):
        cmpn = Campaign.load(self.request.POST.get('campaign_id'))
        if not cmpn:
            cmpn = Campaign()
        else:
            self.forbid_if(cmpn.company.enterprise_id != self.enterprise_id)
        cmpn.bind(self.request.POST)
        cmpn.save()

        cmpn.clear_attributes()
        for i in range(10):
            attr_name = self.request.POST.get('attr_name[%d]' % i)
            attr_value = self.request.POST.get('attr_value[%d]' % i)
            if attr_name and attr_value:
                cmpn.set_attr(attr_name, attr_value)

        cmpn.save()
        cmpn.flush()
        cmpn.invalidate_self()
        cmpn.invalidate_caches()
        self.request.session.flash('Successfully saved %s.' % cmpn.name)
        return HTTPFound('/crm/campaign/edit/%s' % cmpn.campaign_id)