chore: frappe.whitelist for doc methods (#25068)

* chore: frappe.whitelist for doc methods

* fix: incorrect spelling

* fix: sider issue

Co-authored-by: Sagar Vora <sagar@resilient.tech>
This commit is contained in:
Walstan Baptista
2021-03-31 12:30:32 +05:30
committed by GitHub
parent 353aa59c42
commit d6360755b9
79 changed files with 149 additions and 60 deletions

View File

@@ -11,7 +11,8 @@ from frappe.utils.file_manager import get_file, get_file_path
from six.moves.urllib.parse import urlencode
class LinkedInSettings(Document):
def get_authorization_url(self):
@frappe.whitelist()
def get_authorization_url(self):
params = urlencode({
"response_type":"code",
"client_id": self.consumer_key,
@@ -35,7 +36,7 @@ class LinkedInSettings(Document):
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
response = self.http_post(url=url, data=body, headers=headers)
response = frappe.parse_json(response.content.decode())
self.db_set("access_token", response["access_token"])

View File

@@ -85,6 +85,7 @@ class Opportunity(TransactionBase):
self.opportunity_from = "Lead"
self.party_name = lead_name
@frappe.whitelist()
def declare_enquiry_lost(self, lost_reasons_list, detailed_reason=None):
if not self.has_active_quotation():
frappe.db.set(self, 'status', 'Lost')

View File

@@ -11,6 +11,7 @@ from frappe.utils import get_url_to_form, get_link_to_form
from tweepy.error import TweepError
class TwitterSettings(Document):
@frappe.whitelist()
def get_authorize_url(self):
callback_url = "{0}/api/method/erpnext.crm.doctype.twitter_settings.twitter_settings.callback?".format(frappe.utils.get_url())
auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"), callback_url)
@@ -21,12 +22,12 @@ class TwitterSettings(Document):
frappe.msgprint(_("Error! Failed to get request token."))
frappe.throw(_('Invalid {0} or {1}').format(frappe.bold("Consumer Key"), frappe.bold("Consumer Secret Key")))
def get_access_token(self, oauth_token, oauth_verifier):
auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"))
auth.request_token = {
auth.request_token = {
'oauth_token' : oauth_token,
'oauth_token_secret' : oauth_verifier
'oauth_token_secret' : oauth_verifier
}
try:
@@ -50,10 +51,10 @@ class TwitterSettings(Document):
frappe.throw(_('Invalid Consumer Key or Consumer Secret Key'))
def get_api(self, access_token, access_token_secret):
# authentication of consumer key and secret
auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"))
# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
# authentication of consumer key and secret
auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"))
# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
return tweepy.API(auth)
@@ -64,7 +65,7 @@ class TwitterSettings(Document):
if media:
media_id = self.upload_image(media)
return self.send_tweet(text, media_id)
def upload_image(self, media):
media = get_file_path(media)
api = self.get_api(self.access_token, self.access_token_secret)