Example #1
0
def addTags():
    from models import User, Tags, db
    user = User.query.filter_by(email=session.get('emailId')).first_or_404()
    print(user.email)
    tag = request.form['done_btn1']

    print(tag.split(","))
    tags = tag.split(",")
    for tag in tags:
        db.session.add(Tags(tag_name=tag, user=user))
    db.session.commit()
    userTags1 = user.tags.all()

    for usertags in userTags1:
        print(usertags.tag_name + ", ")

    people = []
    for user1 in User.query.all():
        if user1.email != user.email:
            people.append(user1)

    return render_template('tagsAdded.html',
                           user=user,
                           tagsAdded=userTags1,
                           people=people)
Example #2
0
def submit_tag_form():
    tag_name = request.form["tag_name"]
    new_tag = Tags(name=tag_name)
    db.session.add(new_tag)
    db.session.commit()

    return redirect('/tags')
Example #3
0
def edit_post(id):

    form = PostForm()
    if users.is_current_user_admin() and form.validate_on_submit():
        try:
            tags = Tags()

            categories = Categories()

            updating_post = BlogPost.get(int(id))

            title = request.json['title']
            body = request.json['body']
            raw_category = request.json['category']
            editing_tags = request.json['tags']
            raw_summary = request.json['summary']

            tags_keys = tags.update(editing_tags, updating_post)

            category_key = categories.update(raw_category,
                                             updating_post.category)

            updating_post.edit(title,
                               body,
                               datetime.now(),
                               tags_keys,
                               category_key,
                               raw_summary,
                               raw_answers=request.json['answers'])
        except AttributeError:
            abort(500)

        return jsonify(updating_post.to_json())  # dangerous
Example #4
0
def edit(article_id):
    user_id=flask.session.get('id')
    if user_id:
        article=Articles.query.filter(Articles.id==article_id).first()
        tag=Tags.query.filter(Tags.id==article.tag_id).first()
        if flask.request.method=='GET':
            context={
                'article': article,
                'tag':tag
            }
            print(article.content)
            return flask.render_template('edit.html',**context)
        else:
            title=flask.request.form.get('title')
            content=flask.request.form.get('content')
            tagname=flask.request.form.get('tagname')
            id = flask.request.form.get('id')
            tag=Tags.query.filter(Tags.tagname==tagname).first()
            if tag:
                tag_id=tag.id
            else:
                tag=Tags(tagname=tagname)
                db.session.add(tag)
                db.session.commit()
                tag_id=Tags.query.filter(Tags.tagname==tagname).first().id
            article.id=id
            article.title=title
            article.content=content
            article.tag_id=tag_id
            db.session.commit()
            return flask.redirect(flask.url_for('index'))
    else:
        return flask.redirect(flask.url_for('login'))
Example #5
0
def formCreateDish():
    tags = Tags()
    allTags = tags.list_tags()
    countTags = len(allTags)
    return render_template('formCreateDish.html',
                           tags=allTags,
                           countTags=countTags)
Example #6
0
def make_posts():
    if request.method == "GET":
        user = g.user.nickname
        email = g.user.email
        image = g.user.image
        user_id = g.user.id
        return render_template('make_posts.html',
                               user=user,
                               email=email,
                               image=image,
                               id=user_id)
    elif request.method == "POST":
        content = request.form["post_content"]
        user_id = request.form['id']
        list_of_tags = json.loads(request.form['tags'])
        list_of_tags.append(
            user_id)  # little hacky way, doing because of shortage of time
        # first insert the post, get the post id and then insert in the tag table
        post_obj = Posts(post_content=content,
                         source_user=user_id,
                         created_at=datetime.datetime.now())
        db.session.add(post_obj)
    db.session.commit()

    post_id = post_obj.id
    # now make tags
    for tag in list_of_tags:
        tag_obj = Tags(source_user=user_id, end_user=tag, post_id=post_id)
        db.session.add(tag_obj)
        db.session.commit()
    return "Success"
Example #7
0
File: views.py Project: 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))
Example #8
0
 def get(self):
     user = users.get_current_user()
     tag_str = self.request.get('tag')
     if user:
         tag = Tags.query(Tags.user == user, Tags.name == tag_str).get()
         if tag is None:
             newtag = Tags()
             newtag.name = tag_str
             newtag.user = user
         else:
             newtag = tag
         newtag.put()
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']
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
Example #11
0
def deleteTag():
    tags = Tags()
    params = {}
    if request:
        # params["tag"] = request.args.get('tag', '')
        params['tag_id'] = request.args.get('tag_id', '')
        print(params)
        tags.delete_tag(params)
        tags.__del__
        del (tags)
        # return redirect(url_for('getTags'), msg='Tag created')
        return redirect(url_for('getTags'))
        # return "{0}".format(params)
    else:
        return "Fehler"
