예제 #1
0
파일: views.py 프로젝트: jdjebi/TECHNOHACK
def check_user_eat1(request, participant_id):

    response = {
        'error': False,
        #'details': None,
        'participant': None
    }

    participant = Participant.objects.filter(id=participant_id)

    if not participant:
        response['error_message'] = 'Identifiant du participant inconnue.'
    else:

        participant = participant.first()

        response['participant'] = {
            "info": {
                'id': participant.id,
                'nom': participant.user.first_name,
                'prenom': participant.user.last_name,
                'username': participant.user.username,
                'numero': participant.numero,
                'email': participant.user.email,
                'equipe': participant.equipe.nom,
                'is_chief': participant.is_chief
            },
            "bilan": {
                "plat_total": Plat.get_total(),
                "plat_conso": Plat.get_conso(),
                "plat_restant": Plat.get_restant(),
                "plat_imprevu": Plat.get_imprevu()
            }
        }

    return JsonResponse(response, safe=False)
예제 #2
0
파일: views.py 프로젝트: jdjebi/TECHNOHACK
def check_user_eat2(request, jour, periode, participant_id):

    response = {
        'error': False,
        'error_message': None,
        'can_eat': False,
        'participant': None
    }

    participant = Participant.objects.filter(id=participant_id)

    if not participant:
        response["error"] = True
        response['error_message'] = 'Identifiant du participant inconnue.'
    else:
        participant = participant.filter(equipe__selectionner=True)

        if not participant:
            participant_not_selected = Participant.objects.filter(
                id=participant_id).first()
            response['error'] = True
            response[
                'error_message'] = "L'equipe du participant {} n'a pas ete selectionner({}).".format(
                    participant_not_selected, participant_not_selected.equipe)
        else:
            participant = participant.first()
            # Vérifie si le participant peut manger
            if not (jour, periode) in Plat.periode_authorize:
                response["error"] = True
                response[
                    'error_message'] = "la periode ({}/{}) n'est pas autorisée. Periodes autorisées: {}".format(
                        jour, periode, Plat.periode_authorize)
            else:
                plats = Plat.objects.filter(participant=participant,
                                            type="repas")
                nbr_plats = plats.count()
                # Si on a pas encore atteint
                mx_plat = PlatConstante.get_plat_mx()

                if not nbr_plats < mx_plat:
                    response[
                        'can_eat_message'] = "Le participant {} a consomme tous ses les plats. Restants: {}".format(
                            participant, mx_plat - nbr_plats)
                else:
                    plat_de_periode = plats.filter(periode=periode).count()
                    if not plat_de_periode < PlatConstante.periodes[periode]:
                        response[
                            'can_eat_message'] = "Le participant {} n'a plus de plats pour la periode '{}'. Restants: {}".format(
                                participant, periode,
                                PlatConstante.periodes[periode] -
                                plat_de_periode)
                    else:
                        # On vérifie que le participant n'a pas encore mangé pour cette période de la journnée
                        plat_du_momment = plats.filter(periode=periode,
                                                       jour=jour).count()
                        if plat_du_momment >= 1:
                            response[
                                'can_eat_message'] = "Le participant {} a deja mange pour le {} {}, {} fois".format(
                                    participant, jour, periode,
                                    plat_du_momment)
                        else:
                            response['can_eat'] = True
                            response[
                                'can_eat_message'] = "Le participant {} est autorise a manger pour le {} {}. Restants: {}".format(
                                    participant, jour, periode,
                                    mx_plat - nbr_plats)

                response['participant'] = {
                    "info": {
                        'id': participant.id,
                        'nom': participant.user.first_name,
                        'prenom': participant.user.last_name,
                        'username': participant.user.username,
                        'numero': participant.numero,
                        'email': participant.user.email,
                        'equipe': participant.equipe.nom,
                        'is_chief': participant.is_chief
                    },
                    "stats": {
                        "plat_total": Plat.get_participant_total(),
                        "plat_conso": Plat.get_participant_conso(participant),
                        "plat_restant":
                        Plat.get_participant_restant(participant),
                        "plat_imprevu":
                        Plat.get_participant_imprevu(participant)
                    }
                }

                response['global_stats'] = {
                    "plat_total": Plat.get_total(),
                    "plat_conso": Plat.get_conso(),
                    "plat_restant": Plat.get_restant(),
                    "plat_imprevu": Plat.get_imprevu()
                }

    return JsonResponse(response, safe=False)