Example #1
0
def edit(title):
    Title = "Edit Article"
    form = ArticleForm()
    article = posts.find_one({'title': title})
    form.title.data = article['title']
    form.body.data = article['body']

    if request.method == 'POST' and form.validate_on_submit():
        title = request.form['title']
        body = request.form['body']
        posts.update_one({'_id': article['_id']}, {
            "$set": {
                'title': title,
                'body': body,
                'timestamp': datetime.datetime.now().strftime('%d-%m-%Y %H:%M')
            }
        })

        flash('Article Edited.', 'success')
        return redirect(url_for("articles"))

    return render_template("edit.html",
                           article=article,
                           title=Title,
                           form=form)
Example #2
0
def change1(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():

            title1 = request.POST.get('title')
            content1 = request.POST.get('content')
            user1 = request.POST.get('user')
            if not Article.objects.all().filter(title=title1):
                return HttpResponseRedirect('/article/failure1/')
            else:
                username = request.user

                u1 = Article.objects.get(title=title1)

                u1.content = content1
                u1.user = user1
                u1.save()

                #用户扩展信息 profile

                user2 = UserProfile.objects.get(user=username)
                user2.point = user2.point + 1
                user2.save()

                return render_to_response('result.html', {
                    'title1': title1,
                    'user1': user1,
                    'content1': content1
                })
Example #3
0
def savearticle(request):
    error = []
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            title = request.POST.get('title')
            content = request.POST.get('content')
            user = request.POST.get('user')

            username = request.user

            if not Article.objects.all().filter(title=title):

                u1 = Article(title=title, content=content, user=user)
                u1.save()

                #用户扩展信息 profile

                user1 = UserProfile.objects.get(user=username)
                user1.point = user1.point + 1
                user1.save()
                return HttpResponseRedirect('/article/success/')

            else:
                return HttpResponseRedirect('/article/failure/')
Example #4
0
def create_article():
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        title = article_form.title.data
        body = article_form.body.data
        address = article_form.address.data
        img = article_form.img.data
        category_id = article_form.category_id.data
        author_id = current_user.name
        phone_number = article_form.phone_number.data
        article = Post(title=title, body=body,address=address,category_id=category_id,img=img,phone_number=phone_number,author_id=author_id)
        db.session.add(article)
        db.session.commit()
        return redirect('/')
    return render_template('add.html', form=article_form)
Example #5
0
def create_post(request):
  if request.method == "POST":
    print request.POST
    print '============'
    form = ArticleForm(request.POST)
    if form.is_valid():
      return HttpResponse ("Thanks for the entry. Your Feedback will be saved")
    '''
    article_user = request.user
    article_title = request.POST['article_title']
    article_content = request.POST['article_content']
    article_post = articles(user=str(article_user), body=str(article_content), title=str(article_title))
    article_post.save()
    '''
  else:
    form = ArticleForm()
  return render(request, 'create_post.html', {'form': form})
Example #6
0
def create(request):
    if request.POST:
	form = ArticleForm(request.POST,request.FILES)#request.files is for uploading a files
	if form.is_valid():
	    form.save()
			
	    return HttpResponseRedirect('/articles/all')
		
    else:
	form = ArticleForm()
		
    args ={}
    args.update(csrf(request))
		
    args['form'] = form
		
    return render_to_response('create_article.html',args)
Example #7
0
def write(request):
	if request.method == 'POST':
		form = ArticleForm(request.POST)
		if form.is_valid():
			id = form.cleaned_data.get('id')
			try:
				article = Article.objects.get(id=id)
			except Article.DoesNotExist:
				article = Article()
			article.user = request.user
			article.title = form.cleaned_data.get('title')
			article.content = form.cleaned_data.get('content')
			article.status = form.cleaned_data.get('status')
			article.markdown = form.cleaned_data.get('markdown')
			article.save()
			tags = form.cleaned_data.get('tags')
			article.create_tags(tags)
			return redirect(reverse('blog:home'))
		else:
			return HttpResponse(form.errors.as_json());
			
	elif request.GET.get('id'):
		id = request.GET.get('id')
		article = Article.objects.get(id=id)
		tags = article.get_tags_str()
		form = ArticleForm(instance=article,initial={'tags': tags})

	else:
		form = ArticleForm()
	
	return render(request, 'blog/write.html', {'form':form})
Example #8
0
def add_article():
    title = "Blog"
    form = ArticleForm()

    if request.method == 'POST' and form.validate_on_submit():
        user = users.find_one({'username': current_user.username})

        articles = {
            'title': form.title.data,
            'body': form.body.data,
            'timestamp': datetime.datetime.now().strftime('%d-%m-%Y %H:%M'),
            'user_id': user['_id'],
            'author': user['username'],
            'comments': {}
        }

        if user:
            posts.insert(articles)

        flash('Article Created', 'success')
        return redirect(url_for('dashboard'))

    return render_template("add_article.html", form=form, title=title)
Example #9
0
def edit_article(request, id=None):
    data = {}
    article = Article()
    
    if request.method == "POST":
        form = ArticleForm(request.POST,instance=article) # A form bound to the POST data
        if form.is_valid():
            article.title = form.cleaned_data['title']
            article.content = form.cleaned_data['content']
            article.author = User.objects.get(pk=request.user.id)

            article.save()
            return HttpResponseRedirect('/blog/view/%s' % article.id)
    elif request.method == "GET":
        if id != None:
            article = Article.objects.get(pk=id)
        form = ArticleForm(instance=article)
    else:
        raise Http404

    data['form'] = form
    print form.errors
    return render_to_response(BLOG_TEMPLATE + 'edit.html', data, context_instance=RequestContext(request))
Example #10
0
def newarti():
    form = ArticleForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            ar = Article()
            ar.create_time = request.form.get('create_time')
            ar.project_type = request.form.get('project_type')
            ar.project_name = request.form.get('project_name')
            ar.fiber_type = request.form.get('fiber_type')
            ar.fiber_length = request.form.get('fiber_length')
            ar.closure_type = request.form.get('closure_type')
            ar.closure_number = request.form.get('closure_number')
            ar.other_things = request.form.get('other_things')
            ar.reason = request.form.get('reason')
            ar.recycle_fiber_type = request.form.get('recycle_fiber_type')
            ar.recycle_fiber_length = request.form.get('recycle_fiber_length')
            ar.create_user_id = current_user.id
            ar.approver_id = current_user.id
            db.session.add(ar)
            db.session.commit()
            return redirect('/newarti')

    articles = Article.query.filter_by(create_user_id=current_user.id)
    return render_template("createArti.html", form=form, articles=articles)
Example #11
0
def edit_article(id):
    form = ArticleForm(request.form)
    can_edit = request.method == 'POST'  #and form.validate() # for some reason form stop validating, therefore it's comment out for edit to "work"
    # print(can_edit)
    # print(form.validate())
    return render_view(presenter.edit_article(id, can_edit, form))
Example #12
0
def add_article():
    form = ArticleForm(request.form)
    can_add = request.method == 'POST' and form.validate()
    print(request.method)
    print(form.validate())
    return render_view(presenter.add_article(can_add, form))