Пример #1
0
        def filter_by_creator_id(request, qs, creator_id):
            log.info("Filter by creator id")

            if request.user.is_authenticated():
                # exclude from queryset annotations which are private
                # and are not owned by registered user
                qs = qs.exclude(~Q(author=request.user), private=True)

            else:
                # if user is not logged in exclude all private annotations
                qs = qs.exclude(private=True)

            # NOTE: Django user id has low priority before drupal user id
            # Drupal user? we need to remove this.
            if creator_id:
                # user = (get_object_or_None(Profile, username=self.fake_username(creator_id)) or get_object_or_None(Profile, id=creator_id))
                user = get_object_or_None(Profile, username=self.fake_username(creator_id)) or get_object_or_None(
                    Profile, id=creator_id
                )

                if not user:
                    raise NotFoundError("User not found")

                qs = qs.filter(author=user) if user else qs
            return qs
Пример #2
0
def profile(request, creator):
    if creator:
        creator = get_object_or_None(Profile, username=creator)

        if not creator:
            return direct_to_template(
                request,
                'profile/does_not_exists.html',
                {
                    'username': creator,
                    'all_users': Profile.objects.all()
                }
            )
    else:
        creator = request.user

    annots = Annotation.objects.filter(
        author=creator,
        deleted=False,
    )
    if request.user.is_authenticated():
        annots = annots.exclude(~Q(author=request.user), private=True)

    return direct_to_template(
        request,
        'profile/profile.html',
        {
            'annotations': annots.filter(type='Comment'),
            'replies': annots.filter(type='Reply'),
            'creator': creator,
            'all_users': User.objects.all()

        }
    )