示例#1
0
    def setUp(self):
        """Recreates the tables for a fresh start and populates them with a single user and post"""

        # Creates empty tables
        db.drop_all()
        db.create_all()

        # Adds a single user
        new_user = User(first_name='John', last_name='Doe')
        db.session.add(new_user)
        db.session.commit()

        # Adds a single post to new_user
        new_post = Post(title='A Test', content='Testing posts', user_id=1)
        db.session.add(new_post)
        db.session.commit()

        # Adds a single tag
        new_tag = Tag(name='Testing')
        db.session.add(new_tag)
        db.session.commit()

        # Tags 'A Test' as 'Testing'
        new_post_tag = PostTag(post_id=1, tag_id=1)
        db.session.add(new_post_tag)
        db.session.commit()
示例#2
0
def unpublished_post(user, session):
    new_post = Post(author=user,
                    title=fake.sentence(),
                    content=fake.paragraph(),
                    is_published=False)
    session.add(new_post)
    session.commit()
    return new_post
示例#3
0
def posts(count=100):
    fake = Faker()
    user_count = User.query.count()
    for i in range(count):
        u = User.query.offset(randint(0, user_count - 1)).first()
        p = Post(body=fake.text(), timestamp=fake.past_date(), author=u)
        db.session.add(p)
    db.session.commit()
示例#4
0
class UserTest(unittest.TestCase):
    def setUp(self):
        self.new_post = Post(password='******')

    def test_login_scope(self):
        with self.assertRaises(AttributeError):
            self.new_post.password

    def test_password_verification(self):
        self.assertTrue(self.new_post.verify_password('password'))
示例#5
0
def bunch_of_posts(user, session):
    for x in range(30):
        new_post = Post(author=user,
                        title=fake.sentence(),
                        content=fake.paragraph(),
                        is_published=fake.boolean())
        session.add(new_post)
        new_post.comments.append(Comment(author=user,
                                         content=fake.paragraph()))
    session.commit()
示例#6
0
def new_post_db(source_inf0):
    global inn
    soup = BeautifulSoup(source_inf0.text, 'lxml')
    # Заголовок статьи.
    title = soup.find('h1', {'class': 'detailed'}).text
    # Краткое описание статьи.
    info = soup.find('span', {'class': 'detailed_full'}).text.strip()
    # Ингредиенты:
    ingredients = soup.find_all('li', {'itemprop': 'recipeIngredient'})
    for ing in ingredients:
        string_den(ing)
    # Назначения.
    destinations = soup.find_all('span', {'class': 'detailed_tags'})
    for i in destinations:
        qw = i.text
    des = qw.split('/')  # Преобразуем стоку в список.
    des = des[1:6]  # Получем срез нужных элементов
    des = ','.join(des)

    # Полное содержание статьи.
    text_s = soup.find_all('div', {'class': 'detailed_step_description_big'})
    text_post = ''
    for i in text_s:
        text_post = text_post + i.text

    links = soup.find_all('div',
                          attrs={'class': 'bigImgBox'
                                 })  # Получаем все куски кода где есть ссылки.
    # В цикле перебираем полученые куски кода.
    for link in links:
        image_url = link.find('img').get(
            'src', '-')  # Получаем ссылку на картинку с поста.
        # Получаем название картинки.(Ссылку разбиваем в список по сиволу '/'
        # и вырезаем последный элемент списка.
        title_image = image_url.split('/')[-1]

    # Передаем ссылку и названия файла для загрузки.
    uploading_an_image(image_url, title_image)

    # Добавляем статью в базу данных.
    new_post = Post(
        title=title,  # Заголовок статьи.
        destinations=des,
        integritty=inn,
        image_name=title_image,  # Имя картинки
        info=info,  # Короткая информация о статье.
        text=text_post)  # Полный текст статьи.
    try:
        db.session.add(new_post)
        db.session.commit()

    except ValueError:
        pass
