def savee(request,nam,status):
    f=bform(request.POST)
    a=''
    l=[]
    pos=posts.objects.filter(name=nam)
    now=datetime.datetime.now()
    time=datetime.datetime.now().time()
    if f.is_valid():
        cd=f.cleaned_data
        l=cd['head']
    for each in pos:
        if l==each.post:
            a=l
            break
    if len(a)>0:
        p=posts.objects.get(post=l)
        os.remove('blog'+'/'+'blogs'+'/'+p.pl)
        p.pl=str(time)
        p.date=str(now.day)+'/'+str(now.month)+'/'+str(now.year)
        p.status=status
        p.save()
    else:
        p=posts(name=nam,post=cd['head'],pl=str(time),comment=cd['head'][:5],cn=0,date=str(now.day)+'/'+str(now.month)+'/'+str(now.year),status=status)
        p.save()
    d=open('blog'+'/'+'blogs'+'/'+str(time),'w')
    d.write(cd['body'])
    d.close()
    d=open('blog'+'/'+'blogs'+'/'+str(time),'r')
    k=''
    q=d.readlines()
    for each in q:
        k+=each
    data={'body':k}
    return data 
Example #2
0
def index():
    if not current_user.is_authenticated:
        return render_template("home.html")

    title = body = price = pic = None
    post_form = PostForm()
    if post_form.validate_on_submit():
        title = post_form.title.data
        body = post_form.body.data
        price = post_form.price.data
        pic = post_form.pic.data
        uuid_filename = str(uuid.uuid4())
        pic.save(os.path.join(app.root_path, 'static/img', uuid_filename))

        db_entry = posts(title=title,
                         body=body,
                         price=price,
                         pic=uuid_filename,
                         author_username=current_user.username,
                         author_email=current_user.email)
        try:
            db.session.add(db_entry)
            db.session.commit()
        except:
            return "Database error"
    else:
        print(post_form.errors)
    items_list = [item.post_id for item in cart_list()]
    return render_template('index.html',
                           post_form=post_form,
                           posts_table=posts.query.order_by(
                               posts.id.desc()).all(),
                           current_user=current_user,
                           cart_list=items_list,
                           len_cart_list=len(items_list))
Example #3
0
def addposts(details):
    get_name, get_post, get_contact, get_email = details.split('_')
    pos = posts(name=get_name,
                post=get_post,
                contact=get_contact,
                email=get_email)
    db.session.add(pos)
    db.session.commit()
    return "sucessfully added"
Example #4
0
def UserView(request, user):
    all_post = posts.objects(user=str(request.user)).order_by('-time')
    if request.method == 'GET':
        return render(request, 'user.html', {'all_post': all_post})

    if request.method == 'POST':
        try:
            new_post = posts(user=str(request.user),
                             post=str(request.POST['post']),
                             time=datetime.now())
            new_post.save()
            messages.success(request, "new post added")
            return redirect('/microblog/u/%s' % (user))
        except:
            messages.error(request, "create post error")
            return redirect('/microblog/u/%s' % (user))
Example #5
0
def UserView(request, user):
    all_post = posts.objects(user= str(request.user)).order_by('-time')
    if request.method == 'GET':
        return render(request, 'user.html',{'all_post': all_post})

    if request.method == 'POST':
        try:
            new_post = posts(user = str(request.user),
                             post = str(request.POST['post']),
                             time = datetime.now()
                            )
            new_post.save()
            messages.success(request, "new post added")
            return redirect('/microblog/u/%s' % (user) )
        except:
            messages.error(request, "create post error")
            return redirect('/microblog/u/%s' % (user) )
Example #6
0
def refresh():
    post_list = posts.objects.all()
    url = 'https://blog.prisync.com/feed/'
    source = requests.get(url)
    soup = BeautifulSoup(source.content, 'xml')
    soups = soup.find_all('item')
    same_list = []
    for i in post_list:
        same_list.append(i.title)
    for i in soups:
        if i.title.text not in same_list:
            create_post = posts(title=i.title.text,
                                link=i.link.next,
                                category=i.category.text,
                                creator=i.creator.text,
                                pubdate=i.pubDate.text[:16],
                                description=i.description.text)
            create_post.save()
Example #7
0
def newpost():
    if len(request.form['title']) < 2:
        return redirect(
            url_for('links_blog.addpost',
                    messages=json.dumps({'title': 'Enter longer title'})))
    if not request.files['image']:
        return redirect(
            url_for('links_blog.addpost',
                    messages=json.dumps({'image': 'Please upload a picture'})))

    now = datetime.now()
    timestamp = datetime.timestamp(now)
    file = request.files['image']
    filename = secure_filename(str(timestamp) + file.filename)
    file.save(os.path.join('app/static/images', filename))
    user = users.query.filter(users.id == session['user']['id']).first()
    post = posts(title=request.form['title'],
                 content=request.form['content'],
                 image=filename,
                 user=user)
    db.session.add(post)
    db.session.commit()
    return redirect(url_for('links_blog.addpost'))