Example #1
0
def search_view(request):
    users = []
    table = False
    form = search_form.Search_form()
    if request.GET:
        form = search_form.Search_form(request.GET)
        table = True
        users = User_profile.objects.all().filter(is_searchable=True)
        if form.is_valid():
            if form.cleaned_data['username']:
                un = form.cleaned_data['username']
                users = users.filter(user__username__contains = un)
            if form.cleaned_data['first_name']:
                fn = form.cleaned_data['first_name']
                users = users.filter(user__first_name__contains = fn)
            if form.cleaned_data['last_name']:
                ln= form.cleaned_data['last_name']
                users = users.filter(user__last_name__contains = ln)
            if form.cleaned_data['city']:
                city = form.cleaned_data['city']
                users = users.filter(city__contains = city)
            if form.cleaned_data['age_min']!="nothing":
                age_min = int(form.cleaned_data['age_min'])
                users = users.filter(age__gte = age_min)
            if form.cleaned_data['age_max']!="nothing":
                age_max = int(form.cleaned_data['age_max'])
                users = users.filter(age__lte = age_max)
            if form.cleaned_data['is_available']:
                users = users.filter(status = "available")
    return my_rtr('search_view.html', {'users':users,'table':table,'form':form}, request)
Example #2
0
def add_to_friends(request, user_id=""):
    if user_id=="":
        return HttpResponseRedirect("/")

    friend = User.objects.filter(id = user_id)[0]
    friend_profile = User_profile.objects.filter(user = friend)[0]
    owner_profile = User_profile.objects.filter(user = request.user)[0]

    contact = Contact()
    contact.owner=owner_profile
    contact.friend=friend_profile
    contact.pseudo = friend.username
    contact.save()

    d = {}

    if Contact.objects.filter(Q(owner=owner_profile) & Q(friend=friend_profile)):
        d["state"] = "Now you are friends!"

    if user_id == request.user.id:
        d["state"]="You cannot add yourself to friends list!"

    d["person"] = friend
    d["person_profile"]=friend_profile

    return my_rtr('user_view.html',d, request)
Example #3
0
def edit_info_view(request, state = ""):
    if request.user.is_authenticated() == False:
        return HttpResponseRedirect("/")
    edit_form = edit_info_form.Edit_form()
    change_form = change_pass_form.Change_pass_form()

    if request.POST:
        edit_form = edit_info_form.Edit_form(request.POST)
        if edit_form.is_valid():
            user_profile = User_profile.objects.filter(user = request.user)[0]
            user = User.objects.filter(id = request.user.id)[0]

            user.first_name = edit_form.cleaned_data['first_name']
            user.last_name = edit_form.cleaned_data['last_name']

            user.save()

            user_profile.age = edit_form.cleaned_data['age']
            user_profile.city = edit_form.cleaned_data['city']
            user_profile.is_searchable = edit_form.cleaned_data['is_searchable']

            user_profile.save()
            return HttpResponseRedirect("/profile")
    else:
        user_profile = User_profile.objects.filter(user = request.user)[0]
        user = User.objects.filter(id = request.user.id)[0]
        edit_form = edit_info_form.Edit_form({"first_name":user.first_name,'last_name':user.last_name,'age':user_profile.age,'city':user_profile.city,'is_searchable':user_profile.is_searchable})

    return my_rtr('edit_info_view.html',{'edit_form':edit_form,'change_form':change_form, 'state':state}, request)
Example #4
0
def user_view(request, user_id="", state=""):
    if user_id=="":
        return HttpResponseRedirect("/")

    if state=="friends_already":
        state = "You are friends already!"
    elif state=="added":
        state = "You are friends now!"
    elif state=="self-friend":
        state = "You can't add yourself to your friends!"

    person = User.objects.filter(id = user_id)[0]
    person_profile = User_profile.objects.filter(user = person)[0]

    owner_profile = User_profile.objects.filter(user = request.user)[0]
    d = {}

    if Contact.objects.filter(Q(owner=owner_profile) & Q(friend=person_profile)):
        d["friends_already"]=1

    if int(user_id) == int(request.user.id):
        d["its_me"]=1

    d["person"] = person
    d["person_profile"]=person_profile
    d["state"] = state

    return my_rtr('user_view.html',d, request)
Example #5
0
def join_view(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/")

    state = []
    if request.POST:
        form = register_form.Register_form(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            if User.objects.filter(username=username):
                state.append("This username is occupied already")

            password = form.cleaned_data['password']
            repeat_password = form.cleaned_data['repeat_password']
            if password != repeat_password:
                state.append("You have to repeat your password twice.")

            email = form.cleaned_data['email']

            age = form.cleaned_data['age']
            city = form.cleaned_data['city']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']

            if len(state) == 0:
                user = User.objects.create_user(username=username,password=password,email=email)
                user.first_name = first_name
                user.last_name = last_name
                user.is_active = True
                user.save()

                user_profile = User_profile()
                user_profile.age = age
                user_profile.city = city
                user_profile.user = user
                user_profile.save()

                return HttpResponseRedirect("/user_created")
    else:
        form = register_form.Register_form()

    return my_rtr("create.html",{'form':form, 'state':state}, request)
Example #6
0
def login_view(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/")

    state = ""
    if request.POST:
        form = login_form.Login_form(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect("/")
            else:
                state = "Username or password seems to be incorrect."
    else:
        form = login_form.Login_form()
    return my_rtr("login.html",{'form':form, 'state':state}, request)
Example #7
0
def about_view(request):
    return my_rtr('about_view.html', {}, request)
Example #8
0
def download_view(request):
    return my_rtr('download_view.html',{},request)
Example #9
0
def user_created_view(request):
    return my_rtr('user_created_view.html',{},request)
Example #10
0
def friends_view(request):
    user_profile = User_profile.objects.filter(user = request.user)
    friends = Contact.objects.filter(owner = user_profile).order_by("name").order_by('friend__status')

    return my_rtr('friends_view.html', {'friends':friends}, request)
Example #11
0
def profile_view(request):
    user_profile = User_profile.objects.filter(user=request.user)[0]
    return my_rtr('profile_view.html', {'user_profile':user_profile}, request)
Example #12
0
def home(request):
    news = News.objects.all()
    return my_rtr('home.html', {'news':news},request)