예제 #1
0
파일: admin.py 프로젝트: ella/ella-imports
 def __call__(self, request, url):
     """Defines "*/fetch" page which starts the import procedure and shows the result status."""
     if url and url.endswith('fetch'):
         pk = url.split('/')[-2]
         server = get_cached_object_or_404(Server, pk=pk)
         try:
             server.fetch()
             return http.HttpResponse('OK')
         except Exception, e:
             return http.HttpResponse('KO ' + str(e))
예제 #2
0
파일: admin.py 프로젝트: whit/ella
 def __call__(self, request, url):
     """Defines "*/fetch" page which starts the import procedure and shows the result status."""
     if url and url.endswith('fetch'):
         pk = url.split('/')[-2]
         server = get_cached_object_or_404(Server, pk=pk)
         try:
             server.fetch()
             return http.HttpResponse('OK')
         except Exception, e:
             return http.HttpResponse('KO ' + str(e))
예제 #3
0
파일: views.py 프로젝트: dhruvAdhia/ella
def add_post(content, thread, user = False, nickname = False, email = '', ip='0.0.0.0', parent = None):
    """
    PARAMS
    content: post content
    thread: TopicThread instance
    ip: IP address
    """
    # invalidate cached thread posts
    delete_cached_object(get_key_comments_on_thread__by_submit_date(None, thread))
    delete_cached_object(get_key_comments_on_thread__spec_filter(None, thread))

    content = filter_banned_strings(content)
    comment_set = get_comments_on_thread(thread).order_by('-parent')
    CT_THREAD = ContentType.objects.get_for_model(TopicThread)

    if comment_set.count() > 0 and not parent:
        parent = comment_set[0]
    elif parent:
        parent = get_cached_object_or_404(Comment, pk = parent)

    if (user):
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            user=user,
)

        cmt.save()

        # post is viewed by its autor
        make_objects_viewed(user, (cmt,))

    elif nickname:
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            nickname=nickname,
            email=email,
)

        cmt.save()

    else:
        raise Exception("Either user or nickname param required!")
예제 #4
0
def add_post(content, thread, user = False, nickname = False, email = '', ip='0.0.0.0', parent = None):
    """
    PARAMS
    content: post content
    thread: TopicThread instance
    ip: IP address
    """
    # invalidate cached thread posts
    delete_cached_object(get_key_comments_on_thread__by_submit_date(None, thread))
    delete_cached_object(get_key_comments_on_thread__spec_filter(None, thread))

    content = filter_banned_strings(content)
    comment_set = get_comments_on_thread(thread).order_by('-parent')
    CT_THREAD = ContentType.objects.get_for_model(TopicThread)

    if comment_set.count() > 0 and not parent:
        parent = comment_set[0]
    elif parent:
        parent = get_cached_object_or_404(Comment, pk = parent)

    if (user):
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            user=user,
        )

        cmt.save()

        # post is viewed by its autor
        make_objects_viewed(user, (cmt,))

    elif nickname:
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            nickname=nickname,
            email=email,
        )

        cmt.save()

    else:
        raise Exception("Either user or nickname param required!")
예제 #5
0
파일: feeds.py 프로젝트: rpgplanet/ella
    def get_object(self, bits):
        try:
            ct = get_content_type(bits[-1])
            bits = bits[:-1]
        except (Http404, IndexError):
            ct = False

        if bits:
            cat = get_cached_object_or_404(Category, tree_path=u'/'.join(bits), site__id=settings.SITE_ID)
        else:
            cat = get_cached_object(Category, tree_parent__isnull=True, site__id=settings.SITE_ID)

        if ct:
            return (cat, ct)
        return cat
예제 #6
0
파일: feeds.py 프로젝트: whit/ella
    def get_object(self, bits):
        try:
            ct = get_content_type(bits[-1])
            bits = bits[:-1]
        except (Http404, IndexError):
            ct = False

        if bits:
            cat = get_cached_object_or_404(Category, tree_path=u'/'.join(bits), site__id=settings.SITE_ID)
        else:
            cat = get_cached_object(Category, tree_parent__isnull=True, site__id=settings.SITE_ID)

        if ct:
            return (cat, ct)
        return cat
