Ejemplo n.º 1
0
def branch_ban(request, branch_id, user_id):
    """ Ban an user form the branch id """
    branch = get_object_or_404(Branch, pk=branch_id)
    user = get_object_or_404(User, pk=user_id)

    if can_manage(user, request.user):
        try:
            to_remove = BranchMembers.objects.get(branch=branch_id,
                                                  user=user_id)
            to_remove.delete()
            branch.banned.add(to_remove.user)
        except:
            pass

        subject = _('Bannissement de la branche {branch}').format(
            branch=branch.name)
        body = _(
            'Vous avez été banni de la branche {branch}. Vous ne pouvez à présent plus rejoindre cette branche. Pour plus d\'informations, contactez un adminstrateur ou l\'officier en charge de la branche en question'
        ).format(branch=branch.name)
        pm_write(request.user, user, subject, body)
        messages.add_message(
            request, messages.INFO,
            _('{user} a été banni de la branche {branch}').format(
                branch=branch, user=user))

        Offer.objects.filter(branch=branch, donor=user).delete()
        Demand.objects.filter(branch=branch,
                              receiver=user,
                              success=None,
                              closed=False).delete()

    else:
        return refuse(request)

    return redirect(branch.get_absolute_url())
Ejemplo n.º 2
0
def verified_display_view(request, user_id):
    """show verified informations on user selected"""
    user_to_display = get_object_or_404(User, pk=user_id)
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    if not can_manage(user_to_display, request.user) or user_to_display.id == request.user.id:
        return refuse(request)
    return render(request, 'verified/verified_display.html', locals())
Ejemplo n.º 3
0
def branch_leave(request, branch_id, user_id):
    """ Leave a branch """
    branch = get_object_or_404(Branch, pk=branch_id)
    user = get_object_or_404(User, pk=user_id)

    if can_manage(user, request.user) and user.id != branch.creator:
        try:
            to_remove = BranchMembers.objects.get(branch=branch_id,
                                                  user=user_id)
            to_remove.delete()
            Demand.objects.filter(branch=branch,
                                  receiver=user,
                                  success=None,
                                  closed=False).delete()
            Offer.objects.filter(branch=branch, donor=user).delete()
            messages.add_message(
                request, messages.INFO,
                _('Vous avez quitté la branche {branch}').format(
                    branch=branch))
        except:
            pass
    else:
        return refuse(request)

    return redirect('home')
Ejemplo n.º 4
0
def branch_ban(request, branch_id, user_id):
    """ Ban an user form the branch id """
    branch = get_object_or_404(Branch, pk=branch_id)
    user = get_object_or_404(User, pk=user_id)

    if can_manage(user, request.user):
        try:
            to_remove = BranchMembers.objects.get(branch=branch_id, user=user_id)
            to_remove.delete()
            branch.banned.add(to_remove.user)
        except:
            pass

        subject = _('Bannissement de la branche {branch}').format(branch=branch.name)
        body = _('Vous avez été banni de la branche {branch}. Vous ne pouvez à présent plus rejoindre cette branche. Pour plus d\'informations, contactez un adminstrateur ou l\'officier en charge de la branche en question').format(branch=branch.name)
        pm_write(request.user, user, subject, body)
        messages.add_message(request, messages.INFO, _('{user} a été banni de la branche {branch}').format(branch=branch, user=user))

        Offer.objects.filter(branch=branch, donor=user).delete()
        Demand.objects.filter(branch=branch, receiver=user, success=None, closed=False).delete()

    else :
        return refuse(request)

    return redirect(branch.get_absolute_url())
Ejemplo n.º 5
0
def verified_display_view(request, user_id):
    """show verified informations on user selected"""
    user_to_display = get_object_or_404(User, pk=user_id)
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    if not can_manage(user_to_display,
                      request.user) or user_to_display.id == request.user.id:
        return refuse(request)
    return render(request, 'verified/verified_display.html', locals())
