Example #1
0
 def create_tags(cls):
     faker = Faker()
     for i in range(TAGS_COUNT):
         tag = Tag(name=faker.word())
         try:
             tag.save()
         except IntegrityError:
             continue
     stdout_writer.stdout.write("Created test data: TAGS")
Example #2
0
def deletepage():
	form=request.form
	pagelist=[]
	for item in form:
		pagelist.append(int(item))
	for item in pagelist:
		post=Post.all().filter('post_id',item).get()
		if post:
			post.remove()
	Tag.updatecache()
	Post.updatecache()
	return json.dumps({'status':1})
Example #3
0
def deletepage():
    form = request.form
    pagelist = []
    for item in form:
        pagelist.append(int(item))
    for item in pagelist:
        post = Post.all().filter('post_id', item).get()
        if post:
            post.remove()
    Tag.updatecache()
    Post.updatecache()
    return json.dumps({'status': 1})
Example #4
0
def setting():
    if request.method == 'GET':
        post_id = User.POST_ID
        postnumberhome = User.PER_PAGE_IN_HOME
        postnumberadmin = User.PER_PAGE_IN_ADMIN
        showtagnumber = User.SHOW_TAG_NUMBER
        showtagsearchnumber = User.SHOW_TAGSEARCH_NUMBER
        showlinknumber = User.SHOW_LINK_NUMBER
        mediainadmin = User.MEDIA_IN_ADMIN
        commentinadmin = User.COMMENT_IN_ADMIN
        commentinsidebar = User.COMMENT_IN_SIDEBAR
        announcelength = User.ANNOUNCELENGTH
        return render_template('admin/setting.html',
                               post_id=post_id,
                               postnumberhome=postnumberhome,
                               postnumberadmin=postnumberadmin,
                               showtagnumber=showtagnumber,
                               showtagsearchnumber=showtagsearchnumber,
                               showlinknumber=showlinknumber,
                               mediainadmin=mediainadmin,
                               commentinadmin=commentinadmin,
                               commentinsidebar=commentinsidebar,
                               announcelength=announcelength)
    else:
        needupdate = False
        form = request.form
        one = User.all().get()
        one.postnumberhome = int(form['postnumberhome'])
        one.postnumberadmin = int(form['postnumberadmin'])
        one.showtagnumber = int(form['showtagnumber'])
        one.showmediaadmin = int(form['mediainadmin'])
        one.commentinadmin = int(form['commentinadmin'])
        one.commentinsidebar = int(form['commentinsidebar'])
        one.announcelength = int(form['announcelength'])
        if int(form['showtagsearchnumber']) != one.showtagsearchnumber:
            needupdate = True
        one.showtagsearchnumber = int(form['showtagsearchnumber'])
        one.showlinknumber = int(form['showlinknumber'])
        one.post_id = int(form['post_id'])
        another = Post.all().filter('post_id', int(form['post_id'])).get()
        if not another:
            one.post_id = -1

        one.put()
        User.updatecache(one)
        Tag.updatecache()
        Comment.updatecache()
        Link.updatecache()

        return json.dumps({'message': 'success'})
Example #5
0
def updatepost():
	form =request.args
#	print request.data
	if form.has_key('post_id'):
		post=Post.getone(form['post_id'])
		post.title=form['title']
		post.content=urllib.unquote(request.data).decode('utf-8')
		post.settags(form['tags'])
		post.update_time=int(time.time())
		if form['posttype']=='saveonly':
			post.saveonly=True
		else :
			post.saveonly=False
		if form.has_key('allowcomment') and form['allowcomment']=='on':
			post.allowcomment=True
		else :
			post.allowcomment=False
		post.put_into()
		Tag.updatecache()
		return json.dumps({'message':'success','post_id':form['post_id']})
	return "no such key exsits"
Example #6
0
def updatepost():
    form = request.args
    #	print request.data
    if form.has_key('post_id'):
        post = Post.getone(form['post_id'])
        post.title = form['title']
        post.content = urllib.unquote(request.data).decode('utf-8')
        post.settags(form['tags'])
        post.update_time = int(time.time())
        if form['posttype'] == 'saveonly':
            post.saveonly = True
        else:
            post.saveonly = False
        if form.has_key('allowcomment') and form['allowcomment'] == 'on':
            post.allowcomment = True
        else:
            post.allowcomment = False
        post.put_into()
        Tag.updatecache()
        return json.dumps({'message': 'success', 'post_id': form['post_id']})
    return "no such key exsits"
