Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing fuzzy NOW date #612

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
491 changes: 249 additions & 242 deletions GTG/core/dates.py

Large diffs are not rendered by default.

37 changes: 11 additions & 26 deletions GTG/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import xml.sax.saxutils as saxutils

from gettext import gettext as _
from GTG.core.dates import Date, convert_datetime_to_date
from GTG.core.tag import extract_tags_from_text
from GTG.core.dates import Date
from liblarch import TreeNode

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -61,7 +60,7 @@ def __init__(self, task_id, requester, newtask=False):

self.added_date = Date.no_date()
if newtask:
self.added_date = datetime.now()
self.added_date = Date(datetime.now())

self.closed_date = Date.no_date()
self.due_date = Date.no_date()
Expand All @@ -87,19 +86,8 @@ def __init__(self, task_id, requester, newtask=False):
def get_added_date(self):
return self.added_date

def get_added_date_string(self):
FORMAT = '%Y-%m-%dT%H:%M:%S'

if self.added_date:
return self.added_date.strftime(FORMAT)
else:
return datetime.now().strftime(FORMAT)

def get_added_date_simple(self):
return self.added_date.strftime("%Y/%m/%d") if self.added_date else ""

def set_added_date(self, date):
self.added_date = date
self.added_date = Date(date)

def is_loaded(self):
return self.loaded
Expand Down Expand Up @@ -256,11 +244,8 @@ def get_status(self):
def get_modified(self):
return self.last_modified

def get_modified_string(self):
return self.last_modified.strftime("%Y-%m-%dT%H:%M:%S")

def set_modified(self, modified):
self.last_modified = modified
def set_modified(self, value):
self.last_modified = Date(value)

def recursive_sync(self):
"""Recursively sync the task and all task children. Defined"""
Expand Down Expand Up @@ -310,14 +295,14 @@ def is_valid_term():
# If a start date is already set,
# we should calculate the next date from that day.
if self.start_date == Date.no_date():
start_from = Date(convert_datetime_to_date(date.today()))
start_from = Date(datetime.now())
else:
start_from = self.start_date

newdate = start_from.parse_from_date(recurring_term, newtask)
return (True, newdate)
except ValueError as e:
return (False, None)
return True, newdate
except ValueError:
return False, None

self.recurring = recurring
# We verifiy if the term passed is valid
Expand Down Expand Up @@ -370,7 +355,7 @@ def get_recurring_updated_date(self):
return self.recurring_updated_date

def set_recurring_updated_date(self, date):
self.recurring_updated_date = date
self.recurring_updated_date = Date(date)

