Esempio n. 1
0
    def testDateRangeFromPath(self):
        from zim.plugins.calendar import daterange_from_path

        # Day
        for path in (Path('Foo:2012:04:27'), Path('Foo:2012:4:27')):
            type, start, end = daterange_from_path(path)
            self.assertEqual(type, 'day')
            self.assertEqual(start, dateclass(2012, 4, 27))
            self.assertEqual(end, dateclass(2012, 4, 27))

        # Week
        zim.datetimetz.FIRST_DAY_OF_WEEK = \
         zim.datetimetz.MONDAY
        type, start, end = daterange_from_path(Path('Foo:2012:Week 17'))
        self.assertEqual(type, 'week')
        self.assertEqual(start, dateclass(2012, 4, 23))  # a monday
        self.assertEqual(end, dateclass(2012, 4, 29))  # a sunday

        # Month
        for path in (Path('Foo:2012:04'), Path('Foo:2012:4')):
            type, start, end = daterange_from_path(path)
            self.assertEqual(type, 'month')
            self.assertEqual(start, dateclass(2012, 4, 1))
            self.assertEqual(end, dateclass(2012, 4, 30))

        # Year
        type, start, end = daterange_from_path(Path('Foo:2012'))
        self.assertEqual(type, 'year')
        self.assertEqual(start, dateclass(2012, 1, 1))
        self.assertEqual(end, dateclass(2012, 12, 31))
Esempio n. 2
0
File: calendar.py Progetto: gdw2/zim
	def testDateRangeFromPath(self):
		from zim.plugins.calendar import daterange_from_path

		# Day
		for path in (Path('Foo:2012:04:27'), Path('Foo:2012:4:27')):
			type, start, end = daterange_from_path(path)
			self.assertEqual(type, 'day')
			self.assertEqual(start, dateclass(2012, 4, 27))
			self.assertEqual(end, dateclass(2012, 4, 27))

		# Week
		zim.datetimetz.FIRST_DAY_OF_WEEK = \
			zim.datetimetz.MONDAY
		type, start, end = daterange_from_path(Path('Foo:2012:Week 17'))
		self.assertEqual(type, 'week')
		self.assertEqual(start, dateclass(2012, 4, 23)) # a monday
		self.assertEqual(end, dateclass(2012, 4, 29)) # a sunday

		# Month
		for path in (Path('Foo:2012:04'), Path('Foo:2012:4')):
			type, start, end = daterange_from_path(path)
			self.assertEqual(type, 'month')
			self.assertEqual(start, dateclass(2012, 4, 1))
			self.assertEqual(end, dateclass(2012, 4, 30))

		# Year
		type, start, end = daterange_from_path(Path('Foo:2012'))
		self.assertEqual(type, 'year')
		self.assertEqual(start, dateclass(2012, 1, 1))
		self.assertEqual(end, dateclass(2012, 12, 31))
Esempio n. 3
0
    def on_page_changed(self, o, row, doc):
        if self.included_subtrees:
            if not any(row['name'].startswith(n)
                       for n in self.included_subtrees):
                return
        if self.excluded_subtrees:
            if any(row['name'].startswith(n) for n in self.excluded_subtrees):
                return

        changes = False
        count, = self.db.execute(
            'SELECT count(*) FROM tasklist WHERE source=?',
            (row['id'], )).fetchone()
        if count > 0:
            self.db.execute('DELETE FROM tasklist WHERE source=?',
                            (row['id'], ))
            changes = True

        opts = {}
        if self.integrate_with_journal:
            date = daterange_from_path(Path(row['name']))
            if date and self.integrate_with_journal == 'start':
                opts['default_start_date'] = date[1]
            elif date and self.integrate_with_journal == 'due':
                opts['default_due_date'] = date[2]

        tasks = self.parser.parse(doc.iter_tokens(), **opts)
        c = self.db.cursor()
        count = c.rowcount
        self._insert_tasks(c, row['id'], 0, tasks)
        if changes or c.rowcount > count:
            self.emit('tasklist-changed')
Esempio n. 4
0
    def index_page(self, index, path, page):
        if not self.db_initialized: return
        #~ print '>>>>>', path, page, page.hascontent

        tasksfound = self.remove_page(index, path, _emit=False)
        if self._excluded(path):
            if tasksfound:
                self.emit('tasklist-changed')
            return

        parsetree = page.get_parsetree()
        if not parsetree:
            return

        #~ print '!! Checking for tasks in', path
        dates = daterange_from_path(path)
        if dates and self.preferences['deadline_by_page']:
            deadline = dates[2]
        else:
            deadline = None
        tasks = self._extract_tasks(parsetree, deadline)

        if tasks:
            # Do insert with a single commit
            with self.index.db_commit:
                self._insert(path, 0, tasks)

        if tasks or tasksfound:
            self.emit('tasklist-changed')
Esempio n. 5
0
	def index_page(self, index, path, page):
		if not self.db_initialized: return
		#~ print '>>>>>', path, page, page.hascontent

		tasksfound = self.remove_page(index, path, _emit=False)
		if self._excluded(path):
			if tasksfound:
				self.emit('tasklist-changed')
			return

		parsetree = page.get_parsetree()
		if not parsetree:
			return

		#~ print '!! Checking for tasks in', path
		dates = daterange_from_path(path)
		if dates and self.preferences['deadline_by_page']:
			deadline = dates[2]
		else:
			deadline = None
		tasks = self._extract_tasks(parsetree, deadline)

		if tasks:
			# Do insert with a single commit
			with self.index.db_commit:
				self._insert(path, 0, tasks)

		if tasks or tasksfound:
			self.emit('tasklist-changed')
Esempio n. 6
0
    def index_page(self, index, path, page):
        if not self.db_initialized: return
        # ~ print '>>>>>', path, page, page.hascontent

        tasksfound = self.remove_page(index, path, _emit=False)
        if self._excluded(path):
            if tasksfound:
                self.emit('tasklist-changed')
            return

        parsetree = page.get_parsetree()
        if not parsetree:
            return

        if page._ui_object:
            # FIXME - HACK - dump and parse as wiki first to work
            # around glitches in pageview parsetree dumper
            # make sure we get paragraphs and bullets are nested properly
            # Same hack in gui clipboard code
            dumper = get_format('wiki').Dumper()
            text = ''.join(dumper.dump(parsetree)).encode('utf-8')
            parser = get_format('wiki').Parser()
            parsetree = parser.parse(text)

        # ~ print '!! Checking for tasks in', path
        dates = daterange_from_path(path)
        if dates and self.preferences['deadline_by_page']:
            deadline = dates[2]
        else:
            deadline = None

        tasks = self._extract_tasks(parsetree, deadline)
        # ~ print 'TASKS', tasks

        if tasks:
            # Do insert with a single commit
            with self.index.db_commit:
                self._insert(path, 0, tasks)

        if tasks or tasksfound:
            self.emit('tasklist-changed')