How to use post method in Playwright Internal

Best JavaScript code snippet using playwright-internal

views.py

Source:views.py Github

copy

Full Screen

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,...

Full Screen

Full Screen

default.py

Source:default.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

test_forum.py

Source:test_forum.py Github

copy

Full Screen

...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):...

Full Screen

Full Screen

functions.js

Source:functions.js Github

copy

Full Screen

...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}...

Full Screen

Full Screen

post.py

Source:post.py Github

copy

Full Screen

...42 posts = [post] if post else frappe.db.sql_list("select name from `tabPost`")43 for post in posts:44 cache.delete_value("website_group_post:{}".format(post))45@frappe.whitelist(allow_guest=True)46def add_post(group, content, picture, picture_name, title=None, parent_post=None,47 assigned_to=None, status=None, event_datetime=None):48 doc = frappe.get_doc("Website Group", group)49 access = get_access(doc, doc.get_route())50 if not access.get("write"):51 raise frappe.PermissionError52 if parent_post:53 if frappe.db.get_value("Post", parent_post, "parent_post"):54 frappe.throw(_("Cannot reply to a reply"))55 group = frappe.get_doc("Website Group", group)56 post = frappe.get_doc({57 "doctype":"Post",58 "title": (title or "").title(),59 "content": content,60 "website_group": group.name,61 "parent_post": parent_post or None62 })63 if not parent_post:64 if group.group_type == "Tasks":65 post.is_task = 166 post.assigned_to = assigned_to67 elif group.group_type == "Events":68 post.is_event = 169 post.event_datetime = event_datetime70 post.ignore_permissions = True71 post.insert()72 if picture_name and picture:73 process_picture(post, picture_name, picture)74 # send email75 if parent_post:76 post.run_method("send_email_on_reply")77 return post.parent_post or post.name78@frappe.whitelist(allow_guest=True)79def save_post(post, content, picture=None, picture_name=None, title=None,80 assigned_to=None, status=None, event_datetime=None):81 post = frappe.get_doc("Post", post)82 group = frappe.get_doc("Website Group", post.website_group)83 access = get_access(group, group.get_route())84 if not access.get("write"):85 raise frappe.PermissionError86 # TODO improve error message87 if frappe.session.user != post.owner:88 for fieldname in ("title", "content"):89 if post.get(fieldname) != locals().get(fieldname):90 frappe.throw(_("Cannot change {0}").format(fieldname))91 if picture and picture_name:92 frappe.throw(_("Cannot change picture"))93 post.update({...

Full Screen

Full Screen

post_content.js

Source:post_content.js Github

copy

Full Screen

