From de8b6aadafbde05ac5a56d199c083e599068aead Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 24 Sep 2013 17:17:39 +0530 Subject: [PATCH] [minor] fixes for import conf --- portal/templates/pages/profile.py | 2 +- selling/utils/cart.py | 6 +++--- setup/doctype/backup_manager/backup_googledrive.py | 2 +- setup/doctype/email_digest/email_digest.py | 2 +- startup/boot.py | 2 +- startup/event_handlers.py | 4 ++-- support/doctype/newsletter/newsletter.py | 2 +- utilities/demo/demo_control_panel.py | 2 +- utilities/demo/make_demo.py | 6 +++++- utilities/demo/make_erpnext_demo.py | 4 ++-- 10 files changed, 18 insertions(+), 14 deletions(-) diff --git a/portal/templates/pages/profile.py b/portal/templates/pages/profile.py index 8edd830d47..3d6a86f9cc 100644 --- a/portal/templates/pages/profile.py +++ b/portal/templates/pages/profile.py @@ -33,7 +33,7 @@ def update_profile(fullname, password=None, company_name=None, mobile_no=None, p return _("Name is required") webnotes.conn.set_value("Profile", webnotes.session.user, "first_name", fullname) - webnotes.add_cookies["full_name"] = fullname + webnotes._response.set_cookie("full_name", fullname) return _("Updated") \ No newline at end of file diff --git a/selling/utils/cart.py b/selling/utils/cart.py index fc7d062d0d..92d37ea969 100644 --- a/selling/utils/cart.py +++ b/selling/utils/cart.py @@ -12,8 +12,8 @@ class WebsitePriceListMissingError(webnotes.ValidationError): pass def set_cart_count(quotation=None): if not quotation: quotation = _get_cart_quotation() - webnotes.add_cookies["cart_count"] = cstr(len(quotation.doclist.get( - {"parentfield": "quotation_details"})) or "") + cart_count = cstr(len(quotation.doclist.get({"parentfield": "quotation_details"}))) + webnotes._response.set_cookie("cart_count", cart_count) @webnotes.whitelist() def get_cart_quotation(doclist=None): @@ -47,7 +47,7 @@ def place_order(): sales_order.ignore_permissions = True sales_order.insert() sales_order.submit() - webnotes.add_cookies["cart_count"] = "" + webnotes._response.set_cookie("cart_count", "") return sales_order.doc.name diff --git a/setup/doctype/backup_manager/backup_googledrive.py b/setup/doctype/backup_manager/backup_googledrive.py index ee795186da..daf852c425 100644 --- a/setup/doctype/backup_manager/backup_googledrive.py +++ b/setup/doctype/backup_manager/backup_googledrive.py @@ -115,7 +115,7 @@ def get_gdrive_flow(): from oauth2client.client import OAuth2WebServerFlow from webnotes import conf - if not hasattr(conf, "gdrive_client_id"): + if not "gdrive_client_id" in conf: webnotes.msgprint(_("Please set Google Drive access keys in") + " conf.py", raise_exception=True) diff --git a/setup/doctype/email_digest/email_digest.py b/setup/doctype/email_digest/email_digest.py index 2a9acaa8b9..a05bae9896 100644 --- a/setup/doctype/email_digest/email_digest.py +++ b/setup/doctype/email_digest/email_digest.py @@ -458,7 +458,7 @@ def send(): now_date = now_datetime().date() from webnotes import conf - if hasattr(conf, "expires_on") and now_date > getdate(conf.expires_on): + if "expires_on" in conf and now_date > getdate(conf.expires_on): # do not send email digests to expired accounts return diff --git a/startup/boot.py b/startup/boot.py index 20887f720c..d27c0b73e3 100644 --- a/startup/boot.py +++ b/startup/boot.py @@ -34,7 +34,7 @@ def boot_session(bootinfo): # load subscription info from webnotes import conf for key in ['max_users', 'expires_on', 'max_space', 'status', 'commercial_support']: - if hasattr(conf, key): bootinfo[key] = getattr(conf, key) + if key in conf: bootinfo[key] = conf.get(key) bootinfo['docs'] += webnotes.conn.sql("""select name, default_currency, cost_center from `tabCompany`""", as_dict=1, update={"doctype":":Company"}) diff --git a/startup/event_handlers.py b/startup/event_handlers.py index a333857b1b..fc95414baf 100644 --- a/startup/event_handlers.py +++ b/startup/event_handlers.py @@ -35,13 +35,13 @@ def on_login_post_session(login_manager): set_cart_count() def on_logout(login_manager): - webnotes.add_cookies["cart_count"] = "" + webnotes._response.set_cookie("cart_count", "") def check_if_expired(): """check if account is expired. If expired, do not allow login""" from webnotes import conf # check if expires_on is specified - if not hasattr(conf, 'expires_on'): return + if not 'expires_on' in conf: return # check if expired from datetime import datetime, date diff --git a/support/doctype/newsletter/newsletter.py b/support/doctype/newsletter/newsletter.py index 13ad47a0d8..a6b5aa29e8 100644 --- a/support/doctype/newsletter/newsletter.py +++ b/support/doctype/newsletter/newsletter.py @@ -91,7 +91,7 @@ class DocType(): raise_exception=1) from webnotes import conf - if getattr(conf, "status", None) == "Trial": + if (conf.get("status") or None) == "Trial": webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \ to prevent abuse of this feature."""), raise_exception=1) diff --git a/utilities/demo/demo_control_panel.py b/utilities/demo/demo_control_panel.py index 1da690245c..3123f41e08 100644 --- a/utilities/demo/demo_control_panel.py +++ b/utilities/demo/demo_control_panel.py @@ -2,7 +2,7 @@ def on_login(self): from webnotes.utils import validate_email_add from webnotes import conf - if hasattr(conf, "demo_notify_url"): + if "demo_notify_url" in conf: if webnotes.form_dict.lead_email and validate_email_add(webnotes.form_dict.lead_email): import requests response = requests.post(conf.demo_notify_url, data={ diff --git a/utilities/demo/make_demo.py b/utilities/demo/make_demo.py index 883186791a..99bc018394 100644 --- a/utilities/demo/make_demo.py +++ b/utilities/demo/make_demo.py @@ -36,11 +36,15 @@ def make(reset=False, simulate=True): if reset: setup() + else: + webnotes.connect() + if simulate: _simulate() - + def setup(): install() + webnotes.connect() complete_setup() make_customers_suppliers_contacts() make_items() diff --git a/utilities/demo/make_erpnext_demo.py b/utilities/demo/make_erpnext_demo.py index 6426367a95..4a72e4b589 100644 --- a/utilities/demo/make_erpnext_demo.py +++ b/utilities/demo/make_erpnext_demo.py @@ -5,9 +5,9 @@ if __name__=="__main__": import webnotes, os import utilities.demo.make_demo -def make_demo_app(): +def make_demo_app(site=None): webnotes.mute_emails = 1 - webnotes.connect() + webnotes.connect(site) utilities.demo.make_demo.make(reset=True, simulate=False) # setup demo user etc so that the site it up faster, while the data loads make_demo_user()