예제 #7
0
파일: views.py 프로젝트: chewable/ella
def send_it(custom_message, sender_name, sender_mail, target_object, recipient_mail):

    site = get_cached_object_or_404(Site, pk=settings.SITE_ID)

    mail_body = render_to_string(['page/sendmail/mail-body.html'], {
        'custom_message' : custom_message,
        'sender_name' : sender_name,
        'sender_mail' : sender_mail,
        'object' : target_object,
        'site' : site})
    mail_subject = render_to_string(['page/sendmail/mail-subject.html'], {
        'sender_name' : sender_name,
        'sender_mail' : sender_mail,
        'object' : target_object,
        'site' : site})
    mail.send_mail(
        subject=mail_subject.strip(),
        message=mail_body,
        from_email=sender_mail,
        recipient_list=[recipient_mail])
예제 #8
0
파일: views.py 프로젝트: whit/ella
def send_it(custom_message, sender_name, sender_mail, target_object, recipient_mail):

    site = get_cached_object_or_404(Site, pk=settings.SITE_ID)

    mail_body = render_to_string(['page/sendmail/mail-body.html'], {
        'custom_message' : custom_message,
        'sender_name' : sender_name,
        'sender_mail' : sender_mail,
        'object' : target_object,
        'site' : site})
    mail_subject = render_to_string(['page/sendmail/mail-subject.html'], {
        'sender_name' : sender_name,
        'sender_mail' : sender_mail,
        'object' : target_object,
        'site' : site})
    mail.send_mail(
        subject=mail_subject.strip(),
        message=mail_body,
        from_email=sender_mail,
        recipient_list=[recipient_mail])
예제 #9
0
파일: views.py 프로젝트: dhruvAdhia/ella
def post_reply(request, context, reply, thread):
    """new reply to a post in the thread"""


    if not settings.DEBUG and not request.is_ajax():
        raise Http404, "Accept only AJAX calls."

    thr = TopicThread.objects.get(slug = thread)
    thread_url = '%s?p=%i' % (thr.get_absolute_url(), int(float(thr.num_posts+1)/DISCUSSIONS_PAGINATE_BY + 0.9999))

    init_props = {}
    init_props['options'] = FORM_OPTIONS['UNAUTHORIZED_ONLY']
    user = get_user(request)
    if user.is_authenticated():
        init_props['nickname'] = user.username
        init_props['email'] = user.email

    if reply:
        parent = get_cached_object_or_404(Comment, pk=reply)
        init_props['target'] = '%d:%d' % (parent.target_ct.id, parent.target.id)
        init_props['parent'] = reply
        context.update ({
                'reply' : True,
               'parent' : parent,
})
        form = CommentForm(init_props=init_props)
    else:
        ct = ContentType.objects.get_for_model(TopicThread)
        init_props['target'] = '%d:%d' % (ct.id, thr.id)
        form = PostForm(initial=init_props)


    context['form'] = form
    context['form_action'] = thread_url
    return render_to_response(
        ('common/page/discussions/form.html',),
        context,
        context_instance=RequestContext(request)
)
예제 #10
0
def post_reply(request, context, reply, thread):
    """new reply to a post in the thread"""


    if not settings.DEBUG and not request.is_ajax():
        raise Http404, "Accept only AJAX calls."

    thr = TopicThread.objects.get(slug = thread)
    thread_url = '%s?p=%i' % (thr.get_absolute_url(), int(float(thr.num_posts+1)/DISCUSSIONS_PAGINATE_BY + 0.9999))

    init_props = {}
    init_props['options'] = FORM_OPTIONS['UNAUTHORIZED_ONLY']
    user = get_user(request)
    if user.is_authenticated():
        init_props['nickname'] = user.username
        init_props['email'] = user.email

    if reply:
        parent = get_cached_object_or_404(Comment, pk=reply)
        init_props['target'] = '%d:%d' % (parent.target_ct.id, parent.target.id)
        init_props['parent'] = reply
        context.update ({
                'reply' : True,
               'parent' : parent,
        })
        form = CommentForm(init_props=init_props)
    else:
        ct = ContentType.objects.get_for_model(TopicThread)
        init_props['target'] = '%d:%d' % (ct.id, thr.id)
        form = PostForm(initial=init_props)


    context['form'] = form
    context['form_action'] = thread_url
    return render_to_response(
        ('common/page/discussions/form.html',),
        context,
        context_instance=RequestContext(request)
    )
예제 #11
0
파일: views.py 프로젝트: ella/ella-taggit
 def get_queryset(self, **kwargs):
     self.tag = get_cached_object_or_404(PublishableTag, slug=self.kwargs['tag'])
     return publishables_with_tag(self.tag, filters=kwargs)
예제 #12
0
def record_hit(request, publishable_id):
    p = get_cached_object_or_404(Publishable, pk=publishable_id)
    HitCount.objects.hit(p)
    return HttpResponse(status=204)