Example #12
0
def tag_add():
    input_list = request.form.getlist('create_tag')

    if input_list[0] != '':
        tag = Tags(tag=input_list[0])
    else:
        return redirect("/tags")

    post_ids = [int(num) for num in input_list[1:] if num != '']
    tag.posts = Posts.query.filter(Posts.id.in_(post_ids)).all()

    db.session.add(tag)
    db.session.commit()

    return redirect("/tags")
Example #13
0
def main():

    if users.is_current_user_admin():
        if request.method == 'GET':  #all entitites
            posts = Posts()

            return jsonify(posts.to_json())

        elif request.method == "POST":

            form = PostForm()
            if form.validate_on_submit():  #new entity
                posts = Posts()
                categories = Categories()
                tags = Tags()

                raw_post = request.get_json()
                raw_category = raw_post["category"]
                editing_tags = raw_post["tags"]
                raw_summary = raw_post["summary"]

                tag_keys = tags.update(editing_tags)
                category_key = categories.update(raw_category)

                post_id = posts.add(raw_title=raw_post["title"],
                                    raw_body=raw_post["body"],
                                    category_key=category_key,
                                    tags_ids=tag_keys,
                                    summary=raw_summary,
                                    answers=raw_post["answers"]).id()
                post = BlogPost.get(post_id)
                if "images" in raw_post.keys() and raw_post["images"]:
                    for img in raw_post["images"]:
                        image_base64 = img["url"].split("base64,")[-1]
                        mime_type = img["url"].split("base64,")[0].replace(
                            'data:', '').replace(';', '')
                        image_filename = img["filename"].split("\\")[-1]

                        if allowed_file(image_filename):
                            image_filename = secure_filename(image_filename)
                            post.add_blob(base64.b64decode(image_base64),
                                          image_filename, mime_type)

                return jsonify(post.to_json())  #  Needs check
            else:
                return jsonify(msg="missing token")
    else:
        return jsonify({})
Example #14
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
Example #15
0
def formEditDish():
    """ Zeigt ein Formular zur bearbeitung eines Gerichts an. Parameter: dish_id """

    # Abfragen, ob Daten übergeben wurden
    if request:
        dish_id = request.args.get('dish_id', '')
    else:
        return "Error"

    # Falls dish_id als String übergeben wurde -> in Integer umwandeln

    if type(dish_id) == str:
        dish_id = int(dish_id)

    # Gericht & Tags mit Namen laden
    dishes = Dishes()
    dish = dishes.getDish(dish_id)[0]
    taggedDishes = TaggedDishes()
    tag_for_dish = taggedDishes.list_with_names(dish['dish_id'])
    dish['tags'] = tag_for_dish

    # Allgemeine Tags laden
    tags = Tags()
    allTags = tags.list_tags()
    countTags = len(allTags)

    # Zutaten für das Gericht laden
    ingredientsAll = Ingredients()
    ingredients = ingredientsAll.list(dish_id)

    # Alle Namen und Einheiten der Zutaten laden
    suggestions = ingredientsAll.get_suggestions()
    # print(suggestions)

    # Tags selektieren
    for index in range(len(allTags)):
        for tag2 in tag_for_dish:
            if allTags[index]['tag_id'] == tag2['tag_id']:
                allTags[index]['selected'] = " selected"

    # Template füllen und zurückgeben
    return render_template('formEditDish.html',
                           allTags=allTags,
                           countTags=countTags,
                           dish=dish,
                           ingredients=ingredients,
                           ingredientsCount=len(ingredients),
                           suggestions=suggestions)
Example #16
0
def create_tag():
    tags = Tags()
    params = {}
    if request:
        params["tag"] = request.args.get('tag', '')
        if len(params["tag"]) == 0:
            return redirect(url_for('getTags'))

        tag_id = tags.create_tag(params)
        print(tag_id)
        # return "yay {0}".format(params["tag"])
        # return redirect(url_for('getTags', msg='Tag {0} wurde hinzugefügt.'.format(params['name'])))
        return redirect(url_for('getTags'))
    else:
        return "Fehler"
    return "Fehler"
Example #17
0
def get_single_tag(id):
    with sqlite3.connect("./rare.db") as conn:
        conn.row_factory = sqlite3.Row
        db_cursor = conn.cursor()
        db_cursor.execute(
            """
        SELECT
            c.id,
            c.label
        FROM tags c
        WHERE c.id = ?
        """, (id, ))

        dataset = db_cursor.fetchone()
        tag = Tags(dataset['id'], dataset['label'])
    return json.dumps(tag.__dict__)
