Beispiel #1
0
    def handle(self, *args, **opts):
        if opts['quiet']: self.stdout = open(devnull, 'w')
        # Format names
        if opts['names']:
            names = [ n.strip() for n in opts['names'].split(',') ]
        else:
            self.stdout.write("You must give one or more name.")
            self.print_help('group', 'help')
            sys.exit(1)

        self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'name': 'Name'}))
        # Walk on names and valid with form.
        form_errors = []
        for n in names:
            F = Group_Form(data={'name':n})
            if F.is_valid():
                g = F.save()
                self.stdout.write(ROW_FORMAT.format(**g.__dict__))
            else:
                form_errors.append((n,F.errors))
        self.stdout.write('Created count: %i' % (len(names) - len(form_errors)))
        # Print errors
        if form_errors and not opts['quiet']:
            self.stdout.write('* Error(s)')
            for n, errs in form_errors:
                self.stdout.write('* %s:' % n)
                for field,errors in errs.items():
                    self.stdout.write(field)
                    for err in errors:
                        self.stdout.write('\t'+err)
Beispiel #2
0
def update(request, group_id):
    G = get_object_or_404(Group.objects.filter(pk=group_id))
    F = Group_Form(data=request.POST, instance=G)
    data = {}
    if F.is_valid():
        F.save()
        messages.success(request, _("Group updated with success."))
        data['response'] = 'ok'
        data['callback-url'] = G.get_absolute_url()
    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', {})
Beispiel #3
0
def update(request, group_id):
    G = get_object_or_404(Group.objects.filter(pk=group_id))
    F = Group_Form(data=request.POST, instance=G)
    data = {}
    if F.is_valid():
        F.save()
        messages.success(request, _("Group updated with success."))
        data['response'] = 'ok'
        data['callback-url'] = G.get_absolute_url()
    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', {})
Beispiel #4
0
def add(request):
    if request.method == 'POST':
        F = Group_Form(request.POST)
        data = {}
        if F.is_valid():
            G = F.save()
            messages.success(request, _("Group added with success."))
            data['response'] = 'ok'
            data['callback-url'] = G.get_absolute_url()
        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, 'users/group.html', {
            'Group_Form': Group_Form(),
        })
Beispiel #5
0
def add(request):
    if request.method == 'POST':
        F = Group_Form(request.POST)
        data = {}
        if F.is_valid():
            G = F.save()
            messages.success(request, _("Group added with success."))
            data['response'] = 'ok'
            data['callback-url'] = G.get_absolute_url()
        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, 'users/group.html', {
            'Group_Form': Group_Form(),
        })
Beispiel #6
0
    def handle(self, *args, **opts):
        if opts['quiet']: self.stdout = open(devnull, 'w')
        # Select group by id
        if not Group.objects.filter(id=opts['id']).exists():
            self.stdout.write("No group with id '%s' exists." % opts['id'])
            sys.exit(1)
        # Valid and save
        g = Group.objects.get(id=opts['id'])
        F = Group_Form(data=opts, instance=g)
        if F.is_valid():
            g = F.save()
            self.stdout.write(ROW_FORMAT.format(**{u'id': 'ID', 'name': 'Name'}))
            self.stdout.write(ROW_FORMAT.format(**g.__dict__))

        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)
Beispiel #7
0
def get(request, group_id):
    G = get_object_or_404(Group.objects.filter(pk=group_id))
    F = Group_Form(instance=G)
    return render(request, 'users/group.html', {
        'Group_Form': F,
    })
Beispiel #8
0
def add(request):
    return render(request, 'users/group.html', {
        'Group_Form': Group_Form(),
    })