I'm using the Python mandrill package 1.0.57, as a part of the mandrill add-on for my Heroku application. I attempt to add the following template:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Title</title>
<!-- TODO styles -->
<style>
</style>
</head>
<body>
{{#each projects}}
<h3>{{this.name}}</h3>
<form>
<label for="log">Log</label>
<input type="number" id="log" name="log">
<input type="submit" value="Submit">
</form>
{{/each}}
</body>
</html>
The each loop and h3 work fine. However, I notice that upon adding the template, it has actually been modified. Specifically, the 'code' attribute of the template appears to be missing the form and input elements. The label is missing too, but its text, 'Log', is still present
This happens even if I place the elements outside of the loop. Are forms, inputs, and labels special?
Edit: I also directly tried a curl and it still modified my template.
curl -X POST -H "Content-Type: application/json" --data #test.json https://mandrillapp.com/api/1.0/templates/add.json -v
Edit 2: I guess a working workaround is to just use messages.send()
Related
I need to test requests that can be sent through iframe. For example: i have some page on domain_01:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
body {
margin: 0 auto;
}
</style>
<body>
<iframe id="inlineFrameExample"
title="Inline Frame Example"
width="1600"
height="900"
src="http://domain_02:8000/app/dashboard">
</iframe>
</body>
</html>
And as you can see here this page contains iframe with link to page on domain_02. I try to understand: is it possible to emulate request that goes to domain_02 through this iframe on doamin_01 with pytest.
Main task what i need to solve it's create tests with different requests and check that there is no CORS issues with it.
How i check it now: manually only. I run second web-server through inner python server (python -m http.server 8090) and set dns-record on local dns-server to emulate domain_01. It will be so cool to run this tests with pytest.
I am trying to delete a record in a database when a yes button is clicked using django.
views.py
def deleteServer(request, server_id):
server = Server.objects.get(pk=server_id)
print(request.POST)
if request.POST.get('yesBtn'):
server.delete()
return HttpResponseRedirect('homepage')
elif request.POST.get('noBtn'):
return HttpResponseRedirect('homepage')
return render(request, 'deleteServer.html', {'value': request.POST})
deleteServer.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Cancella server</title>
</head>
<body>
<button onclick="document.getElementById('id01').style.display='block'"
class="w3-button">Cancella server</button>
<!-- The Modal -->
<div id="id01" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-display-topright">×</span>
<p>Vuoi davvero cancellare il server selezionato?</p>
SI
NO
</div>
</div>
</div>
</body>
</html>
When I click on the yes button the record is not deleted. I thought the problem is in the deleteServer function in the file views.py.
EDIT
I printed the results of request.GET and the output is QueryDict = {}
You just have to pass the values in the GET.. Normally it's like ?key=value and if you have multiple its ?key0=value0&key1=value1
SI
NO
Note: the =True doesn't matter, It could be literally anything because in the view it just looks ~"Is key in GET" and doesn't actually look at the value itself
Edit
I completely missed that your view used request.POST.get(x)
It should use request.GET.get(x)
def deleteServer(request, server_id):
server = Server.objects.get(pk=server_id)
print('POST:', request.POST)
print('GET:', request.GET)
if request.GET.get('yesBtn'):
server.delete()
return HttpResponseRedirect('homepage')
elif request.GET.get('noBtn'):
return HttpResponseRedirect('homepage')
return render(request, 'deleteServer.html', {'value': request.POST})
I have a Flask app where I want to click a button on the home page, which will
On click, run Python script and route to my results.html. (which i have done)
Auto-fill certain fields on that page with results from a python script. (what i need help with)
The python script (parser.py) may take a 30-40 minutes to run, as its job is to start a test that takes about that long, then process and grab/parse the results. After that, some other fields will be filled in by the user, then the form on results.html is submitted to a database.
I hope i'm closer to my answer than I think, but where/how do I introduce my python into this and pass it into the form on results.html?
parser.py
import csv
import pandas as pd
import numpy as np
# Test data
body = pd.read_csv('path-to-test-data.csv', skiprows=11)
# Build dataframe of test info
frame = body['Frame Size']
loss = body['Loss Rate (Percent)']
speed = body['Tx Rate (L1) (Bit/s)']
grade = body['Result State']
lst = pd.concat([frame,loss,speed,grade], axis = 1)
selected_df = pd.DataFrame(data=lst)
selected_df.set_index('Frame Size')
# Select all 64b frame results
print(selected_df[np.isclose(selected_df['Frame Size'].values[:, None], [64],).any(axis=1)])
# Select all tests that fail
print(selected_df.loc[selected_df['Result State'] == 'FAIL'])
app.py:
import os
from flask import Flask, escape, request, redirect, render_template
app = Flask(__name__)
#app.route('/')
def home():
return render_template('index.html')
#app.route('/results/')
def about():
return render_template('results.html')
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OLT TESTER</title>
</head>
<body>
<div class="index">
Press This Button to Begin Testing
<button onclick=""></button>
</div>
</body>
</html>
results.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Results</title>
</head>
<body>
<div class="results">
Initialize Test
<form action="#.php" method="post">
Job Order: <input type="text" name="jobOrder"><br>
Serial Number: <input type="text" name="serialNo"><br>
Frame Size: <input type="text" name="jobOrder"><br> <!--Fill this field with Python output -->
Result State: <input type="text" name="serialNo"><br> <!--Fill this field with Python output -->
<input type="submit">
</form>
</div>
</body>
</html>
I am migrating several pages over to use our site's new template. These are legacy pages, though, so they need a couple extra global js files.
I was hoping to set a legacy flag in the child page views, and then have an if check in the master template, but this didn't seem to work.
Is there a better way to do this?
The ideal approach would mean I could simply declare the global legacy scripts in one place. I don't want to have to include them on every legacy child page, which is what we're doing now.
Parent template:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=.5"/>
<title>Title</title>
<link rel="stylesheet" href="/static/css/global.css"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<%block name="page_css" />
</head>
<body>
<!-- Body -->
<div class="bc-page-wrapper">
${self.body()}
</div>
<script type="text/javascript" src="/static/globals.js"></script>
% if legacy == 1:
<script type="text/javascript" src="/static/js/legacy.js"></script>
% endif
</body>
</html>
Legacy Page Inheriting Template:
<%
legacy = true
%>
<%inherit file="/global/ko_admin_template.html" />
<div class="legacy-container">
content here
</div>
Say I have a web page like this on an Ubuntu 12.04 web server running apache:
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Name Input</title>
</head>
<body>
<form action="./test.py" method="post">
<p> Name: <input type="text" name="name" id="name" value=""/></p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
I want to use the value of name as input to a shell script which is called by a Python CGI script like this.
test.py:
#!/usr/bin/env python
import commands, cgi, cgitb
form = cgi.FieldStorage()
name = form.getvalue('name')
result = commands.getoutput("/usr/lib/cgi-bin/test.sh name")
contents = pageTemplate.format(**locals())
print "Content-type: text/html\n\n"
print contents
In the example code above, how should name be passed to test.sh?
For completeness, say that pageTemplate looks like this:
pageTemplate = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Name Output</title>
</head>
<body>
{result}
</body>
</html>
'''
Just pass it into the command:
result = commands.getoutput("/usr/lib/cgi-bin/test.sh %s" % name)