Ejemplo n.º 6
0
def verified_status_refuse_view(request, user_id):
    """Refuse verified status to user with user_id, send a specific message and remove verified demand"""
    user = get_object_or_404(User, pk=user_id)
    if not can_manage(user, request.user) or user.id == request.user.id:
        return refuse(request)
    user.is_verified = False
    user.save()
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    verified_documents.delete()
    subject = _("Accord du status de membre vérifié")
    body = _("Le status de membre vérifié vous a été refusé. Pour plus d'informations, contactez l'officier responsable de votre branche.")
    pm_write(request.user, user, subject, body)
    messages.add_message(request, messages.INFO, _('Droit refusé et demande supprimée'))
    return redirect(user.get_absolute_url())
Ejemplo n.º 7
0
def verified_status_giving_view(request, user_id):
    """Give verified status to user with user_id and send a message"""
    user = get_object_or_404(User, pk=user_id)
    if not can_manage(user, request.user) or user.id == request.user.id:
        return refuse(request)
    user.is_verified = True
    user.user_type = MemberType.VERIFIED_MEMBER
    user.save()
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    verified_documents.delete()
    subject = _("Accord du status de membre vérifié")
    body = _("Le status de membre vérifié vous a été accordé ! Félicitations.")
    pm_write(request.user, user, subject, body)
    messages.add_message(request, messages.INFO, _('Droit accordé'))
    return redirect(user.get_absolute_url())
Ejemplo n.º 8
0
def verified_status_giving_view(request, user_id):
    """Give verified status to user with user_id and send a message"""
    user = get_object_or_404(User, pk=user_id)
    if not can_manage(user, request.user) or user.id == request.user.id:
        return refuse(request)
    user.is_verified = True
    user.user_type = MemberType.VERIFIED_MEMBER
    user.save()
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    verified_documents.delete()
    subject = _("Accord du status de membre vérifié")
    body = _("Le status de membre vérifié vous a été accordé ! Félicitations.")
    pm_write(request.user, user, subject, body)
    messages.add_message(request, messages.INFO, _('Droit accordé'))
    return redirect(user.get_absolute_url())
Ejemplo n.º 9
0
def verified_status_refuse_view(request, user_id):
    """Refuse verified status to user with user_id, send a specific message and remove verified demand"""
    user = get_object_or_404(User, pk=user_id)
    if not can_manage(user, request.user) or user.id == request.user.id:
        return refuse(request)
    user.is_verified = False
    user.save()
    verified_documents = get_object_or_404(VerifiedInformation, user=user_id)
    verified_documents.delete()
    subject = _("Accord du status de membre vérifié")
    body = _(
        "Le status de membre vérifié vous a été refusé. Pour plus d'informations, contactez l'officier responsable de votre branche."
    )
    pm_write(request.user, user, subject, body)
    messages.add_message(request, messages.INFO,
                         _('Droit refusé et demande supprimée'))
    return redirect(user.get_absolute_url())
Ejemplo n.º 10
0
def branch_leave(request, branch_id, user_id):
    """ Leave a branch """
    branch = get_object_or_404(Branch, pk=branch_id)
    user = get_object_or_404(User, pk=user_id)

    if can_manage(user, request.user) and user.id != branch.creator :
        try:
            to_remove = BranchMembers.objects.get(branch=branch_id, user=user_id)
            to_remove.delete()
            Demand.objects.filter(branch=branch, receiver=user, success=None, closed=False).delete()
            Offer.objects.filter(branch=branch, donor=user).delete()
            messages.add_message(request, messages.INFO, _('Vous avez quitté la branche {branch}').format(branch=branch))
        except:
            pass
    else :
        return refuse(request)

    return redirect('home')
