Some refactoring in Notification model and streams
authorMarek Marecki <marekjm@taistelu.com>
Sun, 4 Aug 2013 13:30:43 +0000 (15:30 +0200)
committerMarek Marecki <marekjm@taistelu.com>
Sun, 4 Aug 2013 13:30:43 +0000 (15:30 +0200)
Changelog.markdown
diaspy/models.py
diaspy/streams.py

index fc71af80ef96f1debd36a5c76001299b60ddfaa7..304079c9b86afb3103a7cc6200d9c15a2221d557 100644 (file)
@@ -24,6 +24,7 @@ up-to-date than manual and if conflicts appear they should follow the order:
 Version `0.3.1` (2013-07-12):
 
 * __upd__:  `diaspy.people.sephandle()` raises `InvalidHandleError` instead of `UserError`
+* __upd__:  `models.Post()._fetch()` renamed to `_fetchdata()` (because of new `_fetchcomments()` method)
 * __new__:  `models.Comment()` object: wrapper for comments, not to be created manually
 * __new__:  `comments` parameter in `models.Post`: defines whether to fetch post's commets
 * __new__:  `connection.Connection` has new parameter in `__init__()`: it's `schema`
index dce4b63bc63b19a983e3a19a3681dae45bcc1cd3..ea881999a34ad8473d6b8295d07af2511c21f2cf 100644 (file)
@@ -150,6 +150,7 @@ class Notification():
     """
     _who_regexp = re.compile(r'/people/[0-9a-z]+" class=\'hovercardable')
     _when_regexp = re.compile(r'[0-9]{4,4}(-[0-9]{2,2}){2,2} [0-9]{2,2}(:[0-9]{2,2}){2,2} UTC')
+    _aboutid_regexp = re.compile(r'/posts/[0-9]+')
 
     def __init__(self, connection, data):
         self._connection = connection
@@ -166,8 +167,7 @@ class Notification():
     def __str__(self):
         """Returns notification note.
         """
-        print(self.data['note_html'])
-        string = re.sub('</?[a-z]+( *[a-z_-]+=["\'][\w():.,!?#/\- ]*["\'])* */?>', '', self.data['note_html'])
+        string = re.sub('</?[a-z]+( *[a-z_-]+=["\'][\w():.,!?#@=/\- ]*["\'])* */?>', '', self.data['note_html'])
         string = string.strip().split('\n')[0]
         while '  ' in string: string = string.replace('  ', ' ')
         return string
@@ -177,6 +177,14 @@ class Notification():
         """
         return '{0}: {1}'.format(self.when(), str(self))
 
+    def about(self):
+        """Returns id of post about which the notification is informing.
+        """
+        about = self._aboutid_regexp.search(self.data['note_html'])
+        if about is None: about = self.who()
+        else: about = int(about.group(0)[7:])
+        return about
+
     def who(self):
         """Returns list of guids of the users who caused you to get the notification.
         """
index 6be8667f9def7eec8f9cfd0c6267216db3919354..d1834b95605c2ffb1a04ef44f775cd5bada1e8fb 100644 (file)
@@ -14,9 +14,6 @@ class Generic():
     """Object representing generic stream.
     """
     _location = 'stream.json'
-    _stream = []
-    #   since epoch
-    max_time = int(time.mktime(time.gmtime()))
 
     def __init__(self, connection, location=''):
         """
@@ -27,6 +24,9 @@ class Generic():
         """
         self._connection = connection
         if location: self._location = location
+        self._stream = []
+        #   since epoch
+        self.max_time = int(time.mktime(time.gmtime()))
         self.fill()
 
     def __contains__(self, post):
@@ -232,8 +232,7 @@ class Activity(Stream):
         """
         if type(post) == str: self._delid(post)
         elif type(post) == Post: post.delete()
-        else:
-            raise TypeError('this method accepts str or Post types: {0} given')
+        else: raise TypeError('this method accepts str or Post types: {0} given')
         self.fill()