Best Python code snippet using ATX
views.py
Source:views.py
1from django.shortcuts import render,get_object_or_404, redirect2from django.utils import timezone3from .models import Post,Post14from .forms import PostForm,Post1Form5from django.core.files import File6import cv2 as cv7import numpy as np8import matplotlib.pyplot as plt9from .PointOperator.PointOperator import PointOperator as PO10#direccion a operadores punto#11from .HistogramEqual.HistogramEqual import HistogramEqual as HE12from .Lab2.contrastStretching import ConstS as CS13from .LogarithmOperator.pointOperator import pointOperator as _PO14from .Threasholding.th import Threshold as TH15from .OperadorExponencial.OpExp import pointOperator as POO16from .Sustraccion.subtraccion import subtraccion as SO17from .Addition.Addition import AdditionOperator as AO18from .Blending.Blending import blendingOperator as BO19from .Division.Division import divisionOperator as DO20from .multiplication.Multiplication import MultiplicationOperator as MO21from .LogicoOperator.logicoOperator import Imagen as LO22# Create your views here.23def resize(img1,img2):24 size1=img1.shape[0]+img1.shape[1]25 size2=img2.shape[0]+img2.shape[1]26 27 if(size1 > size2):28 img1 = cv.resize(img1,img2.shape[1::-1])29 else:30 img2 = cv.resize(img2,img1.shape[1::-1])31 return img1,img232def post_list(request):33 posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')34 return render(request,'blog/post_list.html',{35 'posts':posts})36def post_detail(request, pk):37 post = get_object_or_404(Post, pk=pk)38 return render(request, 'blog/post_detail.html', {'post': post})39def post_new(request):40 if request.method == "POST":41 form = PostForm(request.POST,request.FILES)42 if form.is_valid():43 post = form.save(commit=False)44 post.author = request.user45 post.published_date = timezone.now()46 post.save()47 return redirect('post_detail', pk=post.pk)48 else:49 form = PostForm()50 return render(request, 'blog/post_edit.html', {'form': form})51def post_edit(request, pk):52 post = get_object_or_404(Post, pk=pk)53 if request.method == "POST":54 form = PostForm(request.POST,request.FILES, instance=post)55 if form.is_valid():56 post = form.save(commit=False)57 post.author = request.user58 post.published_date = timezone.now()59 post.save()60 return redirect('post_detail', pk=post.pk)61 else:62 form = PostForm(instance=post)63 return render(request, 'blog/post_edit.html', {'form': form})64def post_remove(request, pk):65 post = get_object_or_404(Post, pk=pk)66 post.delete()67 return redirect('post_list')68def post_scale(request,pk):69 post = get_object_or_404(Post,pk=pk)70 pageTitle="scale"71 if request.method == "POST":72 form = Post1Form(request.POST,request.FILES)73 if form.is_valid():74 post1=form.save(commit=False)75 post1.author = request.user76 post1.post=post77 direccion = post.imagen.url78 img = cv.imread(direccion[1:],0) 79 data = PO(img)80 newimg = data.contrastStretching()81 name = 'images/scale_'+post.imagen.name[7:]82 cv.imwrite('media/'+name,newimg)83 nameh = 'images/sc_h'+post.imagen.name[7:]84 cv.imwrite('media/'+nameh,newimg)85 ropen = open('media/'+name,'rb')86 hopen = open('media/'+nameh,'rb')87 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)88 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)89 post1.save()90 return redirect('post_show',pk=post.pk,pk1=post1.pk)91 else:92 form = Post1Form()93 return render(request,'blog/post_scale.html',{'form': form,94 'post':post,95 'pageTitle':pageTitle})96def post_save(request,pk):97 post1 = get_object_or_404(Post1,pk=pk)98 post2 = get_object_or_404(Post, pk=post1.post.pk)99 post2.imagen.delete()100 direccion = post1.result.url101 ropen=open(direccion[1:],'rb')102 post2.imagen.save(direccion[14:],File(ropen),save=True)103 post2.save()104 Post1.objects.all().delete()105 return redirect('post_detail',pk=post2.pk)106def post_show(request,pk,pk1):107 post1 = get_object_or_404(Post, pk=pk)108 post2 = get_object_or_404(Post1, pk=pk1)109 return render(request, 'blog/post_show.html', {'post': post1,110 'post1': post2})111 112def post_thresholding(request,pk):113 post = get_object_or_404(Post,pk=pk)114 pageTitle="THRESHOLDING"115 if request.method == "POST":116 form = Post1Form(request.POST,request.FILES)117 if form.is_valid():118 post1=form.save(commit=False)119 post1.author = request.user120 post1.post=post121 direccion = post.imagen.url122 img = cv.imread(direccion[1:],0) 123 data = TH(img)124 l=0125 r=255126 if post1.limite_a:127 l=int(post1.limite_a)128 if post1.limite_b:129 r=int(post1.limite_b)130 131 newimg = data.thresholding(l,r)132 name = 'images/scale_'+post.imagen.name[7:]133 cv.imwrite('media/'+name,newimg)134 nameh = 'images/sc_h'+post.imagen.name[7:]135 cv.imwrite('media/'+nameh,newimg)136 ropen = open('media/'+name,'rb')137 hopen = open('media/'+nameh,'rb')138 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)139 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)140 post1.save()141 return redirect('post_show',pk=post.pk,pk1=post1.pk)142 else:143 form = Post1Form()144 return render(request,'blog/post_scale.html',{'form': form,145 'post':post,146 'pageTitle':pageTitle})147 148def post_contrast(request,pk):149 post = get_object_or_404(Post,pk=pk)150 pageTitle="CONTRAST STRETCHING"151 if request.method == "POST":152 form = Post1Form(request.POST,request.FILES)153 if form.is_valid():154 post1=form.save(commit=False)155 post1.author = request.user156 post1.post=post157 direccion = post.imagen.url158 img = cv.imread(direccion[1:],0) 159 data = CS(img)160 161 d=15162 verbose=False163 if post1.limite_a:164 d=int(post1.limite_a)165 verbose=True166 167 if verbose:168 data.CDlimit(d)169 newimg = data.Stretch()170 171 name = 'images/scale_'+post.imagen.name[7:]172 cv.imwrite('media/'+name,newimg)173 nameh = 'images/sc_h'+post.imagen.name[7:]174 cv.imwrite('media/'+nameh,newimg)175 ropen = open('media/'+name,'rb')176 hopen = open('media/'+nameh,'rb')177 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)178 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)179 post1.save()180 return redirect('post_show',pk=post.pk,pk1=post1.pk)181 else:182 form = Post1Form()183 return render(request,'blog/post_scale.html',{'form': form,184 'post':post,185 'pageTitle':pageTitle})186 187def post_equalizer(request,pk):188 post = get_object_or_404(Post,pk=pk)189 pageTitle="ECUALIZADOR DE HISTOGRAMA"190 if request.method == "POST":191 form = Post1Form(request.POST,request.FILES)192 if form.is_valid():193 post1=form.save(commit=False)194 post1.author = request.user195 post1.post=post196 direccion = post.imagen.url197 img = cv.imread(direccion[1:],0) 198 data = HE(img)199 newimg = data.Equalization()200 name = 'images/scale_'+post.imagen.name[7:]201 cv.imwrite('media/'+name,newimg)202 nameh = 'images/sc_h'+post.imagen.name[7:]203 cv.imwrite('media/'+nameh,newimg)204 ropen = open('media/'+name,'rb')205 hopen = open('media/'+nameh,'rb')206 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)207 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)208 post1.save()209 return redirect('post_show',pk=post.pk,pk1=post1.pk)210 else:211 form = Post1Form()212 return render(request,'blog/post_scale.html',{'form': form,213 'post':post,214 'pageTitle':pageTitle})215 216def post_logaritmo(request,pk):217 post = get_object_or_404(Post,pk=pk)218 pageTitle="LOGARITMO"219 if request.method == "POST":220 form = Post1Form(request.POST,request.FILES)221 if form.is_valid():222 post1=form.save(commit=False)223 post1.author = request.user224 post1.post=post225 direccion = post.imagen.url226 img = cv.imread(direccion[1:],0) 227 data = _PO(img)228 229 d=15230 if post1.limite_a:231 d=int(post1.limite_a)232 233 newimg = data.logarithmOperator(d)234 name = 'images/scale_'+post.imagen.name[7:]235 cv.imwrite('media/'+name,newimg)236 nameh = 'images/sc_h'+post.imagen.name[7:]237 cv.imwrite('media/'+nameh,newimg)238 ropen = open('media/'+name,'rb')239 hopen = open('media/'+nameh,'rb')240 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)241 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)242 post1.save()243 return redirect('post_show',pk=post.pk,pk1=post1.pk)244 else:245 form = Post1Form()246 return render(request,'blog/post_scale.html',{'form': form,247 'post':post,248 'pageTitle':pageTitle})249 250def post_raiz(request,pk):251 post = get_object_or_404(Post,pk=pk)252 pageTitle="RAIZ"253 if request.method == "POST":254 form = Post1Form(request.POST,request.FILES)255 if form.is_valid():256 post1=form.save(commit=False)257 post1.author = request.user258 post1.post=post259 direccion = post.imagen.url260 img = cv.imread(direccion[1:],0) 261 data = _PO(img)262 263 d=15264 if post1.limite_a:265 d=int(post1.limite_a)266 newimg = data.raizOperator(d)267 name = 'images/scale_'+post.imagen.name[7:]268 cv.imwrite('media/'+name,newimg)269 nameh = 'images/sc_h'+post.imagen.name[7:]270 cv.imwrite('media/'+nameh,newimg)271 ropen = open('media/'+name,'rb')272 hopen = open('media/'+nameh,'rb')273 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)274 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)275 post1.save()276 return redirect('post_show',pk=post.pk,pk1=post1.pk)277 else:278 form = Post1Form()279 return render(request,'blog/post_scale.html',{'form': form,280 'post':post,281 'pageTitle':pageTitle})282 283def post_exponencial(request,pk):284 post = get_object_or_404(Post,pk=pk)285 pageTitle="EXPONENCIAL"286 if request.method == "POST":287 form = Post1Form(request.POST,request.FILES)288 if form.is_valid():289 post1=form.save(commit=False)290 post1.author = request.user291 post1.post=post292 direccion = post.imagen.url293 img = cv.imread(direccion[1:],0) 294 data = POO(img)295 b=1.005296 c=5297 if post1.limite_a:298 b=post1.limite_a299 if post1.limite_b:300 c=post1.limite_b301 302 newimg = data.expoOperator(b,c)303 name = 'images/scale_'+post.imagen.name[7:]304 cv.imwrite('media/'+name,newimg)305 nameh = 'images/sc_h'+post.imagen.name[7:]306 cv.imwrite('media/'+nameh,newimg)307 ropen = open('media/'+name,'rb')308 hopen = open('media/'+nameh,'rb')309 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)310 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)311 post1.save()312 return redirect('post_show',pk=post.pk,pk1=post1.pk)313 else:314 form = Post1Form()315 return render(request,'blog/post_scale.html',{'form': form,316 'post':post,317 'pageTitle':pageTitle})318def post_raizpower(request,pk):319 post = get_object_or_404(Post,pk=pk)320 pageTitle="RAISE TO POWER"321 if request.method == "POST":322 form = Post1Form(request.POST,request.FILES)323 if form.is_valid():324 post1=form.save(commit=False)325 post1.author = request.user326 post1.post=post327 direccion = post.imagen.url328 img = cv.imread(direccion[1:],0) 329 data = POO(img)330 331 b=1.005332 c=5333 if post1.limite_a:334 b=post1.limite_a335 if post1.limite_b:336 c=post1.limite_b337 338 newimg = data.raiseOperator(b,c)339 name = 'images/scale_'+post.imagen.name[7:]340 cv.imwrite('media/'+name,newimg)341 nameh = 'images/sc_h'+post.imagen.name[7:]342 cv.imwrite('media/'+nameh,newimg)343 ropen = open('media/'+name,'rb')344 hopen = open('media/'+nameh,'rb')345 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)346 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)347 post1.save()348 return redirect('post_show',pk=post.pk,pk1=post1.pk)349 else:350 form = Post1Form()351 return render(request,'blog/post_scale.html',{'form': form,352 'post':post,353 'pageTitle':pageTitle})354 355def post_adicion(request,pk):356 post = get_object_or_404(Post,pk=pk)357 pageTitle="ADICION"358 if request.method == "POST":359 form = Post1Form(request.POST,request.FILES)360 if form.is_valid():361 post1=form.save(commit=False)362 post1.author = request.user363 post1.post=post364 post1.save()365 direccion = post.imagen.url366 img = cv.imread(direccion[1:]) 367 368 verbose=False369 r=1370 if post1.limite_a:371 verbose=True372 r=int(post1.limite_a)373 if post1.imagen:374 direc = post1.imagen.url375 img1 = cv.imread(direc[1:])376 img,img1 = resize(img,img1)377 378 data = AO(img)379 if verbose:380 newimg=data.additionC(r)381 else:382 newimg=data.additionImg(img1)383 384 name = 'images/scale_'+post.imagen.name[7:]385 cv.imwrite('media/'+name,newimg)386 nameh = 'images/sc_h'+post.imagen.name[7:]387 cv.imwrite('media/'+nameh,newimg)388 ropen = open('media/'+name,'rb')389 hopen = open('media/'+nameh,'rb')390 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)391 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)392 post1.save()393 return redirect('post_show',pk=post.pk,pk1=post1.pk)394 else:395 form = Post1Form()396 return render(request,'blog/post_scale.html',{'form': form,397 'post':post,398 'pageTitle':pageTitle})399 400def post_sustraccion(request,pk):401 post = get_object_or_404(Post,pk=pk)402 pageTitle="SUSTRACCION"403 if request.method == "POST":404 form = Post1Form(request.POST,request.FILES)405 if form.is_valid(): 406 post1=form.save(commit=False)407 post1.author = request.user408 post1.post=post409 post1.save()410 direccion = post.imagen.url411 img = cv.imread(direccion[1:]) 412 413 verbose=False414 r=1415 if post1.limite_a:416 verbose=True417 r=int(post1.limite_a)418 if post1.imagen:419 direc = post1.imagen.url420 img1 = cv.imread(direc[1:])421 422 data = SO(img)423 if verbose:424 newimg=data.subtraccionC(r)425 else:426 newimg=data.subtraccionImg(img1)427 428 name = 'images/scale_'+post.imagen.name[7:]429 cv.imwrite('media/'+name,newimg)430 nameh = 'images/sc_h'+post.imagen.name[7:]431 cv.imwrite('media/'+nameh,newimg)432 ropen = open('media/'+name,'rb')433 hopen = open('media/'+nameh,'rb')434 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)435 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)436 post1.save()437 return redirect('post_show',pk=post.pk,pk1=post1.pk)438 else:439 form = Post1Form()440 return render(request,'blog/post_scale.html',{'form': form,441 'post':post,442 'pageTitle':pageTitle})443 444def post_multiplicacion(request,pk):445 post = get_object_or_404(Post,pk=pk)446 pageTitle="MULTIPLICACION"447 if request.method == "POST":448 form = Post1Form(request.POST,request.FILES)449 if form.is_valid():450 post1=form.save(commit=False)451 post1.author = request.user452 post1.post=post453 post1.save()454 direccion = post.imagen.url455 img = cv.imread(direccion[1:]) 456 457 verbose=False458 r=1459 if post1.limite_a:460 verbose=True461 r=int(post1.limite_a)462 if post1.imagen:463 direc = post1.imagen.url464 img1 = cv.imread(direc[1:])465 img,img1 = resize(img,img1)466 467 data = MO(img)468 if verbose:469 newimg=data.MultiplicacionC(r)470 else:471 newimg=data.multiplicacionImg(img1)472 473 name = 'images/scale_'+post.imagen.name[7:]474 cv.imwrite('media/'+name,newimg)475 nameh = 'images/sc_h'+post.imagen.name[7:]476 cv.imwrite('media/'+nameh,newimg)477 ropen = open('media/'+name,'rb')478 hopen = open('media/'+nameh,'rb')479 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)480 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)481 post1.save()482 return redirect('post_show',pk=post.pk,pk1=post1.pk)483 else:484 form = Post1Form()485 return render(request,'blog/post_scale.html',{'form': form,486 'post':post,487 'pageTitle':pageTitle})488 489def post_division(request,pk):490 post = get_object_or_404(Post,pk=pk)491 pageTitle="DIVISION"492 if request.method == "POST":493 form = Post1Form(request.POST,request.FILES)494 if form.is_valid():495 post1=form.save(commit=False)496 post1.author = request.user497 post1.post=post498 post1.save()499 direccion = post.imagen.url500 img = cv.imread(direccion[1:],0) 501 502 verbose=False503 r=1504 if post1.limite_a:505 verbose=True506 r=int(post1.limite_a)507 if post1.imagen:508 direc = post1.imagen.url509 img1 = cv.imread(direc[1:],0)510 img,img1 = resize(img,img1)511 512 data = DO(img)513 if verbose:514 newimg=data.divisionC(r)515 else:516 newimg=data.divisionImg(img1)517 518 name = 'images/scale_'+post.imagen.name[7:]519 cv.imwrite('media/'+name,newimg)520 nameh = 'images/sc_h'+post.imagen.name[7:]521 cv.imwrite('media/'+nameh,newimg)522 ropen = open('media/'+name,'rb')523 hopen = open('media/'+nameh,'rb')524 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)525 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)526 post1.save()527 return redirect('post_show',pk=post.pk,pk1=post1.pk)528 else:529 form = Post1Form()530 return render(request,'blog/post_scale.html',{'form': form,531 'post':post,532 'pageTitle':pageTitle})533 534def post_blending(request,pk):535 post = get_object_or_404(Post,pk=pk)536 pageTitle="BLENDING"537 if request.method == "POST":538 form = Post1Form(request.POST,request.FILES) 539 if form.is_valid():540 post1=form.save(commit=False)541 post1.author = request.user542 post1.post=post543 post1.save()544 direccion = post.imagen.url545 img = cv.imread(direccion[1:])546 547 verbose=False548 r=0.25549 if post1.limite_a:550 verbose=True551 r=float(post1.limite_a)552 direc = post1.imagen.url553 img1 = cv.imread(direc[1:])554 img,img1 = resize(img,img1)555 556 data = BO(img)557 newimg=data.blending(img1,float(r))558 559 name = 'images/scale_'+post.imagen.name[7:]560 cv.imwrite('media/'+name,newimg)561 nameh = 'images/sc_h'+post.imagen.name[7:]562 cv.imwrite('media/'+nameh,newimg)563 ropen = open('media/'+name,'rb')564 hopen = open('media/'+nameh,'rb')565 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)566 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)567 post1.save()568 return redirect('post_show',pk=post.pk,pk1=post1.pk)569 else:570 form = Post1Form()571 return render(request,'blog/post_scale.html',{'form': form,572 'post':post,573 'pageTitle':pageTitle})574 575def post_not(request,pk):576 post = get_object_or_404(Post,pk=pk)577 pageTitle="NOT"578 if request.method == "POST":579 form = Post1Form(request.POST,request.FILES)580 if form.is_valid():581 post1=form.save(commit=False)582 post1.author = request.user583 post1.post=post584 direccion = post.imagen.url585 img = cv.imread(direccion[1:],0) 586 data = LO(img)587 newimg = data.notFunction()588 name = 'images/scale_'+post.imagen.name[7:]589 cv.imwrite('media/'+name,newimg)590 nameh = 'images/sc_h'+post.imagen.name[7:]591 cv.imwrite('media/'+nameh,newimg)592 ropen = open('media/'+name,'rb')593 hopen = open('media/'+nameh,'rb')594 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)595 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)596 post1.save()597 return redirect('post_show',pk=post.pk,pk1=post1.pk)598 else:599 form = Post1Form()600 return render(request,'blog/post_scale.html',{'form': form,601 'post':post,602 'pageTitle':pageTitle})603 604def post_and(request,pk):605 post = get_object_or_404(Post,pk=pk)606 pageTitle="AND"607 if request.method == "POST":608 form = Post1Form(request.POST,request.FILES)609 if form.is_valid():610 post1=form.save(commit=False)611 post1.author = request.user612 post1.post=post613 post1.save()614 direccion = post.imagen.url615 img = cv.imread(direccion[1:]) 616 data = LO(img)617 direc = post1.imagen.url618 img1 = cv.imread(direc[1:])619 newimg = data.andFunction(img1)620 name = 'images/scale_'+post.imagen.name[7:]621 cv.imwrite('media/'+name,newimg)622 nameh = 'images/sc_h'+post.imagen.name[7:]623 cv.imwrite('media/'+nameh,newimg)624 ropen = open('media/'+name,'rb')625 hopen = open('media/'+nameh,'rb')626 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)627 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)628 post1.save()629 return redirect('post_show',pk=post.pk,pk1=post1.pk)630 else:631 form = Post1Form()632 return render(request,'blog/post_scale.html',{'form': form,633 'post':post,634 'pageTitle':pageTitle})635 636def post_or(request,pk):637 post = get_object_or_404(Post,pk=pk)638 pageTitle="OR"639 if request.method == "POST":640 form = Post1Form(request.POST,request.FILES)641 if form.is_valid():642 post1=form.save(commit=False)643 post1.author = request.user644 post1.post=post645 post1.save()646 direccion = post.imagen.url647 img = cv.imread(direccion[1:]) 648 data = LO(img)649 direc = post1.imagen.url650 img1 = cv.imread(direc[1:])651 newimg = data.orFunction(img1)652 name = 'images/scale_'+post.imagen.name[7:]653 cv.imwrite('media/'+name,newimg)654 nameh = 'images/sc_h'+post.imagen.name[7:]655 cv.imwrite('media/'+nameh,newimg)656 ropen = open('media/'+name,'rb')657 hopen = open('media/'+nameh,'rb')658 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)659 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)660 post1.save()661 return redirect('post_show',pk=post.pk,pk1=post1.pk)662 else:663 form = Post1Form()664 return render(request,'blog/post_scale.html',{'form': form,665 'post':post,666 'pageTitle':pageTitle})667 668def post_xor(request,pk):669 post = get_object_or_404(Post,pk=pk)670 pageTitle="XOR"671 if request.method == "POST":672 form = Post1Form(request.POST,request.FILES)673 if form.is_valid():674 post1=form.save(commit=False)675 post1.author = request.user676 post1.post=post677 post1.save()678 direccion = post.imagen.url679 img = cv.imread(direccion[1:]) 680 data = LO(img)681 direc = post1.imagen.url682 img1 = cv.imread(direc[1:])683 newimg = data.xorFunction(img1)684 name = 'images/scale_'+post.imagen.name[7:]685 cv.imwrite('media/'+name,newimg)686 nameh = 'images/sc_h'+post.imagen.name[7:]687 cv.imwrite('media/'+nameh,newimg)688 ropen = open('media/'+name,'rb')689 hopen = open('media/'+nameh,'rb')690 post1.result.save('scale_'+post.imagen.name[7:],File(ropen),save=True)691 post1.histogram.save('sc_h'+post.imagen.name[7:],File(hopen),save=True)692 post1.save()693 return redirect('post_show',pk=post.pk,pk1=post1.pk)694 else:695 form = Post1Form()696 return render(request,'blog/post_scale.html',{'form': form,697 'post':post,...
default.py
Source:default.py
...476 return redirect(URL('default', 'index'))477@auth.requires_login()478def add():479 """More sophisticated way, in which we use web2py to come up with the form."""480 record = db.post(request.args(0))481 form = SQLFORM(db.post, record, upload=URL('download'))482 form.add_button(T('Cancel'), URL(r=request, f='index'))483 # We can process the form. This will check that the request is a POST,484 # and also perform validation, but in this case there is no validation.485 # THIS process() also inserts.486 if form.process().accepted:487 redirect(URL('default', 'index'))488 # We ask web2py to lay out the form for us.489 logger.info("My session is: %r" % session)490 return dict(form=form)491# We require login.492@auth.requires_login()493def edit():494 """Allows editing of a post. URL form: /default/edit/<n> where n is the post id."""495 # For this controller only, we hide the author.496 db.post.post_author.readable = False497 post = db.post(request.args(0))498 # We must validate everything we receive.499 if post is None:500 logging.info("Invalid edit call")501 redirect(URL('default', 'index'))502 # One can edit only one's own posts.503 if post.post_author != auth.user.email:504 logging.info("Attempt to edit some one else's post by: %r" % auth.user.email)505 redirect(URL('default', 'index'))506 # Now we must generate a form that allows editing the post.507 form = SQLFORM(db.post, record=post)508 if form.process().accepted:509 # The deed is done.510 redirect(URL('default', 'index'))511 return dict(form=form)...
test_forum.py
Source:test_forum.py
...197 self.post.with_user(self.user_portal).vote(upvote=False)198 self.assertEqual(self.post.create_uid.karma, 50 + KARMA['gen_que_dwv'], 'website_forum: wrong karma generation of downvoted question author')199 def test_comment_crash(self):200 with self.assertRaises(AccessError):201 self.post.with_user(self.user_portal).message_post(body='Should crash', message_type='comment')202 def test_comment(self):203 self.post.with_user(self.user_employee).message_post(body='Test0', message_type='notification')204 self.user_employee.karma = KARMA['com_all']205 self.post.with_user(self.user_employee).message_post(body='Test1', message_type='comment')206 self.assertEqual(len(self.post.message_ids), 4, 'website_forum: wrong behavior of message_post')207 def test_flag_a_post(self):208 Post = self.env['forum.post']209 self.user_portal.karma = KARMA['ask']210 post = Post.with_user(self.user_portal).create({211 'name': "Q0",212 'forum_id': self.forum.id,213 })214 # portal user flags a post: not allowed, unsufficient karma215 with self.assertRaises(AccessError):216 post.with_user(self.user_portal).flag()217 # portal user flags a post: ok if enough karma218 self.user_portal.karma = KARMA['flag']219 post.state = 'active'220 post.with_user(self.user_portal).flag()221 self.assertEqual(post.state, 'flagged', 'website_forum: wrong state when flagging a post')222 def test_validate_a_post(self):223 Post = self.env['forum.post']224 self.user_portal.karma = KARMA['ask']225 post = Post.with_user(self.user_portal).create({226 'name': "Q0",227 'forum_id': self.forum.id,228 })229 # portal user validate a post: not allowed, unsufficient karma230 with self.assertRaises(AccessError):231 post.with_user(self.user_portal).validate()232 # portal user validate a pending post233 self.user_portal.karma = KARMA['moderate']234 post.state = 'pending'235 init_karma = post.create_uid.karma236 post.with_user(self.user_portal).validate()237 self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after pending')238 self.assertEqual(post.create_uid.karma, init_karma + KARMA['gen_que_new'], 'website_forum: wrong karma when validate a post after pending')239 # portal user validate a flagged post: ok if enough karma240 self.user_portal.karma = KARMA['moderate']241 post.state = 'flagged'242 post.with_user(self.user_portal).validate()243 self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after flagged')244 # portal user validate an offensive post: ok if enough karma245 self.user_portal.karma = KARMA['moderate']246 post.state = 'offensive'247 init_karma = post.create_uid.karma248 post.with_user(self.user_portal).validate()249 self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after offensive')250 def test_refuse_a_post(self):251 Post = self.env['forum.post']252 self.user_portal.karma = KARMA['ask']253 post = Post.with_user(self.user_portal).create({254 'name': "Q0",255 'forum_id': self.forum.id,256 })257 # portal user validate a post: not allowed, unsufficient karma258 with self.assertRaises(AccessError):259 post.with_user(self.user_portal).refuse()260 # portal user validate a pending post261 self.user_portal.karma = KARMA['moderate']262 post.state = 'pending'263 init_karma = post.create_uid.karma264 post.with_user(self.user_portal).refuse()265 self.assertEqual(post.moderator_id, self.user_portal, 'website_forum: wrong moderator_id when refusing')266 self.assertEqual(post.create_uid.karma, init_karma, 'website_forum: wrong karma when refusing a post')267 def test_mark_a_post_as_offensive(self):268 Post = self.env['forum.post']269 self.user_portal.karma = KARMA['ask']270 post = Post.with_user(self.user_portal).create({271 'name': "Q0",272 'forum_id': self.forum.id,273 })274 # portal user mark a post as offensive: not allowed, unsufficient karma275 with self.assertRaises(AccessError):276 post.with_user(self.user_portal).mark_as_offensive(12)277 # portal user mark a post as offensive278 self.user_portal.karma = KARMA['moderate']279 post.state = 'flagged'280 init_karma = post.create_uid.karma281 post.with_user(self.user_portal).mark_as_offensive(12)282 self.assertEqual(post.state, 'offensive', 'website_forum: wrong state when marking a post as offensive')283 self.assertEqual(post.create_uid.karma, init_karma + KARMA['gen_ans_flag'], 'website_forum: wrong karma when marking a post as offensive')284 def test_convert_answer_to_comment_crash(self):285 Post = self.env['forum.post']286 # converting a question does nothing287 new_msg = self.post.with_user(self.user_portal).convert_answer_to_comment()288 self.assertEqual(new_msg.id, False, 'website_forum: question to comment conversion failed')289 self.assertEqual(Post.search([('name', '=', 'TestQuestion')])[0].forum_id.name, 'TestForum', 'website_forum: question to comment conversion failed')290 with self.assertRaises(AccessError):291 self.answer.with_user(self.user_portal).convert_answer_to_comment()292 def test_convert_answer_to_comment(self):293 self.user_portal.karma = KARMA['com_conv_all']294 post_author = self.answer.create_uid.partner_id295 new_msg = self.answer.with_user(self.user_portal).convert_answer_to_comment()296 self.assertEqual(len(new_msg), 1, 'website_forum: wrong answer to comment conversion')297 self.assertEqual(new_msg.author_id, post_author, 'website_forum: wrong answer to comment conversion')298 self.assertIn('I am an anteater', new_msg.body, 'website_forum: wrong answer to comment conversion')299 def test_edit_post_crash(self):300 with self.assertRaises(AccessError):301 self.post.with_user(self.user_portal).write({'name': 'I am not your father.'})302 def test_edit_post(self):303 self.post.create_uid.karma = KARMA['edit_own']304 self.post.write({'name': 'Actually I am your dog.'})305 self.user_portal.karma = KARMA['edit_all']306 self.post.with_user(self.user_portal).write({'name': 'Actually I am your cat.'})307 def test_close_post_crash(self):308 with self.assertRaises(AccessError):309 self.post.with_user(self.user_portal).close(None)310 def test_close_post_own(self):311 self.post.create_uid.karma = KARMA['close_own']312 self.post.close(None)313 def test_close_post_all(self):314 self.user_portal.karma = KARMA['close_all']315 self.post.with_user(self.user_portal).close(None)316 def test_deactivate_post_crash(self):...
functions.js
Source:functions.js
...178}179 });180 return false;181}182function post()183{184 var post = 'lock';185 var dataString = 'post='+post;186 $.ajax ({187 type:"post",188 url: "relayFunctions.php",189 data:dataString,190 cache:false,191 success: function(html){192 $('#door').html(html);193}194 });195 return false;196}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!