def add(request): task_lists = TaskList.objects.all() task_categories = TaskCategory.objects.all() task_status = TaskStatus.objects.all() users = User.objects.filter(is_superuser=0) extra_content = { 'task_lists' : task_lists, 'task_categories' : task_categories, 'task_status' : task_status, 'users' : users } if request.method == "POST": print request.POST['task_status'] task = Task(name=request.POST['name'], description=request.POST['description'], progress=request.POST['progress'], task_list_id=request.POST['task_list'], task_category_id=request.POST['task_category'], task_status_id=request.POST['task_status'], user_id=request.POST['user']) task.save() extra_content['message'] = "Tarefa aficionada com sucesso" extra_content['type'] = "alert-success" return render_to_response(request, 'task_add.html', extra_content)
def add(request): extra_content = { 'title': u"Criar Conta", } if request.method == 'POST': # verifica se já existe o usuário verify_user = User.objects.filter(username=request.POST['username']) if verify_user: extra_content['message'] = "Usuário já cadastrado" extra_content['type'] = "alert-error" else: # username, email, password new_user = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password']) new_user.is_staff = True new_user.is_active = True new_user.first_name = request.POST['first_name'] new_user.last_name = request.POST['last_name'] new_user.save() extra_content['message'] = "Usuário cadastrado com sucesso" extra_content['type'] = "alert-success" return render_to_response(request, 'add.html', extra_content)
def do_login(request): extra_content = { 'title': u"Login de Usuário", 'next' : request.REQUEST.get('next', ''), } if request.method == "POST": username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) extra_content['message'] = "Login efetuado com sucesso" extra_content['type'] = "alert-success" if request.POST['next']: return redirect(request.POST['next']) else: extra_content['message'] = "Esta conta não está ativa" extra_content['type'] = "" else: extra_content['message'] = "Login falhou" extra_content['type'] = "alert-error" return render_to_response(request, 'login.html', extra_content)
def index(request): tasks = Task.objects.all() extra_content = { 'tasks' : tasks } return render_to_response(request, 'task_index.html', extra_content)
def home(request): return render_to_response(request, 'home.html', None)# Create your views here.