def handle(self, *files, **options): label = options.get('model') if label is None: raise CommandError('Please, specify model.') if not files: raise CommandError('Please, give me one or more files with commands.') model = get_model(*label.split('.', 1)) if model is None: raise CommandError('Model "%s" not found.' % label) ctype = ContentType._default_manager.get_for_model(model) for file in files: print 'Processing commands from "%s"' % file process_commands(ctype, open(file).readlines()) print 'Done'
def cloud(request, ctype_id): admin_index = reverse('admin:index') if request.user.is_staff == False: return redirect(admin_index) ctype = ContentType._default_manager.get(id = ctype_id) if request.method == 'POST': changes = request.POST.getlist('changes') save_to = getattr(settings, 'ANTICHAOS_SAVE_DIR', None) if save_to is not None: save_to = os.path.join(save_to, datetime.now().strftime('%y%m%d-%H%M%S.csv')) process_commands(ctype, changes, save_to) json = request.GET.get('json', False) model = ctype.model_class() objects = Tag.objects.usage_for_model(model, counts = True) data = dict( title = _('Tag cloud for %s') % _(ctype.model), ctype = ctype, objects = objects, root_path = admin_index, ) if json: data['objects'] = [ dict( id = tag.id, name = tag.name or tag.name_any, count = tag.count, ) for tag in objects] data['ctype'] = ctype.id data = simplejson.dumps(data) return HttpResponse(data, 'text/html') return render_to_response( template_list(model, 'tag_cloud'), data, context_instance = RequestContext(request))