예제 #1
0
파일: views.py 프로젝트: erdnaxe/aube
def finish_results(results, col, order):
    """Sort the results by applying filters and then limit them to the
    number of max results. Finally add the info of the nmax number of results
    to the dict"""

    results['users'] = SortTable.sort(results['users'], col, order,
                                      SortTable.USERS_INDEX)
    results['machines'] = SortTable.sort(results['machines'], col, order,
                                         SortTable.MACHINES_INDEX)
    results['factures'] = SortTable.sort(results['factures'], col, order,
                                         SortTable.COTISATIONS_INDEX)
    results['bans'] = SortTable.sort(results['bans'], col, order,
                                     SortTable.USERS_INDEX_BAN)
    results['whitelists'] = SortTable.sort(results['whitelists'], col, order,
                                           SortTable.USERS_INDEX_WHITE)
    results['rooms'] = SortTable.sort(results['rooms'], col, order,
                                      SortTable.TOPOLOGIE_INDEX_ROOM)
    results['ports'] = SortTable.sort(results['ports'], col, order,
                                      SortTable.TOPOLOGIE_INDEX_PORT)
    results['switches'] = SortTable.sort(results['switches'], col, order,
                                         SortTable.TOPOLOGIE_INDEX)

    max_result = GeneralOption.get_cached_value('search_display_page')
    for name, val in results.items():
        results[name] = val.distinct()[:max_result]
    results.update({'max_result': max_result})

    return results
예제 #2
0
def index_physical_grouping(request):
    """Affichage de la liste des stacks (affiche l'ensemble des switches)"""
    stack_list = (Stack.objects.prefetch_related(
        'switch_set__interface_set__domain__extension'))
    switch_bay_list = SwitchBay.objects.select_related('building')
    stack_list = SortTable.sort(stack_list, request.GET.get('col'),
                                request.GET.get('order'),
                                SortTable.TOPOLOGIE_INDEX_STACK)
    switch_bay_list = SortTable.sort(switch_bay_list, request.GET.get('col'),
                                     request.GET.get('order'),
                                     SortTable.TOPOLOGIE_INDEX_SWITCH_BAY)
    return render(request, 'topologie/index_physical_grouping.html', {
        'stack_list': stack_list,
        'switch_bay_list': switch_bay_list,
    })
예제 #3
0
def stats_logs(request):
    """View used to do an advanced search through the logs."""
    actions_form = ActionsSearchForm(request.GET or None)

    if actions_form.is_valid():
        actions = ActionsSearch()
        revisions = actions.get(actions_form.cleaned_data)
        revisions = SortTable.sort(
            revisions,
            request.GET.get("col"),
            request.GET.get("order"),
            SortTable.LOGS_STATS_LOGS,
        )

        pagination_number = GeneralOption.get_cached_value("pagination_number")
        revisions = re2o_paginator(request, revisions, pagination_number)

        # Only do this now so it's not applied to objects which aren't displayed
        # It can take a bit of time because it has to compute the diff of each version
        revisions.object_list = [RevisionAction(r) for r in revisions.object_list]
        return render(request, "logs/stats_logs.html", {"revisions_list": revisions})

    return render(
        request, "logs/search_stats_logs.html", {"actions_form": actions_form}
    )
예제 #4
0
def index(request):
    """ Vue d'affichage de tous les swicthes"""
    switch_list = (Switch.objects.prefetch_related(
        Prefetch(
            'interface_set',
            queryset=(
                Interface.objects.select_related('ipv4__ip_type__extension').
                select_related('domain__extension')))).select_related('stack'))
    switch_list = SortTable.sort(switch_list, request.GET.get('col'),
                                 request.GET.get('order'),
                                 SortTable.TOPOLOGIE_INDEX)

    pagination_number = GeneralOption.get_cached_value('pagination_number')
    switch_list = re2o_paginator(request, switch_list, pagination_number)

    if any(service_link.need_regen
           for service_link in Service_link.objects.filter(
               service__service_type='graph_topo')):
        make_machine_graph()
        for service_link in Service_link.objects.filter(
                service__service_type='graph_topo'):
            service_link.done_regen()

    if not isfile("/var/www/re2o/media/images/switchs.png"):
        make_machine_graph()
    return render(request, 'topologie/index.html',
                  {'switch_list': switch_list})
