blob: 05c695d24831b7c4128f4f3fa33710750dbba908 [file] [log] [blame]
Rushabh Mehtaaaf86ba2012-02-28 17:40:13 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Rushabh Mehta2886b952012-02-24 11:26:31 +053017import webnotes
18from webnotes.model.doc import Document
19
20@webnotes.whitelist()
21def get(arg=None):
22 """get todo list"""
23 return webnotes.conn.sql("""select name, owner, description, date,
24 priority, checked, reference_type, reference_name, assigned_by
Anand Doshi64ddb9f2012-06-12 19:24:12 +053025 from `tabToDo` where (owner=%s or assigned_by=%s)
Rushabh Mehta2886b952012-02-24 11:26:31 +053026 order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
Anand Doshi64ddb9f2012-06-12 19:24:12 +053027 (webnotes.session['user'], webnotes.session['user']), as_dict=1)
Rushabh Mehta2886b952012-02-24 11:26:31 +053028
29@webnotes.whitelist()
30def edit(arg=None):
Rushabh Mehta6252c132012-08-07 12:53:49 +053031 import markdown2
Rushabh Mehta2886b952012-02-24 11:26:31 +053032 args = webnotes.form_dict
33
Anand Doshifedfd892012-03-30 12:29:06 +053034 d = Document('ToDo', args.get('name') or None)
Rushabh Mehta2886b952012-02-24 11:26:31 +053035 d.description = args['description']
36 d.date = args['date']
37 d.priority = args['priority']
38 d.checked = args.get('checked', 0)
Anand Doshi64ddb9f2012-06-12 19:24:12 +053039 if not d.owner: d.owner = webnotes.session['user']
Rushabh Mehta2886b952012-02-24 11:26:31 +053040 d.save(not args.get('name') and 1 or 0)
41
42 if args.get('name') and d.checked:
43 notify_assignment(d)
44
45 return d.name
46
47@webnotes.whitelist()
48def delete(arg=None):
49 name = webnotes.form_dict['name']
Anand Doshifedfd892012-03-30 12:29:06 +053050 d = Document('ToDo', name)
Rushabh Mehta2886b952012-02-24 11:26:31 +053051 if d and d.name:
52 notify_assignment(d)
Anand Doshifedfd892012-03-30 12:29:06 +053053 webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
Rushabh Mehta2886b952012-02-24 11:26:31 +053054
55def notify_assignment(d):
56 doc_type = d.reference_type
57 doc_name = d.reference_name
58 assigned_by = d.assigned_by
59
60 if doc_type and doc_name and assigned_by:
61 from webnotes.widgets.form import assign_to
62 assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name)
63