def handle(self, *args, **opts): if opts['quiet']: self.stdout = open(devnull, 'w') # Set view to add or del to_set = set([ i.strip() for i in opts.pop('views', '').split(',') if i ]) to_add = set([ i.strip() for i in opts.pop('add_views', '').split(',') ]) to_del = set([ i.strip() for i in opts.pop('rm_views', '').split(',') ]) opts = dict([ (k,v) for k,v in opts.items() if v is not None ]) # Valid and save m = Multiview.objects.get(id=opts['id']) data = m.__dict__ data.update(dict([ (k,v) for k,v in opts.items() if v ])) data['views'] = to_set or [ str(v.id) for v in m.views.all() ] data['views'] = set(data['views']) - to_del data['views'] = list(data['views'] | to_add) data['views'] = [ i for i in data['views'] if i ] F = Multiview_Form(data=data, instance=m) if F.is_valid(): m = F.save() m_data = m.__dict__ m_data['views'] = ','.join([ str(_v.id) for _v in m.views.all() ]) self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'views': 'Views ID', 'name': u'Name'})) self.stdout.write(ROW_FORMAT.format(**m_data)) elif not opts['quiet']: self.stdout.write('* Error(s)') for field,errors in F.errors.items(): self.stdout.write(field) for err in errors: self.stdout.write('\t'+err)
def handle(self, *args, **opts): if opts['quiet']: self.stdout = open(devnull, 'w') # Set view to add or del to_set = set( [i.strip() for i in opts.pop('views', '').split(',') if i]) to_add = set([i.strip() for i in opts.pop('add_views', '').split(',')]) to_del = set([i.strip() for i in opts.pop('rm_views', '').split(',')]) opts = dict([(k, v) for k, v in opts.items() if v is not None]) # Valid and save m = Multiview.objects.get(id=opts['id']) data = m.__dict__ data.update(dict([(k, v) for k, v in opts.items() if v])) data['views'] = to_set or [str(v.id) for v in m.views.all()] data['views'] = set(data['views']) - to_del data['views'] = list(data['views'] | to_add) data['views'] = [i for i in data['views'] if i] F = Multiview_Form(data=data, instance=m) if F.is_valid(): m = F.save() m_data = m.__dict__ m_data['views'] = ','.join([str(_v.id) for _v in m.views.all()]) self.stdout.write( ROW_FORMAT.format(**{ u'id': 'ID', 'views': 'Views ID', 'name': u'Name' })) self.stdout.write(ROW_FORMAT.format(**m_data)) elif not opts['quiet']: self.stdout.write('* Error(s)') for field, errors in F.errors.items(): self.stdout.write(field) for err in errors: self.stdout.write('\t' + err)
def handle(self, *args, **opts): if opts['quiet']: self.stdout = open(devnull, 'w') # Format field view_ids = [ i.strip() for i in opts['views'].split(',') ] opts['views'] = view_ids F = Multiview_Form(data=opts) if F.is_valid(): m = F.save() m_data = m.__dict__ m_data['views'] = ','.join([ str(_v.id) for _v in m.views.all() ]) self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'views': 'Views ID', 'name': u'Name'})) self.stdout.write(ROW_FORMAT.format(**m_data)) elif not opts['quiet']: self.stdout.write('* Error(s)') for f,errs in F.errors.items(): self.stdout.write(f) for err in errs: self.stdout.write('\t'+err)
def handle(self, *args, **opts): if opts['quiet']: self.stdout = open(devnull, 'w') # Format field view_ids = [i.strip() for i in opts['views'].split(',')] opts['views'] = view_ids F = Multiview_Form(data=opts) if F.is_valid(): m = F.save() m_data = m.__dict__ m_data['views'] = ','.join([str(_v.id) for _v in m.views.all()]) self.stdout.write( ROW_FORMAT.format(**{ u'id': 'ID', 'views': 'Views ID', 'name': u'Name' })) self.stdout.write(ROW_FORMAT.format(**m_data)) elif not opts['quiet']: self.stdout.write('* Error(s)') for f, errs in F.errors.items(): self.stdout.write(f) for err in errs: self.stdout.write('\t' + err)