Esempio n. 1
0
def machines_edit(request, uuid, mac):
    member = None
    try:
        member = Member.objects.get(uuid=uuid)
    except Member.DoesNotExist:
        messages.warning(request, u"Impossible de trouver la personne demandée")
        return redirect("ogre_member")
    machine = None
    try:
        machine = Machine.objects.get(mac=mac)
    except Machine.DoesNotExist:
        messages.warning(request, u"Impossible de trouver la machine à éditer")
        return redirect("ogre_member_show", uuid=uuid)
    
    form = MachineForm(request.POST or None, instance=machine)
    form.fields['mac'].widget.attrs['readonly'] = True
    if request.method == 'POST':
        if form.is_valid():
            machine = form.save(commit=False)
            machine.name = check_machine_name(machine, member)
            machine.save(update_fields=['name'])
            return redirect("ogre_member_show", uuid=uuid)
    return render(request, "ogre/member/machine.html", {
        'form': form,
        'machine': machine,
        'member': member,
    })
Esempio n. 2
0
def show(request, uuid, payment_page=None, history_page=None, page_size=10):
    try:
        member = Member.objects.get(uuid=uuid)
        machine_form = MachineForm(request.POST or None)
        if request.method == 'POST':
            if machine_form.is_valid():
                machine = machine_form.save(commit=False)
                machine.owner = member
                machine.name = check_machine_name(machine, member)
                machine.save()
                new_ip = Ippool.objects.filter(mac=None)[0]
                new_ip.mac = machine
                new_ip.save()
                messages.info(request, u"La machine a été ajoutée")
                return redirect("ogre_member_show", uuid=uuid)
            else:
                messages.error(request, u"La machine n'a pas pu être ajoutée")
        
        payments = Paginator(Payment.objects.filter(member=member).order_by('date').reverse(), page_size).page(payment_page or 1)
        history = Paginator(History.objects.filter(member=member).order_by('date').reverse(), page_size).page(history_page or 1)
        machines = Machine.objects.filter(owner=member)
        member_machines = list()
        for machine in machines:
            try:
                ip = Ippool.objects.get(mac=machine)
            except Ippool.DoesNotExist:
                ip = None
            member_machines.append((machine, ip))
        
        
        return render(request, "ogre/member/details.html",{
            'member': member,
            'machines': member_machines,
            'payments': payments,
            'history': history,
            'machine_form': machine_form,
            'can_renew': is_year_registration(member.networkuntil, today=date.today()) if member.networkuntil else True,
            'new_machine_name': check_machine_name(None, member),
        })
    except Member.DoesNotExist:
        messages.warning(request, u"Impossible de trouver la personne demandée")
        return redirect("ogre_member")