Exemple #1
0
def index(request):
    current_page = 'index'
    page_title = u'首页'
    topics = Topic.objects.filter(deleted=False).order_by('-id')[0:16]
    codes = Base.objects.filter(display=True).order_by('-id')[0:20]
    jobs = Job.objects.order_by('-sub_time').filter(
        display=True).order_by('-id')[0:15]
    wiki_first = Entry.objects.filter(public=True).order_by('-sub_time')[0]
    wiki_second = Entry.objects.filter(public=True).order_by('-sub_time')[1]
    wikis = Entry.objects.filter(public=True).exclude(
        id__in=[wiki_first.id, wiki_second.id]).order_by('-id')[0:20]

    from accounts.signals import update_user_repulation
    from django.contrib.auth.models import User
    update_user_repulation.send(
        sender=__name__,
        user=User.objects.get(pk=1),
        action='add',
        content_type='wiki',
        title='test signal',
        message=u'分享文章成功',
        url='/',
        request=request,
    )
    return render('index.html',
                  locals(),
                  context_instance=RequestContext(request))
Exemple #2
0
def delete(request,wiki_id):
    """
    用户删除文章

    """
    try:
        wiki = Entry.objects.get(id=wiki_id,author=request.user)
        wiki_title = wiki.title
    except Entry.DoesNotExist:
        raise Http404()

    if request.user == wiki.author:
        try:
            wiki.delete()
            # 扣除声望
            profile = request.user.get_profile()
            profile.score -= 15
            profile.save()
        except Exception,e:
            pass
        else:
            # 发送增加声望的信号
            update_user_repulation.send(
                    sender = __name__,
                    request = request,
                    message = u'删除文章成功',
                    user  = request.user,
                    action = 'delete',
                    content_type = 'wiki',
                    title  = wiki_title,
                    url    = '/',
            )
        return HttpResponseRedirect('/wiki/')
Exemple #3
0
def delete(request,wiki_id):
    """
    用户删除文章

    """
    try:
        wiki = Entry.objects.get(id=wiki_id,author=request.user)
        wiki_title = wiki.title
    except Entry.DoesNotExist:
        raise Http404()

    if request.user == wiki.author:
        try:
            wiki.delete()
            # 扣除声望
            profile = request.user.get_profile()
            profile.score -= 15
            profile.save()
        except Exception,e:
            pass
        else:
            # 发送增加声望的信号
            update_user_repulation.send(
                    sender = __name__,
                    request = request,
                    message = u'删除文章成功',
                    user  = request.user,
                    action = 'delete',
                    content_type = 'wiki',
                    title  = wiki_title,
                    url    = '/',
            )
        return HttpResponseRedirect('/wiki/')
Exemple #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))
Exemple #5
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))
Exemple #6
0
def index(request):
    current_page = 'index'
    page_title   = u'首页'
    topics       = Topic.objects.filter(deleted=False).order_by('-id')[0:16]
    codes        = Base.objects.filter(display=True).order_by('-id')[0:20]
    jobs         = Job.objects.order_by('-sub_time').filter(display=True).order_by('-id')[0:15]
    wiki_first   = Entry.objects.filter(public=True).order_by('-sub_time')[0]
    wiki_second  = Entry.objects.filter(public=True).order_by('-sub_time')[1]
    wikis        = Entry.objects.filter(public=True).exclude(id__in=[wiki_first.id,wiki_second.id]).order_by('-id')[0:20]


    from accounts.signals import update_user_repulation
    from django.contrib.auth.models import User
    update_user_repulation.send(
            sender = __name__,
            user  = User.objects.get(pk=1),
            action = 'add',
            content_type = 'wiki',
            title  = 'test signal',
            message = u'分享文章成功',
            url    = '/',
            request = request,
    )
    return render('index.html',locals(),context_instance=RequestContext(request))