1var db = require('./db');2module.exports = {3 getAll : function(callback){4 var sql = "select * from post_content";5 db.getResults(sql, null, function(results){6 // console.log("result from table:", results);7 if(results.length > 0){8 callback(results);9 }else{10 callback([]);11 }12 });13 },14 delete : function(post_id, callback){15 var sql = "Delete from post_content where post_id=?";16 db.execute(sql, [post_id], function(status){17 if(status){18 callback(true);19 }else{20 callback(false);21 }22 });23 },24 getNextId : function(callback){25 var sql = "SELECT auto_increment AS id FROM `information_schema`.`tables` WHERE table_name = 'post_content' AND table_schema = 'express'";26 db.getResults(sql, null, function(result){27 if(result.length > 0){28 callback(result);29 }else{30 callback([]);31 }32 });33 },34 insert : function(data, callback){35 var sql = "INSERT INTO `post_content`(`post_text`, `post_image`) VALUES (?, ?)";36 db.execute(sql, [data.post_text, data.post_image], function(status){37 if(status){38 callback(true);39 }40 else{41 callback(false);42 }43 })44 },45 getAllFromSearch : function(string, callback){46 var sql = "select post_info.post_time, user_details.username, post_type.post_type_name, post_content.post_id, post_content.post_text, post_content.post_image, post_status.post_status_name from post_content, post_status, post_type, post_info, user_details WHERE post_content.post_id = post_info.post_id AND user_details.username = (SELECT user_details.username WHERE user_details.user_id = post_info.user_id) AND post_type.post_type_name = (SELECT post_type.post_type_name WHERE post_type.post_type_id = post_info.post_type_id) AND post_status.post_status_name = (SELECT post_status.post_status_name WHERE post_info.post_status_id = post_status.post_status_id) AND post_status.post_status_name = 'approve' AND post_content.post_text LIKE '%' ? '%'";47 db.getResults(sql, [string], function(results){48 if(results.length > 0){49 callback(results);50 }else{51 callback([]);52 }53 });54 },55 getAllPost : function(callback){56 var sql = "select post_info.post_time, user_details.username, post_type.post_type_name, post_content.post_id, post_content.post_text, post_content.post_image, post_status.post_status_name from post_content, post_status, post_type, post_info, user_details WHERE post_content.post_id = post_info.post_id AND user_details.username = (SELECT user_details.username WHERE user_details.user_id = post_info.user_id) AND post_type.post_type_name = (SELECT post_type.post_type_name WHERE post_type.post_type_id = post_info.post_type_id) AND post_status.post_status_name = (SELECT post_status.post_status_name WHERE post_info.post_status_id = post_status.post_status_id) AND post_status.post_status_name = 'approve'";57 db.getResults(sql, null, function(results){58 if(results.length > 0){59 callback(results);60 }else{61 callback([]);62 }63 });64 },65 getReported : function(callback){66 var sql = "select * from post_content,post_info where post_info.post_id=post_content.post_id and post_info.post_status_id=53";67 db.getResults(sql, null, function(results){68 if(results.length > 0){69 callback(results);70 }else{71 callback([]);72 }73 });74 },75 getById : function(userid,callback){76 var sql = "select post_info.user_id, post_info.post_id,post_info.post_type_id,post_status_id,post_content.post_text,post_info.post_time from post_content,post_info where post_content.post_id=post_info.post_id and post_info.user_id=? order by post_info.post_id desc";77 db.getResults(sql, [userid], function(results){78 if(results.length > 0){79 callback(results);80 }else{81 callback([]);82 }83 });84 },85 getLikeComment : function(callback){86 var sql = "select count(*) as res from post_info,post_like where post_info.post_id=post_like.post_id and post_info.post_status_id=53 group by post_like.post_id";87 db.getResults(sql, null , function(results){88 if(results.length > 0){89 callback(results);90 }else{91 callback([]);92 }93 });94 },95 getLikeById : function(id,callback){96 var sql = "SELECT count(*) as res FROM post_like,post_info WHERE post_like.post_id=post_info.post_id and post_info.user_id="+id;97 db.getResults(sql, [id] , function(results){98 if(results.length > 0){99 callback(results);100 }else{101 callback([]);102 }103 });104 }...

Full Screen

Full Screen

routes.py

Source:routes.py Github

copy

Full Screen

...6from spcforum.posts.forms import PostForm7posts = Blueprint('posts', __name__)8@posts.route("/post/new", methods=['GET', 'POST'])9@login_required10def new_post():11 form = PostForm()12 if form.validate_on_submit():13 post = Post(title=form.title.data, content=form.content.data, author=current_user)14 db.session.add(post)15 db.session.commit()16 flash('Your post has been created!', 'success')17 return redirect(url_for('main.home'))18 return render_template('create_post.html', title='New Post',19 form=form, legend='New Post')20@posts.route("/post/<int:post_id>")21def post(post_id):22 post = Post.query.get_or_404(post_id)23 return render_template('post.html', title=post.title, post=post)24@posts.route("/post/<int:post_id>/update", methods=['GET', 'POST'])25@login_required26def update_post(post_id):27 post = Post.query.get_or_404(post_id)28 if post.author != current_user:29 abort(403)30 form = PostForm()31 if form.validate_on_submit():32 post.title = form.title.data33 post.content = form.content.data34 db.session.commit()35 flash('Your post has been updated!', 'success')36 return redirect(url_for('posts.post', post_id=post.id))37 elif request.method == 'GET':38 form.title.data = post.title39 form.content.data = post.content40 return render_template('create_post.html', title='Update Post',41 form=form, legend='Update Post')42@posts.route("/post/<int:post_id>/delete", methods=['POST'])43@login_required44def delete_post(post_id):45 post = Post.query.get_or_404(post_id)46 if post.author != current_user:47 abort(403)48 db.session.delete(post)49 db.session.commit()50 flash('Your post has been deleted!', 'success')...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.urls import path2from . import views3urlpatterns = [4 path('',views.post_list, name='post_list'),5 path('post/<int:pk>/', views.post_detail, name='post_detail'),6 path('post/new', views.post_new, name='post_new'),7 path('post/<int:pk>/edit/', views.post_edit, name='post_edit'),8 path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),9 path('post/<int:pk>/<int:pk1>', views.post_show, name='post_show'),10 path('post/<int:pk>/save/',views.post_save,name='post_save'),11 path('post/<int:pk>/scale/', views.post_scale, name='post_scale'),12 path('post/<int:pk>/thresholding/', views.post_thresholding, name='post_thresholding'),13 path('post/<int:pk>/contrast/', views.post_contrast, name='post_contrast'),14 path('post/<int:pk>/equalizer/', views.post_equalizer, name='post_equalizer'),15 path('post/<int:pk>/logaritmo/', views.post_logaritmo, name='post_logaritmo'),16 path('post/<int:pk>/raiz/', views.post_raiz, name='post_raiz'),17 path('post/<int:pk>/exponencial/', views.post_exponencial, name='post_exponencial'),18 path('post/<int:pk>/raizpower/', views.post_raizpower, name='post_raizpower'),19 path('post/<int:pk>/adicion/', views.post_adicion, name='post_adicion'),20 path('post/<int:pk>/sustraccion/', views.post_sustraccion, name='post_sustraccion'),21 path('post/<int:pk>/multiplicacion/', views.post_multiplicacion, name='post_multiplicacion'),22 path('post/<int:pk>/division/', views.post_division, name='post_division'),23 path('post/<int:pk>/blending/', views.post_blending, name='post_blending'),24 path('post/<int:pk>/not/', views.post_not, name='post_not'),25 path('post/<int:pk>/and/', views.post_and, name='post_and'),26 path('post/<int:pk>/or/', views.post_or, name='post_or'),27 path('post/<int:pk>/xor/', views.post_xor, name='post_xor'),...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful