Ejemplo n.º 1
0
    def handle(self, *args, **options):

        LEVEL_MAPPING = {
            'prive': 'private',
            'groupe': 'com',
            'member': 'agep',
            'public': 'all'
        }

        retour = []

        for user in TruffeUser.objects.all():

            data = {
                'username': user.username,
                'emailEpfl': user.email,
                'prenom': user.first_name,
                'nom': user.last_name,
                'mobile': user.mobile,
                'adresse': user.adresse,
                'banque': user.nom_banque,
                'ibanOrCcp': user.iban_ou_ccp,
                'emailPerso': user.email_perso,
                'password': user.password,
                'mobileVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'mobile')),
                'adresseVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'adresse')),
                'banqueVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'nom_banque')),
                'ibanOrCcpVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'iban_ou_ccp')),
            }


            retour.append(data)

        print(json.dumps({'data': retour}))
Ejemplo n.º 2
0
    def handle(self, *args, **options):

        LEVEL_MAPPING = {
            'prive': 'private',
            'groupe': 'com',
            'member': 'agep',
            'public': 'all'
        }

        retour = []

        for user in TruffeUser.objects.all():

            data = {
                'username': user.username,
                'emailEpfl': user.email,
                'prenom': user.first_name,
                'nom': user.last_name,
                'mobile': user.mobile,
                'adresse': user.adresse,
                'banque': user.nom_banque,
                'ibanOrCcp': user.iban_ou_ccp,
                'emailPerso': user.email_perso,
                'password': user.password,
                'mobileVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'mobile')),
                'adresseVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'adresse')),
                'banqueVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'nom_banque')),
                'ibanOrCcpVisibility': LEVEL_MAPPING.get(UserPrivacy.get_privacy_for_field(user, 'iban_ou_ccp')),
            }


            retour.append(data)

        print json.dumps({'data': retour})
Ejemplo n.º 3
0
def users_profile(request, pk):
    """Display a user profile"""

    user = get_object_or_404(TruffeUser, pk=pk)

    privacy_values = {}

    for field in UserPrivacy.FIELD_CHOICES:
        privacy_values[field[0]] = UserPrivacy.user_can_access(request.user, user, field[0])

    return render(request, "users/users/profile.html", {"user_to_display": user, "privacy_values": privacy_values})
Ejemplo n.º 4
0
def users_profile(request, pk):
    """Display a user profile"""

    user = get_object_or_404(TruffeUser, pk=pk)

    privacy_values = {}

    for field in UserPrivacy.FIELD_CHOICES:
        privacy_values[field[0]] = UserPrivacy.user_can_access(request.user, user, field[0])

    return render(request, 'users/users/profile.html', {'user_to_display': user, 'privacy_values': privacy_values})
Ejemplo n.º 5
0
def users_edit(request, pk):
    """Edit a user profile"""

    user = get_object_or_404(TruffeUser, pk=pk)

    if not user.rights_can("EDIT", request.user):
        raise Http404

    if request.method == "POST":  # If the form has been submitted...
        form = TruffeUserForm(request.user, request.POST, request.FILES, instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = request.POST.get("priv_val_" + field[0])

        if form.is_valid():  # If the form is valid
            user = form.save()

            if user.mobile:
                user.mobile = phonenumbers.format_number(
                    phonenumbers.parse(user.mobile, "CH"), phonenumbers.PhoneNumberFormat.E164
                )
                user.save()

            for (field, value) in privacy_values.iteritems():
                # At this point, the object should exist !
                UserPrivacy.objects.filter(user=user, field=field).update(level=value)

            messages.success(request, _(u"Profil sauvegardé !"))

            return redirect("users.views.users_profile", pk=user.pk)
    else:
        form = TruffeUserForm(request.user, instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = UserPrivacy.get_privacy_for_field(user, field[0])

    privacy_choices = UserPrivacy.LEVEL_CHOICES

    return render(
        request,
        "users/users/edit.html",
        {"form": form, "privacy_choices": privacy_choices, "privacy_values": privacy_values},
    )
Ejemplo n.º 6
0
def users_edit(request, pk):
    """Edit a user profile"""

    user = get_object_or_404(TruffeUser, pk=pk)

    if not user.rights_can('EDIT', request.user):
        raise Http404

    if request.method == 'POST':  # If the form has been submitted...
        form = TruffeUserForm(request.user,
                              request.POST,
                              request.FILES,
                              instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = request.POST.get('priv_val_' + field[0])

        if form.is_valid():  # If the form is valid
            user = form.save()

            for (field, value) in privacy_values.iteritems():
                # At this point, the object should exist !
                UserPrivacy.objects.filter(user=user,
                                           field=field).update(level=value)

            messages.success(request, _(u'Profil sauvegardé !'))

            return redirect('users.views.users_profile', pk=user.pk)
    else:
        form = TruffeUserForm(request.user, instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = UserPrivacy.get_privacy_for_field(
                user, field[0])

    privacy_choices = UserPrivacy.LEVEL_CHOICES

    return render(
        request, 'users/users/edit.html', {
            'form': form,
            'privacy_choices': privacy_choices,
            'privacy_values': privacy_values
        })
Ejemplo n.º 7
0
def users_myunit_pdf(request):
    """PDF of users in the current unit"""

    current_unit = get_current_unit(request)

    if not current_unit.is_user_in_groupe(request.user):
        raise Http404

    no_display = bool(request.GET.get('no_display', False))

    liste = []

    for accred in current_unit.current_accreds():
        accred.truffe2_tmp_pdf_display_mobile = UserPrivacy.user_can_access(request.user, accred.user, 'mobile')
        liste.append(accred)

    return generate_pdf("users/users/myunit_pdf.html", request, {'unit': current_unit, 'liste': liste, 'no_display_name': no_display})
Ejemplo n.º 8
0
def users_myunit_pdf(request):
    """PDF of users in the current unit"""

    current_unit = get_current_unit(request)

    if not current_unit.is_user_in_groupe(request.user):
        raise Http404

    no_display = bool(request.GET.get('no_display', False))

    liste = []

    for accred in current_unit.current_accreds():
        accred.truffe2_tmp_pdf_display_mobile = UserPrivacy.user_can_access(request.user, accred.user, 'mobile')
        liste.append(accred)

    return generate_pdf("users/users/myunit_pdf.html", request, {'unit': current_unit, 'liste': liste, 'no_display_name': no_display})
Ejemplo n.º 9
0
def users_edit(request, pk):
    """Edit a user profile"""

    user = get_object_or_404(TruffeUser, pk=pk)

    if not user.rights_can('EDIT', request.user):
        raise Http404

    if request.method == 'POST':  # If the form has been submitted...
        form = TruffeUserForm(request.user, request.POST, request.FILES, instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = request.POST.get('priv_val_' + field[0])

        if form.is_valid():  # If the form is valid
            user = form.save()

            for (field, value) in privacy_values.iteritems():
                # At this point, the object should exist !
                UserPrivacy.objects.filter(user=user, field=field).update(level=value)

            messages.success(request, _(u'Profil sauvegardé !'))

            return redirect('users.views.users_profile', pk=user.pk)
    else:
        form = TruffeUserForm(request.user, instance=user)

        privacy_values = {}

        for field in UserPrivacy.FIELD_CHOICES:
            privacy_values[field[0]] = UserPrivacy.get_privacy_for_field(user, field[0])

    privacy_choices = UserPrivacy.LEVEL_CHOICES

    return render(request, 'users/users/edit.html', {'form': form, 'privacy_choices': privacy_choices, 'privacy_values': privacy_values})