# Path: quora/core/views.py
# def fblogin(request):
#    context = RequestContext(request,
#                            {'request': request,
#                             'user': request.user})
#    return render_to_response('core/fblogin.html',
#                              context_instance=context)
# 
# def home(request):
#     if request.user.is_authenticated():
#         return redirect('/questions/')
#     else:
#         all_questions = Question.get_published()[:10]
#         return render(request, 'core/splash.html', {'questions': all_questions})
# 
# @login_required
# def password(request):
#     user = request.user
#     if request.method == 'POST':
#         form = ChangePasswordForm(request.POST)
#         if form.is_valid():
#             new_password = form.cleaned_data.get('new_password')
#             user.set_password(new_password)
#             user.save()
#             messages.add_message(request, messages.SUCCESS, 'Your password were successfully changed.')
#     else:
#         form = ChangePasswordForm(instance=user)
#     return render(request, 'core/password.html', {'form':form})
# 
# @login_required
# def picture(request):
#     uploaded_picture = False
#     try:
#         if request.GET.get('upload_picture') == 'uploaded':
#             uploaded_picture = True
#     except Exception, e:
#         pass
#     return render(request, 'core/picture.html', {'uploaded_picture': uploaded_picture})
# 
# @login_required
# def profile(request):
#     user = request.user
#     if request.method == 'POST':
#         form = ProfileForm(request.POST)
#         if form.is_valid():
#             user.first_name = form.cleaned_data.get('first_name')
#             user.email = form.cleaned_data.get('email')
#             user.save()
#             messages.add_message(request, messages.SUCCESS, 'Your profile were successfully edited.')
#     else:
#         form = ProfileForm(instance=user, initial={
#             'email': user.email
#             })
#     return render(request, 'core/profile.html', {'form':form})
# 
# def public_profile(request, id):
#     public_user = User.objects.filter(id=id).first()
#     return render(request, 'core/public_profile.html', {'public_user': public_user})
# 
# @login_required
# def settings(request):
#     user = request.user
#     return render(request, 'core/activity.html')
# 
# Path: quora/search/views.py
# def search(request):
#     if 'q' in request.GET:
#         querystring = request.GET.get('q').strip()
#         if len(querystring) == 0:
#             return redirect('/search/')
# 
#         search_type = 'questions'
# 
#         count = {}
#         results = {}
# 
#         results['questions'] = Question.objects.filter(Q(title__icontains=querystring) | Q(content__icontains=querystring))
#         count['questions'] = results['questions'].count()
# 
#         return render(request, 'search/results.html', {
#             'querystring': querystring,
#             'results': results['questions']})
#     else:
#         return render(request, 'search/search.html', { 'hide_search': True })
# 
# Path: quora/profile/views.py
# def signup(request):
#     if request.method == 'POST':
#         form = SignUpForm(request.POST)
#         if not form.is_valid():
#             return render(request, 'auth/signup.html', {'form': form})
#         else:
#             firstname = form.cleaned_data.get('firstname')
#             username = form.cleaned_data.get('username')
#             password = form.cleaned_data.get('password')
#             User.objects.create_user(
#                 first_name=firstname,
#                 username=username,
#                 password=password)
#             user = authenticate(username=username, password=password)
#             login(request, user)
#             return redirect('/')
#     else:
#         return render(request, 'auth/signup.html', {'form': SignUpForm()})


from django.contrib.auth.views import login, logout
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from quora.core.views import (
    fblogin,
    home,
    password,
    picture,
    profile,
    public_profile,
    settings,
)
from quora.search.views import search
from quora.profile.views import signup



admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', home, name='home'),
    url(r'^hidden_login', login, {'template_name': 'core/cover.html'}, name='login'),
    url(r'^fblogin', fblogin, name='fblogin'),
    url(r'^logout', logout, {'next_page': '/'}, name='logout'),
    url(r'^signup/$', signup, name='signup'),
    url(r'^public_profile/(?P<id>\d+)/$', public_profile, name='public_profile'),
    url(r'^settings/$', settings, name='settings'),
    url(r'^settings/profile/$', profile, name='profile'),
    url(r'^settings/password/$', password, name='password'),
    url(r'^questions/', include('quora.questions.urls')),
    url(r'^search/$', search, name='search'),

