Unable to find link (Capybara::ElementNotFound) - ruby-on-rails-3

I have problem:
When I follow "Find Movies With Same Director" #
features/step_definitions/web_steps.rb:56
Unable to find link "Find Movies With Same Director" (Capybara::ElementNotFound)
in web_steps.rb:
When /^(?:|I )follow "([^"]*)"$/ do |link|
click_link(link)
end
in my routes:
find_movies_with_same_director_movie GET /movies/:id/find_movies_with_same_director(.:format) {:action=>"find_movies_with_same_director", :controller=>"movies"}
movies GET /movies(.:format)
in my view show.html.haml:
%br
= link_to 'Find Movies With Same Director', find_movies_with_same_director_movie_path(#movie)
in controller movies_controller.rb:
def find_movies_with_same_director
# some code
end
What wrong?

Thanks sevenseacat for hint: save_and_open_page
I have Scenario:
Scenario: find movie with same director
Given I am on the details page for "Star Wars"
When I follow "Find Movies With Same Director"
In step: Given I am on the details page for "Star Wars"
I have mistake:
when /^the details page for "(.*)"$/
movies_path(Movie.find_by_title($1))
Right path:
when /^the details page for "(.*)"$/
movie_path(Movie.find_by_title($1))

Related

Permission of ir.config_paramenter in odoo 12

I got this problem. Why i get this access error and how can i fix it?
Odoo Server Error - Access Error
Sorry, you are not allowed to access
this document. Only users with the following access level are
currently allowed to do that:
Administration/Settings
(Document model: ir.config_parameter) - (Operation: read, User: 21)
Here is my code:
Button submit:
<button string="Confirm" name="button_submit" states="draft" type="object" class="oe_highlight"/>
My python code:
def send_email(self, subject, message_body, email_from, email_to):
template_obj = self.env['mail.mail']
template_data = {
'subject': subject,
'body_html': message_body,
'email_from': email_from,
'email_to': email_to
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
template_id.send()
#api.multi
def request_recuitment_send_mail(self):
""" Send mail with wizard """
base_url = request.env['ir.config_parameter'].get_param('web.base.url')
base_url += '/web#id=%d&view_type=form&model=%s' % (self.id, self._name)
subject = '''Request recuitment for {}'''.format(self.job_id.name)
message_body = '''
<div style="font-size: medium;">
Dear {},
Please check this link for more information Click here
'''.format(
self.user_id.name,
base_url,
)
email_from = '''HR Recruiment <{}>'''.format(self.approver_id.work_email)
email_to = self.user_id.email
self.send_email(subject, message_body, email_from, email_to)
#api.multi
def button_approve(self):
subject = "Request recruitment for {self.job_id.name} has been approved "
body = '''
Position Request: {}
Quantity of Position: {}
Department: {}
Expected Gross Salary: {}
'''.format(
self.job_id.name,
self.quantity,
self.department_id.name,
self.salary_cross_expected
)
self.env['mail.message'].create({'message_type': "notification",
"subtype": self.env.ref("mail.mt_comment").id,
'body': body,
'subject': subject,
'needaction_partner_ids': [(4, self.user_id.partner_id.id,)],
'model': self._name,
'res_id': self.id,
})
self.request_recuitment_approved_send_mail()
self.write({'state': 'approved'})
It should be safe to use sudo() in this case:
request.env['ir.config_parameter'].sudo().get_param('web.base.url')
"Normal" Users don't have any rights on model ir.config_parameter (System parameters). Only the admin (one of its default access groups) or the superuser can read such parameters.
About sudo([flag=True]) from the current documentation (Odoo 15):
Returns a new version of this recordset with superuser mode enabled or disabled, depending on flag. The superuser mode does not change the current user, and simply bypasses access rights checks.
IMPORTANT: I'm not completely sure when it was changed, but IIRC the "current user change" was removed since Odoo 13. So for Odoo 12 sudo will change the current user, which for example will have impacts on default values on creation, created message authors, and so on.
In your case that's irrelevant, because you're only getting the base url or the parameter value, and that's it.

All li tag under first ul tag

I want to scrape all a tags with href attrs in all li tags under first ul tag. The below code scrape all all a tags under all li tags in all ul tags. (I want only under the first ul tag). You can see the website.
https://www.mindtools.com/pages/main/newMN_CDV.htm
my code is:
for ultag in soup.find_all('ul', {'class': 'collection test_further_resource'}):
for litag in ultag.find_all('li'):
print(litag.find("a")["href"])
Please see the website. Please go to "Browse tools by Category" and "Thinking about Career direction". I want to scrape the href for this category which are 13.
Thank you in advance.
.find() will return the first tag it finds that matches, as opposed to .find_all() which will return a list of all the matches.
import requests
from bs4 import BeautifulSoup
url = 'https://www.mindtools.com/pages/main/newMN_CDV.htm'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
ultag = soup.find('ul', {'class': 'collection test_further_resource'})
for litag in ultag.find_all('li'):
print(litag.find("a")["href"])
Output:
/pages/article/managing-career.htm
/pages/article/newCDV_97.htm
/pages/article/career-strategy.htm
/pages/article/personal-ansoff-matrix.htm
/pages/article/career-opportunities.htm
/pages/article/managing-yourself.htm
/pages/article/newCDV_99.htm
/pages/article/newCDV_89.htm
/pages/article/rebooting-your-career.htm
/pages/article/newCDV_98.htm
/pages/article/locus-of-control.htm
/pages/article/newCDV_90.htm
/pages/article/seat-on-the-board.htm

Odoo13: How to assign followers to a record via Controller

In my webform controller, I am attempting to assign email addresses entered in a webform to a given record. This is the snippet of code in my controller responsible for that
if 'followers' in request.params:
raw_emails = request.httprequest.form.get('followers').split(',')
emails = [user.strip() for user in raw_emails]
#emails = ['foo#bar.com', 'foo2#bar.com',..]
for email in emails:
follower = request.env['res.users'].search(
[('email', '=', email)])
if bool(follower):
reg = {
'res_id': new_ticket.id,
'res_model': 'helpdesk.ticket',
'partner_id': follower.id
}
request.env['mail.followers'].create(reg)
else:
message = "TO DO: Add {} to the system and make the user a follower of this ticket".format(
email)
new_ticket.message_post(body=message)
With this I get strange results i.e after entering "user A" as a follower on the webform, "user B" gets added as a follower. I'm thinking the problem might be from the wrong user record being loaded into the follower variable but I'm not seeing why. Any feedback would be really appreciated.
You can use the message_subscribe method to add followers to a record set.
def message_subscribe(self, partner_ids=None, channel_ids=None, subtype_ids=None):
    """ Main public API to add followers to a record set. Its main purpose is
    to perform access rights checks before calling _message_subscribe. """
You have already an example in the account move, in message_new method that add a list of partners.
# Assign followers.
all_followers_ids = set(partner.id for partner in followers + senders + partners if is_internal_partner(partner))
move.message_subscribe(list(all_followers_ids))

Link from Wordpress site to Buddypress Profile

I try to link from the Wordpress Page Editor to the Buddypress Profile.
I installed 'Insert PHP v1.2' to use php, but i still dont get it. Actually I do the following steps in my Wordpress page:
[kleo_h3]Füge weitere [kleo_colored_text color="#F00056"]Fotos [/kleo_colored_text]zu deinem Profil hinzu.[/kleo_h3]
[rtmedia_uploader]
[insert_php]
&var = bp_loggedin_user_domain();
echo do_shortcode('[kleo_button url=&var style="standard" size="small" round="round" icon="{fontawesome-icon,after" target="_self"] Profil [/kleo_button]');
[/insert_php]
But the programm crahes. How I get that URL into the shortcode?
Got it finally:
[kleo_h3]Füge weitere [kleo_colored_text color="#F00056"]Fotos [/kleo_colored_text]zu deinem Profil hinzu.[/kleo_h3]
[rtmedia_uploader]
[insert_php]
//$var =bp_core_get_userlink( bp_loggedin_user_id());
$id= bp_loggedin_user_id();
$name = bp_core_get_user_displayname($id);
$url = site_url()."/members/$name";
echo do_shortcode('[kleo_button url='.$url.' style="standard" size="small" round="round" icon="{fontawesome-icon,after" target="_self"] Profil [/kleo_button]');
[/insert_php]

openerp page numbers

I have tried to add page numbers in my document using the following two ways
I just want default page 1, page 2 etc.
1)
<para>
<drawCentredString x="18.5cm" y="1.5cm"> Page: <pageNumber/></drawCentredString></para>
2)
<para><drawCentredString x="18.5cm" y="1.5cm"> Page: <pageCount/></drawCentredString></para>
for option 2, I changed the pagecount class in trml2pdf.py as below
class PageCount(platypus.Flowable):
def draw(self):
self.canv.beginForm("pageCount")
self.canv.setFont("Helvetica", utils.unit_get(str(8)))
## self.canv.drawString(0, 0, str(self.canv.getPageNumber()))
self.canv.drawString(0, 0, str(self.canv._pageCount))
self.canv.endForm()
class PageReset(platypus.Flowable):
def draw(self):
self.canv._pageNumber = 0
--
No Luck !! I just get page : or or
error
Thanks in advance,Usha
You can do so by just writing "< pageNumber/>" in your .rml, but you have to write it under "template/paggeTemplate/pageGraphics" tags.
For example:
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
<pageTemplate>
<pageGraphics>
<drawCentredString x="10.5cm" y="0.8cm">Page: <pageNumber/></drawCentredString>
</pageGraphics>
</pageTemplate>
Hope this will solve your problem.
For the report with header = internal , you will have the 1/2 style page Count in report automatically .
as in report of openerp it is using Numbered canvasing for the internal Heard report .