def inherit_recursion(self):
""" Inherits the recurrent state of the parent.
Expand Down Expand Up @@ -917,5 +902,5 @@ def __str__(self):
self.tid,
self.status,
str(self.tags),
str(self.added_date),
self.added_date,
str(self.recurring))
10 changes: 5 additions & 5 deletions GTG/core/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,23 @@ def convert_task(task: et.Element, ds: datastore) -> Optional[et.Element]:
new_modified = et.SubElement(dates, 'modified')

if added:
added = Date(added).xml_str()
added = str(Date(added))
else:
added = date.today().isoformat()

new_added.text = added

if modified:
modified = modified[:10]
modified = Date(modified).xml_str()
modified = str(Date(modified))
else:
modified = date.today().isoformat()

new_modified.text = modified

if done_date:
new_done = et.SubElement(dates, 'done')
new_done.text = Date(done_date).xml_str()
new_done.text = str(Date(done_date))

if start:
start = Date(start)
Expand All @@ -234,7 +234,7 @@ def convert_task(task: et.Element, ds: datastore) -> Optional[et.Element]:
else:
new_start = et.SubElement(dates, 'start')

new_start.text = start.xml_str()
new_start.text = str(start)

if due_date:
due_date = Date(due_date)
Expand All @@ -244,7 +244,7 @@ def convert_task(task: et.Element, ds: datastore) -> Optional[et.Element]:
else:
new_due = et.SubElement(dates, 'due')

new_due.text = due_date.xml_str()
new_due.text = str(due_date)

recurring = et.SubElement(new_task, 'recurring')
recurring.set('enabled', 'false')
Expand Down
80 changes: 28 additions & 52 deletions GTG/core/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,26 @@ def task_from_element(task, element: etree.Element):

task.set_title(element.find('title').text)
task.set_uuid(element.get('id'))
task.set_status(element.attrib['status'])

# Retrieving all dates
dates = element.find('dates')

modified = dates.find('modified').text
task.set_modified(datetime.fromisoformat(modified))

added = dates.find('added').text
task.set_added_date(datetime.fromisoformat(added))

# Dates
try:
done_date = Date.parse(dates.find('done').text)
task.set_status(element.attrib['status'], donedate=done_date)
except AttributeError:
pass


fuzzy_due_date = Date.parse(dates.findtext('fuzzyDue'))
due_date = Date.parse(dates.findtext('due'))

if fuzzy_due_date:
task.set_due_date(fuzzy_due_date)
elif due_date:
task.set_due_date(due_date)


fuzzy_start = dates.findtext('fuzzyStart')
start = dates.findtext('start')

if fuzzy_start:
task.set_start_date(fuzzy_start)
elif start:
task.set_start_date(start)

for key, set_date in (('modified', task.set_modified),
('added', task.set_added_date),
('due', task.set_due_date),
('done', task.set_closed_date),
('start', task.set_start_date)):
value = dates.find(key)
if value is not None and value.text:
set_date(Date(value.text))

# supporting old ways of salvaging fuzzy dates
for key, get_date, set_date in (
('fuzzyDue', task.get_due_date, task.set_due_date),
('fuzzyStart', task.get_start_date, task.set_start_date)):
if not get_date() and dates.find(key) is not None \
and dates.find(key).text:
set_date(Date(dates.find(key).text))

# Recurring tasks
recurring = element.find('recurring')
Expand All @@ -85,7 +71,7 @@ def task_from_element(task, element: etree.Element):

try:
recurring_updated_date = recurring.find('updated_date').text
task.set_recurring_updated_date(datetime.fromisoformat(recurring_updated_date))
task.set_recurring_updated_date(Date(recurring_updated_date))
except AttributeError:
pass

Expand Down Expand Up @@ -131,24 +117,14 @@ def task_to_element(task) -> etree.Element:

dates = etree.SubElement(element, 'dates')

added_date = etree.SubElement(dates, 'added')
added_date.text = task.get_added_date().isoformat()

modified_date = etree.SubElement(dates, 'modified')
modified_date.text = Date(task.get_modified()).xml_str()

done_date = etree.SubElement(dates, 'done')
done_date.text = task.get_closed_date().xml_str()

due_date = task.get_due_date()
due_tag = 'fuzzyDue' if due_date.is_fuzzy() else 'due'
due = etree.SubElement(dates, due_tag)
due.text = due_date.xml_str()

start_date = task.get_start_date()
start_tag = 'fuzzyStart' if start_date.is_fuzzy() else 'start'
start = etree.SubElement(dates, start_tag)
start.text = start_date.xml_str()
for key, get_date in (('added', task.get_added_date),
('modified', task.get_modified),
('done', task.get_closed_date),
('due', task.get_due_date),
('start', task.get_start_date)):
value = get_date()
if value:
etree.SubElement(dates, key).text = str(value)

recurring = etree.SubElement(element, 'recurring')
recurring.set('enabled', str(task.recurring).lower())
Expand All @@ -157,7 +133,7 @@ def task_to_element(task) -> etree.Element:
recurring_term.text = str(task.get_recurring_term())

recurring_updated_date = etree.SubElement(recurring, 'updated_date')
recurring_updated_date.text = task.get_recurring_updated_date().isoformat()
recurring_updated_date.text = str(task.get_recurring_updated_date())

subtasks = etree.SubElement(element, 'subtasks')

Expand Down
42 changes: 21 additions & 21 deletions GTG/gtk/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,34 @@
The main text widget is a home-made TextView called TaskView (see taskview.py)
The rest is the logic of the widget: date changing widgets, buttons, ...
"""
import time
import datetime
import logging
import os
import time
from gettext import gettext as _
from gettext import ngettext

from gi.repository import Gdk, Gtk, Pango
from gi.repository.GObject import signal_handler_block

from GTG.core.dates import Accuracy, Date
from GTG.core.dirs import UI_DIR
from GTG.core.plugins.api import PluginAPI
from GTG.core.plugins.engine import PluginEngine
from GTG.core.task import Task
from gettext import gettext as _, ngettext
from GTG.gtk.editor import GnomeConfig
from GTG.gtk.editor.calendar import GTGCalendar
from GTG.gtk.editor.recurring_menu import RecurringMenu
from GTG.gtk.editor.taskview import TaskView
from GTG.gtk.tag_completion import tag_filter
from GTG.core.dates import Date