Example #7
0
def tag_request(tag_request):
    post_tags = []
    if tag_request:
        existing_tags = [name for name, in Tag.query.with_entities(Tag.name)]
        form_tags = tag_request.split(', ')
        for tag in form_tags:
            if tag not in existing_tags:
                t = Tag(name=tag)
                db.session.add(t)
                post_tags.append(t)
            else:
                post_tags.append(Tag.query.filter(Tag.name == tag).first())
    return post_tags
Example #8
0
def newpost():
    form = request.args
    newpost = Post(title=form['title'],
                   content=urllib.unquote(request.data).decode('utf-8'),
                   num_lookup=0)
    if form['posttype'] == 'saveonly':
        newpost.saveonly = True
    else:
        newpost.saveonly = False
    if form.has_key('allowcomment') and form['allowcomment'] == 'on':
        newpost.allowcomment = True
    else:
        newpost.allowcomment = False
    newpost.post_id = Post.properid()
    newpost.settags(form['tags'])
    newpost.create_date = int(time.time())
    newpost.update_time = newpost.create_date
    newpost.put_into()
    Tag.updatecache()
    Post.updatecache()
    #return json.dumps({'message':newpost.content,'post_id':newpost.post_id})
    return json.dumps({'message': 'success', 'post_id': newpost.post_id})
Example #9
0
def newpost():
	form=request.args
	newpost=Post(title=form['title'],
				content=urllib.unquote(request.data).decode('utf-8'),
				num_lookup=0
				)
	if form['posttype']=='saveonly':
		newpost.saveonly=True
	else :
		newpost.saveonly=False
	if form.has_key('allowcomment') and form['allowcomment']=='on':
		newpost.allowcomment=True
	else :
		newpost.allowcomment=False
	newpost.post_id=Post.properid()
	newpost.settags(form['tags'])
	newpost.create_date=int(time.time())
	newpost.update_time=newpost.create_date
	newpost.put_into()
	Tag.updatecache()
	Post.updatecache()
	#return json.dumps({'message':newpost.content,'post_id':newpost.post_id})
	return json.dumps({'message':'success','post_id':newpost.post_id})
Example #10
0
def attach_tag(id):
    link = Link.query.get(id)
    if request.method == 'POST':
        user = User.query.filter_by(id=current_user.id).first()
        name = request.form['tag']
        tag = Tag.query.filter_by(name=name.lower()).first()
        if tag is None:
            tag = Tag(name.lower(), user)

        link.tags.append(tag)
        db.session.add(link)
        db.session.commit()
        return render_template('links/attach.html', link=link)

    return render_template('links/attach.html', link=link)
Example #11
0
def main(location):
    clear_all()
    html_parser = HTMLParser()

    # parse a file
    if not location:
        path = os.path.dirname(os.path.realpath(__file__))
        wp = wxr_parser.parse(os.path.join(path, 'wp.xml'))
    else:
        wp = wxr_parser.parse(location)

    tags = wp['tags']
    for _, kv in tags.iteritems():
        Tag(name=kv['title'], slug=kv['slug']).save()
    cates = wp['categories']
    for _, kv in cates.iteritems():
        Category(name=kv['title']).save()
    posts = wp['posts']
    for post in posts:
        markdown, content = convert_content(post['content'])
        creator = post['creator']
        user = User.objects.filter(name=creator).first()
        if not user:
            role = Role.objects.filter(name="READER").first()
            if not role:
                role = Role.objects.create(name="READER",
                                           permission=Permission.READ)
            password = ''.join([
                random.choice(string.ascii_uppercase + string.ascii_lowercase +
                              string.digits) for i in xrange(16)
            ])
            user = User.objects.create(name=creator,
                                       email='*****@*****.**',
                                       role=[role],
                                       password=password)

        Post(title=html_parser.unescape(post['title']),
             slug=post['slug'],
             content=content,
             markdown=markdown,
             page=False,
             author=user,
             status=convert_status(post['status'].upper()),
             published_at=post['pub_date'],
             created_at=post['pub_date']).save()
Example #12
0
def tag_add():
    form = TagForm()
    if form.validate_on_submit():
        data = form.data
        tag = Tag.query.filter_by(name=data["name"]).count()
        if tag > 0:
            flash("This tag is already existed", "err")
            return redirect(url_for('admin.tag_add'))
        tag = Tag(name=data["name"], addtime=db.func.current_timestamp())
        db.session().add(tag)
        db.session().commit()
        flash("Tag is saved successfully", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="added tag %s" % data["name"],
                      addtime=db.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
        redirect(url_for('admin.tag_add'))
    return render_template("admin/tag_add.html", form=form)