Example #18
0
def request_json(**kwargs):
    if request.json:
        global r
        r = Resource()
        for k, v in kwargs.iteritems():
            r.rid = v  # Now automatically updated
        r.title = request.json['title']
        r.link = str(request.json['link'])
        # Insert Tags to Tags Object
        r.tags = []
        for item in request.json['tags']:
            t = Tags()
            t.tag_name = item['tag_name']
            r.tags.append(t)
        r.description = request.json['description']
        r.save(upsert=True)
Example #19
0
File: views.py Project: 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))
Example #20
0
def getTags():
    has_message = False
    if request:
        if request.args.get('msg', ''):
            has_message = request.args.get('msg', '')
        # return redirect(url_for('listDishes'))
    else:
        has_message = False
        return "Fehler! <br /><a href\"" + url_for(
            'listDishes') + "\">Liste</a>"
    tags = Tags()
    allTags = tags.list_tags()
    # if len(allTags) > 0:
    #     for tag in allTags:
    #         print(tag)

    return render_template('tags.html', tags=allTags, has_message=has_message)
Example #21
0
def get_all_tags():
    with sqlite3.connect("./rare.db") as conn:
        conn.row_factory = sqlite3.Row
        db_cursor = conn.cursor()
        db_cursor.execute("""
        SELECT
            c.id,
            c.label
        FROM tags c
        ORDER by label
        """)
        tags = []
        dataset = db_cursor.fetchall()
        for row in dataset:
            tag = Tags(row['id'], row['label'])
            tags.append(tag.__dict__)
    return json.dumps(tags)
Example #22
0
def delete_post(id):

    if users.is_current_user_admin():
        posts = Posts()

        tags = Tags()

        categories = Categories()

        updating_post = BlogPost.get(int(id))

        categories.delete(updating_post.category)

        posts.delete(updating_post.key)

        tags.update([])

    return jsonify(msg="OK")
Example #23
0
def createDish():
    params = {}
    if request:
        params["name"] = request.args.get('name', '')
        params["note"] = request.args.get('note', '')
        params["ingredients"] = request.args.get('ingredients', '')
        params["countCooked"] = 0
        params["tags"] = request.args.get('tags', '')
        params["tags"] = request.args.getlist('tags')
        tags_list = []

        # Datenbank öffnen
        tags = Tags()

        for tag_name_request in params["tags"]:
            tag_id = tags.get_tag_id(tag_name_request)[0]['tag_id']
            print("Tag_name: {0}".format(tag_name_request))
            print("   Tag_id ist: {0}".format(tag_id))
            if not tag_id:
                print("   Tag erstellen")
                tag_id = tags.create_tag("tag_name_request")
            tags_list.append(tag_id)

        print("")
        # Datenbank und Tabelle schließen
        del tags

        # Datenbank öffnen & Gericht erstellen
        dishes = Dishes()
        dish_id = dishes.create(params)
        del dishes
        # Zum testen hier die feste dish_id 22, somit wird nicht jedes mal ein Gericht angelegt
        # dish_id = 22

        if dish_id:
            taggedDishes = TaggedDishes()
            for tag_id in tags_list:
                print("Zuweisung: {0} zu {1}".format(dish_id, tag_id))
                taggedDishes.assign_tag_to_dish(dish_id, tag_id)
            return "Erfolgreich<br /><a href=\"" + url_for(
                'listDishes') + "\">Gerichte anzeigen</a>"
    else:
        return "Fehler"
Example #24
0
def add_tags_to_project(prj_id, tags):
    sesion = db_session.create_session()
    for tag_name in tags:
        tag = sesion.query(Tags).filter(Tags.interest == tag_name).first()
        if not tag:
            new_tag = Tags(interest=tag_name)
            sesion.add(new_tag)
            sesion.commit()
            last_id = sesion.query(func.max(Tags.id)).one()[0]
            last_id = last_id if last_id else 1
            print('last tag id', last_id)
        else:
            last_id = tag.id
        print('Ths', prj_id, last_id)
        conn = db_session.create_coon()
        ins = project_tag_table.insert().values(project_id=prj_id,
                                                tag_id=last_id)
        conn.execute(ins)
    return