예제 #5
0
def index_model_switch(request):
    """ Affichage de l'ensemble des modèles de switches"""
    model_switch_list = ModelSwitch.objects.select_related('constructor')
    constructor_switch_list = ConstructorSwitch.objects
    model_switch_list = SortTable.sort(model_switch_list,
                                       request.GET.get('col'),
                                       request.GET.get('order'),
                                       SortTable.TOPOLOGIE_INDEX_MODEL_SWITCH)
    constructor_switch_list = SortTable.sort(
        constructor_switch_list, request.GET.get('col'),
        request.GET.get('order'), SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH)
    return render(
        request, 'topologie/index_model_switch.html', {
            'model_switch_list': model_switch_list,
            'constructor_switch_list': constructor_switch_list,
        })
예제 #6
0
def control(request):
    """
    View used to control the invoices all at once.
    """
    pagination_number = GeneralOption.get_cached_value("pagination_number")
    invoice_list = Facture.objects.select_related("user").select_related(
        "paiement")
    invoice_list = SortTable.sort(
        invoice_list,
        request.GET.get("col"),
        request.GET.get("order"),
        SortTable.COTISATIONS_CONTROL,
    )
    control_invoices_formset = modelformset_factory(Facture,
                                                    fields=("control",
                                                            "valid"),
                                                    extra=0)
    invoice_list = re2o_paginator(request, invoice_list, pagination_number)
    control_invoices_form = control_invoices_formset(
        request.POST or None, queryset=invoice_list.object_list)
    if control_invoices_form.is_valid():
        control_invoices_form.save()
        reversion.set_comment("Control")
        messages.success(
            request, _("Your changes have been properly taken into account."))
        return redirect(reverse("cotisations:control"))
    return render(
        request,
        "cotisations/control.html",
        {
            "facture_list": invoice_list,
            "controlform": control_invoices_form
        },
    )
예제 #7
0
파일: views.py 프로젝트: erdnaxe/aube
def index(request):
    """ The home view for this app. Displays the list of registered
    machines in Re2o """
    pagination_large_number = (GeneralOption
                               .get_cached_value('pagination_large_number'))
    machines_list = (Machine.objects
                     .select_related('user')
                     .prefetch_related('interface_set__domain__extension')
                     .prefetch_related('interface_set__ipv4__ip_type')
                     .prefetch_related(
        'interface_set__machine_type__ip_type__extension'
    ).prefetch_related(
        'interface_set__domain__related_domain__extension'
    ).prefetch_related('interface_set__ipv6list'))
    machines_list = SortTable.sort(
        machines_list,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.MACHINES_INDEX
    )
    machines_list = re2o_paginator(
        request,
        machines_list,
        pagination_large_number
    )
    return render(
        request,
        'machines/index.html',
        {'machines_list': machines_list}
    )
예제 #8
0
파일: views.py 프로젝트: erdnaxe/aube
def index(request):
    """ Affiche l'ensemble des adherents, need droit cableur """
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    users_list = Adherent.objects.select_related('room')
    users_list = SortTable.sort(
        users_list,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.USERS_INDEX
    )
    users_list = re2o_paginator(request, users_list, pagination_number)
    return render(request, 'users/index.html', {'users_list': users_list})
예제 #9
0
파일: views.py 프로젝트: erdnaxe/aube
def index(request):
    """
    View used to display the list of all exisitng invoices.
    """
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    invoice_list = Facture.objects.select_related('user')\
        .select_related('paiement').prefetch_related('vente_set')
    invoice_list = SortTable.sort(invoice_list, request.GET.get('col'),
                                  request.GET.get('order'),
                                  SortTable.COTISATIONS_INDEX)
    invoice_list = re2o_paginator(request, invoice_list, pagination_number)
    return render(request, 'cotisations/index.html', {
        'facture_list': invoice_list,
    })
예제 #10
0
def index_ap(request):
    """ Affichage de l'ensemble des bornes"""
    ap_list = (AccessPoint.objects.prefetch_related(
        Prefetch(
            'interface_set',
            queryset=(
                Interface.objects.select_related('ipv4__ip_type__extension').
                select_related('domain__extension')))).distinct())
    ap_list = SortTable.sort(ap_list, request.GET.get('col'),
                             request.GET.get('order'),
                             SortTable.TOPOLOGIE_INDEX_BORNE)
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    ap_list = re2o_paginator(request, ap_list, pagination_number)
    return render(request, 'topologie/index_ap.html', {'ap_list': ap_list})
