pytask/taskapp/views/user.py
changeset 14 f2623fb8041a
parent 13 4da58abdf6ff
child 16 d57e63325759
equal deleted inserted replaced
13:4da58abdf6ff 14:f2623fb8041a
     4 from pytask.taskapp.forms.user import RegistrationForm, LoginForm
     4 from pytask.taskapp.forms.user import RegistrationForm, LoginForm
     5 from pytask.taskapp.events.user import createUser
     5 from pytask.taskapp.events.user import createUser
     6 from django.contrib.auth import login, logout, authenticate
     6 from django.contrib.auth import login, logout, authenticate
     7 from django.contrib.auth.models import User
     7 from django.contrib.auth.models import User
     8 
     8 
     9 def show_msg(message):
     9 def show_msg(message, redirect_url=None, url_desc=None):
    10     """ simply redirect to homepage """
    10     """ simply redirect to homepage """
    11     
    11     
    12     return render_to_response('show_msg.html',{'message':message})
    12     return render_to_response('show_msg.html',{'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc})
    13 
    13 
    14 def homepage(request):
    14 def homepage(request):
    15     """ check for authentication and display accordingly. """
    15     """ check for authentication and display accordingly. """
    16     
    16     
    17     user = request.user
    17     user = request.user
    26         tasks_count = Task.objects.count()
    26         tasks_count = Task.objects.count()
    27         if tasks_count <= disp_num:
    27         if tasks_count <= disp_num:
    28             task_list = Task.objects.order_by('id').reverse()
    28             task_list = Task.objects.order_by('id').reverse()
    29         else:
    29         else:
    30             task_list = Task.objects.order_by('id').reverse()[:10]
    30             task_list = Task.objects.order_by('id').reverse()[:10]
       
    31             
       
    32         return render_to_response('index.html', {'is_guest':is_guest, 'task_list':task_list})
       
    33         
    31     else:
    34     else:
    32         user_profile = user.get_profile()
    35         user_profile = user.get_profile()
    33         is_mentor = True if user.task_mentors.all() else False
    36         is_mentor = True if user.task_mentors.all() else False
    34         can_create_task = False if user_profile.rights == u"CT" else True
    37         can_create_task = False if user_profile.rights == u"CT" else True
    35         
    38         
    36     context = {'user':user,
    39         context = {'user':user,
    37                'is_guest':is_guest,
    40                    'is_guest':is_guest,
    38                'is_mentor':is_mentor,
    41                    'is_mentor':is_mentor,
    39                'task_list':task_list,
    42                    'task_list':task_list,
    40                'can_create_task':can_create_task,
    43                    'can_create_task':can_create_task,
    41                }
    44                    }
    42                
    45                    
    43     return render_to_response('index.html', context)
    46         return render_to_response('index.html', context)
    44 
    47 
    45 
    48 
    46 def register(request):
    49 def register(request):
    47     """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
    50     """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
    48     if request.method == 'POST':
    51     if request.method == 'POST':