Exemple #1
0
def create_db():
    db.drop_all()
    db.create_all()

    hash = hash_password('password')
    user_datastore.create_user(email='*****@*****.**',
                               password=hash,
                               username='******')
    admin = user_datastore.create_user(email='*****@*****.**',
                                       password=hash,
                                       username='******')
    role = user_datastore.create_role(
        name='admin', description='user with administrative privileges')
    admin.roles.append(role)

    bestsellers = Topic(name='Bestsellers',
                        description='Discussions about best-selling books')
    new_releases = Topic(
        name='New Releases',
        description='Discussions about upcoming book releases')
    what_to_read = Topic(name='What Should I Read Next?',
                         description='Discussions about reading suggestions')
    authors = Topic(name='Authors',
                    description='Discussions about book authors')

    db.session.add_all([bestsellers, new_releases, what_to_read, authors])
    db.session.commit()
Exemple #2
0
def topics_index():
    topics = Topic.query.all()
    latest_message = Topic.latest()
    filtered_messages = []
    for topic in topics:
        for x in latest_message:
            if x['topic_id'] == topic.id:
                filtered_messages.append(x)
                break
    
    replies = Topic.replycount()

    return render_template("topics/list.html", topics = topics, places = Place.query.all(), latest_message = filtered_messages, datetime = datetime, replies = replies)
Exemple #3
0
def topics_create():
    form = TopicForm(request.form)

    if not form.validate():
        return render_template("topics/new_topic.html", form=form)

    t = Topic(form.title.data)
    t.creator = current_user.name

    if current_user.admin:
        db.session.add(t)
        db.session.commit()

    return redirect(url_for("topics_index"))
Exemple #4
0
def create_topic():
    form = TopicForm(request.form)

    form.tags.choices = [form.tags.data]

    if not form.validate():
        return render_template("topics/new.html", form=form)

    subject = form.subject.data
    body = form.body.data
    author_id = current_user.id

    initial_post = Post(body)
    initial_post.author_id = author_id
    topic = Topic(subject, author_id)
    topic.posts.append(initial_post)

    tag_names = form.tags.data[0].split(",")
    for tag_name in tag_names:
        tag = Tag.query.filter_by(name=tag_name).first()
        if not tag:
            tag = Tag(tag_name)
        topic.tags.append(tag)

    db.session().add(topic)
    db.session().commit()

    return redirect(url_for("topics_index"))
Exemple #5
0
def topics_create():
    form = TopicForm(request.form)
    if form.title.validate(form) and form.message.validate(form):
        place = db.session.query(Place).get(form.place.data)
        if form.place.data == 0:
            place_id = 0
        else:
            place_id = place.id
          
        topic = Topic(form.title.data, place_id)
        db.session().add(topic)
        db.session().commit()
        topic_timefix = Topic.query.get(topic.id)
        topic_timefix.date_created = datetime.now().replace(microsecond=0, second = 0)
        db.session().commit

        message = Message(form.message.data, topic.id, current_user.id)
        db.session().add(message)
        db.session().commit()
        message_timefix = Message.query.get(message.id)
        message_timefix.date_created = datetime.now().replace(microsecond=0, second = 0)
        db.session().commit()

        newTopicAccount = topicAccount.insert().values(topic_id=topic.id, account_id=current_user.id)
        db.session().execute(newTopicAccount)
        db.session.commit()

        return redirect(url_for("topics_index"))
    
    places = db.session.query(Place)
    form=TopicForm()
    form.place.choices = [("0", "---")] + [(i.id, i.name) for i in places]

    return render_template("topics/new.html", form = form, error="topic name must be between 1-100 characters and message between 1-1000 characters")
Exemple #6
0
def messages_index(topic_id):
    t = Topic.find_topic_with_creator_info(topic_id)
    # will be form [{ "name": '', "id": '', "date_created": row[2], "date_modified": row[3], "desription": row[4], "category_id": row[5], "account": {"id": row[6], "username": row[7]} }]
    c = Category.query.get(t[0]["category_id"])
    topic_messages = Message.find_messages_for_topic_with_users(topic_id)
    # will be form { message: { message: '', id: '' }, account: { username: '', id: '' } }
    return render_template("messages/list.html", messages = topic_messages, topic = t[0], category = c)
Exemple #7
0
def profile_show(account_id):
    user = User.query.get(account_id)
    latest_messages = Message.find_ten_latest_messages_by_user_id(user.id)
    latest_topics = Topic.find_ten_latest_topics_by_user_id(user.id)
    return render_template("auth/show.html",
                           user=user,
                           latest_messages=latest_messages,
                           latest_topics=latest_topics)
Exemple #8
0
def search_topics():
    form = SearchForm(request.form)

    if not form.validate():
        return render_template("topics/search.html", form=form)

    search_results = Topic.search_topics(subject=form.subject.data,
                                         author=form.author.data)

    return render_template("topics/search_results.html", topics=search_results)
Exemple #9
0
def topic_create():
    form = TopicForm(request.form)
    name = form.name.data

    # validoidaan syöte
    if not form.validate():
        return render_template("topic_creation_form.html", form=form)

    # tarkistetaan löytyykö aihe jo tietokannasta, estetään duplikaatti
    already_exists = Topic.topic_already_exists(name)
    if already_exists == True:
        return render_template("topic_list.html", topics=Topic.query.all())

    # lisätään tietokantaan
    new_topic = Topic(name=form.name.data)
    db.session.add(new_topic)
    db.session.commit()

    # paluu aihelistaan
    return render_template("topic_list.html", topics=Topic.query.all())
Exemple #10
0
def topics_create():
    form = TopicForm(request.form)

    if not form.validate():
        return render_template("topics/new.html", form=form)

    topic = Topic(form.name.data)

    db.session().add(topic)
    db.session().commit()

    return redirect(url_for("topics_index"))
Exemple #11
0
def rename_topic(topic_id):
    form = TopicForm(request.form)

    topic = Topic.query.get(topic_id)
    topicname = Topic(form.name.data)

    if not form.validate():
        return render_template("topics/list.html",
                               topics=Topic.query.all(),
                               form=form)

    topic.name = topicname.name
    db.session().commit()

    return redirect(url_for("topics_index"))
Exemple #12
0
def search_from_everywhere(text):

    query = text.lower()

    messages = Message.find_by_given_text(query)

    topics = Topic.find_by_given_text(query)

    users = User.find_by_given_text(query)

    categories = Category.find_by_given_text(query)

    return render_template('search_results.html',
                           text=text,
                           messages=messages,
                           topics=topics,
                           users=users,
                           categories=categories)
Exemple #13
0
def topics_popular_sql():
    return render_template("topics/list_newest_sql_postgre.html",
                           topics=Topic.find_latest_sql())
Exemple #14
0
def topics_popular():
    return render_template("topics/list_popular_topics.html",
                           topics=Topic.find_most_popular())
Exemple #15
0
def index():
    return render_template("index.html", all_topics=Topic.all_topics())
Exemple #16
0
def search():
    name = request.form.get("option")
    return render_template("coursesbytopic.html",
                           find_courses=Topic.find_courses_by_topic(name))