project.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:montage 作者: storyful 项目源码 文件源码
def from_instance(cls, project):
        """
            Factory method for creating a project document from
            a Project model instance.
        """
        doc = cls(doc_id=str(project.pk))
        copy_attrs = ['name', 'description']
        for attr in copy_attrs:
            setattr(doc, attr, getattr(project, attr, None))
        doc.id = unicode(project.pk)

        # make datetimes timezone naive as appengine doesnt support
        # indexing aware datetime objects which is annoying
        doc.created = timezone.make_naive(project.created, timezone.utc)
        doc.modified = timezone.make_naive(project.modified, timezone.utc)

        # manually add data that we cant directly copy from the instance
        if project.owner:
            doc.owner_id = unicode(project.owner.id)
            doc.owner_name = '%s %s' % (
                project.owner.first_name, project.owner.last_name)

        # add assigned users
        doc.assigned_users = ' '.join(
            str(user_id) for user_id in project.projectusers.filter(
                is_pending=False, is_assigned=True).values_list(
                    'user_id', flat=True)).strip()

        # build ngrams
        doc.n_grams = cls.make_ngrams(project.name)

        # return completed doc.
        return doc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号