コード例 #1
0
ファイル: views.py プロジェクト: linlihai/pyblog
def post(request, slug):
    try:
        db_blog = Posts.objects.get(slug=slug)
    except:
        db_blog = None
    if db_blog:
        db_blog.tag_set.all().delete()
    form = PostsForm(request.POST, instance=db_blog)
    ##print( "content %s" % request.POST.get("content"))
    if form.is_valid():
        blog_post = form.save(commit=False)
        blog_post.mark_down = blogContentRender(blog_post.content)
        tags = blog_post.tags.split(',')
        blog_post.save()
        for tag in tags:
            t = Tags()
            t.post = Posts.objects.get(slug=blog_post.slug)
            t.name = tag.strip()
            t.save()
        form.save_m2m()
        return HttpResponseRedirect("/")
    c = {"form": form, "slug": slug}
    c.update(csrf(request))
    t = get_template("publish.html")
    return HttpResponse(t.render(Context(c)))
コード例 #2
0
ファイル: views.py プロジェクト: qiankai/cms
def insert(request):
    status = None
    if request.method == 'POST':
        # save new post
        Usr_Name = request.POST.get('name', '')
        Usr_Mobile = request.POST.get('mobile', '')
        Usr_Remark = request.POST.get('remark', '')
        tags = request.POST.get('tags', '')
        pre_id = request.POST.get('pre_id', '')
        p_uuid = uuid.uuid1()
        p = People(
            Usr_Name=Usr_Name,
            Usr_Mobile=Usr_Mobile,
            Usr_Remark=Usr_Remark,
            active=0,
            isdel=0,
            uuid=p_uuid,
        )
        p.save()

        for tag in tags.replace(u',', ',').split(','):
            try:
                t = Tags.objects.get(tag=tag)
            except Tags.DoesNotExist:
                newtag = Tags(tag=tag)
                newtag.save()
                p.tags.add(newtag)
                p.save()
            else:
                p.tags.add(t)
                p.save()
        if request.user.is_superuser:
            status = "ok"
            p.Cluster_id = 0
            p.save()
            return render_to_response('usernet/index.html', {
                'status': status,
            },
                                      context_instance=RequestContext(request))
        if pre_id == '':
            pre_id = request.user
        if pre_id != '':
            try:
                pre = People.objects.filter(Usr_Mobile=pre_id, active=1)
            except People.DoesNotExist:
                print "error"
            else:
                p.Prev_Usr = pre[0]
                p.Cluster_id = pre[0].Cluster_id
                p.save()
        status = "ok"
    # Get all posts from DB
    return render_to_response('usernet/index.html', {
        'status': status,
    },
                              context_instance=RequestContext(request))
コード例 #3
0
def getTagId(ro, ru, key):
    ob = Tags.objects(select=key, ro=ro)
    if ob:
        return ob.get().clean_data()['_id']
    new_Tags = {
        "select": key,
        "ro": ro,
        "ru": ru,
        "en": "-",
        "is_active": True
    }
    comment = Tags(**new_Tags)
    comment.save()
    return comment.clean_data()['_id']
コード例 #4
0
def registerTag(requestjson, created_by):
    """create a new user"""
    new_Tags = requestjson
    if len(created_by) > 30:
        user = Operator.verify_auth_token(created_by)
        created_by = user.get().clean_data()['email']
    # TODO: get authenticated operator and assignee to new Tags
    # new_Tags["created_by"] = authenticated_oprator
    try:
        new_Tags['created_by'] = created_by  #g.user.get().clean_data()['_id']
        comment = Tags(**new_Tags)
        comment.save()
        return jsonify({"response": "success", 'user': comment.clean_data()})
    except Exception as error:
        return jsonify({"error": str(error)}), 400
