Change button image in web.py - web.py

I have the following code in my python script. How do I change the image of my button instead of the default ugly looking button?
import web
from web import form
render = web.template.render('templates/')
urls = ('/','index')
register_form = form.Form(
form.Textbox("name",size=40, description="Please enter name: "),
form.Button("Query", type="submit", description="Query")
)
I was hoping to have an effect similar to this:
< button>< img src="index.png">< /img>< /button>

The html option allows you to enter any html tags. :)
form.Button("Query", type="submit", description="Query" html="<img src="hello.png"/)

Related

how to make snippets auto complete in my custom vs code extension?

im korean beginner developer... help... T^T
i want to make auto complete like snippets in my custom vs code extension.
now my code,
const snippetBase = `axios.({
url: "${service.url}",
method: "${service.description}",
`
const editor = vscode.window.activeTextEditor
const selection: any = editor?.selection
editor?.edit(builder => {
builder.replace(
selection,
snippetBase + snippetHeaders(snippetRes.data.header) + snippetBody(snippetRes.data.body)
)
})
then, my extension auto complete image
I want to focus my cursor automatically inside the format after the snippet is shown.
Just like picture below.
snippets image
help me plz!!
It sounds from your comment that you want the edit to act as a snippet. Then you need to make a SnippetString and use the editor.insertSnippet() command which can take that SnippetString as an argument. This should work for you:
const editor = vscode.window.activeTextEditor
const selection = editor?.selection
const axiosSnippet = new vscode.SnippetString("axios.({\n")
axiosSnippet.appendText("\turl: \"")
axiosSnippet.appendPlaceholder(service.url)
axiosSnippet.appendText("\",\n")
axiosSnippet.appendText("\tmethod: \"")
axiosSnippet.appendPlaceholder(service.description)
axiosSnippet.appendText("\",\n")
editor.insertSnippet(axiosSnippet, selection)
axiosSnippet.appendPlaceholder(service.url); is the key to this, as it will select that placeholder first and then allow you to tab to the next placeholder axiosSnippet.appendPlaceholder(service.description).
[I don't know the structure of the rest of your snippet,e.g., snippetHeaders(snippetRes.data.header). If it is just text than you can use the appendText method with \n for newlines.

How to display an image uploaded with input type="file" as a src attribute

I tried creating an input which allows users to display images they uploaded as an html img. All of this needs to happen on 'submit'.
My js code for input (which is inside a form) looks like this:
const imageInput = document.createElement('input');
imageInput.type = 'file';
imageInput.accept = ".png, .jpg, .jpeg";
and this is how I'd like to output my image
const displayImg = (e) => {
e.preventDefault();
const questionImg = document.createElement('img');
questionImg.src = imageInput.value;
}
image.addEventListener('submit', displayImg);
It obviously doesn't work since imageInput.value looks something like this C:\fakepath\pizza.jpg
Then how can I set the uploaded file as the source of an image.
I found some helpful code on youtube that I tried that manages to output the uploaded img as div's background-image https://codepen.io/codefoxx/pen/QWvqMya but it stops working once I try to output it as the src or add form, submit button and change the event listener to "submit".

Replace HTML in response using Fiddler

I want to do something as simple as changing a color code in the response of an HTTP request, but I can't seem to figure it out. Basically, when a certain website loads, The background is set with the color code "#db4437" and I'd like to have it always be changed to "#09C3FF" when the website loads.
I found this code for Fiddlerscript in the Fiddler guides, but it doesn't seem to really do anything at all
if (oSession.HostnameIs("www.bayden.com") &&
oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}
This example from Telerik documentation works for me:
Remove all DIV tags (and content inside the DIV tag)
// If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
oBody = oBody.replace(oRegEx, "");
// Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);
}

Confluence create page with custom image

I want to create a page in confluence with custom information.
API - (POST) confluence/rest/api/content
I am able to upload text and image successfully. If I use src for image that is uploaded somewhere,
e.g. www.example.com/myimage.png
then this image is successfully visible on my newly created page on confluence.
But, if I use src as data uri,
e.g. data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
then it does not display the image.
Please note that API does not throw any error but does not display the image as well.
Working:
{
"type":"page",
"title":"Document",
"space":{"key":"DEMO"},
"body":{
"storage":{
"value":"<img src='http://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028'/>",
"representation":"storage"
}
}
}
Not working:
{
"type":"page",
"title":"Document",
"space":{"key":"DEMO"},
"body":{
"storage":{
"value":"<p>Hello</p><img height='284' width='750' src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'/><p>Hi</p>",
"representation":"storage"
}
}
}
Any help would be appreciated.
Thanks
You can get around this if you use an HTML Macro. See the "Storage format example" on this page: HTML Macro.
You would just surround your html like this:
< ac:structured-macro ac:name = "html" >
< ac:plain-text-body >
<![CDATA[<div>HTML HERE</div>]]>
</ ac:plain-text-body >
</ ac:structured-macro >
But you have to have the HTML Macro enabled.

Autocomplete and browse for a RelationChoice field are not working in a tile

I have a tile with a RelationChoice field, but the field just has the static html form elements (a "nothing" radio button, a text input and a 'Search' button), and it does not respond dynamically. In comparing it with an identical tile on another site that works, I noticed that the field-specific js code from plone.formwidget.contenttree and plone.formwidget.autocomplete is not embedded in the tile source. I put breakpoints in https://github.com/plone/plone.formwidget.autocomplete/blob/master/plone/formwidget/autocomplete/widget.py#L142 and in https://github.com/plone/plone.formwidget.contenttree/blob/master/plone/formwidget/contenttree/widget.py#L253, and they are getting hit when the tile loads, and the proper js is being returned. But I don't know why it doesn't get sent to the client.
Any ideas?
Everything else on the tile works fine, and the standard jquery resources are loaded:
++resource++plone.formwidget.autocomplete/jquery.autocomplete.min.js
++resource++plone.formwidget.autocomplete/formwidget-autocomplete.js
++resource++plone.formwidget.contenttree/contenttree.js
Here is the zcml for my tile:
<plone:tile
name="peps.tiles.calltoaction"
title="PEPS call to action tile"
description="A tile containing a full-size link, enclosing plain text"
add_permission="cmf.ModifyPortalContent"
schema=".tile.ICallToActionData"
class=".tile.CallToActionTile"
template="templates/calltoaction.pt"
permission="zope2.View"
for="*"
/>
And here is the tile schema and class:
class ICallToActionData(IRichTextTileData):
target = RelationChoice(
title=_(u"Link target"),
description=_(u'Choose the item to which this button will link'),
source=UUIDSourceBinder(),
required=False,
)
link_text = Text(
title=_(u"Link button text"),
description=_(u"The text for the link button at the bottom"),
)
class CallToActionTile(RichTextTile):
def target_url(self):
url = None
if self.data['target']:
obj = uuidUtils.uuidToObject(self.data['target'])
if obj is not None:
if obj.portal_type == "Link":
site_url = getToolByName(obj, 'portal_url')()
if not obj.getRemoteUrl().startswith(site_url):
url = obj.getRemoteUrl()
else:
url = obj.absolute_url()
return url
def link_text(self):
return self.text_value('link_text')
Plone 4.2.5
plone.app.tiles 1.0.1
plone.formwidget.contenttree 1.0.6
plone.formwidget.autocomplete 1.2.4
The cause of the problem were these Diazo rules:
<drop css:content="body script" />
<after css:theme-children="html body" css:content="html body script" method="raw" />
If a Diazo theme is active, it's always a good idea to deactivate it when debugging issues.