I'm trying to get the value of a key in the URL (localhost:8080?color=red) and display different pages according to what value is in the url (red or blue...etc). I'm not sure how to set that up, though, because nothing I've tried works. Any ideas? It's for a class assignment, so I can't use query_string.
if self.request.GET(['color','red']):
view = ContentPage()
fetch_data = Data()
name = fetch_data.red.name
description = fetch_data.red.description
self.response.write(view.print_first() + name + description + view.print_end())
else:
see = Page()
self.response.write(see.output())
Use self.request.get, like this:
color = self.request.get('color')
# do something with color
Related
I have this function that uses PrettyTables to gather information about the Virtual Machines owned by a user. Right now, it only shows information and it works well. I have a new idea where I want to add a button to a new column which allows the user to reboot the virutal machine. I already know how to restart the virtual machines but what I'm struggling to figure out is the best way to create a dataset which i can iterate through and then create a HTML table. I've done similar stuff with PHP/SQL in the past and it was straight forward. I don't think I can iterate through PrettyTables so I'm wondering what is my best option? Pretty tables does a very good job of making it simple to create the table (as you can see below). I'm hoping to use another method, but also keep it very simple. Basically, making it relational and easy to iterate through. Any other suggestions are welcome. Thanks!
Here is my current code:
x = PrettyTable()
x.field_names = ["VM Name", "OS", "IP", "Power State"]
for uuid in virtual_machines:
vm = search_index.FindByUuid(None, uuid, True, False)
if vm.summary.guest.ipAddress == None:
ip = "Unavailable"
else:
ip = vm.summary.guest.ipAddress
if vm.summary.runtime.powerState == "poweredOff":
power_state = "OFF"
else:
power_state = "ON"
if vm.summary.guest.guestFullName == None:
os = "Unavailable"
else:
os = vm.summary.guest.guestFullName
x.add_row([vm.summary.config.name, os, ip, power_state])
table = x.get_html_string(attributes = {"class":"table table-striped"})
return table
Here is a sample of what it looks like and also what I plan to do with the button. http://prntscr.com/nki3ci
Figured out how to query the prettytable. It was a minor addition without having to redo it all.
html = '<table class="table"><tr><th>VM Name</th><th>OS</th><th>IP</th><th>Power
State</th></tr>'
htmlend = '</tr></table>'
body = ''
for vmm in x:
vmm.border = False
vmm.header = False
vm_name = (vmm.get_string(fields=["VM Name"]))
operating_system = (vmm.get_string(fields=["OS"]))
ip_addr = ((vmm.get_string(fields=["IP"])))
body += '<tr><td>'+ vm_name + '</td><td>' + operating_system + '</td> <td>'+ ip_addr +'</td> <td>ON</td></tr>'
html += body
html += htmlend
print(html)
Consider the configuration below:
#URLMapping(id = "programaManter", parentId = "homeTreinamento", pattern = "/programa/#{id : programaManter.id}", viewId = "/pages/treinamento/ProgramaManter.xhtml")
Lets say that I need to navigate to /programa/1. I've tried the following:
return "/pages/treinamento/ProgramaManter.xhtml?faces-redirect=true&id=" + id;
But instead of navigating to /programa/1 it's navigating to /programa/?id=1, how can I force it to build the url using path parameter instead of query parameter?
Solution posted here on the OCPsoft support forums: http://ocpsoft.org/support/topic/navigation-using-path-parameter-on-pretty-faces-2-0-8-final/#post-25822
I am looking for a quick and dirty way to query the layouts files of a particular page by its friendly url. This is probably easy, but I can't find the solution.
Basically I want to say something like the following. Pseudo-code:
var mainpage = Sitecore.EasyQueryUtility.GetItemByFriendlyUrl(requestedUrl);
or
var mainpage = Sitecore.EasyQueryUtility.GetOppositeOfFriendlyUrl(friendlyurl);
It sounds like you want to do two things here:
Determine an item based on its rendered URL in the address bar (i.e. friendly URL)
Determine the layout being used by the item once you determine the item.
If those are correct, hopefully this can help you out:
Note: untested code I did on-the-fly
// if you have the full URL with protocol and host
public static Item GetItemFromUrl(string url)
{
string path = new Uri(url).PathAndQuery;
return GetItemFromPath(path);
}
// if you have just the path after the hostname
public static Item GetItemFromPath(string path)
{
// remove query string
if(path.Contains("?"))
path = path.split('?')[0];
path = path.Replace(".aspx", "");
return Sitecore.Context.Database.GetItem(path);
}
Once you have the item you can get the layout's name like so:
item.Visualization.GetLayout(Sitecore.Context.Device).Name;
Or the layout's physical file path to the ASPX:
item.Visualization.GetLayout(Sitecore.Context.Device).FilePath;
If you want to get the path of the aspx file which is used for the layout of your page, you can use:
Sitecore.Context.Item.Visualization.Layout.FilePath
I may have misunderstood you but if you want to control the format of friendly URLs you can set several attributes via the Sitecore.Links.UrlOptions class and pass an instance of this in to the link manager. See here for more details. (Note - the LinkManager class is only available from SiteCore 6 I beleive).
The code you would end up with looks like this:
Sitecore.Links.UrlOptions urlOptions = (Sitecore.Links.UrlOptions)Sitecore.Links.UrlOptions.DefaultOptions.Clone();
urlOptions.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;
string url = Sitecore.Links.LinkManager.GetItemUrl(item, urlOptions);
You can then set fields like AddAspxExtension on the urlOptions you pass in.
As you can see, the process is reliant on you passing in an item - whether it be obtained via the current context or retrieved from the URL you start off with.
If you were asking about obtaining the layout definition item, take a look at this which shows you how.
I'm trying to create a thumbnail from a pdf in coldfusion, but no thumbnail gets created and no exception is thrown.
(coldfusion 9)
my code:
var source = "A:\testfolder\test.pdf";
var destination = "A:\testfolder\";
createImageFromPdf(source, destination);
createImageFromPdf function:
public void function createImageFromPdf(required string source, required string destination,
numeric pages = 1, string resolution = "low",
numeric scale = 100, boolean overwrite = true){
var pdf = new pdf();
pdf.setSource(arguments.source);
pdf.thumbnail(pages = arguments.pages, resolution = arguments.resolution,
scale = arguments.scale, overwrite = arguments.overwrite);
}
After running this code, i don't receive errors or exceptions, but no image was generated in A:\testfolder\
I'm probably missing something obvious here, but can't find it.
Also no log records are created in application or exception log, pdf is not protected and I'm sure that the folder is writable.
All help is appreciated.
Thanks.
You just forgot to pass along the destination
pdf.thumbnail(destination=arguments.destination
, pages = arguments.pages
, resolution = arguments.resolution
, scale = arguments.scale
, overwrite = arguments.overwrite);
I would like to know the .ini config file setup to make a route wherein the page number parameter is optional so that
http://news.mysite.com/national
http://news.mysite.com/national/1
point to the same page.
I have the code as follows
resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9\-]+)/([0-9\-]+)"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%s"
can some1 help me out with a solution to modify this code to make it work for both urls
You can do this without the regex route using:
routes.news_list.route = ":action/:page"
routes.news_list.defaults.module = "news"
routes.news_list.defaults.controller = "index"
routes.news_list.defaults.action = "category"
routes.news_list.defaults.page = 1
I assume that you want every request to go to the "news" module and the "index" controller. Only the action and the page are variable in the url.
resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9-]+)/?([0-9]+)?"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%d"
Something like this could work too in case you need to use Regex.