예제 #1
0
파일: views.py 프로젝트: tikonen/pullaclub
def iframe(request):

    if request.method == 'GET':
        return render_to_response('members/comment_iframe.html')

    message = request.POST['message']     # new comment
    if not message:
        return render_to_response('members/comment_iframe.html')

    update = Comment()
    message = message[:Comment.MAX_LENGTH]

    if 'poll' in request.POST and request.POST['poll'] == 'on':  # this is poll
        #import pdb
        #pdb.set_trace()
        # convert message list items to poll json structure if possible
        (message, polld) = _parse_poll_choices(message)
        if len(polld) > 0:
            update.poll = simplejson.dumps(polld)

    update.user = request.user
    update.message = message
    update.bysource = Comment.BY_WEB
    if len(request.FILES) > 0:
        # save uploaded file
        uploaded_file = request.FILES['image0']
        update.image0.save(uploaded_file.name, uploaded_file)

    update.save()
        
    return render_to_response('members/comment_iframe.html', {
            'user': request.user,
            'view_list': [ { 'rootcomment': update } ],
            })
예제 #2
0
파일: api.py 프로젝트: tikonen/pullaclub
def api_comment(request, action, comment_id):

    comment_id = int(comment_id)

    if action == 'new':
        # new comment
        if request.method == 'POST':
            message = request.POST['message']
            if not message:
                raise Http404
            message = message[:Comment.MAX_LENGTH]

            if len(message) is 0:
                raise Http404

            comment = Comment()
            comment.user = request.user
            comment.message = message
            comment.bysource = Comment.BY_API
            if comment_id is not 0:
                comment.parent = get_object_or_404(Comment,pk=comment_id)
            comment.save()
            
            response_dict = {
                'id' :  comment.id,
                'status': 'new',
                }

            return HttpResponse(simplejson.dumps(response_dict), 
                                mimetype='application/javascript')

    elif action == 'delete':
        comment = get_object_or_404(Comment,pk=comment_id,user=request.user)

        if len(Comment.objects.filter(parent=comment)) == 0: # root comment
            comment.delete()
            response_dict = {
                'status' :  'remove',
                }
        else:
            comment.message = "This comment has been deleted"
            comment.image0 = None
            comment.save()
            response_dict = {
                'status' :  'update',
                'message' : comment.message,
                }

        return HttpResponse(simplejson.dumps(response_dict), 
                            mimetype='application/javascript')

    raise Http404
예제 #3
0
    if message_count == 0: # nothing to do
        mlog.info('no messages')
        mailbox.quit()
        return

    mlog.info('processing %s messages',message_count)

    for message in mailbox.list()[1]:
        idx,_ = message.split()
        resp = mailbox.retr(idx)
        
        if dumpOnly:
            dump_mail(resp[1],idx)  # debug
            continue

        newcomment = Comment()

        parsedmsg = email.message_from_string('\n'.join(resp[1]))
        (subject, enc) = decode_header(parsedmsg['Subject'])[0]

        if enc is None:
            enc = 'ascii'
        if subject is None:
            subject = ''
        else:
            subject = unicode(subject,enc)

        sender = parsedmsg['From']
        if parsedmsg['X-Razor'] == 'SPAM': # spam message in dreamhost
            mlog.info('deleting spam message from %s',sender)
            mailbox.dele(idx)
예제 #4
0
파일: views.py 프로젝트: tikonen/pullaclub
def comment(request, action, comment_id):

    if action == 'new' or action == 'edit':

        # new comment
        if request.method == 'POST':
            message = request.POST['message']
            if not message:
                raise Http404
            message = message[:Comment.MAX_LENGTH]

            if action == 'edit':
                if request.user.is_staff:
                    comment = get_object_or_404(Comment,pk=comment_id)
                else:
                    comment = get_object_or_404(Comment,pk=comment_id,user=request.user)
                comment.message = message
                comment.save()
            else: # new comment
                comment = Comment()
                comment.user = request.user
                comment.message = message
                comment.bysource = Comment.BY_WEB
                comment.parent = get_object_or_404(Comment,pk=comment_id)
                comment.save()

            t = loader.get_template('members/sub_comment.html')
            c = Context({
                    'user' : request.user,
                    'comment': comment,
                    })
            response_dict = {
                'url' : request.user.get_profile().user_image.url,
                'description' : request.user.get_profile().description,
                'fullname' : request.user.get_full_name(),
                'message' : comment.message,
                'id' :  comment.parent.id,
                'status': 'new',
                'render' : t.render(c),
                }
                
            return HttpResponse(simplejson.dumps(response_dict), 
                                mimetype='application/javascript')

    elif action == 'delete':
        comment = get_object_or_404(Comment,pk=comment_id,user=request.user)

        if len(Comment.objects.filter(parent=comment)) == 0: # root comment
            comment.delete()
            response_dict = {
                'status' :  'remove',
                }
        else:
            comment.message = "This comment has been deleted"
            comment.image0 = None
            comment.save()
            response_dict = {
                'status' :  'update',
                'message' : comment.message,
                }

        return HttpResponse(simplejson.dumps(response_dict), 
                                mimetype='application/javascript')

    elif action == 'deleteimg':
        comment = get_object_or_404(Comment,pk=comment_id,user=request.user)
        comment.image0 = None
        comment.save()
        response_dict = {
                'status' :  'OK',
        }
        return HttpResponse(simplejson.dumps(response_dict), 
                                mimetype='application/javascript')

    raise Http404