Example #25
0
def publish():
    user_id=flask.session.get('id')
    if user_id:
        if flask.request.method=='GET':
            return flask.render_template('publish.html')
        else:
            title=flask.request.form.get('title')
            content=flask.request.form.get('content')
            tagname=flask.request.form.get('tagname')
            id=flask.request.form.get('id')
            tag=Tags.query.filter(Tags.tagname==tagname).first()
            if tag:
                tag_id=tag.id
            else:
                tag=Tags(tagname=tagname)
                db.session.add(tag)
                db.session.commit()
                tag_id = Tags.query.filter(Tags.tagname == tagname).first().id
            article=Articles(id=id,title=title,content=content,tag_id=tag_id)
            db.session.add(article)
            db.session.commit()
            return flask.redirect(flask.url_for('index'))
            # title = form.title.data
            # content = form.content.data
            # tagname = form.tagname.data
            # tag = Tags.query.filter(Tags.tagname == tagname).first()
            # if tag:
            #     tag_id = tag.id
            # else:
            #     tag=Tags(tagname=tagname)
            #     db.session.add(tag)
            #     db.session.commit()
            #     tag_id = Tags.query.filter(Tags.tagname == tagname).first().id
            # article=Articles(title=title,content=content,tag_id=tag_id)
            # db.session.add(article)
            # db.session.commit()
            # return flask.redirect(flask.url_for('index'))
    else:
        return flask.redirect(flask.url_for('login'))
Example #26
0
def tag_post(post_id):
    """Update a post if the current user is the author."""
    db_session = current_app.config["db_session"]
    post = db_session.query(Referral).filter(Referral.id_ == post_id).first()
    user = db_session.query(User).filter(User.id_ == session.get("user_id")).first()
    if post is None:
        abort(404)
    if user.id_ != post.user_id:
        abort(405)

    tag_id = int(request.form["tag"])
    tag = db_session.query(Tag).filter(Tag.id_ == tag_id).first()
    if not tag:
        abort(405)

    tagged = db_session.query(Tags).filter(Tags.post_id == post_id).first()
    if tagged:
        abort(405)

    tagged = Tags(post_id, tag_id)
    db_session.add(tagged)
    db_session.commit()
    return redirect(url_for('post.view', id=post.id_))
Example #27
0
def editDish():
    params = {}
    if request:
        params["dish_id"] = request.form.get('dish_id', '')
        params["name"] = request.form.get('name', '')
        params["note"] = request.form.get('note', '')
        # params["ingredients"] = request.args.get('ingredients', '')
        params["countCooked"] = "0"
        params["lastCooked"] = "2019-01-01"
        # params["tags"] = request.args.get('tags','')
        params["tags"] = request.form.getlist('tags')
        tags_list = []

        # print(params["tags"])

        # Datenbank öffnen
        tags = Tags()

        for tag_name_request in params["tags"]:
            tag_id = tags.get_tag_id(tag_name_request)[0]['tag_id']
            # print("Tag_name: {0}".format(tag_name_request))
            # print("   Tag_id ist: {0}".format(tag_id))
            if not tag_id:
                # print("   Tag erstellen")
                tag_id = tags.create_tag("tag_name_request")
            tags_list.append(tag_id)

        # Übergabeparameter zusammenstellen
        dish_stuff = {}
        # dish_stuff['dish_id'] = params['dish_id']
        dish_stuff['name'] = params['name']
        dish_stuff['note'] = params['note'].splitlines()
        # dish_stuff['ingredients'] = params['ingredients']
        dish_stuff['countCooked'] = params['countCooked']
        # dish_stuff['lastCooked'] = params['lastCooked']
        dish_stuff['lastCooked'] = params['lastCooked']

        # Datenbank und Tabelle schließen
        del tags

        # Datenbank öffnen & Gericht erstellen
        dishes = Dishes()
        returnValue = dishes.update(params["dish_id"], dish_stuff)
        del dishes
        # Zum testen hier die feste dish_id 22, somit wird nicht jedes mal ein Gericht angelegt
        # dish_id = 22

        taggedDishes = TaggedDishes()
        # print(tags_list)
        existing_tags = taggedDishes.list(params["dish_id"])
        # print("Existing Tags: {0}".format(existing_tags))
        # print("tags_list: {0}".format(tags_list))
        for tag_id in tags_list:
            # print([item for item in existing_tags if item["tag_id"] == tag_id])
            if not [
                    item for item in existing_tags if item["tag_id"] == tag_id
            ]:
                # print("tag_id: {0} - existing_tag: {1}".format(tag_id, existing_tag))
                # print("Zuweisung: {1} zu {0}".format(params["dish_id"], tag_id))
                taggedDishes.assign_tag_to_dish(params["dish_id"], tag_id)

        for existing_tag in existing_tags:
            if not existing_tag['tag_id'] in tags_list:
                # print("Zuweisung löschen: {1} zu {0}".format(params["dish_id"], existing_tag['tag_id']))
                taggedDishes.remove_tag_from_dish(params["dish_id"],
                                                  existing_tag['tag_id'])
        return redirect(url_for('showDish', dish_id=params["dish_id"]))
Example #28
0
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())
Example #29
0
def updateTags(tagname):

    if users.is_current_user_admin():
        tags = Tags()
Example #30
0
def fetch_everything_from_db():
    return Posts(), Tags(), Categories()