コード例 #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
ファイル: mailimport.py プロジェクト: tikonen/pullaclub
            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)
            continue
        
        description = ''
        has_image = False

        mlog.info('processing message %s (%s)',sender,subject)
        
        newcomment.bysource = _resolve_by_source(parsedmsg)
        newcomment.bysource_detail = sender
        (owner, user, resolved) = _resolve_comment_owner(sender)
        newcomment.user = owner

        mlog.info('owner: %s, sender %s',owner.username,user.username)

        for msgpart in parsedmsg.walk():
            ctype = msgpart.get_content_type()

            if ctype == 'text/plain':
                description = msgpart.get_payload(decode=True)
                charset = msgpart.get_content_charset()
                if charset is not None:
                    description = unicode(description,charset)
                mlog.info('text/plain(%s) "%s"',charset,description)
コード例 #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