Example #1
0
def can_vote_test(request, content_type, object_id, vote):
    return can_vote(
        content_type.get_object_for_this_type(id=object_id),
        request.user,
        request,
        vote
    )
Example #2
0
def like(request, content_type, id, vote):
    #content_type = content_type.replace("-", ".")
    app, modelname = content_type.split('-')
    object = ContentType.objects.get(app_label=app, model__iexact=modelname).model_class().objects.get(id=id)

    if can_vote(object, request.user, request):
        UserActivity.track_activity(user=request.user.member,
                                    activity=activity_constants.ACTIVITY_LIKED,
                                    sub=ugettext('<a href="%s">%s</a>' % (object.get_absolute_url(),
                                                                          object.comment if isinstance(object, FoundryComment) else object.title)),
                                    content_object=object,
                                    image_object=object)
    return likes_views.like(request, content_type, id, vote)
def likes(context, obj):
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    context.update({
        'content_obj': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, obj._meta.module_name)),
        'import_js': import_js
    })
    return context
def likes(context, obj, template=None):
    """
           Register a callable as an inclusion tag:

           @register.inclusion_tag('results.html')
           def show_results(poll):
               choices = poll.choice_set.all()
               return {'choices': choices}
    """
    if template is None:
        template = 'cclikes/inclusion_tags/cclikes.html'
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    try:
        model_name = obj._meta.model_name
    except AttributeError:
        model_name = obj._meta.module_name
    context.update({
        'template': template,
        'content_obj': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, model_name)),
        'import_js': import_js
    })
    return context

    def inclusion_tag(self, filename, func=None, takes_context=None, name=None):
        def dec(func):
            params, varargs, varkw, defaults = getargspec(func)
            function_name = (name or getattr(func, '_decorated_function', func).__name__)
            @functools.wraps(func)
            def compile_func(parser, token):
                bits = token.split_contents()[1:]
                args, kwargs = parse_bits(
                    parser, bits, params, varargs, varkw, defaults,
                    takes_context, function_name,
                )
                return InclusionNode(
                    func, takes_context, args, kwargs, filename,
                )
            self.tag(function_name, compile_func)
            return func
        return dec
def adlikes(context, obj, template=None):
    if template is None:
        template = 'likes/inclusion_tags/likes.html'
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    context.update({
        'template': template,
        'object': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, obj._meta.model_name)),
        'import_js': import_js
    })
    return context
Example #6
0
def likes(context, obj, template=None):
    if template is None:
        template = 'likes/inclusion_tags/likes.html'
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    try:
        model_name = obj._meta.model_name
    except AttributeError:
        model_name = obj._meta.module_name
    context.update({
        'template': template,
        'content_obj': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, model_name)),
        'import_js': import_js
    })
    return context
def likes(context, obj, template=None):
    """
           Register a callable as an inclusion tag:

           @register.inclusion_tag('results.html')
           def show_results(poll):
               choices = poll.choice_set.all()
               return {'choices': choices}
    """
    if template is None:
        template = 'cclikes/inclusion_tags/cclikes.html'
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    try:
        model_name = obj._meta.model_name
    except AttributeError:
        model_name = obj._meta.module_name
    context.update({
        'template': template,
        'content_obj': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, model_name)),
        'import_js': import_js
    })
    return context

    def inclusion_tag(self,
                      filename,
                      func=None,
                      takes_context=None,
                      name=None):
        def dec(func):
            params, varargs, varkw, defaults = getargspec(func)
            function_name = (name or getattr(func, '_decorated_function',
                                             func).__name__)

            @functools.wraps(func)
            def compile_func(parser, token):
                bits = token.split_contents()[1:]
                args, kwargs = parse_bits(
                    parser,
                    bits,
                    params,
                    varargs,
                    varkw,
                    defaults,
                    takes_context,
                    function_name,
                )
                return InclusionNode(
                    func,
                    takes_context,
                    args,
                    kwargs,
                    filename,
                )

            self.tag(function_name, compile_func)
            return func

        return dec
Example #8
0
def can_vote_test(request, content_type, object_id, vote):
    return can_vote(content_type.get_object_for_this_type(id=object_id),
                    request.user, request)
Example #9
0
def can_vote_test(request, content_type, object_id, vote):
    return can_vote(
        content_type.model_class().objects.get(id=object_id),
        request.user,
        request
    )
Example #10
0
 def get_can_vote(self, obj):
     request = self.context['request']
     return can_vote(obj, request.user, request)