blob: f0de04ec9b1b8954d615900c588f1f5e1b762697 [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
Anand Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
Rushabh Mehta2886b952012-02-24 11:26:31 +053018import webnotes
19from webnotes.model.doc import Document
20
21@webnotes.whitelist()
22def get(arg=None):
23 """get todo list"""
24 return webnotes.conn.sql("""select name, owner, description, date,
25 priority, checked, reference_type, reference_name, assigned_by
Anand Doshi64ddb9f2012-06-12 19:24:12 +053026 from `tabToDo` where (owner=%s or assigned_by=%s)
Rushabh Mehta2886b952012-02-24 11:26:31 +053027 order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
Anand Doshi64ddb9f2012-06-12 19:24:12 +053028 (webnotes.session['user'], webnotes.session['user']), as_dict=1)
Rushabh Mehta2886b952012-02-24 11:26:31 +053029
30@webnotes.whitelist()
31def edit(arg=None):
Rushabh Mehta6252c132012-08-07 12:53:49 +053032 import markdown2
Rushabh Mehta2886b952012-02-24 11:26:31 +053033 args = webnotes.form_dict
34
Anand Doshifedfd892012-03-30 12:29:06 +053035 d = Document('ToDo', args.get('name') or None)
Rushabh Mehta2886b952012-02-24 11:26:31 +053036 d.description = args['description']
37 d.date = args['date']
38 d.priority = args['priority']
39 d.checked = args.get('checked', 0)
Anand Doshi64ddb9f2012-06-12 19:24:12 +053040 if not d.owner: d.owner = webnotes.session['user']
Rushabh Mehta2886b952012-02-24 11:26:31 +053041 d.save(not args.get('name') and 1 or 0)
42
43 if args.get('name') and d.checked:
44 notify_assignment(d)
45
46 return d.name
47
48@webnotes.whitelist()
49def delete(arg=None):
50 name = webnotes.form_dict['name']
Anand Doshifedfd892012-03-30 12:29:06 +053051 d = Document('ToDo', name)
Rushabh Mehta38cc3d62012-09-07 09:54:19 +053052 if d and d.name and d.owner != webnotes.session['user']:
Rushabh Mehta2886b952012-02-24 11:26:31 +053053 notify_assignment(d)
Anand Doshifedfd892012-03-30 12:29:06 +053054 webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
Rushabh Mehta2886b952012-02-24 11:26:31 +053055
56def notify_assignment(d):
57 doc_type = d.reference_type
58 doc_name = d.reference_name
59 assigned_by = d.assigned_by
60
61 if doc_type and doc_name and assigned_by:
62 from webnotes.widgets.form import assign_to
63 assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name)
64