Ejemplo n.º 1
0
def blogs(user):
    for i in range(30):
        Blog.create(
            title="test_blog" + str(i),
            url="test_blog" + str(i),
            creator=user,
            created_date=datetime.datetime.now(),
            updated_date=datetime.datetime.now(),
        )

    from src.model import db

    db.db_wrapper.database.close()
Ejemplo n.º 2
0
def blog(user, reader_token):
    blog = Blog.create(
        title="test_blog",
        url="test_blog",
        creator=user,
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
    )
    BlogParticipiation.create(blog=blog, user=user, role=1)

    writer = User.create(
        username="******",
        password="******",
        email="asd",
        registration_date=datetime.datetime.now(),
        last_active_date=datetime.datetime.now(),
    )
    BlogParticipiation.create(blog=blog, user=writer, role=2)

    BlogParticipiation.create(blog=blog, user=reader_token[0], role=3)

    from src.model import db

    db.db_wrapper.database.close()

    return blog
Ejemplo n.º 3
0
def blog(user):
    blog = Blog.create(
        title="test_blog",
        url="test_blog",
        creator=user,
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
    )
    BlogParticipiation.create(blog=blog, user=user, role=1)

    from src.model import db

    db.db_wrapper.database.close()

    return blog
Ejemplo n.º 4
0
def create_blog_for_jam(user, title, url, image=None):
    blog = Blog.create(
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
        creator=user,
    )
    BlogParticipiation.create(blog=blog, user=user, role=1)

    blog.title = title
    blog.description = f'Это блог для джема "{title}"'
    blog.url = url
    blog.blog_type = 1
    if image:
        blog.image = Content.get_or_none(Content.id == image)

    blog.updated_date = datetime.datetime.now()
    blog.save()

    return blog
Ejemplo n.º 5
0
def create_blog():
    """Создать блог"""
    user = get_user_from_request()

    url = request.get_json()["url"]
    if Blog.get_or_none(Blog.url == url) is not None:
        return errors.blog_url_already_taken()

    blog = Blog.create(
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
        creator=user,
    )

    BlogParticipiation.create(blog=blog, user=user, role=1)

    fill_blog_from_json(blog, request.get_json())
    blog.save()

    return jsonify({"success": 1, "blog": blog.to_json()})
Ejemplo n.º 6
0
def jam(user, reader_token):
    jam_title = "test jam"
    jam_url = "test-jam"

    blog = Blog.create(
        title="test_blog",
        url="test_blog",
        creator=user,
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
    )
    BlogParticipiation.create(blog=blog, user=user, role=1)

    blog.title = jam_title
    blog.description = f'Это блог для джема "{jam_title}"'
    blog.url = jam_url
    blog.blog_type = 1
    blog.save()

    jam = Jam.create(
        created_date=datetime.datetime.now(),
        updated_date=datetime.datetime.now(),
        creator=user,
        blog=blog,
        title=jam_title,
        url=jam_url,
        description="some description without tags",
        short_description="short description",
        start_date=datetime.datetime.now() + timedelta(seconds=1),
        end_date=datetime.datetime.now() + timedelta(seconds=5),
    )

    from src.model import db

    db.db_wrapper.database.close()

    return jam
Ejemplo n.º 7
0
def convert():
    create_app()

    def get_blog_type(blog):
        if blog.blog_type == "open":
            return 1
        elif blog.blog_type == "hidden":
            return 3
        else:
            return 2

    for b in TuBlog.select():
        blog_type = get_blog_type(b)

        year = b.blog_date_add.year
        month = b.blog_date_add.month
        avatar = content.create_content(b.blog_avatar, "blog_avatar", b.blog,
                                        b.user_owner, year, month)

        updated = b.blog_date_edit
        if not updated:
            updated = b.blog_date_add

        owner = User.get_or_none(User.id == b.user_owner)
        if not owner:
            print("Skipped blog. Owner:" +
                  TuUser.get(TuUser.user == b.user_owner).user_login)
            continue

        about = content.replace_uploads_in_text(owner, b.blog_description)

        url = b.blog_url or "blog" + str(b.blog)
        blog = Blog.create(
            id=b.blog,
            created_date=b.blog_date_add,
            updated_date=updated,
            description=about,
            title=b.blog_title,
            url=url,
            blog_type=blog_type,
            creator=owner,
            image=avatar,
        )

        BlogParticipiation.create(
            blog=blog,
            user=owner,
            role=1,
        )

    for bu in TuBlogUser.select():
        role = 1
        if bu.user_role == 1:
            role = 3
        if bu.user_role > 1:
            role = 1

        BlogParticipiation.create(
            blog=Blog.get(Blog.id == bu.blog),
            user=User.get(User.id == bu.user),
            role=role,
        )