def create(request): if request.method == 'POST': form = CreateForm(request.POST, request.FILES) if form.is_valid(): project = Project( author=request.user, name=form.cleaned_data['name'], description=form.cleaned_data['description'], status=form.cleaned_data['status'], area=form.cleaned_data['area'], website=form.cleaned_data['website'], image=form.cleaned_data['image'] ) project.save() return redirect( request, 'project-read', [project.id], {request.url_name: 'True'} ) else: form = CreateForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def create(request, project_id): project = get_object_or_404( Project, id=project_id, is_active=True, author__is_active=True ) if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): message = Message( author=request.user, project=project, text=form.cleaned_data['text'] ) message.save() return redirect( request, 'project-message_list', [project.id], {request.url_name: 'True'} ) else: form = MessageForm() params = {'project': project, 'form': form} params.update(csrf(request)) return response(request, params)
def create(request, ask_code): ask = get_object_or_404(Ask, code=ask_code) if request.method == 'POST': form = CreateForm(request.POST, request.FILES) if form.is_valid(): user = User.objects.create_user( ask.username, form.cleaned_data['email'], form.cleaned_data['passwd'] ) user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.save() profile = user.get_profile() profile.birthday = form.cleaned_data['birthday'] profile.faculty = form.cleaned_data['faculty'] profile.image = form.cleaned_data['image'] profile.save() user = auth.authenticate( username=ask.username, password=form.cleaned_data['passwd'] ) auth.login(request, user) return redirect( request, 'src-home', query_string={request.url_name: 'True'} ) else: form = CreateForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def update(request): profile = request.user.get_profile() if request.method == 'POST': form = UpdateForm(request.POST, request.FILES) if form.is_valid(): request.user.first_name = form.cleaned_data['first_name'] request.user.last_name = form.cleaned_data['last_name'] request.user.email = form.cleaned_data['email'] request.user.save() profile.birthday = form.cleaned_data['birthday'] profile.faculty = form.cleaned_data['faculty'] profile.image = form.cleaned_data['image'] or profile.image profile.save() return redirect( request, 'account-read', [request.user.id], {request.url_name: 'True'} ) else: form = UpdateForm({ 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'email': request.user.email, 'birthday': profile.birthday, 'faculty': profile.faculty }) params = {'form': form} params.update(csrf(request)) return response(request, params)
def logout(request): auth.logout(request) return redirect( request, 'src-index', query_string={request.url_name: 'True'} )
def create(request, project_id): project = get_object_or_404( Project, id=project_id, is_active=True, author=request.user ) if request.method == 'POST': form = JobForm(request.POST) if form.is_valid(): job = Job( project=project, title=form.cleaned_data['title'], area=form.cleaned_data['area'], description=form.cleaned_data['description'] ) job.save() return redirect( request, 'project-read', [project.id], {request.url_name: 'True'} ) else: form = JobForm() params = {'project': project, 'form': form} params.update(csrf(request)) return response(request, params)
def update(request, job_id): job = get_object_or_404( Job, id=job_id, is_active=True, project__is_active=True, project__author=request.user ) if request.method == 'POST': form = JobForm(request.POST) if form.is_valid(): job.title = form.cleaned_data['title'] job.area = form.cleaned_data['area'] job.description = form.cleaned_data['description'] job.save() return redirect( request, 'job-read', [job.id], {request.url_name: 'True'} ) else: form = JobForm({ 'title': job.title, 'area': job.area, 'description': job.description }) params = {'job': job, 'project': job.project, 'form': form} params.update(csrf(request)) return response(request, params)
def update(request, project_id): project = get_object_or_404( Project, id=project_id, author=request.user, is_active=True ) if request.method == 'POST': form = CreateForm(request.POST, request.FILES) if form.is_valid(): project.name = form.cleaned_data['name'] project.description = form.cleaned_data['description'] project.status = form.cleaned_data['status'] project.area = form.cleaned_data['area'] project.website = form.cleaned_data['website'] project.image = form.cleaned_data['image'] or project.image project.save() return redirect( request, 'project-read', [project.id], {request.url_name: 'True'} ) else: form = CreateForm({ 'name': project.name, 'description': project.description, 'status': project.status, 'area': project.area, 'website': project.website }) params = {'project': project, 'form': form} params.update(csrf(request)) return response(request, params)
def delete(request): if request.method == 'POST': request.user.is_active = False request.user.save() auth.logout(request) return redirect( request, 'src-index', query_string={request.url_name: 'True'} ) return response(request, csrf(request))
def change_password(request): if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): request.user.set_password(form.cleaned_data['passwd']) request.user.save() return redirect( request, 'src-home', query_string={request.url_name: 'True'} ) else: form = ChangePasswordForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def login(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): user = auth.authenticate( username=form.cleaned_data['username'], password=form.cleaned_data['passwd'] ) if user is not None: auth.login(request, user) return redirect(request, 'src-home') else: form = LoginForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def ask(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] ask, created = Ask.objects.get_or_create(username=username) # TODO: enviar e-mail com o código para cadastro. return redirect( request, 'src-index', query_string={request.url_name: username} ) else: form = AskForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def delete(request, project_id): project = get_object_or_404( Project, id=project_id, author=request.user, is_active=True ) if request.method == 'POST': project.is_active = False project.save() return redirect( request, 'src-home', query_string={request.url_name: 'True'} ) params = {'project': project} params.update(csrf(request)) return response(request, params)
def recover_password(request): if request.method == 'POST': form = RecoverPasswordForm(request.POST) if form.is_valid(): user = User.objects.get(username=form.cleaned_data['username']) passwd = make_random_passwd() user.set_password(passwd) user.save() # TODO: enviar e-mail com a nova senha. return redirect( request, 'src-index', query_string={request.url_name: user.email} ) else: form = RecoverPasswordForm() params = {'form': form} params.update(csrf(request)) return response(request, params)
def delete(request, job_id): job = get_object_or_404( Job, id=job_id, is_active=True, project__is_active=True, project__author=request.user ) if request.method == 'POST': job.is_active = False job.save() return redirect( request, 'project-read', [job.project.id], {request.url_name: 'True'} ) params = {'job': job, 'project': job.project} params.update(csrf(request)) return response(request, params)
def delete(request, message_id): message = get_object_or_404( Message, id=message_id, is_active=True, project__is_active=True, project__author__is_active=True ) if message.author != request.user and \ message.project.author != request.user: raise Http404 if request.method == 'POST': message.is_active = False message.save() return redirect( request, 'project-message_list', [message.project.id], {request.url_name: 'True'} ) params = {'message': message} params.update(csrf(request)) return response(request, params)
def home(request): if not request.user.is_authenticated(): return redirect(request, 'src-index') return response(request)