예제 #1
0
파일: models.py 프로젝트: ronhuang/adieu
    def to_dict(self, details=False, current_user=None):
        localtime = self.pubtime + timedelta(hours=8)
        fmt = None
        if localtime.hour < 12:
            fmt = "%Y年%m月%d號 上午%I:%M:%S"
        else:
            fmt = "%Y年%m月%d號 下午%I:%M:%S"

        uid = self.owner.id
        relative_url = '/object/%s' % self.key().id()

        result = {'owner_picture': 'http://graph.facebook.com/%s/picture?type=square' % uid,
                  'title': self.title,
                  'pubtime': pretty_time(self.pubtime),
                  'relative_url': relative_url,
                  'absolute_url': 'http://midautumn.ronhuang.org' + relative_url,
                  }

        if details:
            query = self.edge_set
            query.filter('connected =', True)
            result['like_count'] = query.count()

            query = self.comment_set
            result['comment_count'] = query.count()

            result['owner'] = self.owner.profile

        if current_user:
            if current_user.id == self.owner.id:
                result['modifiable'] = True

        return result
예제 #2
0
파일: models.py 프로젝트: ronhuang/adieu
 def profile(self):
     relative_url = '/profile/%s' % self.id
     return {'relative_url': relative_url,
             'absolute_url': 'http://midautumn.ronhuang.org' + relative_url,
             'picture': 'http://graph.facebook.com/%s/picture?type=square' % self.id,
             'name': self.name,
             'id': self.id,
             'created': pretty_time(self.created),
             }