コード例 #1
0
def _create_the_update(instances, communities, **kwargs):
    instance = kwargs["instance"]
    user = kwargs["user"]
    type_ = kwargs["type"]

    ago = dict(days=1) if (type_ == Update.DISCUSSION) else dict(hours=12)
    recent_update = Update.get_recent_for(instance, type_, **ago)
    if recent_update:
        update = recent_update
        ids = [u_dict['id'] for u_dict in update.users]
        if user.id not in ids:
            update.push_user(user)
    else:
        data = {
            'object_id': instance.id,
            'object_type': instance._meta.verbose_name,
            'type': type_,
            'users': [user],
        }
        update = Update(**data)

    update.instances = instances
    update.communities = communities
    update.comments_count = Comment.comments_count_for(instance)
    update.save()
コード例 #2
0
def _create_the_update(instances, communities, **kwargs):
    instance = kwargs["instance"]
    user = kwargs["user"]
    type_ = kwargs["type"]

    ago = dict(days=1) if (type_ == Update.DISCUSSION) else dict(hours=12)
    recent_update = Update.get_recent_for(instance, type_, **ago)
    if recent_update:
        update = recent_update
        ids = [u_dict['id'] for u_dict in update.users]
        if user.id not in ids:
            update.push_user(user)
    else:
        data = {
            'object_id': instance.id,
            'object_type': instance._meta.verbose_name,
            'type': type_,
            'users': [user],
        }
        update = Update(**data)

    update.instances = instances
    update.communities = communities
    update.comments_count = Comment.comments_count_for(instance)
    update.save()
コード例 #3
0
ファイル: views.py プロジェクト: CodingForChange/mootiro-maps
def comments_list(content_object=None, parent_id=None, page=0, root=False,
        width=settings.KOMOO_COMMENTS_WIDTH,
        height=settings.KOMOO_COMMENTS_HEIGHT, context=None, comment_class='',
        wrap=True, *args, **kwargs):
    """
    builds a list o comments recursivelly and returns its rendered template
    params:
        content_object : object that these comments references
            (if Nones gets comments for any objects)
        parent_id : id of the parent for subcomments
            (default: None -> retrieves root comments)
        page : page number
        width: depth of subcomments to be loaded
        height: number of 'root' (in this sub-tree) comments to be loaded
        context: a RequestContext object, needed for csrf purposes
        comment_class: used for controlling the css classes (depth striped) on
            comment-container
        root : flag to identify if its a root comment
        wrap : defines if the comments list renders wrapped by a
            div.comments-list or not
    """
    # logger.debug('accessing Comments > comments_list')
    width = int(width[0]) if isinstance(width, list)\
                    else int(width)
    height = int(height[0]) if isinstance(height, list) \
                    else int(height)
    parent_id = int(parent_id[0]) if parent_id and isinstance(parent_id, list) \
                    else parent_id
    wrap = int(wrap[0]) if wrap and isinstance(wrap, list) \
                    else wrap
    page = int(page[0]) if isinstance(page, list) \
                    else int(page)

    logger.debug('loading comment with parent={} , page={} , width={} , height={}'.\
        format(parent_id, page, width, height))
    start, end = page * height, (page + 1) * height
    comments_query = Comment.get_comments_for(content_object) if content_object \
        else Comment.objects
    if parent_id:
        comments = comments_query.filter(parent=parent_id).\
            order_by('-pub_date')[start:end]
    else:
        comments = comments_query.filter(parent__isnull=True).\
            order_by('-pub_date')[start:end]
    if width:
        for comment in comments:
            if comment.sub_comments > 0:
                comment.sub_comments_list = comments_list(parent_id=comment.id,
                    width=width - 1, context=context,
                    comment_class='inner-comment' if 'odd' in comment_class \
                        else 'inner-comment odd',).content
    if not root:
        comment_class += ' inner-comment'
    return render_to_response('comments/comments_list.html',
            dict(parent_id=parent_id, comments=comments,
                 comment_class=comment_class, wrap=wrap),
            context_instance=context)
