def save(self, id=None, **kw): """Save or create record to model""" #update kw log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) try: if isinstance(kw['user_groups'], list): groups = Group.select(Group.c.group_id.in_(*kw['user_groups'])) else: groups = Group.select(Group.c.group_id.in_(kw['user_groups'])) except: groups = [] #create if not id: kw['groups'] = groups User(**kw) flash("User was successfully created.") raise redirect("list") #update else: record = User.get_by(user_id=int(id)) for attr in kw: setattr(record, attr, kw[attr]) record.groups = groups log.info("Saved update on user " + record.user_name + str(kw)) flash("User was successfully updated.") raise redirect("../list")
def list(self, **kw): """List records in model""" records = User.select() grid = PaginateDataGrid(fields=[('User Id', 'user_id'), ('User Name', 'user_name'),('Show',show_link),('Edit',edit_link),('Delete',destroy_link)]) return dict(records = records, modelname=self.modelname, grid=grid, now=datetime.today().strftime("%A, %d %b %Y"))
def list(self, **kw): """List records in model""" records = User.select() grid = PaginateDataGrid( fields=[('User Id', 'user_id'), ('User Name', 'user_name'), ( 'Show', show_link), ('Edit', edit_link), ('Delete', destroy_link)]) return dict(records=records, modelname=self.modelname, grid=grid, now=datetime.today().strftime("%A, %d %b %Y"))
def edit(self, id, **kw): """Edit record in model""" try: record = User.get(int(id)) group_defaults=[entry.group_id for entry in record.groups] except: flash = "Not valid edit" log.info("user_name: "+str(record.user_name)) log.info("group_defaults: "+str(group_defaults)) return dict(modelname = self.modelname, record = record, value=dict(user_name = record.user_name,status=record.status,user_groups = group_defaults, display_name=record.display_name, password='******', password_confirm='password'), #options=dict(user_groups=[(entry.group_id, entry.group_name) for entry in Group.select()]), form = model_edit_form, now= datetime.today().strftime("%A, %d %b %Y"))
def update(self, id=None, **kw): """Save or create record to model""" #update kw log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) log.info('kw: ' + str(kw)) try: if isinstance(kw['user_groups'],list): groups = Group.select(Group.c.group_id.in_(*kw['user_groups'])) else: groups = Group.select(Group.c.group_id.in_(kw['user_groups'])) except: groups = [] #create if not id: kw['groups']=groups User(**kw) flash("User was successfully created.") raise redirect("list") #update else: record = User.get_by(user_id=int(id)) for attr in kw: if attr == 'password': setattr(record, attr, identity.encrypt_password(kw[attr])) else: setattr(record, attr, kw[attr]) record.groups = groups log.info("Saved update on user " + record.user_name + str(kw)) flash("User was successfully updated.") raise redirect("../list")
def edit(self, id, **kw): """Edit record in model""" try: record = User.get(int(id)) group_defaults = [entry.group_id for entry in record.groups] except: flash = "Not valid edit" log.info("user_name: " + str(record.user_name)) log.info("group_defaults: " + str(group_defaults)) return dict( modelname=self.modelname, record=record, value=dict(user_name=record.user_name, status=record.status, user_groups=group_defaults, display_name=record.display_name, password='******', password_confirm='password'), #options=dict(user_groups=[(entry.group_id, entry.group_name) for entry in Group.select()]), form=model_edit_form, now=datetime.today().strftime("%A, %d %b %Y"))
def destroy(self, id): """Destroy record in model""" record = User.get(int(id)) session.delete(record) flash("User was successfully destroyed.") raise redirect("../list")
def show(self, id, **kw): """Show record in model""" record = User.get(int(id)) return dict(record=record, now=datetime.today().strftime("%A, %d %b %Y"))
def show(self,id, **kw): """Show record in model""" record = User.get(int(id)) return dict(record = record, now= datetime.today().strftime("%A, %d %b %Y"))