def filter(args): wf = workflow() prefs = Preferences.current_prefs() command = args[1] if len(args) > 1 else None duration_info = _duration_info(prefs.completed_duration) if command == 'duration': selected_duration = prefs.completed_duration # Apply selected duration option if len(args) > 2: try: selected_duration = int(args[2]) except: pass duration_info = _duration_info(selected_duration) if 'custom' in duration_info: wf.add_item(duration_info['label'], duration_info['subtitle'], arg='-completed duration %d' % (duration_info['days']), valid=True, icon=icons.RADIO_SELECTED if duration_info['days'] == selected_duration else icons.RADIO) for duration_info in _durations: wf.add_item(duration_info['label'], duration_info['subtitle'], arg='-completed duration %d' % (duration_info['days']), valid=True, icon=icons.RADIO_SELECTED if duration_info['days'] == selected_duration else icons.RADIO) wf.add_item('Back', autocomplete='-completed ', icon=icons.BACK) return # Force a sync if not done recently or join if already running if not prefs.last_sync or \ datetime.utcnow() - prefs.last_sync > timedelta(seconds=30) or \ is_running('sync'): sync() wf.add_item(duration_info['label'], subtitle='Change the duration for completed tasks', autocomplete='-completed duration ', icon=icons.YESTERDAY) conditions = True # Build task title query based on the args for arg in args[1:]: if len(arg) > 1: conditions = conditions & (Task.title.contains(arg) | TaskFolder.title.contains(arg)) if conditions is None: conditions = True tasks = Task.select().join(TaskFolder).where( (Task.completedDateTime > date.today() - timedelta(days=duration_info['days'])) & Task.list.is_null(False) & conditions )\ .order_by(Task.completedDateTime.desc(), Task.reminderDateTime.asc(), Task.changeKey.asc()) try: for t in tasks: wf.add_item(u'%s – %s' % (t.list_title, t.title), t.subtitle(), autocomplete='-task %s ' % t.id, icon=icons.TASK_COMPLETED if t.status == 'completed' else icons.TASK) except OperationalError: background_sync() wf.add_item('Main menu', autocomplete='', icon=icons.BACK) # Make sure tasks stay up-to-date background_sync_if_necessary(seconds=2)
def filter(args): wf = workflow() prefs = Preferences.current_prefs() command = args[1] if len(args) > 1 else None # Show sort options if command == 'sort': for i, order_info in enumerate(_due_orders): wf.add_item(order_info['title'], order_info['subtitle'], arg='-due sort %d' % (i + 1), valid=True, icon=icons.RADIO_SELECTED if order_info['due_order'] == prefs.due_order else icons.RADIO) wf.add_item( 'Highlight skipped recurring tasks', 'Hoists recurring tasks that have been missed multiple times over to the top', arg='-due sort toggle-skipped', valid=True, icon=icons.CHECKBOX_SELECTED if prefs.hoist_skipped_tasks else icons.CHECKBOX) wf.add_item('Back', autocomplete='-due ', icon=icons.BACK) return # Force a sync if not done recently or wait on the current sync if not prefs.last_sync or \ datetime.utcnow() - prefs.last_sync > timedelta(seconds=30) or \ is_running('sync'): sync() conditions = True # Build task title query based on the args for arg in args[1:]: if len(arg) > 1: conditions = conditions & (Task.title.contains(arg) | TaskFolder.title.contains(arg)) if conditions is None: conditions = True tasks = Task.select().join(TaskFolder).where( (Task.status != 'completed') & (Task.dueDateTime < datetime.now() + timedelta(days=1)) & Task.list_id.is_null(False) & conditions) # Sort the tasks according to user preference for key in prefs.due_order: order = 'asc' field = None if key[0] == '-': order = 'desc' key = key[1:] if key == 'due_date': field = Task.dueDateTime elif key == 'taskfolder.id': field = TaskFolder.id elif key == 'order': field = Task.lastModifiedDateTime if field: if order == 'asc': tasks = tasks.order_by(field.asc()) else: tasks = tasks.order_by(field.desc()) try: if prefs.hoist_skipped_tasks: log.debug('hoisting skipped tasks') tasks = sorted(tasks, key=lambda t: -t.overdue_times) for t in tasks: wf.add_item(u'%s – %s' % (t.list_title, t.title), t.subtitle(), autocomplete='-task %s ' % t.id, icon=icons.TASK_COMPLETED if t.status == 'completed' else icons.TASK) except OperationalError: background_sync() wf.add_item(u'Sort order', 'Change the display order of due tasks', autocomplete='-due sort', icon=icons.SORT) wf.add_item('Main menu', autocomplete='', icon=icons.BACK) # Make sure tasks stay up-to-date background_sync_if_necessary(seconds=2)
def commit(args, modifier=None): prefs = Preferences.current_prefs() relaunch_command = '-pref' if '--alfred' in args: relaunch_command = ' '.join(args[args.index('--alfred') + 1:]) if 'sync' in args: from mstodo.sync import sync sync('background' in args) relaunch_command = None elif 'show_completed_tasks' in args: prefs.show_completed_tasks = not prefs.show_completed_tasks if prefs.show_completed_tasks: print('Completed tasks are now visible in the workflow') else: print('Completed tasks will not be visible in the workflow') elif 'default_folder' in args: default_taskfolder_id = None taskfolders = workflow().stored_data('taskfolders') if len(args) > 2: default_taskfolder_id = args[2] prefs.default_taskfolder_id = default_taskfolder_id if default_taskfolder_id: default_folder_name = next( (f['title'] for f in taskfolders if f['id'] == default_taskfolder_id), 'most recent') print('Tasks will be added to your %s folder by default' % default_folder_name) else: print('Tasks will be added to the Tasks folder by default') elif 'explicit_keywords' in args: prefs.explicit_keywords = not prefs.explicit_keywords if prefs.explicit_keywords: print('Remember to use the "due" keyword') else: print('Implicit due dates enabled (e.g. "Recycling tomorrow")') elif 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: prefs.reminder_time = reminder_time print('Reminders will now default to %s' % format_time(reminder_time, 'short')) elif 'reminder_today' in args: reminder_today_offset = None if not 'disabled' in args: reminder_today_offset = _parse_time(' '.join(args)) prefs.reminder_today_offset = reminder_today_offset print('The offset for current-day reminders is now %s' % _format_time_offset(reminder_today_offset)) elif 'automatic_reminders' in args: prefs.automatic_reminders = not prefs.automatic_reminders if prefs.automatic_reminders: print('A reminder will automatically be set for due tasks') else: print('A reminder will not be added automatically') elif 'retheme' in args: prefs.icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark' print('The workflow is now using the %s icon theme' % (prefs.icon_theme)) elif 'prerelease_channel' in args: prefs.prerelease_channel = not prefs.prerelease_channel # Update the workflow settings and reverify the update data workflow().check_update(True) if prefs.prerelease_channel: print( 'The workflow will prompt you to update to experimental pre-releases' ) else: print( 'The workflow will only prompt you to update to final releases' ) elif 'force_en_US' in args: if prefs.date_locale: prefs.date_locale = None print( 'The workflow will expect your local language and date format') else: prefs.date_locale = 'en_US' print('The workflow will expect dates in US English') if relaunch_command: relaunch_alfred('td%s' % relaunch_command)