示例#7
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        category = Category.query.get(form.category.data)
        post = Post(title=title, body=body, category=category)
        db.session.add(post)
        db.session.commit()
        flash('发表成功.', 'success')
        return redirect(url_for('web.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
示例#8
0
def user_new_contribute():
    form = PostTweetForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.text.data
        addr = form.source_addr.data
        post_value = form.source_value.data
        post = Post(title=title,
                    body=body,
                    source_addr=addr,
                    source_value=post_value)
        current_user.posts.append(post)
        db.session.commit()
        flash('最新资源发送成功!浏览全部内容!', category='success')
        return redirect(url_for('all_posts'))
    return render_template('newContribute.html', form=form)
示例#9
0
def test_creating_Post(db_init):
    admin = User(username='******', email='*****@*****.**')
    category = Category(name='Python')
    post = Post(
        title='New Python Book', body='New Book released!!',
        category=category, user=admin
    )

    db.session.add(category)
    db.session.add(admin)
    db.session.commit()

    assert Post.query.filter_by(title='New Python Book').first().category == category
    assert Post.query.filter_by(title='New Python Book').first().user == admin
    assert Category.query.first().posts[0] == post
    assert User.query.first().posts[0] == post
示例#10
0
文件: routes.py 项目: olexsahka/board
def reg_post():
    if request.method == 'POST':
        name = request.form.get('name')
        category = request.form.get('category')
        description = request.form.get('description')
        hostel = request.form.get('hostel')
        cost = request.form.get('cost')
        urlon = request.form.get('urlon')
        user_id = current_user.id
        photo0 = save_img(request.files['photo0'])
        photo1 = save_img(request.files['photo1'])
        photo2 = save_img(request.files['photo2'])
        photo3 = save_img(request.files['photo3'])
        active = True

        if name == None or category == None or description == None or hostel == None or cost == None or urlon == None or photo0 == None:
            flash(
                "Необходимо заполнить поля:Название объявления,Категория,Описание,Цена,Общежитие и выбрать хотя бы 1 фото"
            )
        else:
            new_post = Post(category=category,
                            name=name,
                            description=description,
                            hostel=hostel,
                            cost=cost,
                            urlon=urlon,
                            timestamp=datetime.datetime.now(),
                            user_id=user_id,
                            active=active,
                            img_0=photo0,
                            img_1=photo1,
                            img_2=photo2,
                            img_3=photo3)
            db.session.add(new_post)
            db.session.commit()
            return redirect(url_for('hello_world'))
    return render_template('registration_post_page.html')
示例#11
0
from app import db, Post, User

if False:  # __name__ == '__main__':
    print(User.query.all())

if __name__ == '__main__':
    db.create_all()
    hello_post = Post(title='Hello')
    bye_post = Post(title='Bye')
    seeyou_post = Post(title='See you')
    user_kelvin = User(name='kelvin', post=hello_post)
    user_andrew = User(name='andrew', post=bye_post)
    user_michael = User(name='michael', post=seeyou_post)

    db.session.add_all([hello_post, bye_post, seeyou_post,
                        user_kelvin, user_andrew, user_michael])
    print(hello_post.userid)
    # db.session.add(hello_post)
    # db.session.add(bye_post)
    # db.session.add(seeyou_post)
    # db.session.add(user_kelvin)
    # db.session.add(user_andrew)
    # db.session.add(user_michael)
    db.session.commit()
    print(hello_post.userid)

    print(Post.query.all())
    print(User.query.all())

    # joined = User.query.join(Post)
    #     .add_columns(User.id, User.username, User.role_id, Role.name)
from app import db, User, Post

if __name__ == '__main__':
    db.drop_all()
    db.create_all()
    user_sikyung = User(name='Sikyung')
    user_youngjung = User(name='Youngjung')
    post_skysky = Post(title='skysky', body='skyskysky', user=user_sikyung)
    post_jyjy = Post(title='yjyj', body='jyujyu', user=user_youngjung)

    db.session.add_all([user_sikyung, user_youngjung, post_skysky, post_jyjy])
    db.session.commit()

    print(User.query.all())
    print(Post.query.all())
示例#13
0
from app import db, User, Post

db.create_all()  # create tables from models

user1 = User(name="Sadhan Sarker", email='*****@*****.**')

post1 = Post()
post1.title = "Blog Post Title 1"
post1.body = "This is the first blog post 1"
post1.author = user1

db.session.add(post1)
db.session.add(user1)
db.session.commit()

print(User.query.all())
print(Post.query.all())
示例#14
0
def create_post(title,author, content, adress, note):
	p = Post(title = title, author = author, adress = adress, content = content, created_at = datetime.now(), note =note)
	db.session.add(p)
	db.session.commit()
示例#15
0
    # print(admin_role.id)
    # db.session.commit()
    # print(admin_role.id)

    admin_role.name = 'Adminstrator'
    db.session.add(admin_role)
    # db.session.commit()

    # db.session.delete(mod_role)
    # db.session.commit()

    # joined = User.query.join(Role\
    #                          .add_columns(User.id, User.username, User.role_id, Role.name)\
    #                          .filter(User.role))

    bp_ex1 = Post(body='example 1', title="example 1", user_id=user_john.id)
    bp_ex2 = Post(body='example 2', title="example 2", user_id=user_david.id)
    bp_ex3 = Post(body='example 3', title="example 3", user_id=user_susan.id)
    db.session.add_all([bp_ex1, bp_ex2, bp_ex3])
    db.session.commit()

    # print(Role.query.all())
    # print(User.query.all())
    # print(User.query.filter_by(role=user_role).all())
    # print(str(User.query.filter_by(role=user_role)))
    #
    # user_role = Role.query.filter_by(name='User').first()
    # print(user_role)
    # users = user_role.users
    # print(users)
    # print(users[0].role)
示例#16
0
user = User('*****@*****.**', 'test', 'test', 'test', '5555', "")
db.session.add(user)

#6
user = User('*****@*****.**', 'dresser', 'Tracy', 'Miller', '5555', "")
db.session.add(user)

# create dummy posts for post.db
# using python time object for date/time value in db field
now = time.strftime('%Y-%m-%d %H:%M:%S')

# 1
post = Post(1,
            'Rubiks Cube',
            13.99,
            "awesome toy",
            None,
            "sports",
            image="http://www.goo.gl/ZJCcHQ")
db.session.add(post)

# 2
post = Post(1,
            'Kitchen Table',
            50.00,
            "Ikea table",
            None,
            "furniture",
            image="http://www.goo.gl/MXX8WG")
db.session.add(post)
示例#17
0
from app import app, db, User, Post

db.create_all()

user = User(username='******', email='*****@*****.**', password='******')
db.session.add(user)
db.session.commit()

post1 = Post(title='첫 번째 포스트', content='첫 번째 포스트 내용', author=user)
post2 = Post(title='두 번째 포스트', content='두 번째 포스트 내용', author=user)
db.session.add(post1)
db.session.add(post2)
db.session.commit()
示例#18
0
 def setUp(self):
     self.new_post = Post(password='******')
示例#19
0
from app import Post

LOGIN = "******"
PASSWORD = "******"

if __name__ == "__main__":

    post = Post(LOGIN, PASSWORD)
    print post
示例#20
0
from app import db, User, Post
db.create_all()
john = User(username='******')
post = Post()
post.title = "Hello World"
post.body = "This is the first post of jhon"
post.author = john
db.session.add(post)
db.session.add(john)
jim = User(username='******')
db.session.add(jim)
post2 = Post()
post2.title = "Woooow"
post2.body = "I'm the maaaaask"
post2.author = jim
db.session.add(post2)

db.session.commit()
print(User.query.all())
print(Post.query.all())
示例#21
0
from app import app, db, Post

post1 = Post(server='126.12.195.155', dns_server='Active')
post2 = Post(server='171.244.33.114', dns_server='Active')
post3 = Post(server='126.6.95.109', dns_server='Active')
post4 = Post(server='126.11.119.226', dns_server='Active')
post5 = Post(server='126.76.104.82', dns_server='Active')
post6 = Post(server='126.12.184.215', dns_server='Active')
post7 = Post(server='126.11.106.224', dns_server='Active')
post8 = Post(server='126.75.159.47', dns_server='Active')
post9 = Post(server='126.68.89.112', dns_server='Active')
post10 = Post(server='128.14.6.12', dns_server='Active')
post11 = Post(server='126.11.242.134', dns_server='Active')
post12 = Post(server='67.198.246.244', dns_server='Active')
post13 = Post(server='220.130.175.203', dns_server='Active')
post14 = Post(server='203.67.223.176', dns_server='Active')
post15 = Post(server='122.131.83.35', dns_server='Active')
post16 = Post(server='128.14.6.13', dns_server='Active')
post17 = Post(server='100.43.160.50', dns_server='Active')
post18 = Post(server='126.12.196.105', dns_server='Active')
post19 = Post(server='98.126.8.82', dns_server='Active')
post20 = Post(server='126.11.123.243', dns_server='Active')
post21 = Post(server='202.239.38.236', dns_server='Active')
post22 = Post(server='67.198.141.132', dns_server='Active')
post23 = Post(server='174.139.8.11', dns_server='Active')
post24 = Post(server='126.12.197.233', dns_server='Active')
post25 = Post(server='103.250.72.189', dns_server='Active')
post26 = Post(server='126.12.209.60', dns_server='Active')
post27 = Post(server='174.139.65.10', dns_server='Active')
post28 = Post(server='202.239.38.222', dns_server='Active')
post29 = Post(server='126.68.92.161', dns_server='Active')
示例#22
0
# sudo pip3 install flask_sqlalchemy, mysqlclient
# sudo pip3 install pymongo

# mysql -u root
# create database news;
# mongo
# use news;

# ./inti_test_data.py

db.create_all()
# # ?? MySQL ????

java = Category('Java')
python = Category('Python')
post1 = Post('Hello Java', java, 'File Content - Java is cool!',
             datetime.utcnow())
post2 = Post('Hello Python', python, 'File Content - Python is cool!',
             datetime.utcnow())
db.session.add(java)
db.session.add(python)
db.session.add(post1)
db.session.add(post2)
db.session.commit()

# ?? MongoDB ????
# client = MongoClient('127.0.0.1', 27017)
# mdb = client.news
post1.add_tag('tech')
post1.add_tag('java')
post1.add_tag('linux')
post2.add_tag('tech')
示例#23
0
 def post(self):
     new_post = Post(category=request.json['category'],
                     note=request.json['note'])
     db.session.add(new_post)
     db.session.commit()
     return post_schema.dump(new_post)