Ejemplo n.º 1
0
def add(request):
    current_page = 'topic'
    title = '发起新话题'
    """
    写新的话题
    """

    form_action = '/topic/add/'
    if request.method == 'GET':
        form = TopicForm()
        return render('topic_edit.html',locals(),context_instance=RequestContext(request))

    form = TopicForm(request.POST)
    if form.is_valid():
        data = form.clean()
        new_topic = Topic(**data)
        new_topic.author = request.user
        new_topic.latest_response = datetime.datetime.now()
        new_topic.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
        try:
            new_topic.save()
        except Exception,e:
            messages.error(request,'服务器出现了错误,发表话题失败,请稍候重试')
            return render('topic_edit.html',locals(),context_instance=RequestContext(request))
        else:
            print 3
            #发送信号
            new_topic_was_posted.send(
                sender = new_topic.__class__,
                topic = new_topic
            )
        return HttpResponseRedirect('/topic/{0}/'.format(new_topic.id))
Ejemplo n.º 2
0
def add(request):
    current_page = 'topic'
    title = '发起新话题'
    """
    写新的话题
    """

    form_action = '/topic/add/'
    if request.method == 'GET':
        form = TopicForm()
        return render('topic_edit.html',
                      locals(),
                      context_instance=RequestContext(request))

    form = TopicForm(request.POST)
    if form.is_valid():
        data = form.clean()
        new_topic = Topic(**data)
        new_topic.author = request.user
        new_topic.latest_response = datetime.datetime.now()
        new_topic.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
        try:
            new_topic.save()
        except Exception, e:
            messages.error(request, '服务器出现了错误,发表话题失败,请稍候重试')
            return render('topic_edit.html',
                          locals(),
                          context_instance=RequestContext(request))
        else:
            print 3
            #发送信号
            new_topic_was_posted.send(sender=new_topic.__class__,
                                      topic=new_topic)
        return HttpResponseRedirect('/topic/')
Ejemplo n.º 3
0
def add(request):
    current_page = 'topic'
    title = '发起新话题'
    """
    写新的话题
    """
   #########################################################################################
    # 用户操作行为安全保护

    # 计时器
    timer = time.time() - request.session.get('time_stamp',0)

    # 危险操作次数
    action_times = request.session.get('action_times',0)

    # 错误次数是否大于最大
    if action_times >= 2:
        if not check_verify(request):
            messages.error(request,'你的输入不正确')
            return render('verify.html',locals(),context_instance=RequestContext(request))
        else:

            # 重置标志位
            reset(request)

    elif timer > 60:
        # 重置标志位
        reset(request)
    #########################################################################################

    form_action = '/topic/add/'
    # 处理GET请求
    if request.method == 'GET':
        form = TopicForm()
        return render('topic_edit.html',locals(),context_instance=RequestContext(request))

    # 处理POST请求
    set(request) # 记录用户操作次数
    form = TopicForm(request.POST)
    if form.is_valid():
        data = form.clean()
        new_topic = Topic()
        new_topic.author = request.user
        new_topic.title = data['title']
        new_topic.latest_response = datetime.datetime.now()
        new_topic.content = data['content']
        new_topic.ip = request.META['REMOTE_ADDR']
        try:
            new_topic.save()
        except Exception,e:
            messages.error(request,'服务器出现了错误,发表话题失败,请稍候重试')
            return render('topic_edit.html',locals(),context_instance=RequestContext(request))
        else:
            #发送信号
            new_topic_was_posted.send(
                sender = new_topic.__class__,
                topic = new_topic
            )
        return HttpResponseRedirect('/topic/')
Ejemplo n.º 4
0
def add(request):
    current_page = 'topic'
    title = '发起新话题'
    """
    写新的话题
    """

    form_action = '/topic/add/'
    if request.method == 'GET':
        form = TopicForm()
        return render('topic_edit.html',
                      locals(),
                      context_instance=RequestContext(request))

    form = TopicForm(request.POST)
    if form.is_valid():
        data = form.clean()
        new_topic = Topic(**data)
        new_topic.author = request.user
        new_topic.latest_response = datetime.datetime.now()
        new_topic.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
        try:
            new_topic.save()
        except Exception, e:
            messages.error(request, '服务器出现了错误,发表话题失败,请稍候重试')
            return render('topic_edit.html',
                          locals(),
                          context_instance=RequestContext(request))
        else:
            # 发送增加声望的信号
            update_user_repulation.send(
                sender=__name__,
                request=request,
                user=request.user,
                action='add',
                content_type='topic',
                message=u'发起新话题成功',
                title=new_topic.title,
                url=new_topic.get_absolute_url(),
            )

            #发送信号
            new_topic_was_posted.send(sender=new_topic.__class__,
                                      topic=new_topic)
        return HttpResponseRedirect('/topic/{0}/'.format(new_topic.id))
Ejemplo n.º 5
0
def add(request):
    current_page = 'topic'
    title = '发起新话题'
    """
    写新的话题
    """
    #########################################################################################
    # 用户操作行为安全保护

    # 计时器
    timer = time.time() - request.session.get('time_stamp', 0)

    # 危险操作次数
    action_times = request.session.get('action_times', 0)

    # 错误次数是否大于最大
    if action_times >= 2:
        if not check_verify(request):
            messages.error(request, '你的输入不正确')
            return render('verify.html',
                          locals(),
                          context_instance=RequestContext(request))
        else:

            # 重置标志位
            reset(request)

    elif timer > 60:
        # 重置标志位
        reset(request)
    #########################################################################################

    form_action = '/topic/add/'
    # 处理GET请求
    if request.method == 'GET':
        form = TopicForm()
        return render('topic_edit.html',
                      locals(),
                      context_instance=RequestContext(request))

    # 处理POST请求
    set(request)  # 记录用户操作次数
    form = TopicForm(request.POST)
    if form.is_valid():
        data = form.clean()
        new_topic = Topic()
        new_topic.author = request.user
        new_topic.title = data['title']
        new_topic.latest_response = datetime.datetime.now()
        new_topic.content = data['content']
        new_topic.ip = request.META['REMOTE_ADDR']
        try:
            new_topic.save()
        except Exception, e:
            messages.error(request, '服务器出现了错误,发表话题失败,请稍候重试')
            return render('topic_edit.html',
                          locals(),
                          context_instance=RequestContext(request))
        else:
            #发送信号
            new_topic_was_posted.send(sender=new_topic.__class__,
                                      topic=new_topic)
        return HttpResponseRedirect('/topic/')