def _delete(self, id): c.social_network = SocialNetwork.find_by_id(id) meta.Session.delete(c.social_network) meta.Session.commit() h.flash("Social Network has been deleted.") redirect_to('index')
def edit(self, id): c.social_network = SocialNetwork.find_by_id(id) defaults = h.object_to_defaults(c.social_network, 'social_network') form = render('/social_network/edit.mako') return htmlfill.render(form, defaults)
def validate_python(self, values, state): name = values['social_network']['name'] social_network = SocialNetwork.find_by_name(name, abort_404=False) if social_network != None and social_network.name == name: message = "Duplicate Social Network name" error_dict = {'social_network.name': "Social Network name already in use"} raise Invalid(message, values, state, error_dict=error_dict)
def validate_python(self, values, state): name = values['social_network']['name'] social_network = SocialNetwork.find_by_name(name, abort_404=False) if social_network != None and social_network.name == name: message = "Duplicate Social Network name" error_dict = { 'social_network.name': "Social Network name already in use" } raise Invalid(message, values, state, error_dict=error_dict)
def delete(self, id): """Delete the social_network GET will return a form asking for approval. POST requests will delete the item. """ c.social_network = SocialNetwork.find_by_id(id) return render('/social_network/confirm_delete.mako')
def _edit(self, id): social_network = SocialNetwork.find_by_id(id) for key in self.form_result['social_network']: setattr(social_network, key, self.form_result['social_network'][key]) # update the objects with the validated form data meta.Session.commit() h.flash("The social_network has been updated successfully.") redirect_to(action='view', id=id)
def _new(self): results = self.form_result['social_network'] print "Gonna make a new SocialNetwork" c.social_network = SocialNetwork(**results) print "New social_network %s" % c.social_network meta.Session.add(c.social_network) meta.Session.commit() h.flash("Social Network created") redirect_to(action='view', id=c.social_network.id)
def index(self): c.can_edit = True c.social_networks = SocialNetwork.find_all() return render('/social_network/list.mako')
def view(self, id): c.social_network = SocialNetwork.find_by_id(id) return render('/social_network/view.mako')