示例#1
0
def Add_groupnote(request, g_id):
    if request.user.is_authenticated():
        form = Add_noteForm()
        username = request.user.username
        count_invation = Invatation.objects.filter(user_to__exact = username).filter(read = False).count()
        count_notice = Notice.objects.filter(owner__exact = username).filter(read_mark = False).count()
        try:
            g_id = int(g_id)
        except ValueError:
            raise Http404()
        group = Group.objects.filter(id__exact = g_id)[0]
        group.count_note += 1
        group.save()
        if request.POST:
                post = request.POST
                if post["title"] and post["content"]:
                    new_note = Note(author = username,
                                    title = post["title"],
                                    content = post["content"],
                                    belong = None)
                    new_note.group = group
                    temp = post["content"]
                    new_note.contentText = dehtml(temp)
                    tags = jieba.analyse.extract_tags(new_note.contentText, topK=3)
                    new_note.tag1 = ""
                    new_note.tag2 = ""
                    new_note.tag3 = ""
                    if len(tags)==1:
                        new_note.tag1 = tags[0]
                    elif len(tags)==2:
                        new_note.tag1 = tags[0]
                        new_note.tag2 = tags[1] 
                    elif len(tags)==3:
                        new_note.tag1 = tags[0]
                        new_note.tag2 = tags[1]
                        new_note.tag3 = tags[2]
                    src = new_note.title.encode('gb2312')
                    md5 = hashlib.md5()
                    md5.update(src)
                    new_note.md5 = md5.hexdigest()[:10]
                    new_note.save()
                    group_log = Group_log.objects.create(group = group,
                                                 character = username,
                                                 event = u'添加了小组笔记 —— %s' % post["title"])
                    group_log.save()
                    return HttpResponseRedirect('/confirm_keyword_g/%d/%s/%s/' % (g_id,str(new_note.id),str(new_note.md5)))
        return render_to_response("add_groupnote.html",locals())
    else:
        return HttpResponseRedirect('/welcome/')
示例#2
0
def add_note(request,q):
    form = Add_noteForm()
    if request.user.is_authenticated():
        username = request.user.username
        count_invation = Invatation.objects.filter(user_to__exact = username).filter(read = False).count()
        count_notice = Notice.objects.filter(owner__exact = username).filter(read_mark = False).count()
        branch = MPTTBranch.objects.filter(m_author=username)
        all_branch = []
        for b in branch:
            path = '\\%s' % b.name
            if b.parent == None:
                tup = branch_tuple(b.id,path)
                all_branch.append(tup)
            else:
                temp = b
                while temp.parent:
                    temp = temp.parent
                    path = '\\%s' % temp.name + path
                tup = branch_tuple(b.id,path)
                all_branch.append(tup)
        if request.POST:
                post = request.POST
                if post["title"] and post["content"]:
                    if q != 'undefined':
                        b = MPTTBranch.objects.get(name=q,m_author=username)
                        b.note_count += 1
                        b.save()
                        new_note = Note(
                            author = username,
                            title = post["title"],
                            content = post["content"],
                            belong = b
                            )
                    else:
                        if(post["bran"] == "undefined"):
                            b = None
                        else:
                            b = MPTTBranch.objects.get(id=post["bran"])
                            b.note_count += 1
                            b.save()
                        new_note = Note(
                            author = username,
                            title = post["title"],
                            content = post["content"],
                            belong = b
                            )
                    if post["visiable"] == 'T':
                        new_note.visiable = True
                    if post["visiable"] == 'F':
                        new_note.visiable = False
                    temp = post["content"]
                    new_note.contentText = dehtml(temp)
                    tags = jieba.analyse.extract_tags(new_note.contentText, topK=3)
                    new_note.tag1 = ""
                    new_note.tag2 = ""
                    new_note.tag3 = ""
                    if len(tags)==1:
                        new_note.tag1 = tags[0]
                    elif len(tags)==2:
                        new_note.tag1 = tags[0]
                        new_note.tag2 = tags[1] 
                    elif len(tags)==3:
                        new_note.tag1 = tags[0]
                        new_note.tag2 = tags[1]
                        new_note.tag3 = tags[2]
                    src = new_note.title.encode('gb2312')
                    md5 = hashlib.md5()
                    md5.update(src)
                    new_note.md5 = md5.hexdigest()[:10] 
                    new_note.save()
                    url = '/confirm_keyword/'+str(new_note.id)+'/'+str(new_note.md5)
                    return HttpResponseRedirect(url)
        return render_to_response("add_note.html",locals())
    else:
        return HttpResponseRedirect('/welcome/')