Skip to content

Commit

Permalink
Fixing task id bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed Jun 15, 2022
1 parent 5eb92ff commit 90739d8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Calcure


Modern TUI calendar and task manager with customizable interface. Manages your events and tasks, displays birthdays from your [abook](https://abook.sourceforge.io/), and can import events and tasks from [calcurse](https://github.com/lfos/calcurse) and [taskwarrior](https://github.com/GothenburgBitFactory/taskwarrior). See [wiki](https://github.com/anufrievroman/calcure/wiki) for more information.

![screenshot](screen.jpg)
Expand Down
2 changes: 1 addition & 1 deletion calcure/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from calcure.controls import *


__version__ = "2.1.0"
__version__ = "2.2.0"


def initialize_colors():
Expand Down
10 changes: 7 additions & 3 deletions calcure/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def control_journal_screen(stdscr, user_tasks, screen, importer):
if screen.key == 'm':
number_from = input_integer(stdscr, screen.y_max-2, 0, MSG_TS_MOVE)
if user_tasks.is_valid_number(number_from):
clear_line(stdscr, screen.y_max-2)
number_to = input_integer(stdscr, screen.y_max-2, 0, MSG_TS_MOVE_TO)
user_tasks.move_task(number_from, number_to)
if screen.key in ['e', 'c']:
Expand All @@ -362,7 +363,8 @@ def control_journal_screen(stdscr, user_tasks, screen, importer):
if user_tasks.is_valid_number(number):
clear_line(stdscr, screen.y_max-2, 0)
task_name = input_string(stdscr, screen.y_max-2, 0, MSG_TS_TITLE, screen.x_max-len(MSG_TS_TITLE)-2)
user_tasks.add_subtask(Task(None, task_name, Status.NORMAL, Timer([]), False), number)
task_id = user_tasks.generate_id()
user_tasks.add_subtask(Task(task_id, task_name, Status.NORMAL, Timer([]), False), number)
screen.selection_mode = False

# Otherwise, we check for user input:
Expand All @@ -378,7 +380,8 @@ def control_journal_screen(stdscr, user_tasks, screen, importer):
if screen.key == "a":
clear_line(stdscr, len(user_tasks.items) + 2, screen.x_min)
task_name = input_string(stdscr, len(user_tasks.items) + 2, screen.x_min, cf.TODO_ICON+' ', screen.x_max - 4)
user_tasks.add_item(Task(len(user_tasks.items), task_name, Status.NORMAL, Timer([]), False))
task_id = user_tasks.generate_id()
user_tasks.add_item(Task(task_id, task_name, Status.NORMAL, Timer([]), False))

# Bulk operations:
if screen.key == "V":
Expand All @@ -391,7 +394,8 @@ def control_journal_screen(stdscr, user_tasks, screen, importer):
user_tasks.change_all_statuses(Status.IMPORTANT)
if screen.key in ["D", "X"]:
confirmed = ask_confirmation(stdscr, MSG_TS_DEL_ALL, cf.ASK_CONFIRMATIONS)
if confirmed: user_tasks.delete_all_items()
if confirmed:
user_tasks.delete_all_items()

# Imports:
if screen.key == "C":
Expand Down
4 changes: 4 additions & 0 deletions calcure/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def move_task(self, number_from, number_to):
self.items.insert(number_to, self.items.pop(number_from))
self.changed = True

def generate_id(self):
"""Generate a id for a new item. The id is generated as maximum of existing ids plus one"""
return max([item.item_id for item in self.items]) + 1


class Events(Collection):
"""List of events created by the user or imported"""
Expand Down
8 changes: 4 additions & 4 deletions calcure/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import csv
import os

from calcure.data import *

import datetime
import jdatetime

from calcure.data import *


def convert_to_persian_date(year, month, day):
"""Convert date from Gregorian to Persian calendar"""
Expand Down Expand Up @@ -270,7 +270,7 @@ def import_tasks_from_calcurse(self):
status = Status.UNIMPORTANT
else:
status = Status.NORMAL
task_id = len(self.user_tasks.items)
task_id = self.user_tasks.generate_id()
privacy = False
self.user_tasks.add_item(Task(task_id, name, status, Timer([]), privacy))

Expand All @@ -282,7 +282,7 @@ def import_tasks_from_taskwarrior(self):
name = line.split('description:"', 1)[1]
name = name.split('"', 1)[0]
if not self.user_tasks.item_exists(name):
task_id = len(self.user_tasks.items)
task_id = self.user_tasks.generate_id()
privacy = False
self.user_tasks.add_item(Task(task_id, name, Status.NORMAL, Timer([]), privacy))

Expand Down

0 comments on commit 90739d8

Please sign in to comment.