Exemple #7
0
def add(request,editor='markdown'):
    """ 用户写新的文章 
    
    """

    current_page = 'user_wiki'

    if request.method == 'GET':
        backup_data = {}
        for k in ['title','content','md_content','source']:
            _k = 'backup_{}'.format(k)
            try:
                v = request.session.get(_k)
                backup_data[k] = v
            except:
                pass

        if editor == 'markdown':
            title = u'分享文章(使用MarkDown编辑器)'
            form = WikiMdForm()
            template = 'wiki_add_md.html'
        else:
            title = u'分享文章(使用富文本编辑器)'
            form = WikiForm()
            template = 'wiki_add.html'
        page_title = title
        form.initial = backup_data
        return render(template,locals(),context_instance=RequestContext(request))
    
    
    if editor == 'markdown':
        form = WikiMdForm(request.POST)
        tpl_name = 'wiki_add_md.html'
    else:
        form = WikiForm(request.POST)
        tpl_name = 'wiki_add.html'

    if form.is_valid():
        data = form.cleaned_data
        if not data.get('md_content') and not data.get('content'):
            messages.error(request,u'文章文章内容不能为空')
            return render(tpl_name,locals(),context_instance=RequestContext(request))

        new_wiki = Entry(**data)
        new_wiki.author = request.user
        
        try:
            new_wiki.save()
        except Exception,e:
            msg = u'保存文章时出错'
            log.error(msg + str(e.message ))
            return HttpResponse(msg)
        else:
            # 发送增加声望的信号
            update_user_repulation.send(
                    sender = __name__,
                    request = request,
                    message = u'分享文章成功',
                    user  = request.user,
                    action = 'add',
                    content_type = 'wiki',
                    title  = new_wiki.title,
                    url    = new_wiki.get_absolute_url(),
            )

            # 发送信号
            new_wiki_was_post.send(
                sender= new_wiki.__class__,
                wiki =  new_wiki,
            )

            # 清除备份数据
            _keys = request.session.keys()
            for k in ['title','content','md_content','source']:
                _k = 'backup_{}'.format(k)
                if _k in  _keys:
                    del request.session[_k]
            return HttpResponseRedirect('/wiki/%d/' %new_wiki.id)
Exemple #8
0
def add(request,editor='markdown'):
    """ 用户写新的文章 
    
    """

    current_page = 'user_wiki'

    if request.method == 'GET':
        backup_data = {}
        for k in ['title','content','md_content','source']:
            _k = 'backup_{}'.format(k)
            try:
                v = request.session.get(_k)
                backup_data[k] = v
            except:
                pass

        if editor == 'markdown':
            title = u'分享文章(使用MarkDown编辑器)'
            form = WikiMdForm()
            template = 'wiki_add_md.html'
        else:
            title = u'分享文章(使用富文本编辑器)'
            form = WikiForm()
            template = 'wiki_add.html'
        page_title = title
        form.initial = backup_data
        return render(template,locals(),context_instance=RequestContext(request))
    
    
    if editor == 'markdown':
        form = WikiMdForm(request.POST)
        tpl_name = 'wiki_add_md.html'
    else:
        form = WikiForm(request.POST)
        tpl_name = 'wiki_add.html'

    if form.is_valid():
        data = form.cleaned_data
        if not data.get('md_content') and not data.get('content'):
            messages.error(request,u'文章文章内容不能为空')
            return render(tpl_name,locals(),context_instance=RequestContext(request))

        new_wiki = Entry(**data)
        new_wiki.author = request.user
        
        try:
            new_wiki.save()
        except Exception,e:
            msg = u'保存文章时出错'
            log.error(msg + str(e.message ))
            return HttpResponse(msg)
        else:
            # 发送增加声望的信号
            update_user_repulation.send(
                    sender = __name__,
                    request = request,
                    message = u'分享文章成功',
                    user  = request.user,
                    action = 'add',
                    content_type = 'wiki',
                    title  = new_wiki.title,
                    url    = new_wiki.get_absolute_url(),
            )

            # 发送信号
            new_wiki_was_post.send(
                sender= new_wiki.__class__,
                wiki =  new_wiki,
            )

            # 清除备份数据
            _keys = request.session.keys()
            for k in ['title','content','md_content','source']:
                _k = 'backup_{}'.format(k)
                if _k in  _keys:
                    del request.session[_k]
            return HttpResponseRedirect('/wiki/%d/' %new_wiki.id)