<commit_before># -*- coding: utf-8
"""
 ain7/annuaire/views.py
"""
#
#   Copyright © 2007-2016 AIn7 Devel Team
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#

import vobject

from autocomplete_light import shortcuts as autocomplete_light

from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect, HttpResponse
from django.utils.translation import ugettext as _
from django.shortcuts import get_object_or_404, redirect, render

from ain7.annuaire.models import (
    PersonPrivate, UserActivity, Promo,
    PhoneNumber, InstantMessaging, Email,
    WebSite, ClubMembership, Person, AIn7Member, Address,
    Position, EducationItem, LeisureItem, PublicationItem,
)
from ain7.annuaire.filters import AIn7MemberFilter, AIn7MemberAdvancedFilter
from ain7.annuaire.forms import (
    ChangePasswordForm, NewMemberForm
)
from ain7.decorators import access_required, confirmation_required
from ain7.utils import ain7_generic_delete, generate_login


@login_required
def home(request, user_name):
    user = get_object_or_404(User, username=user_name)
    user_id = Person.objects.get(user=user).id
    return details(request, user_id)


@login_required
def me(request):
    user_id = Person.objects.get(user=request.user).id
    return edit(request, user_id)


@access_required(groups=['ain7-membre', 'ain7-secretariat'])
def details(request, user_id):

    is_subscriber = False
    ain7member = None
    last_activity = None
    is_myself = int(request.user.id) == int(user_id)

    person = get_object_or_404(Person, pk=user_id)
    personprivate = get_object_or_404(PersonPrivate, person=person)

    if AIn7Member.objects.filter(person=person).count() > 0:
        ain7member = get_object_or_404(AIn7Member, person=person)
        is_subscriber = ain7member.is_subscriber()

    if UserActivity.objects.filter(person=person):
        last_activity = UserActivity.objects.filter(person=person).latest('id')

    return render(request, 'annuaire/details.html', {
        'person': person,
        'personprivate': personprivate,
        'is_subscriber': is_subscriber,
        'ain7member': ain7member,
        'is_myself': is_myself,
        'last_activity': last_activity,
        }
    )


@login_required
def search(request):

    filter = AIn7MemberFilter(request.GET, queryset=AIn7Member.objects.all())
    print filter

    return render(request, 'annuaire/search.html', {
        'filter': filter,
        'request': request,
        }
    )


@login_required
def search_adv(request):

    filter = AIn7MemberAdvancedFilter(
        request.GET,
        queryset=AIn7Member.objects.all()
    )

    return render(request, 'annuaire/search.html', {
        'filter': filter,
        'request': request,
        }
    )


@login_required
def change_credentials(request, user_id):
    is_myself = int(request.user.id) == int(user_id)

    if not is_myself:
        return HttpResponseRedirect(
            reverse('ain7.annuaire.views.details', args=[person.id]))

    person = get_object_or_404(Person, pk=user_id)
    ain7member = get_object_or_404(AIn7Member, person=person)

    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)<commit_msg>Get the Person object before using it in the profile<commit_after># -*- coding: utf-8
"""
 ain7/annuaire/views.py
"""
#
#   Copyright © 2007-2016 AIn7 Devel Team
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#

import vobject

from autocomplete_light import shortcuts as autocomplete_light

from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect, HttpResponse
from django.utils.translation import ugettext as _
from django.shortcuts import get_object_or_404, redirect, render

from ain7.annuaire.models import (
    PersonPrivate, UserActivity, Promo,
    PhoneNumber, InstantMessaging, Email,
    WebSite, ClubMembership, Person, AIn7Member, Address,
    Position, EducationItem, LeisureItem, PublicationItem,
)
from ain7.annuaire.filters import AIn7MemberFilter, AIn7MemberAdvancedFilter
from ain7.annuaire.forms import (
    ChangePasswordForm, NewMemberForm
)
from ain7.decorators import access_required, confirmation_required
from ain7.utils import ain7_generic_delete, generate_login


@login_required
def home(request, user_name):
    user = get_object_or_404(User, username=user_name)
    user_id = Person.objects.get(user=user).id
    return details(request, user_id)


@login_required
def me(request):
    user_id = Person.objects.get(user=request.user).id
    return edit(request, user_id)


@access_required(groups=['ain7-membre', 'ain7-secretariat'])
def details(request, user_id):

    is_subscriber = False
    ain7member = None
    last_activity = None
    is_myself = int(request.user.id) == int(user_id)

    person = get_object_or_404(Person, pk=user_id)
    personprivate = get_object_or_404(PersonPrivate, person=person)

    if AIn7Member.objects.filter(person=person).count() > 0:
        ain7member = get_object_or_404(AIn7Member, person=person)
        is_subscriber = ain7member.is_subscriber()

    if UserActivity.objects.filter(person=person):
        last_activity = UserActivity.objects.filter(person=person).latest('id')

    return render(request, 'annuaire/details.html', {
        'person': person,
        'personprivate': personprivate,
        'is_subscriber': is_subscriber,
        'ain7member': ain7member,
        'is_myself': is_myself,
        'last_activity': last_activity,
        }
    )


@login_required
def search(request):

    filter = AIn7MemberFilter(request.GET, queryset=AIn7Member.objects.all())
    print filter

    return render(request, 'annuaire/search.html', {
        'filter': filter,
        'request': request,
        }
    )


@login_required
def search_adv(request):

    filter = AIn7MemberAdvancedFilter(
        request.GET,
        queryset=AIn7Member.objects.all()
    )

    return render(request, 'annuaire/search.html', {
        'filter': filter,
        'request': request,
        }
    )


@login_required
def change_credentials(request, user_id):
    is_myself = int(request.user.id) == int(user_id)
    person = get_object_or_404(Person, pk=user_id)

    if not is_myself:
        return HttpResponseRedirect(
            reverse('ain7.annuaire.views.details', args=[person.id]))

    ain7member = get_object_or_404(AIn7Member, person=person)

    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
{'fraction_non_alphanumeric': 0.0884741243485638, 'fraction_numerical': 0.016967640286025935, 'mean_word_length': 3.97708082026538, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '198774', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2440, 'n_words': 668}