コード例 #5
0
ファイル: views.py プロジェクト: qiankai/cms
def update(request):
    if request.method == 'GET':
        pid = request.GET.get('id')
        p = People.objects.get(id=pid)
        tags = p.tags.all()
        tag = []
        ta = ''
        for i in tags:
            tag.append(i.tag)
            ta = ta + i.tag + ','
        return render_to_response('usernet/update.html', {
            'person': p,
            'tags': tag,
            'ta': ta,
        },
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        pid = request.POST.get('id')
        Usr_Name = request.POST.get('name', '')
        Usr_Mobile = request.POST.get('mobile', '')
        Usr_Remark = request.POST.get('remark', '')
        tags = request.POST.get('tags', '')
        pre_id = request.POST.get('pre_id', '')

        p = People.objects.get(id=pid)
        p.Usr_Name = Usr_Name
        p.Usr_Mobile = Usr_Mobile
        p.Usr_Remark = Usr_Remark
        for tag in tags.replace(u',', ',').split(','):
            try:
                t = Tags.objects.get(tag=tag)
            except Tags.DoesNotExist:
                newtag = Tags(tag=tag)
                newtag.save()
                p.tags.add(newtag)
                p.save()
            else:
                p.tags.add(t)
                p.save()

        status = "Update " + p.Usr_Name + " successfully!"
        status_code = 1
        return render_to_response('usernet/message.html', {
            'status': status,
            'status_code': status_code,
        },
                                  context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: qiankai/cms
def insert(request):
    status=None
    if request.method == 'POST':
       # save new post
       Usr_Name = request.POST.get('name','')
       Usr_Mobile = request.POST.get('mobile','')
       Usr_Remark = request.POST.get('remark','')
       tags = request.POST.get('tags','')
       pre_id = request.POST.get('pre_id','')
       p_uuid = uuid.uuid1()
       p = People(Usr_Name = Usr_Name,Usr_Mobile = Usr_Mobile,Usr_Remark=Usr_Remark,active = 0,isdel = 0,uuid = p_uuid,)
       p.save()

       for tag in tags.replace(u',',',').split(','):
           try:
               t = Tags.objects.get(tag = tag)
           except Tags.DoesNotExist:
               newtag = Tags(tag=tag)
               newtag.save()
               p.tags.add(newtag)
               p.save()
           else:
               p.tags.add(t)
               p.save()
       if request.user.is_superuser:
           status="ok"
           p.Cluster_id = 0
           p.save()
           return render_to_response('usernet/index.html', {'status':status,},
                              context_instance=RequestContext(request))
       if pre_id =='':
           pre_id = request.user
       if pre_id != '':
           try:
               pre = People.objects.filter(Usr_Mobile = pre_id,active = 1)
           except People.DoesNotExist:
               print "error"
           else:
               p.Prev_Usr=pre[0]
               p.Cluster_id = pre[0].Cluster_id
               p.save()
       status="ok"
    # Get all posts from DB
    return render_to_response('usernet/index.html', {'status':status,},
                              context_instance=RequestContext(request))
コード例 #7
0
ファイル: views.py プロジェクト: qiankai/cms
def update(request):
    if request.method == 'GET':
        pid = request.GET.get('id')
        p = People.objects.get(id = pid)
        tags = p.tags.all()
        tag=[]
        ta = ''
        for i in tags:
            tag.append(i.tag)
            ta = ta+ i.tag+','
        return render_to_response('usernet/update.html',{'person':p ,'tags':tag,'ta':ta,},
                              context_instance=RequestContext(request))
    if request.method == 'POST':
        pid = request.POST.get('id')
        Usr_Name = request.POST.get('name','')
        Usr_Mobile = request.POST.get('mobile','')
        Usr_Remark = request.POST.get('remark','')
        tags = request.POST.get('tags','')
        pre_id = request.POST.get('pre_id','')


        p = People.objects.get(id = pid)
        p.Usr_Name =Usr_Name
        p.Usr_Mobile = Usr_Mobile
        p.Usr_Remark = Usr_Remark
        for tag in tags.replace(u',',',').split(','):
           try:
               t = Tags.objects.get(tag = tag)
           except Tags.DoesNotExist:
               newtag = Tags(tag=tag)
               newtag.save()
               p.tags.add(newtag)
               p.save()
           else:
               p.tags.add(t)
               p.save()

        status = "Update " + p.Usr_Name  + " successfully!"
        status_code = 1
        return render_to_response('usernet/message.html',{'status':status,'status_code':status_code,},
                              context_instance=RequestContext(request))
コード例 #8
0
def api_edit_blog(request, *, id, name, description, summary, content,
                  category_id, tags):
    check_admin(request)
    if not name or not name.strip():
        raise APIValueError('name', 'name can not be empty')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary can not be empty')
    if not content or not content.strip():
        raise APIValueError('content', 'content can not be empty')
    #blog = Blog(user_id = request.__user__.id, user_name= request.__user__.name, user_image = request.__user__.image, name = name.strip(), summary = summary.strip(), content = content.strip())
    blog = yield from Blog.find(id)
    if not blog:
        raise APIValueError('id', 'request path error, id : {}'.format(id))

    category = yield from Category.find(category_id)
    if category:
        #raise APIValueError('category', 'can not find category, category_id:{}'.format(category_id))
        category_id = category.id
        category_name = category.name
    else:
        category_name = ''

    tag_ids = []
    if len(tags) > 0:
        for tag in tags:
            if tag["key"]:
                rs = yield from Tags.find(tag["key"])
                if rs:
                    tag_ids.append(rs.id)
            else:
                rs = yield from Tags.find_all("name=?", [tag["value"]])
                if len(rs) > 0:
                    tag_ids.append(rs[0].id)
                else:  #create new tag
                    tag = Tags(name=tag["value"])
                    rows, lastrowid = yield from tag.save()
                    tag_ids.append(lastrowid)

    blog.name = name
    blog.description = description
    blog.summary = summary
    blog.content = content
    blog.category_id = category_id
    blog.category_name = category_name
    blog.tags = ",".join([str(id) for id in tag_ids])
    blog.updated_at = time.time()
    yield from blog.update()
    return blog
コード例 #9
0
ファイル: views.py プロジェクト: guowei1003/Aboutme
def add_article(request):
    """提交文章"""
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        vsip =  request.META['HTTP_X_FORWARDED_FOR']
    else:
        vsip = request.META['REMOTE_ADDR']

    blog_title = request.POST.get("blog_title","")#根据标题判断是访问还是新增

    if blog_title:
        blog_content = request.POST.get("blog_content","")
        blog_quote = eval(request.POST.get("blog_quote",""))
        blog_class = request.POST.get("blog_class","")
        blog_tags = eval(request.POST.get("blog_tags",""))
        # print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^66"
        # print blog_title
        # print blog_content
        # print blog_quote
        # print blog_class
        # print blog_tags,"|",type(blog_tags)
        # print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
        if not blog_content or not blog_quote or not blog_class or not blog_title:
            return HttpResponse(json.dumps({"status":"1","messages":"parameter error"}), content_type="application/json")
        if blog_quote["sign"] == "C":
            cornerite = "C"
        else:
            cornerite = ""
        # print "***********************************"
        # print blog_title
        # print blog_content
        # print blog_quote
        # print blog_class
        # print blog_tags
        # print "***********************************"
        author = Author.objects.get(author_name="guowei1003")
        NewArticle = Article(
                             title=blog_title,
                             author=author,
                             location="北京",
                             quote=blog_quote["quote_url"],
                             article_class=blog_class,
                             article_lead=blog_content,
                             article_reads='0',
                             article_likes='0',
                             article_collects='0',
                             cornerite=cornerite
                             )
        NewArticle.save()
        for tag in blog_tags:
            try:
                mtag = Tags.objects.get(tag=tag)
            except:
                mtag = Tags(tag=tag)
                mtag.save()
            NewArticle.article_tags.add(mtag)
        return HttpResponse(json.dumps({"status":"0"}), content_type="application/json")
    else:
        ClassList = {}
        AllTags = Tags.objects.all()[:50]
        AllClass = Article.objects.values("article_class")
        for c in AllClass:
            if c["article_class"] in ClassList:
                ClassList[c["article_class"]] +=1
            else:
                ClassList[c["article_class"]] = 1
        title = "撰写博文"
        return render_to_response("blog/blog_addarticle.html",locals())