"""
TODO (jakubbrindza): re-factor tag_filter into a separate module
"""

log = logging.getLogger(__name__)


class TaskEditor():
class TaskEditor:

EDITOR_UI_FILE = os.path.join(UI_DIR, "task_editor.ui")

Expand Down Expand Up @@ -264,7 +265,7 @@ def __init__(self,
def show_popover_start(self, widget, event):
"""Open the start date calendar popup."""

start_date = self.task.get_start_date() or Date.today()
start_date = (self.task.get_start_date() or Date.today()).date()

with signal_handler_block(self.start_calendar, self.start_handle):
self.start_calendar.select_day(start_date.day)
Expand All @@ -281,6 +282,8 @@ def show_popover_due(self, widget, popover):
if not due_date or due_date.is_fuzzy():
due_date = Date.today()

due_date = due_date.date()

with signal_handler_block(self.due_calendar, self.due_handle):
self.due_calendar.select_day(due_date.day)
self.due_calendar.select_month(due_date.month - 1,
Expand All @@ -291,7 +294,7 @@ def show_popover_due(self, widget, popover):
def show_popover_closed(self, widget, popover):
"""Open the closed date calendar popup."""

closed_date = self.task.get_closed_date()
closed_date = self.task.get_closed_date().date()

with signal_handler_block(self.closed_calendar, self.closed_handle):
self.closed_calendar.select_day(closed_date.day)
Expand Down Expand Up @@ -395,13 +398,10 @@ def search_function(self, model, column, key, iter, *search_data):
# otherwise.
return not model.get(iter, column)[0].startswith(key)


def get_monitor_dimensions(self) -> Gdk.Rectangle:
@staticmethod
def get_monitor_dimensions() -> Gdk.Rectangle:
"""Get dimensions for the first monitor."""

monitor = Gdk.Display.get_default().get_monitor(0)
return monitor.get_geometry()

return Gdk.Display.get_default().get_monitor(0).get_geometry()

def init_dimensions(self):
""" Restores position and size of task if possible """
Expand All @@ -427,7 +427,7 @@ def init_dimensions(self):
else:
device_manager = Gdk.Display.get_default().get_device_manager()
pointer = device_manager.get_client_pointer()
screen, x, y = pointer.get_position()
_, x, y = pointer.get_position()
x = int(x)
y = int(y)

Expand Down Expand Up @@ -501,7 +501,7 @@ def refresh_editor(self, title=None, refreshtext=False):
update_date = True

if update_date:
self.start_entry.set_text(str(startdate))
self.start_entry.set_text(startdate.localized_str)

# refreshing the due date field
duedate = self.task.get_due_date()
Expand All @@ -512,13 +512,13 @@ def refresh_editor(self, title=None, refreshtext=False):
update_date = True

if update_date:
self.due_entry.set_text(str(duedate))
self.due_entry.set_text(duedate.localized_str)

# refreshing the closed date field
closeddate = self.task.get_closed_date()
prevcldate = Date.parse(self.closed_entry.get_text())
if closeddate != prevcldate:
self.closed_entry.set_text(str(closeddate))
self.closed_entry.set_text(closeddate.localized_str)

# refreshing the day left label
"""
Expand Down Expand Up @@ -642,7 +642,7 @@ def on_duedate_fuzzy(self, widget, date):
""" Callback when a fuzzy date is selected through the popup. """

self.task.set_due_date(date)
self.due_entry.set_text(str(date))
self.due_entry.set_text(date.localized_str)

def on_date_cleared(self, widget, kind):
""" Callback when a date is cleared through the popups. """
Expand All @@ -662,15 +662,15 @@ def on_date_selected(self, calendar, kind):

if kind == GTGCalendar.DATE_KIND_START:
self.task.set_start_date(Date(date))
self.start_entry.set_text(str(Date(date)))
self.start_entry.set_text(Date(date).localized_str)

elif kind == GTGCalendar.DATE_KIND_DUE:
self.task.set_due_date(Date(date))
self.due_entry.set_text(str(Date(date)))
self.due_entry.set_text(Date(date).localized_str)

elif kind == GTGCalendar.DATE_KIND_CLOSED:
self.task.set_closed_date(Date(date))
self.closed_entry.set_text(str(Date(date)))
self.closed_entry.set_text(Date(date).localized_str)

def on_date_changed(self, calendar):
date, date_kind = calendar.get_selected_date()
Expand Down
Loading