예제 #11
0
파일: views.py 프로젝트: erdnaxe/aube
def index_cost_estimate(request):
    """View used to display every custom invoice."""
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    cost_estimate_list = CostEstimate.objects.prefetch_related('vente_set')
    cost_estimate_list = SortTable.sort(cost_estimate_list,
                                        request.GET.get('col'),
                                        request.GET.get('order'),
                                        SortTable.COTISATIONS_CUSTOM)
    cost_estimate_list = re2o_paginator(
        request,
        cost_estimate_list,
        pagination_number,
    )
    return render(request, 'cotisations/index_cost_estimate.html',
                  {'cost_estimate_list': cost_estimate_list})
예제 #12
0
def stats_logs(request):
    """Affiche l'ensemble des logs et des modifications sur les objets,
    classés par date croissante, en vrac"""
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    revisions = Revision.objects.all().select_related('user')\
        .prefetch_related('version_set__object')
    revisions = SortTable.sort(
        revisions,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.LOGS_STATS_LOGS
    )
    revisions = re2o_paginator(request, revisions, pagination_number)
    return render(request, 'logs/stats_logs.html', {
        'revisions_list': revisions
    })
예제 #13
0
def index(request):
    """
    View used to display the list of all exisitng invoices.
    """
    pagination_number = GeneralOption.get_cached_value("pagination_number")
    invoice_list = (Facture.objects.select_related("user").select_related(
        "paiement").prefetch_related("vente_set"))
    invoice_list = SortTable.sort(
        invoice_list,
        request.GET.get("col"),
        request.GET.get("order"),
        SortTable.COTISATIONS_INDEX,
    )
    invoice_list = re2o_paginator(request, invoice_list, pagination_number)
    return render(request, "cotisations/index.html",
                  {"facture_list": invoice_list})
예제 #14
0
파일: views.py 프로젝트: erdnaxe/aube
def index_clubs(request):
    """ Affiche l'ensemble des clubs, need droit cableur """
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    clubs_list = Club.objects.select_related('room')
    clubs_list = SortTable.sort(
        clubs_list,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.USERS_INDEX
    )
    clubs_list = re2o_paginator(request, clubs_list, pagination_number)
    return render(
        request,
        'users/index_clubs.html',
        {'clubs_list': clubs_list}
    )
예제 #15
0
def index_cost_estimate(request):
    """View used to display every custom invoice."""
    pagination_number = GeneralOption.get_cached_value("pagination_number")
    cost_estimate_list = CostEstimate.objects.prefetch_related("vente_set")
    cost_estimate_list = SortTable.sort(
        cost_estimate_list,
        request.GET.get("col"),
        request.GET.get("order"),
        SortTable.COTISATIONS_CUSTOM,
    )
    cost_estimate_list = re2o_paginator(request, cost_estimate_list,
                                        pagination_number)
    return render(
        request,
        "cotisations/index_cost_estimate.html",
        {"cost_estimate_list": cost_estimate_list},
    )
예제 #16
0
def index_port(request, switch, switchid):
    """ Affichage de l'ensemble des ports reliés à un switch particulier"""
    port_list = (Port.objects.filter(
        switch=switch).select_related('room').select_related(
            'machine_interface__domain__extension'
        ).select_related('machine_interface__machine__user').select_related(
            'related__switch').prefetch_related(
                Prefetch('related__switch__interface_set',
                         queryset=(Interface.objects.select_related(
                             'domain__extension')))).select_related('switch'))
    port_list = SortTable.sort(port_list, request.GET.get('col'),
                               request.GET.get('order'),
                               SortTable.TOPOLOGIE_INDEX_PORT)
    return render(request, 'topologie/index_p.html', {
        'port_list': port_list,
        'id_switch': switchid,
        'switch': switch
    })
예제 #17
0
def index(request):
    """Affiche les logs affinés, date reformatées, selectionne
    les event importants (ajout de droits, ajout de ban/whitelist)"""
    pagination_number = GeneralOption.get_cached_value('pagination_number')
    # The types of content kept for display
    content_type_filter = ['ban', 'whitelist', 'vente', 'interface', 'user']
    # Select only wanted versions
    versions = Version.objects.filter(
        content_type__in=ContentType.objects.filter(
            model__in=content_type_filter
        )
    ).select_related('revision')
    versions = SortTable.sort(
        versions,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.LOGS_INDEX
    )
    versions = re2o_paginator(request, versions, pagination_number)
    # Force to have a list instead of QuerySet
    versions.count(0)
    # Items to remove later because invalid
    to_remove = []
    # Parse every item (max = pagination_number)
    for i in range(len(versions.object_list)):
        if versions.object_list[i].object:
            version = versions.object_list[i]
            versions.object_list[i] = {
                'rev_id': version.revision.id,
                'comment': version.revision.comment,
                'datetime': version.revision.date_created.strftime(
                    '%d/%m/%y %H:%M:%S'
                ),
                'username':
                    version.revision.user.get_username()
                    if version.revision.user else '?',
                'user_id': version.revision.user_id,
                'version': version}
        else:
            to_remove.insert(0, i)
    # Remove all tagged invalid items
    for i in to_remove:
        versions.object_list.pop(i)
    return render(request, 'logs/index.html', {'versions_list': versions})
