def sync_calender(): # check storage for credentials store = Storage('GCal', frappe.session.user) # store = Storage('GCal', "makarand") credentials = store.get() if not credentials or credentials.invalid: url = get_oauth2_authorize_url('gcal') return {"url": url, "is_synced": False} else: from gcal.tasks import sync_google_calendar sync_google_calendar(credentials) return {"url": None, "is_synced": True}
def sync_calender(): # check storage for credentials store = Storage('GCal', frappe.session.user) # store = Storage('GCal', "makarand") credentials = store.get() if not credentials or credentials.invalid: url = get_oauth2_authorize_url('gcal') return { "url":url, "is_synced": False } else: from gcal.tasks import sync_google_calendar sync_google_calendar(credentials) return { "url":None, "is_synced": True }
def get_credentials(code): if code: params = get_oauth_keys('gcal') params.update({ "scope": 'https://www.googleapis.com/auth/calendar', "redirect_uri": get_redirect_uri('gcal'), "params": { "approval_prompt": "force", 'access_type': 'offline', "response_type": "code" } }) flow = OAuth2WebServerFlow(**params) credentials = flow.step2_exchange(code) # Store Credentials in Keyring Storage store = Storage('GCal', frappe.session.user) store.put(credentials) # get events and create new doctype from gcal.tasks import sync_google_calendar sync_google_calendar(credentials) frappe.local.response["type"] = "redirect" frappe.local.response["location"] = "/desk#Calendar/Event"
def get_credentials(code): if code: params = get_oauth_keys('gcal') params.update({ "scope": 'https://www.googleapis.com/auth/calendar', "redirect_uri": get_redirect_uri('gcal'), "params": { "approval_prompt":"force", 'access_type': 'offline', "response_type": "code" } }) flow = OAuth2WebServerFlow(**params) credentials = flow.step2_exchange(code) # Store Credentials in Keyring Storage store = Storage('GCal', frappe.session.user) store.put(credentials) # get events and create new doctype from gcal.tasks import sync_google_calendar sync_google_calendar(credentials) frappe.local.response["type"] = "redirect" frappe.local.response["location"] = "/desk#Calendar/Event"