コード例 #4
0
def delete_object(obj):
    """Delete the object and the related moderation object"""
    moderation = Moderation.objects.get_for_object(obj)
    if moderation:
        moderation.delete()

    # remove possible tag relationship
    if hasattr(obj, 'tags'):
        obj.tags.clear()

    # remove possible comment relationship
    for c in Comment.get_comments_for(obj):
        c.delete()

    ct = ContentType.objects.get_for_model(obj)
    # remove possible project relationship
    for pro in ProjectRelatedObject.objects \
                .filter(content_type=ct, object_id=obj.id):
        pro.delete()

    obj.delete()
コード例 #5
0
def delete_object(obj):
    """Delete the object and the related moderation object"""
    moderation = Moderation.objects.get_for_object(obj)
    if moderation:
        moderation.delete()

    # remove possible tag relationship
    if hasattr(obj, 'tags'):
        obj.tags.clear()

    # remove possible comment relationship
    for c in Comment.get_comments_for(obj):
        c.delete()

    ct = ContentType.objects.get_for_model(obj)
    # remove possible project relationship
    for pro in ProjectRelatedObject.objects \
                .filter(content_type=ct, object_id=obj.id):
        pro.delete()

    obj.delete()
コード例 #6
0
ファイル: views.py プロジェクト: frduda/mootiro-maps
def comments_list(content_object=None,
                  parent_id=None,
                  page=0,
                  root=False,
                  width=settings.KOMOO_COMMENTS_WIDTH,
                  height=settings.KOMOO_COMMENTS_HEIGHT,
                  context=None,
                  comment_class='',
                  wrap=True,
                  *args,
                  **kwargs):
    """
    builds a list o comments recursivelly and returns its rendered template
    params:
        content_object : object that these comments references
            (if Nones gets comments for any objects)
        parent_id : id of the parent for subcomments
            (default: None -> retrieves root comments)
        page : page number
        width: depth of subcomments to be loaded
        height: number of 'root' (in this sub-tree) comments to be loaded
        context: a RequestContext object, needed for csrf purposes
        comment_class: used for controlling the css classes (depth striped) on
            comment-container
        root : flag to identify if its a root comment
        wrap : defines if the comments list renders wrapped by a
            div.comments-list or not
    """
    # logger.debug('accessing Comments > comments_list')
    width = int(width[0]) if isinstance(width, list)\
                    else int(width)
    height = int(height[0]) if isinstance(height, list) \
                    else int(height)
    parent_id = int(parent_id[0]) if parent_id and isinstance(parent_id, list) \
                    else parent_id
    wrap = int(wrap[0]) if wrap and isinstance(wrap, list) \
                    else wrap
    page = int(page[0]) if isinstance(page, list) \
                    else int(page)

    logger.debug('loading comment with parent={} , page={} , width={} , height={}'.\
        format(parent_id, page, width, height))
    start, end = page * height, (page + 1) * height
    comments_query = Comment.get_comments_for(content_object) if content_object \
        else Comment.objects
    if parent_id:
        comments = comments_query.filter(parent=parent_id).\
            order_by('-pub_date')[start:end]
    else:
        comments = comments_query.filter(parent__isnull=True).\
            order_by('-pub_date')[start:end]
    if width:
        for comment in comments:
            if comment.sub_comments > 0:
                comment.sub_comments_list = comments_list(parent_id=comment.id,
                    width=width - 1, context=context,
                    comment_class='inner-comment' if 'odd' in comment_class \
                        else 'inner-comment odd',).content
    if not root:
        comment_class += ' inner-comment'
    return render_to_response('comments/comments_list.html',
                              dict(parent_id=parent_id,
                                   comments=comments,
                                   comment_class=comment_class,
                                   wrap=wrap),
                              context_instance=context)