コード例 #1
0
ファイル: test_Blog.py プロジェクト: bhrigu123/moin-2.0-beta
 def test_do_show_sorted_entries(self):
     item = Item.create(self.name, itemtype=ITEMTYPE_BLOG)
     item._save(self.meta, self.data, comment=self.comment)
     # store entries
     for entry in self.entries:
         item = Item.create(entry['name'], itemtype=ITEMTYPE_BLOG_ENTRY)
         item._save(self.entry_meta, entry['data'], comment=self.comment)
     # Add PTIME to some of the entries, ptime value is a UNIX timestamp. If PTIME
     # is not defined, we use MTIME as publication time (which is usually in the past).
     self._publish_entry(self.entries[0], ptime=2000)
     self._publish_entry(self.entries[1], ptime=1000)
     time_in_future = utctimestamp(datetime(2029, 1, 1))
     self._publish_entry(self.entries[2], ptime=time_in_future)
     # the blog is not empty
     exclude_data_tokens = [
         self.NO_ENTRIES_MSG,
     ]
     # blog entries are listed in reverse order relative to their PTIME/MTIMEs,
     # entries published in the future are also listed here
     ordered_data = [
         self.data,
         self.entries[2]['data'],
         self.entries[3]['data'],
         self.entries[0]['data'],
         self.entries[1]['data'],
     ]
     regex = re.compile(r'{0}.*{1}.*{2}.*{3}.*{4}'.format(*ordered_data),
                        re.DOTALL)
     self._test_view(self.name,
                     exclude_data_tokens=exclude_data_tokens,
                     regex=regex)
コード例 #2
0
ファイル: indexing.py プロジェクト: denedios/moin-2.0
 def __getitem__(self, key):
     if self._meta:
         # we have real metadata (e.g. from storage)
         return self._meta[key]
     elif self._doc and key in self._common_fields:
         # we have a result document from whoosh, which has quite a lot
         # of the usually wanted metadata, avoid storage access, use this.
         value = self._doc[key]
         if key in [MTIME, PTIME]:
             # whoosh has a datetime object, but we want a UNIX timestamp
             value = utctimestamp(value)
         return value
     else:
         self._meta, _ = self.revision._load()
         return self._meta[key]
コード例 #3
0
ファイル: forms.py プロジェクト: rciorba/moin-2.0-mirror
    def adapt(self, value):
        """Coerces value to a native UNIX timestamp.

        If value is an instance of int and it is a correct UNIX timestamp,
        returns it unchanged. Otherwise uses DateTime superclass to parse it.
        """
        if isinstance(value, int):
            try:
                # check if a value is a correct timestamp
                dt = datetime.datetime.utcfromtimestamp(value)
                return value
            except ValueError:
                raise AdaptationError()
        dt = super(DateTimeUNIX, self).adapt(value)
        if isinstance(dt, datetime.datetime):
            # XXX forces circular dependency when it is in the head import block
            from MoinMoin.themes import utctimestamp
            # TODO: Add support for timezones
            dt = utctimestamp(dt)
        return dt
コード例 #4
0
    def adapt(self, value):
        """Coerces value to a native UNIX timestamp.

        If value is an instance of int and it is a correct UNIX timestamp,
        returns it unchanged. Otherwise uses DateTime superclass to parse it.
        """
        if isinstance(value, int):
            try:
                # check if a value is a correct timestamp
                dt = datetime.datetime.utcfromtimestamp(value)
                return value
            except ValueError:
                raise AdaptationError()
        dt = super(DateTimeUNIX, self).adapt(value)
        if isinstance(dt, datetime.datetime):
            # XXX forces circular dependency when it is in the head import block
            from MoinMoin.themes import utctimestamp
            # TODO: Add support for timezones
            dt = utctimestamp(dt)
        return dt
コード例 #5
0
ファイル: test_Blog.py プロジェクト: denedios/moin-2.0
 def test_do_show_sorted_entries(self):
     item = Item.create(self.name, itemtype=ITEMTYPE_BLOG)
     item._save(self.meta, self.data, comment=self.comment)
     # store entries
     for entry in self.entries:
         item = Item.create(entry['name'], itemtype=ITEMTYPE_BLOG_ENTRY)
         item._save(self.entry_meta, entry['data'], comment=self.comment)
     # Add PTIME to some of the entries, ptime value is a UNIX timestamp. If PTIME
     # is not defined, we use MTIME as publication time (which is usually in the past).
     self._publish_entry(self.entries[0], ptime=2000)
     self._publish_entry(self.entries[1], ptime=1000)
     time_in_future = utctimestamp(datetime(2029, 1, 1))
     self._publish_entry(self.entries[2], ptime=time_in_future)
     # the blog is not empty
     exclude_data_tokens = [self.NO_ENTRIES_MSG, ]
     # blog entries are listed in reverse order relative to their PTIME/MTIMEs,
     # entries published in the future are also listed here
     ordered_data = [self.data,
                     self.entries[2]['data'],
                     self.entries[3]['data'],
                     self.entries[0]['data'],
                     self.entries[1]['data'], ]
     regex = re.compile(r'{0}.*{1}.*{2}.*{3}.*{4}'.format(*ordered_data), re.DOTALL)
     self._test_view(self.name, exclude_data_tokens=exclude_data_tokens, regex=regex)
コード例 #6
0
ファイル: indexing.py プロジェクト: denedios/moin-2.0
 def mtime(self):
     dt = self.meta.get(MTIME)
     if dt is not None:
         return utctimestamp(dt)