def save_todo_list(self, todos): tags = defaultdict(list) export_content = [] for i in todos: tags[i['group']].append( {'title': i['title'], 'created': i['created'], 'due': itemlist.feature(i, 'due'), 'done': itemlist.feature(i, 'done'), 'smartcontent_type': itemlist.feature(i, 'smartcontent_type'), 'smartcontent_info': itemlist.feature(i, 'smartcontent_info'), 'pinned': itemlist.feature(i, 'pinned') } ) for tag in tags: # Project export_content.append(tag + ':') for todo in tags[tag]: todo_text = self.get_item_from_todo(todo) # print todo export_content.append('\t'+todo_text) with codecs.open(self.store, "w", "utf-8") as f: for item in export_content: f.write(item + u'\n') self.refresh()
def generate_view(query): if len(query) == 0 and config.get('todo.command.last') == 'quick_create': add_query = config.get('todo.user.query') add_tag = config.get('todo.tag.recent') itemlist.save_todo(add_query,silent=True) config.update_state(command='', query='') info = parser.parse(query) tag = info['tag'] q = info['task'] todos = itemlist.get_todo_list() # view for pinned items # pinned items should have unique uuid and different logo pinned = [t for t in todos if itemlist.feature(t,'pinned') == True] pinned = [t for t in pinned if (tag is None or t['group'] == tag)] pinned = [t for t in pinned if (q is None or t['title'].lower().find(q.lower()) >= 0)] pinned = pinned[::-1] # view for non-pinned items normal = [t for t in todos if itemlist.feature(t,'pinned') == False] normal = [t for t in normal if (tag is None or t['group'] == tag)] normal = [t for t in normal if (q is None or t['title'].lower().find(q.lower()) >= 0)] normal = normal[::-1] feedback_items = [] if len(normal) == 0 and len(pinned) == 0: feedback_items.append( generate_add_feedbackitem(query, info) ) else: pinned = map(lambda x: generate_pinned_feedbackitem(x), pinned) normal = map(lambda x: generate_todo_feedbackitem(x), normal) feedback_items = pinned + normal alfred.write(alfred.xml(feedback_items))
def create_title(t): if smartcontent.smartcontent_enabled(): smartcontent_type = itemlist.feature(t, "smartcontent_type") smartcontent_info = itemlist.feature(t, "smartcontent_info") if len(smartcontent_type) > 0: if smartcontent_type == "File" or smartcontent_type == "Directory": return smartcontent_info elif smartcontent_type == "Application": return smartcontent_info.replace(".app", "") elif smartcontent_type == "Web": if len(smartcontent_info) > 0: return smartcontent_info return t["title"]
def get_tags(self): todos = self.get_todo_list() tags = defaultdict(int) for i in todos: if not itemlist.feature(i, "done"): tags[i["group"]] = tags[i["group"]] + 1 return tags
def export_txt(_tag=None): todos = itemlist.get_todo_list() tags = defaultdict(list) for i in todos: tags[i['group']].append({ 'title': i['title'], 'created': i['created'], 'pinned': itemlist.feature(i, 'pinned'), 'rating': itemlist.feature(i, 'rating') }) for tag in tags: if _tag is None or tag == _tag: print '#' + tag pinned = [t for t in tags[tag] if t['pinned']] normal = [t for t in tags[tag] if not t['pinned']] for todo in pinned: print todo['title'] + ' [pinned]' for todo in normal: print todo['title'] print " "
def get_item_from_todo(self, todo): todo_text = '- ' + todo['title'] if itemlist.feature(todo,'due') is not None: todo_text = todo_text + " @due(" + str(todo['due']) + ")" smartcontent_type = itemlist.feature(todo,'smartcontent_type') if smartcontent_type and len(smartcontent_type) > 0: smartcontent_info = itemlist.feature(todo,'smartcontent_info') smartcontent_type_actions = { 'Web': lambda x: x + " @web(" + smartcontent_info + ")", 'File': lambda x: x + " @file(" + smartcontent_info + ")", 'Folder': lambda x: x + " @folder(" + smartcontent_info + ")", 'Application': lambda x: x + " @app(" + smartcontent_info + ")" } todo_text = smartcontent_type_actions[smartcontent_type](todo_text) if itemlist.feature(todo,'pinned') == True: todo_text = todo_text + " @pinned" if itemlist.feature(todo,'done') == True: todo_text = todo_text + " @done" return todo_text
def apply_filter(todo, q_task, q_tag, q_due, q_done=False): # Narrow down todo list based on what was typed # The following filters are applied, not in the same order # 1. filter by tag if specified # 2. filter by query text if applicable (@ is a special keyword) # 3. filter by done status # 4. filter by due date if its specified # 5. filter by @ for all due items # thank god for short circuiting of boolean clauses :-) todo_is_not_done = itemlist.feature(todo, "done") == q_done todo_has_due_if_needed = q_task != "@" or has_due(todo) todo_matches_due_specified = q_due is None or q_due == itemlist.feature(todo, "due") todo_matches_tag_specified = q_tag is None or todo["group"].lower() == q_tag.lower() todo_matches_task_specified = apply_filter_task(todo, q_task) return ( todo_is_not_done and todo_has_due_if_needed and todo_matches_due_specified and todo_matches_tag_specified and todo_matches_task_specified )
def create_icon(t): pinned = itemlist.feature(t, "pinned") if pinned: return "todo_pin.png" due = itemlist.feature(t, "due") if due and due <= date.today(): return "todo_old.png" if smartcontent.smartcontent_enabled(): smartcontent_type = itemlist.feature(t, "smartcontent_type") icon_types = { "Web": "todo_web.png", "File": "todo_file.png", "Directory": "todo_folder.png", "Application": "todo_app.png", } if smartcontent_type in icon_types: return icon_types[smartcontent_type] return "icon.png"
def export_txt(_tag=None): todos = itemlist.get_todo_list() tags = defaultdict(list) for i in todos: tags[i['group']].append( { 'title' : i['title'], 'created': i['created'], 'pinned' : itemlist.feature(i,'pinned'), 'rating' : itemlist.feature(i,'rating') } ) for tag in tags: if _tag is None or tag==_tag: print '#' + tag pinned = [t for t in tags[tag] if t['pinned']] normal = [t for t in tags[tag] if not t['pinned']] for todo in pinned: print todo['title'] + ' [pinned]' for todo in normal: print todo['title'] print " "
def main(): # export_csv.py input output # input todo file input_file = sys.argv[1] # target csv file export_file = sys.argv[2] if not os.path.exists(input_file): return todos = store.Store().get_store(input_file).get_todo_list() csv_data = [] pinned = [t for t in todos if itemlist.feature(t,'pinned')==True and not itemlist.feature(t,'done')==True] due = [t for t in todos if itemlist.feature(t,'pinned')==False and itemlist.feature(t,'due') is not None and not itemlist.feature(t,'done')==True] others = [t for t in todos if itemlist.feature(t,'pinned')==False and itemlist.feature(t,'due') is None and not itemlist.feature(t,'done')==True] for t in pinned: csv_data.append(get_task_line(t)) for t in due: csv_data.append(get_task_line(t)) for t in others: csv_data.append(get_task_line(t)) if len(csv_data) > 0: with codecs.open(export_file, "w", "utf-8") as f: f.write("\n".join(csv_data))
def create_subtitle(t): # option 1 - simple and clean subtitle = "" if itemlist.feature(t, "due"): subtitle = due_date_text(t["due"]) if t["group"] != "default": subtitle = subtitle + " #" + t["group"] if smartcontent.smartcontent_enabled(): smartcontent_type = itemlist.feature(t, "smartcontent_type") smartcontent_info = itemlist.feature(t, "smartcontent_info") if len(smartcontent_type) > 0: subtitle = subtitle + " " + t["title"] # if smartcontent_type == "Web": # if len(smartcontent_info) > 0: # subtitle = subtitle + " Web: " + t["title"] # else: # subtitle = subtitle + " Web" # else: # subtitle = subtitle + " " + smartcontent_type + ": " + t['title'] return subtitle.strip()
def update_todo(_id, query): info = parser.parse(query) todo = itemlist.get_todo(_id) done = itemlist.feature(todo, 'done') edit_tag = info['tag'] edit_text = info['task'] edit_due = info['due'] edit_clear_due = info['clear_due'] todo_tag = todo['group'] todo_text = todo['title'] todo_due = itemlist.feature(todo, 'due') tag_changed = edit_tag and edit_tag != todo_tag task_changed = len(edit_text) > 0 and edit_text != todo_text due_changed = edit_due and edit_due != todo_due title = todo['title'] tag = todo['group'] update_info = {} if (task_changed): update_info['title'] = edit_text title = edit_text if (tag_changed): update_info['group'] = edit_tag tag = edit_tag if (due_changed): update_info['due'] = edit_due if edit_clear_due: update_info['due'] = None itemlist.update_todo(_id, update_info) config.put(ck.KEY_EDIT_ACTION, 'edit_done' if done else 'edit_todo') if tag != 'default': print ("Updated '" + title + "' tagged #" + tag).encode('utf-8') else: print ("Updated '" + title + "'").encode('utf-8')
def export_txt(_tag=None): todos = itemlist.get_todo_list() tags = defaultdict(list) for i in todos: if not itemlist.feature(i, 'done'): tags[i['group']].append( { 'title': i['title'], 'created': i['created'], 'pinned': itemlist.feature(i, 'pinned'), 'due': itemlist.feature(i, 'due') } ) sorted_tags = sorted(tags, key=lambda x: x) for tag in sorted_tags: if _tag is None or tag == _tag: print u'#' + tag.encode('utf-8') pinned = [t for t in tags[tag] if t['pinned']] normal = [t for t in tags[tag] if not t['pinned']] for todo in pinned: print get_todo_text(todo) for todo in normal: print get_todo_text(todo) print " "
def get_task_line(t): # CSV format # important, task, due + tag important = "important" if itemlist.feature(t,'pinned') else "" due = str(itemlist.feature(t,'due')) if itemlist.feature(t,'due') is not None else "" task = itemlist.feature(t,'title') tag = ("#" + itemlist.feature(t,'group')) if itemlist.feature(t,'group')!='default' else "" task_line = [important, task, due + " " + tag] task_line = u",".join(task_line) return task_line
def generate_view_itemedit(_id, query): todo = itemlist.get_todo(_id) if not todo: generate_select_item() return todo_tag = todo['group'] todo_text = todo['title'] todo_due = itemlist.feature(todo, 'due') info = parser.parse(query) edit_tag = info['tag'] edit_text = info['task'] edit_due = info['due'] edit_clear_due = info['clear_due'] # TODO: Change this later so that parse will handle this clear_due = False if edit_clear_due and todo_due is not None: clear_due = True edit_text = edit_text.replace('@!', '').strip() feedback_items = [] tag_changed = edit_tag and edit_tag != todo_tag task_changed = len(edit_text) > 0 and edit_text != todo_text due_changed = edit_due and edit_due != todo_due nothing_to_update = not task_changed and not tag_changed and not due_changed and not clear_due changed_items = [] if (task_changed): changed_items.append('text') if (tag_changed): changed_items.append('tag') if (due_changed or clear_due): changed_items.append('due') pinned = itemlist.feature(todo, 'pinned') done = itemlist.feature(todo, 'done') # integration items integration.apply_integration(feedback_items, todo, query) # action item feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': query + " ", 'valid': 'no' if nothing_to_update else 'yes' }, title="No change" if nothing_to_update else "Change " + ", ".join(changed_items), subtitle="", icon="todo_edit.png" )) # info item - task title # if a edit tag is specified, append that and add todo text text_autocomplete = "".join([ "" if not edit_tag else "#"+edit_tag+' ', todo_text ]).strip() if len(text_autocomplete) == 2: text_autocomplete = text_autocomplete + " " feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no', 'autocomplete': text_autocomplete }, title=todo_text, subtitle=u"Change to: {0}".format(edit_text) if task_changed else "No change", icon="todo_done.png" if done else ("todo_pin.png" if pinned else "icon.png") )) # info item - tag name formatted_query = query if edit_tag: formatted_query = formatted_query.replace("#"+edit_tag, "") tag_autocomplete = "".join([ "#" + todo_tag + " ", formatted_query.strip() ]).strip() if len(tag_autocomplete) == 2: tag_autocomplete = tag_autocomplete + " " feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no', 'autocomplete': tag_autocomplete }, title="#" + todo_tag, subtitle=u"Change to: #{0}".format(edit_tag) if tag_changed else "No change", icon="todo_tag.png" )) # due item subtitle = "No change" if todo_due is not None: subtitle = subtitle + " (@! will clear)" if due_changed: subtitle = u"Change to: {0}".format(helpers.due_date_text(edit_due)) if clear_due: subtitle = "Clear due" feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no' }, title=helpers.due_date_text(todo_due) if todo_due else "No due date", subtitle=subtitle, icon="todo_due.png" )) # in which list is this item feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no' }, title='List: ' + listmanager.friendly_file(listmanager.active_list()), subtitle="", icon="icon.png" )) alfred.write(alfred.xml(feedback_items))
def has_due(todo): return itemlist.feature(todo, "due") is not None