blob: e3e7fa95d572880ecf015500da2784995f91d4a4 [file] [log] [blame]
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05301import webnotes
Anand Doshi90f6e552012-01-16 14:13:39 +05302import webnotes.defs
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05303from webnotes.utils import cint
Rushabh Mehta63d669f2012-02-03 12:56:12 +05304import home
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05305
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05306def on_login(login_manager):
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +05307 """
8 called from login manager, before login
9 """
Rushabh Mehta63d669f2012-02-03 12:56:12 +053010 if login_manager.user not in ('Guest', None, ''):
11 try:
Rushabh Mehta88ba7b82012-01-18 06:18:52 +010012 import server_tools.gateway_utils
13 server_tools.gateway_utils.check_login(login_manager.user)
Rushabh Mehta63d669f2012-02-03 12:56:12 +053014 except ImportError:
15 pass
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053016
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053017def on_login_post_session(login_manager):
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053018 """
19 called after login
20 update login_from and delete parallel sessions
21 """
Anand Doshib63a0072012-01-03 16:11:04 +053022 # Clear previous sessions i.e. logout previous log-in attempts
Rushabh Mehtad31bf622012-01-19 15:09:49 +053023 exception_list = ['demo@webnotestech.com', 'Administrator', 'Guest']
Anand Doshi9fdee382012-01-03 11:26:00 +053024 if webnotes.session['user'] not in exception_list:
Anand Doshib63a0072012-01-03 16:11:04 +053025 sid_list = webnotes.conn.sql("""
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053026 DELETE FROM `tabSessions`
Anand Doshib63a0072012-01-03 16:11:04 +053027 WHERE
28 user=%s AND
Rushabh Mehtabedc1fe2012-01-17 18:17:06 +053029 sid!=%s""", \
Anand Doshib63a0072012-01-03 16:11:04 +053030 (webnotes.session['user'], webnotes.session['sid']), as_list=1)
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053031
Rushabh Mehta63d669f2012-02-03 12:56:12 +053032 if webnotes.session['user'] not in ('Guest'):
33 # create feed
34 from webnotes.utils import nowtime
35 home.make_feed('Login', 'Profile', login_manager.user, login_manager.user,
36 '%s logged in at %s' % (login_manager.user_fullname, nowtime()),
37 login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D')
38
39def comment_added(doc):
40 """add comment to feed"""
41 import json
42 home.make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
43 '<i>"' + doc.comment + '"</i>', '#6B24B3')
44
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053045def doclist_all(doc, method):
46 """doclist trigger called from webnotes.model.doclist on any event"""
Rushabh Mehta865c00a2012-01-24 14:33:21 +053047 home.update_feed(doc, method)
48
49def boot_session(bootinfo):
50 """boot session - send website info if guest"""
51 import webnotes
52 import webnotes.model.doc
53
54 if webnotes.session['user']=='Guest':
Rushabh Mehta7018b192012-02-02 13:42:28 +053055 bootinfo['website_settings'] = webnotes.model.doc.getsingle('Website Settings')
56 bootinfo['website_menus'] = webnotes.conn.sql("""select label, std_page, custom_page,
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053057 parent_label, parentfield
Rushabh Mehta7018b192012-02-02 13:42:28 +053058 from `tabTop Bar Item` where parent='Website Settings' order by idx asc""", as_dict=1)
59 bootinfo['custom_css'] = webnotes.conn.get_value('Style Settings', None, 'custom_css') or ''
Rushabh Mehta865c00a2012-01-24 14:33:21 +053060 else:
61 bootinfo['letter_heads'] = get_letter_heads()
62
63def get_letter_heads():
64 """load letter heads with startup"""
65 import webnotes
Rushabh Mehta63d669f2012-02-03 12:56:12 +053066 ret = webnotes.conn.sql("""select name, content from `tabLetter Head`
67 where ifnull(disabled,0)=0""")
Rushabh Mehta4b1fe052012-01-25 15:06:28 +053068 return dict(ret)