Beispiel #1
0
def set_tags_for_post(post, json):
    if json is not None:
        tags = json.get("tags", [])
        TagMark.delete().where(TagMark.post == post).execute()
        for t in tags:
            tag = Tag.get_or_none(Tag.title == t)
            if tag is None:
                tag = Tag.create(title=t, created_date=datetime.datetime.now())
            TagMark.create(tag=tag, post=post)
Beispiel #2
0
def tag_no_post():
    tag = Tag.create(created_date=datetime.datetime.now(), title=u"тэг",)

    from src.model import db

    db.db_wrapper.database.close()

    return tag
Beispiel #3
0
def convert():
    create_app()

    for t in TuTopic.select():
        creator = User.get_or_none(User.id == t.user)
        if not creator:
            print("Skipped post. Owner:" +
                  TuUser.get(TuUser.user == t.user).user_login)
            continue

        updated = t.topic_date_edit
        if not updated:
            updated = t.topic_date_add

        topic_content = TuTopicContent.get(TuTopicContent.topic == t.topic)
        text = topic_content.topic_text_source

        text = content.replace_uploads_in_text(creator, text)
        # TODO convert questions and photosets

        cut = text.split("<cut>")[0]
        post = Post.create(
            id=t.topic,
            blog=Blog.get(Blog.id == t.blog),
            creator=creator,
            created_date=t.topic_date_add,
            updated_date=updated,
            title=t.topic_title,
            cut_text=cut,
            has_cut="<cut>" in text,
            text=text,
            rating=0,
            is_draft=t.topic_publish == 0,
            is_on_main=t.topic_publish_index == 1,
            reads=0,
            url=t.topic_url,
        )

        tags = t.topic_tags.split(",")
        for tag in tags:
            tag_obj = Tag.get_or_none(title=tag)
            if tag_obj is None:
                tag_obj = Tag.create(title=tag, created_date=t.topic_date_add)
            TagMark.create(tag=tag_obj, post=post)
Beispiel #4
0
def suggestion():
    """Получить список предлагаемых тегов для автодополнения"""
    json = request.get_json()
    if "title" not in json:
        return errors.wrong_payload("title")

    title = json["title"]
    query = Tag.select().where(Tag.title.contains(title))

    return jsonify({"success": 1, "tags": [t.to_json() for t in query]})
Beispiel #5
0
def tag(post):
    tag = Tag.create(created_date=datetime.datetime.now(), title=u"тэг",)

    TagMark.create(tag=tag, post=post)

    from src.model import db

    db.db_wrapper.database.close()

    return tag
Beispiel #6
0
def seed():
    print("Seeding database...")

    db = get_db()
    tags_table.delete()

    tags = json.loads(open('data/tags.json').read())
    Tag.query.delete()
    for tag in tags:
        tag_model = Tag()
        tag_model.name = tag['name']
        db.add(tag_model)
        db.commit()

    collections = json.loads(open('data/collections.json').read())
    Collection.query.delete()
    db.commit()
    for collection in collections:
        collection_model = Collection()
        collection_model.name = collection['name']
        collection_model.default = collection['default']
        collection_model.tags = [Tag.query.filter_by(name=name).first() for name in collection['tags']]
        db.add(collection_model)
        db.commit()

    characters_file = json.loads(open('data/characters.json').read())
    Character.query.delete()
    for character in characters_file:
        character_model = Character()
        character_model.name = character['name']
        character_model.collection_id = Collection.query.filter_by(name=character['collection_name']).first().id
        if 'image' in character:
            image = Image(image_url=character['image']['url'], license=character['image']['license'],
                          creator=character['image']['creator'])
            character_model.image = image
            db.add(image)
        db.add(character_model)
        db.commit()

    seed_admin()
Beispiel #7
0
def tags():
    """Получить список тегов, отсортированный по популярности"""
    query = Tag.get_tags()
    limit = max(1, min(int(request.args.get("limit") or 20), 100))
    paginated_query = PaginatedQuery(query, paginate_by=limit)

    return jsonify(
        {
            "success": 1,
            "tags": [t.to_json() for t in paginated_query.get_object_list()],
            "meta": {"page_count": paginated_query.get_page_count()},
        }
    )
Beispiel #8
0
def tag(title):
    """Получить посты с указанным тегом"""
    tag = Tag.get_or_none(Tag.title == title)
    if tag is None:
        return errors.not_found()

    query = Post.get_public_posts_with_tag(tag)
    limit = max(1, min(int(request.args.get("limit") or 20), 100))
    paginated_query = PaginatedQuery(query, paginate_by=limit)

    posts = [p.to_json() for p in paginated_query.get_object_list()]
    posts = [Vote.add_votes_info(p, 3, get_user_from_request()) for p in posts]

    return jsonify(
        {
            "success": 1,
            "posts": posts,
            "meta": {"page_count": paginated_query.get_page_count()},
        }
    )