예제 #18
0
def index(request):
    """View used to display summary of events about users."""
    pagination_number = GeneralOption.get_cached_value("pagination_number")
    # The types of content kept for display
    content_type_filter = ["ban", "whitelist", "vente", "interface", "user"]
    # Select only wanted versions
    versions = Version.objects.filter(
        content_type__in=ContentType.objects.filter(model__in=content_type_filter)
    ).select_related("revision")
    versions = SortTable.sort(
        versions, request.GET.get("col"), request.GET.get("order"), SortTable.LOGS_INDEX
    )
    versions = re2o_paginator(request, versions, pagination_number)
    # Force to have a list instead of QuerySet
    versions.count(0)
    # Items to remove later because invalid
    to_remove = []
    # Parse every item (max = pagination_number)
    for i in range(len(versions.object_list)):
        if versions.object_list[i].object:
            version = versions.object_list[i]
            versions.object_list[i] = {
                "rev_id": version.revision.id,
                "comment": version.revision.comment,
                "datetime": version.revision.date_created,
                "username": version.revision.user.get_username()
                if version.revision.user
                else "?",
                "user_id": version.revision.user_id,
                "version": version,
            }
        else:
            to_remove.insert(0, i)
    # Remove all tagged invalid items
    for i in to_remove:
        versions.object_list.pop(i)
    return render(request, "logs/index.html", {"versions_list": versions})
예제 #19
0
def aff_profil(request, user):
    """View used to display the cotisations on a user's profil."""

    factures = Facture.objects.filter(user=user)
    factures = SortTable.sort(
        factures,
        request.GET.get("col"),
        request.GET.get("order"),
        SortTable.COTISATIONS_INDEX,
    )

    pagination_large_number = GeneralOption.get_cached_value(
        "pagination_large_number")
    factures = re2o_paginator(request, factures, pagination_large_number)

    context = {
        "users": user,
        "facture_list": factures,
    }

    return render_to_string("cotisations/aff_profil.html",
                            context=context,
                            request=request,
                            using=None)
예제 #20
0
파일: views.py 프로젝트: erdnaxe/aube
def profil(request, users, **_kwargs):
    """ Affiche un profil, self or cableur, prend un userid en argument """
    machines = Machine.objects.filter(user=users).select_related('user')\
        .prefetch_related('interface_set__domain__extension')\
        .prefetch_related('interface_set__ipv4__ip_type__extension')\
        .prefetch_related('interface_set__machine_type')\
        .prefetch_related('interface_set__domain__related_domain__extension')
    machines = SortTable.sort(
        machines,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.MACHINES_INDEX
    )
    pagination_large_number = GeneralOption.get_cached_value(
        'pagination_large_number'
    )
    nb_machines = machines.count()
    machines = re2o_paginator(request, machines, pagination_large_number)
    factures = Facture.objects.filter(user=users)
    factures = SortTable.sort(
        factures,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.COTISATIONS_INDEX
    )
    bans = Ban.objects.filter(user=users)
    bans = SortTable.sort(
        bans,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.USERS_INDEX_BAN
    )
    whitelists = Whitelist.objects.filter(user=users)
    whitelists = SortTable.sort(
        whitelists,
        request.GET.get('col'),
        request.GET.get('order'),
        SortTable.USERS_INDEX_WHITE
    )
    try:
        balance = find_payment_method(Paiement.objects.get(is_balance=True))
    except Paiement.DoesNotExist:
        user_solde = False
    else:
        user_solde = (
            balance is not None
            and balance.can_credit_balance(request.user)
        )
    return render(
        request,
        'users/profil.html',
        {
            'users': users,
            'machines_list': machines,
            'nb_machines': nb_machines,
            'facture_list': factures,
            'ban_list': bans,
            'white_list': whitelists,
            'user_solde': user_solde,
            'solde_activated': Paiement.objects.filter(is_balance=True).exists(),
            'asso_name': AssoOption.objects.first().name,
            'emailaddress_list': users.email_address,
            'local_email_accounts_enabled': (
                OptionalUser.objects.first().local_email_accounts_enabled
            )
        }
    )