Ejemplo n.º 11
0
def user_profile(request, user_id):
    """ Get profile from a user"""
    user_to_display = get_object_or_404(User, pk=user_id)
    user = request.user
    in_other_network = False
    in_other_ignore_list = False
    can_manage_user = False

    if user.is_authenticated():

        if request.user.id != user_to_display.id:
            if request.user in user_to_display.personal_network.all():
                in_other_network = True
            if request.user in user_to_display.ignore_list.all():
                in_other_ignore_list = True
            if can_manage(user_to_display, user):
                can_manage_user = True
        else:
            can_manage_user = True

        if in_other_ignore_list and not request.user.is_superuser:
            messages.add_message(
                request, messages.INFO,
                _('Vous êtes pas autoriser à consulter ce profil'))
            return redirect('home')

        pending_demands = Demand.objects.filter(donor=user_to_display)
        is_my_friend = False
        is_in_my_network = False
        if user_to_display in user.favorites.all():
            is_my_friend = True
        if user_to_display in user.personal_network.all():
            is_in_my_network = True

        form_favorite = AddUser()
        form_network = AddUser()
        form_ignored = AddUser()

        if request.POST:
            if 'favorite' in request.POST:
                form_favorite = AddUser(request.POST)
                if form_favorite.is_valid():
                    try:
                        added_user = User.objects.get(
                            username=form_favorite.cleaned_data['user'])
                        user_to_display.favorites.add(added_user)
                        messages.add_message(
                            request, messages.INFO,
                            __('Utilisateur {user} ajouté').format(
                                user=added_user))
                    except:
                        pass
                    form_favorite = AddUser()

            if 'network' in request.POST:
                form_network = AddUser(request.POST)
                if form_network.is_valid():
                    try:
                        added_user = User.objects.get(
                            username=form_network.cleaned_data['user'])
                        user_to_display.personal_network.add(added_user)
                        messages.add_message(
                            request, messages.INFO,
                            __('Utilisateur {user} ajouté').format(
                                user=added_user))
                    except:
                        pass
                    form_network = AddUser()

            if 'ignored' in request.POST:
                form_ignored = AddUser(request.POST)
                if form_ignored.is_valid():
                    try:
                        added_user = User.objects.get(
                            username=form_ignored.cleaned_data['user'])
                        user_to_display.ignore_list.add(added_user)
                        messages.add_message(
                            request, messages.INFO,
                            __('Utilisateur {user} ajouté').format(
                                user=added_user))
                    except:
                        pass
                    form_ignored = AddUser()

    return render(request, 'profile/user_profile.html', locals())
Ejemplo n.º 12
0
def user_profile(request, user_id):
    """ Get profile from a user"""
    user_to_display = get_object_or_404(User, pk=user_id)
    user = request.user
    in_other_network = False
    in_other_ignore_list = False
    can_manage_user = False

    if user.is_authenticated():

        if request.user.id != user_to_display.id:
            if request.user in user_to_display.personal_network.all():
                in_other_network = True
            if request.user in user_to_display.ignore_list.all():
                in_other_ignore_list = True
            if can_manage(user_to_display,user):
                can_manage_user = True
        else:
            can_manage_user = True

        if in_other_ignore_list and not request.user.is_superuser :
            messages.add_message(request, messages.INFO, _('Vous êtes pas autoriser à consulter ce profil'))
            return redirect('home')

        pending_demands = Demand.objects.filter(donor=user_to_display)
        is_my_friend = False
        is_in_my_network = False
        if user_to_display in user.favorites.all():
            is_my_friend = True
        if user_to_display in user.personal_network.all():
            is_in_my_network = True

        form_favorite = AddUser()
        form_network = AddUser()
        form_ignored = AddUser()

        if request.POST:
            if 'favorite' in request.POST:
                form_favorite = AddUser(request.POST)
                if form_favorite.is_valid():
                    try:
                        added_user = User.objects.get(username=form_favorite.cleaned_data['user'])
                        user_to_display.favorites.add(added_user)
                        messages.add_message(request, messages.INFO, __('Utilisateur {user} ajouté').format(user=added_user))
                    except:
                        pass
                    form_favorite = AddUser()

            if 'network' in request.POST:
                form_network = AddUser(request.POST)
                if form_network.is_valid():
                    try:
                        added_user = User.objects.get(username=form_network.cleaned_data['user'])
                        user_to_display.personal_network.add(added_user)
                        messages.add_message(request, messages.INFO, __('Utilisateur {user} ajouté').format(user=added_user))
                    except:
                        pass
                    form_network = AddUser()

            if 'ignored' in request.POST:
                form_ignored = AddUser(request.POST)
                if form_ignored.is_valid():
                    try:
                        added_user = User.objects.get(username=form_ignored.cleaned_data['user'])
                        user_to_display.ignore_list.add(added_user)
                        messages.add_message(request, messages.INFO, __('Utilisateur {user} ajouté').format(user=added_user))
                    except:
                        pass
                    form_ignored = AddUser()

    return render(request, 'profile/user_profile.html', locals())