示例#1
0
 def _fixme_edit(self):
     choices = set()
             
     for (name, plugin) in self.request.registry.getAdapters([self.context], IFieldAdapter):
         choices.add((name,plugin.title))
         
     conTemp = ContentTemplateSchema().bind(choices=choices)
     form = Form(conTemp,buttons=('submit',))
     post = self.request.POST
     if 'submit' in post:
         controls = post.items()
         try:
             appstruct = form.validate(controls)
         except ValidationFailure, e:
             return {'form':e.render(),'form_resources':e.get_widget_resources(None)}
         self.data = {}
         
         for field in appstruct['fields']:
             ft = FieldTemplate()
             ft.title = field['title']
             ft.description = field['description']
             ft.field_type = field['field_type']
             self.context[slugify(ft.title)] = ft
             #self.data[slugify(ft.title)] = ft
             #data[slugify(ft.title)] = ft    #adds to the data array
             #results = ResultsView(self, self.context, self.request)
             #results.set_data(self.data)
         
         #url = resource_url(results, self.request)
         return HTTPFound(appstruct)
示例#2
0
 def add_field(self):
     schema = FieldTemplateSchema()
     schema = schema.bind(context = self.context, request = self.request, field_types = self.get_field_types() )
     form = Form(schema, buttons=('save',))
     post = self.request.POST
     response = {}
     response['form_resources'] = form.get_widget_resources(None)
     if 'save' in post:
         controls = post.items()
         try:
             appstruct = form.validate(controls)
         except ValidationFailure, e:
             response['form'] = e.render()
             return response
         
         obj = FieldTemplate()
         obj.title = appstruct['title']
         obj.description = appstruct['description']
         obj.field_type = appstruct['field_type']
         #FIXME: Make adaptable to same titles
         self.context[slugify(obj.title)] = obj
         url = resource_url(self.context, self.request)
         return HTTPFound(location=url)