本文整理汇总了Python中netforce.access.set_active_user函数的典型用法代码示例。如果您正苦于以下问题:Python set_active_user函数的具体用法?Python set_active_user怎么用?Python set_active_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_active_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
try:
db = get_connection()
result = self.get_argument("result")
method = self.get_argument("method", None)
cart_no = result[2:]
res = get_model("ecom.cart").search([["number", "=", cart_no]])
if not res:
raise Exception("Invalid cart number")
cart_id=res[0]
cart=get_model("ecom.cart").browse(cart_id)
if method:
cart.update_paysbuy_method(method)
db = database.get_connection()
db.commit()
if result.startswith("00") and not cart.is_paid:
set_active_user(1)
set_active_company(1)
cart.import_paysbuy_payment() # Inquiry Doublecheck
db.commit()
except Exception as e:
db = get_connection()
db.rollback
import traceback
audit_log("Failed to get result payment from paysbuy", details=traceback.format_exc())
traceback.print_exc()
示例2: default_get
def default_get(self, field_names=None, context=None, **kw):
user_id = get_active_user()
set_active_user(1)
user = get_model("base.user").browse(user_id)
vals = {"name": user.name, "password": user.password, "email": user.email, "mobile": user.mobile}
set_active_user(user_id)
return vals
示例3: post
def post(self):
print("POST ARGUMENT >>>>>>>>>>>>>>>>>>>")
print(self.request.body)
f = open("paypal_return", "a")
s = "################################################################################################################" + \
"\n"
s += "Date : " + time.strftime("%Y-%m-%d %H:%M:%S") + "\n"
s += "Request : " + str(self.request) + "\n"
if self.request.body:
s += "Body : " + str(self.request.body) + "\n"
s += "################################################################################################################" + \
"\n"
f.write(s)
f.close()
cart_id = int(self.get_argument("cart_id"))
token = self.get_argument("token", None)
payer_id = self.get_argument("PayerID", None)
cart = get_model("ecom.cart").browse(cart_id)
if not cart.is_paid:
access.set_active_user(1)
access.set_active_company(1)
cart.import_paypal_payment(token, context={})
db = database.get_connection()
db.commit()
self.redirect("/ecom_order_confirmed?cart_id=%s" % cart_id)
示例4: create
def create(self, vals, **kw):
uid = access.get_active_user()
try:
access.set_active_user(1)
return super().create(vals, **kw)
finally:
access.set_active_user(uid)
示例5: send_email
def send_email(self, ids, context={}):
uid = access.get_active_user()
try:
access.set_active_user(1)
obj = self.browse(ids[0])
# XXX "=" should be changed to "=ilike" later
res = get_model("base.user").search((["email", "=ilike", obj.email.strip()]))
if not res:
raise Exception("User with given email doesn't exist in database")
request = context["request"]
msg = "Somebody requested change of your Netforce password.\n\n"
msg += "If you didn't do it, please ignore this message.\n\n"
msg += "Otherwise if you want to reset your password click on the link below:\n\n"
msg += "http://%s/ui#name=change_passwd&key=%s\n\n\n" % (request.host, obj.key)
msg += "Regards,\n"
msg += "Netforce Team"
vals = {
"type": "out",
"from_addr": "[email protected]",
"to_addrs": obj.email,
"subject": "Netforce reset password request",
"body": msg,
"state": "to_send",
}
get_model("email.message").create(vals)
return {
"next": {
"name": "forgot_passwd_done"
}
}
finally:
access.set_active_user(uid)
示例6: remove_expired_lots
def remove_expired_lots(self, context={}):
print("StockLot.remove_expired_lots")
access.set_active_user(1)
access.set_active_company(1)
settings = get_model("settings").browse(1)
if not settings.lot_expiry_journal_id:
raise Exception("Missing lot expiry journal")
journal = settings.lot_expiry_journal_id
if not journal.location_to_id:
raise Exception("Missing to location in lot expiry journal")
t = time.strftime("%Y-%m-%d")
pick_vals = {"type": "out", "journal_id": journal.id, "lines": []}
n = 0
for obj in self.search_browse([["expiry_date", "<", t]]):
prod = obj.product_id
if not prod:
continue
for bal in obj.stock_balances:
if bal.qty_phys <= 0:
continue
line_vals = {
"product_id": prod.id,
"location_from_id": bal.location_id.id,
"location_to_id": journal.location_to_id.id,
"lot_id": obj.id,
"qty": bal.qty_phys,
"uom_id": prod.uom_id.id,
}
pick_vals["lines"].append(("create", line_vals))
n += 1
if pick_vals["lines"]:
pick_id = get_model("stock.picking").create(pick_vals, context={"pick_type": "out"})
get_model("stock.picking").set_done([pick_id])
get_model("stock.picking").trigger([pick_id], "lot_expired")
return {"flash": "%d lots removed from stock" % n}
示例7: post
def post(self):
try:
db = get_connection()
print("########################################")
print("###########Result Paypal Ipn############")
print("########################################")
payment_status = self.get_argument("payment_status", None)
if payment_status != "Completed":
raise Exception("Paypal transaction is not completed")
invoice = self.get_argument("invoice")
set_active_user(1)
set_active_company(1)
res = get_model("ecom.cart").search([["number", "=", invoice]])
if not res:
raise Exception("Invalid cart number: %s"%invoice)
cart_id = res[0]
cart=get_model("ecom.cart").browse(cart_id)
website=cart.website_id
receiver_email = self.get_argument("receiver_email", None)
if receiver_email != website.paypal_user:
raise Exception("Wrong paypal receiver email")
if not website.paypal_user:
raise Exception("Missing paypal user in cms setting")
if not website.paypal_password:
raise Exception("Missing paypal password in cms setting")
if not website.paypal_signature:
raise Exception("Missing paypal signature in cms setting")
if not website.paypal_url:
raise Exception("Missing paypal URL Server in cms setting")
params = {}
for argument in self.request.arguments:
params[argument] = argument[0].decode('utf-8')
params['cmd'] = '_notify-validate'
if website.paypal_url == "test":
url = "https://www.sandbox.paypal.com/cgi-bin/webscr"
else:
url = "https://www.paypal.com/cgi-bin/webscr"
data = urllib.parse.urlencode(params)
data = data.encode('utf-8')
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
word = response.read()
verify = word.decode('utf-8')
if verify != "VERIFIED":
raise Exception("Failed to verify payment")
mc_gross = float(self.get_argument("mc_gross", None))
if cart.amount_total != mc_gross:
raise Exception("Amount total doesn't match")
cart.import_paypal_payment() # TODO Add Token
print("Payment Created")
db.commit()
except Exception as e:
db = get_connection()
db.rollback
import traceback
audit_log("Failed to get IPN from paypal", details=traceback.format_exc())
traceback.print_exc()
示例8: get
def get(self):
self.get_argument("token") # TODO: check token
dbname=database.get_active_db()
db=database.get_connection()
try:
db.begin()
set_active_user(None)
user_id=1
user=get_model("base.user").browse(user_id)
t=time.strftime("%Y-%m-%d %H:%M:%S")
user.write({"lastlog":t})
comp=get_model("company").browse(1)
set_active_user(user_id)
audit_log("Login token")
url="http://nf1.netforce.com/update_lastlogin?dbname=%s"%dbname
req=urllib.request.Request(url)
try:
urllib.request.urlopen(req).read()
except:
print("ERROR: failed to update last login time")
token=new_token(dbname,user_id)
self.set_cookie("dbname",dbname)
self.set_cookie("user_id",str(user_id))
self.set_cookie("token",token)
self.set_cookie("user_name",quote(user.name)) # XXX: space
self.set_cookie("company_name",quote(comp.name))
self.set_cookie("package",comp.package)
self.redirect("http://%s.my.netforce.com/action#name=account_board"%dbname.replace("_","-"))
db.commit()
except:
db.rollback()
示例9: post
def post(self):
#try:
with database.Transaction():
#db = get_connection()
print("########################################")
print("#######Result Payment Online SCB########")
print("############# POST ##############")
print("########################################")
f = open("scblog", "a")
s = "################################################################################################################" + \
"\n"
s += "Date : " + time.strftime("%Y-%m-%d %H:%M:%S") + "\n"
s += "Request : " + str(self.request) + "\n"
if self.request.body:
s += "Body : " + str(self.request.body) + "\n"
s += "################################################################################################################" + \
"\n"
f.write(s)
f.close()
if self.request.arguments:
website = get_model("website").browse(1)
if not website.scb_mid:
raise Exception("no merchant id in website settings")
if not website.scb_terminal:
raise Exception("no terminal id in website settings")
if not website.scb_url:
raise Exception("no URL server in website settings")
mid = self.get_argument("mid", None)
print(mid)
if mid != website.scb_mid:
raise Exception("Merchant id does not match")
terminal = self.get_argument("terminal", None)
print(terminal)
if terminal != website.scb_terminal:
raise Exception("Terminal id does not match")
command = self.get_argument("command", None)
print(command)
if command != 'CRAUTH':
raise Exception("Command does not match")
payment_status = self.get_argument("payment_status", None)
print(payment_status)
if payment_status == '003':
raise Exception("Payment host reject")
if payment_status == '006':
raise Exception("Payment error")
ref_no = self.get_argument("ref_no", None)
print(ref_no)
if payment_status == '002':
set_active_user(1)
set_active_company(1)
res = get_model("sale.order").search_browse([["number", "=", ref_no]])
if res: # XXX Inquiry double check
sale = res[0]
if not sale.is_paid:
sale.import_scb_payment()
示例10: delete
def delete(self, ids, **kw):
prod_ids = []
for obj in self.browse(ids):
prod_ids.append(obj.product_id.id)
super().delete(ids, **kw)
user_id = get_active_user()
set_active_user(1)
get_model("product").write(prod_ids, {"update_balance": True})
set_active_user(user_id)
示例11: migrate
def migrate(self):
user_id=get_active_user()
set_active_user(1)
for leave in get_model("hr.leave").search_browse([]):
if leave.time_from and leave.time_to:
leave.write({
'start_date': '%s %s:00'%(leave.start_date[0:10],leave.time_from.replace(".",":")),
'end_date': '%s %s:00'%(leave.end_date[0:10],leave.time_to.replace(".",":")),
})
set_active_user(user_id)
示例12: migrate
def migrate(self):
set_active_user(1)
for user in get_model("base.user").search_browse([]):
res=get_model("limit.inspect").search([['user_id','=',user.id]])
if not res:
insp_ids=get_model("inspection").search([['user_id','=',user.id]])
get_model("limit.inspect").create({
'user_id': user.id,
'record_count': len(insp_ids),
})
示例13: save_changes
def save_changes(self, ids, context={}):
obj = self.browse(ids)[0]
check_password(obj.password)
vals = {"name": obj.name, "password": obj.password, "email": obj.email, "mobile": obj.mobile}
user_id = get_active_user()
set_active_user(1)
get_model("base.user").write([user_id], vals)
obj.write({"password": ""})
set_active_user(user_id)
return {"next": "_close"}
示例14: auto_create_purchase_orders
def auto_create_purchase_orders(self,context={}):
access.set_active_user(1)
access.set_active_company(1) # XXX
vals={
"confirm_orders": True,
}
obj_id=self.create(vals)
self.delete_planned_orders([obj_id])
self.fill_products([obj_id])
self.create_po([obj_id])
示例15: migrate
def migrate(self):
user_id = get_active_user()
set_active_user(1)
for payslip in get_model("hr.payslip").search_browse([]):
if not payslip.state:
payslip.write({"state": "draft"})
for payrun in get_model("hr.payrun").search_browse([]):
if not payrun.state:
payrun.write({"state": "draft"})
set_active_user(user_id)