# Path: quora/core/views.py
# def fblogin(request):
#    context = RequestContext(request,
#                            {'request': request,
#                             'user': request.user})
#    return render_to_response('core/fblogin.html',
#                              context_instance=context)
# 
# def home(request):
#     if request.user.is_authenticated():
#         return redirect('/questions/')
#     else:
#         all_questions = Question.get_published()[:10]
#         return render(request, 'core/splash.html', {'questions': all_questions})
# 
# @login_required
# def password(request):
#     user = request.user
#     if request.method == 'POST':
#         form = ChangePasswordForm(request.POST)
#         if form.is_valid():
#             new_password = form.cleaned_data.get('new_password')
#             user.set_password(new_password)
#             user.save()
#             messages.add_message(request, messages.SUCCESS, 'Your password were successfully changed.')
#     else:
#         form = ChangePasswordForm(instance=user)
#     return render(request, 'core/password.html', {'form':form})
# 
# @login_required
# def picture(request):
#     uploaded_picture = False
#     try:
#         if request.GET.get('upload_picture') == 'uploaded':
#             uploaded_picture = True
#     except Exception, e:
#         pass
#     return render(request, 'core/picture.html', {'uploaded_picture': uploaded_picture})
# 
# @login_required
# def profile(request):
#     user = request.user
#     if request.method == 'POST':
#         form = ProfileForm(request.POST)
#         if form.is_valid():
#             user.first_name = form.cleaned_data.get('first_name')
#             user.email = form.cleaned_data.get('email')
#             user.save()
#             messages.add_message(request, messages.SUCCESS, 'Your profile were successfully edited.')
#     else:
#         form = ProfileForm(instance=user, initial={
#             'email': user.email
#             })
#     return render(request, 'core/profile.html', {'form':form})
# 
# def public_profile(request, id):
#     public_user = User.objects.filter(id=id).first()
#     return render(request, 'core/public_profile.html', {'public_user': public_user})
# 
# @login_required
# def settings(request):
#     user = request.user
#     return render(request, 'core/activity.html')
# 
# Path: quora/search/views.py
# def search(request):
#     if 'q' in request.GET:
#         querystring = request.GET.get('q').strip()
#         if len(querystring) == 0:
#             return redirect('/search/')
# 
#         search_type = 'questions'
# 
#         count = {}
#         results = {}
# 
#         results['questions'] = Question.objects.filter(Q(title__icontains=querystring) | Q(content__icontains=querystring))
#         count['questions'] = results['questions'].count()
# 
#         return render(request, 'search/results.html', {
#             'querystring': querystring,
#             'results': results['questions']})
#     else:
#         return render(request, 'search/search.html', { 'hide_search': True })
# 
# Path: quora/profile/views.py
# def signup(request):
#     if request.method == 'POST':
#         form = SignUpForm(request.POST)
#         if not form.is_valid():
#             return render(request, 'auth/signup.html', {'form': form})
#         else:
#             firstname = form.cleaned_data.get('firstname')
#             username = form.cleaned_data.get('username')
#             password = form.cleaned_data.get('password')
#             User.objects.create_user(
#                 first_name=firstname,
#                 username=username,
#                 password=password)
#             user = authenticate(username=username, password=password)
#             login(request, user)
#             return redirect('/')
#     else:
#         return render(request, 'auth/signup.html', {'form': SignUpForm()})


# Path: quora/urls.py
from django.contrib.auth.views import login, logout
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from quora.core.views import (
    fblogin,
    home,
    password,
    picture,
    profile,
    public_profile,
    settings,
)
from quora.search.views import search
from quora.profile.views import signup




admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', home, name='home'),
    url(r'^hidden_login', login, {'template_name': 'core/cover.html'}, name='login'),
    url(r'^fblogin', fblogin, name='fblogin'),
    url(r'^logout', logout, {'next_page': '/'}, name='logout'),
    url(r'^signup/$', signup, name='signup'),
    url(r'^public_profile/(?P<id>\d+)/$', public_profile, name='public_profile'),
    url(r'^settings/$', settings, name='settings'),
    url(r'^settings/profile/$', profile, name='profile'),
    url(r'^settings/password/$', password, name='password'),
    url(r'^questions/', include('quora.questions.urls')),
    url(r'^search/$', search, name='search'),

    url(r'^(?P<username>[^/]+)/$', profile, name='profile'),