I am learning website module of Odoo 9 and want to know the format of route expression. I am aware about the regex but could not get it completely. Take a look to this :-
class WebsiteBlog(http.Controller):
_blog_post_per_page = 20
_post_comment_per_page = 10
# codes
#http.route([
'/blog/<model("blog.blog"):blog>',
'/blog/<model("blog.blog"):blog>/page/<int:page>',
'/blog/<model("blog.blog"):blog>/tag/<string:tag>',
'/blog/<model("blog.blog"):blog>/tag/<string:tag>/page/<int:page>',
], type='http', auth="public", website=True)
def blog(self, blog=None, tag=None, page=1, **opt):
print 123
# etc
You can find this code on Git: Website Blog Module
I want to understand these expression. I can understand that this function will be executed if any one of these four URL will be requested by the browser and blog, tag and page are the variables but what is the meaning of this model(blog.blog) here ?
It defines that you are passing a value in URL is the record of the model blog.blog.
Ex.
your url like this..
localhost:8069/blog/3
Then in the controller you will get the record of model blog.blog which is having id = 3.
Related
I have a problem regarding the sending of data, I have already done a research in this subject but I did not find my answer so I ask for your help
I am building a desktop application with pyqt5 and python, and I would like that the information entered in the form on page 1 to be transferred to page 2
I don't see how to do it at all.
i never worked with PyQt but i can suggest for you a solution , you can use a class
with a static variable on the first page , and make a methode that can alter this variable
whenever you want , and in the other page you can import the class and get the value with a getter , for instance :
Page 1
class Class1 :
your_variable = ''
def set_variable(self,val) :
self.your_variable = val
def get_variable(self) :
return self.your_variable
Page 2
from Page1 import Class1
varibale = Class1.getvariable()
i have this url
path('<slug>/thank_you/<user_id>', thank_you, name='thank_you'),
i want the <user_id> to be optional, but i dont want to make 2 urls like this
path('<slug>/thank_you', thank_you, name='thank_you'),
path('<slug>/thank_you/<user_id>', thank_you, name='thank_you2'),
i understand that you can make it optional using regex, but thats if you're using django <2 (using url, not path)
how do i obtain this ?
You can use URL Query String for this. For example:
# URL
path('/thank_you/', thank_you, name='thank_you'),
# View
def thank_you(request, slug):
user_id = request.GET.get('from')
# rest of the code
# Example route
http://localhost:8000/dummy-slug/thank_you/?from=dummy_user_id
I am running a series of selenium functional tests of a django site for acceptance testing purposes. I notice that when I run these and exceptions occur, I get back an entire page ( eg a HTTP status 500 ).
I am running acceptance testing using a simple loop and storing the outputted html to a db using the django orm:
def my_functional_tests(request):
import requests
from mytests.models import Entry
for i in range(3):
p1 = { ....... }
r1 = requests.post('http://127.0.0.1:8000/testfunction1/',data=p1)
..............
entry = Entry(output1 = r1.text, output2 = r2.text, output3 = r3.text)
entry.save()
return HttpResponse("completed")
My Model is defined as (where the outputs are the HTML results of 3 functional tests ):
class Entry(models.Model):
output1 = models.CharField(max_length=240)
output2 = models.CharField(max_length=240)
output3 = models.CharField(max_length=240)
When I get an error, the resulting approximately 65K webpage causes an exception on saving, and breaks the testing. I want to get as much info as possible, so I could increase the max_length to lets say 70,000 to store the entire page, but is there a more concise way to capture and store relevant data including the specific errors to the db ?
If you did this with Django's testing client, you could get more concise information--but by using requests, you're really hitting your page as a web browser would, so the full page is what you get (but 65K for a 500 Error page? Wow).
Could you embed in the error page an HTML comment with a marker and concise explanation?
<html>
<h1>Error</h1>
... 64k of stuff follows ...
<!-- ERR:"info about error" -->
</html>
That way, you could parse the results for that error code and store just that.
Of course, you'll want to make sure you don't put anything confidential in that error message or, if you do, that you emit it only when in DEBUG mode or when the request comes from localhost, or logged in as staff, or whatever other security constraint would work.
Slightly prettier would be to write a piece of middleware that emits the error-info as an HTTP Header; then your page could stay the same and you could look at the response headers for your error info.
I am trying to scrape from this website http://saintbarnabas.hodesiq.com/joblist.asp?user_id=
and I want to get all the RNs in it... I can scrape a data but cannot continue to the next page
because of its javascript. I tried reading to other questions but I don't get it. This is my code
class MySpider(CrawlSpider):
name = "commu"
allowed_domains = ["saintbarnabas.hodesiq.com"]
start_urls = ["http://saintbarnabas.hodesiq.com/joblist.asp?user_id=",
]
rules = (Rule (SgmlLinkExtractor(allow=('\d+'),restrict_xpaths=('*'))
, callback="parse_items", follow= True),
)
the next button shows as
Next
This pagination is kills me...
In short, you need to figure out what Move('next') does and reproduce that in your code.
A quick inspection of the sites shows that the function code is this:
function Move(strIndicator)
{
document.frm.move_indicator.value = strIndicator;
document.frm.submit();
}
And the document.frm is the form with name "frm":
<form name="frm" action="joblist.asp" method="post">
So, basically you need to build a request to perform the POST for that form with the move_indicator value as 'next'. This is easily done by using the FormRequest class (see the docs) like:
return FormRequest.from_response(response, formname="frm",
formdata={'move_indicator': 'next'})
This technique works in most cases. The difficult part is to figure out what does the javascript code, sometimes it might be obfuscated and perform overly complex stuff just to avoid being scraped.
I am working with python web.py framework,i had an anchor tag with html code as below for example
<p><a href = "/edit.py?tr=%d"%1>Edit</a></p>
So when i click this link it goes to edit.py file in my project directory, but as you observe i am passing some values after edit.py like /edit.py?tr=%d"%1. Actually i will pass these values dynamically in further process.
Here after redirecting to edit.py, how to access the values after ? from the py file?
because my intention is to edit the record after saving in to database.
You can get them using web.input, e.g.
def GET(self):
data = web.input()
tr = data.tr
Documentation is avaliable here: http://webpy.org/cookbook/input