Exemplo n.º 1
0
    def handle(self, *args, **opts):
        if opts['quiet']: self.stdout = open(devnull, 'w')
        # Select host by id or ids
        ids = [ i.strip() for i in opts['ids'].split(',') ]
        skeletons = Skeleton.objects.filter(id__in=ids)
        # Stop if no given id
        if not skeletons.exists():
            self.stdout.write("There's no skeleton with given ID: '%s'" % (opts['ids'] or opts['id']) )
            sys.exit(1)
        # Walk on skeleton for valid or fail
        modified_skeletons = []
        form_error = None
        for s in skeletons:
            # Use Form to valid
            data = s.__dict__
            data.update(dict([ (k,v) for k,v in opts.items() if v ]))
            F = Skeleton_Form(data=data, instance=s)
            if F.is_valid():
                s = F.save()
                modified_skeletons.append(s)
            else:
                form_error = F.errors
        # Walk on all list to print it
        if modified_skeletons:
            self.stdout.write('* Skeleton updated:')
            for s in modified_skeletons:
                self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'plugin_pattern': 'Plugin pattern', 'source_pattern': 'Source Pattern', 'name': u'Name'}))
                self.stdout.write(ROW_FORMAT.format(**s.__dict__))

        if form_error:
            self.stdout.write('* Error:')
            for field,errors in form_error.items():
                self.stdout.write(field)
                for err in errors:
                    self.stdout.write('\t'+err)
Exemplo n.º 2
0
 def handle(self, *args, **opts):
     if opts['quiet']: self.stdout = open(devnull, 'w')
     # Use Form to valid
     F = Skeleton_Form(data=opts)
     if F.is_valid():
         s = F.save()
         self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'plugin_pattern': 'Plugin pattern', 'source_pattern': 'Source Pattern', 'name': u'Name'}))
         self.stdout.write(ROW_FORMAT.format(**s.__dict__))
     else:
         for field,errors in F.errors.items():
             self.stdout.write(field)
             for err in errors:
                 self.stdout.write('\t'+err)
Exemplo n.º 3
0
def update(request, skeleton_id):
    S = get_object_or_404(Skeleton.objects.filter(pk=skeleton_id))
    F = Skeleton_Form(data=request.POST, instance=S)
    data = {}
    if F.is_valid():
        F.save()
        messages.success(request, _("Skeleton updated with success."))
        data.update({
          'response': 'ok',
          'callback-url': S.get_absolute_url(),
          'id': S.id,
        })
    else:
        for field,error in F.errors.items():
            messages.error(request, '<b>%s</b>: %s' % (field,error))
        data['response'] = 'error'
    return render_HTML_JSON(request, data, 'base/messages.html', {})
Exemplo n.º 4
0
def add(request):
    if request.method == 'POST':
        F = Skeleton_Form(data=request.POST)
        data = {}
        if F.is_valid():
            S = F.save()
            messages.success(request, _("Skeleton added with success."))
            data.update({
              'response': 'ok',
              'callback-url': S.get_absolute_url(),
              'id': S.pk,
            })
        else:
            for field,error in F.errors.items():
                messages.error(request, '<b>%s</b>: %s' % (field,error))
            data['response'] = 'error'
        return render_HTML_JSON(request, data, 'base/messages.html', {})
    else:
        return render(request, 'forms/skeleton.html', {
            'Skeleton_Form': Skeleton_Form(),
        })
Exemplo n.º 5
0
def get(request, skeleton_id):
    S = get_object_or_404(Skeleton.objects.filter(pk=skeleton_id))
    F = Skeleton_Form(instance=S)
    return render(request, 'forms/skeleton.html', {
        'Skeleton_Form': F,
    })