def messages_create(channel_id): messageform = MessageForm(request.form) channel = Channel.query.get(channel_id) if not messageform.validate() or messageform.body.data.isspace(): return render_template( "channels/channel.html", messageform=MessageForm(), channel=channel, que=Message.count_how_many_comments_get_first(channel_id), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), allready_join=Channel.is_joined(channel_id, current_user.id), error="message must be 2 character length", public_channels=Channel.get_all_publics()) message = Message(messageform.body.data, current_user.username) message.account_id = current_user.id message.channel_id = channel_id db.session().add(message) db.session().commit() return redirect( url_for("one_channel_index", channel_id=channel_id, sort='first'))
def channel_manager(): return render_template( "channels/manager.html", channels=Channel.query.all(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics())
def channel_change(channel_id): return render_template( "channels/update.html", channel=Channel.query.get(channel_id), channelform=ChannelForm(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics())
def account_list(): if current_user.admin == False: return redirect(url_for("messages_index")) if request.method == "GET": return render_template("auth/list.html", accounts = Account.query.order_by(Account.username).all(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics())
def single_account_index(account_id): account = Account.query.get(account_id) return render_template("auth/index.html", account = account, accountform = AccountForm(), channels = Account.find_accounts_channels(account_id), my_channels=Channel.get_my_channels(account_id), all_channels=Channel.get_channels_where_not_in(account_id), public_channels=Channel.get_all_publics(), messages=Message.query.filter_by(account_id=account_id), comments=Comment.get_comment_message_and_channel_id(account_id))
def channels_create(): if request.method == "GET": return render_template( "channels/new.html", channelform=ChannelForm(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics()) channelform = ChannelForm(request.form) print("tässä errorit jeeeee") for error in channelform.name.errors: print("hellurei täs nyt") print(error) if not channelform.validate(): return render_template( "channels/new.html", channelform=channelform, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics()) channel = Channel(channelform.name.data, channelform.introduction.data, current_user.id) if channelform.public.data == "true": channel.public = True else: channel.public = False channel.accounts.append(current_user) db.session().add(channel) db.session().commit() new_channel = Channel.get_channel_by_name(channel.name) return redirect( url_for("one_channel_index", channel_id=new_channel, sort='first'))
def accounts_update(account_id): accountform = AccountForm(request.form) # check if username is whitespaces only char1 = False email = False not_same = False messages = [] messages.append("THESE ARE THE CONDITIONS YOU MUST PAST") messages.append("*username must be 2 character length") messages.append("*password must be 8 character length") messages.append("*motto must be 2 character length") messages.append("*email must be 6 character length and must be real email") # email check for c in accountform.email.data: if c == '@': char1 = True if char1 == True: if c == '.': email = True if not accountform.password.data == accountform.password2.data: messages.append("*password was not same") not_same = True if not accountform.validate() or email == False or accountform.username.data.isspace() or not_same == True: return render_template("auth/index.html", accountform = AccountForm(), errors = messages, account=current_user, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), channels=Account.find_accounts_channels(current_user.id), public_channels=Channel.get_all_publics(), messages=Message.query.filter_by(account_id=current_user.id), comments=Comment.get_comment_message_and_channel_id(current_user.id)) account = Account.query.get(account_id) account.username = accountform.username.data account.password = accountform.password.data account.motto = accountform.motto.data account.email = accountform.email.data db.session().commit() return redirect(url_for("single_account_index"))
def account_create(): if request.method == "GET": return render_template("auth/new.html", accountform = AccountForm(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics()) messages = [] messages.append("THESE ARE THE CONDITIONS YOU MUST PAST") messages.append("*username must be 2 character length") messages.append("*password must be 8 character length") messages.append("*motto must be 2 character length") messages.append("*email must be 6 character length and must be real email") accountform = AccountForm(request.form) password_wrong = "" not_same = False if not accountform.password.data == accountform.password2.data: password_wrong="Passwords must be same" not_same = True if not accountform.validate() or not_same == True: return render_template("frontpage.html", accountform = AccountForm(), error="somethin went wrong :(", pass_error = password_wrong, errors=messages) account = Account(accountform.username.data, accountform.password.data, accountform.motto.data, accountform.email.data) account.admin = False if current_user.is_authenticated: if request.form.get("super") == "True": account.admin = True db.session().add(account) db.session().commit() # this happens if admin is creating account if current_user.is_authenticated: return redirect(url_for("one_channel_index", channel_id=1, sort="first")) return redirect(url_for("auth_login"))
def message_index(channel_id, message_id): c = Channel.query.get(channel_id) m = Message.query.get(message_id) comments = [] if m is not None: comments = m.comments return render_template( "messages/message.html", channel=c, message=m, comments=comments, messageform=MessageForm(), all_channels=Channel.get_channels_where_not_in(current_user.id), my_channels=Channel.get_my_channels(current_user.id), public_channels=Channel.get_all_publics())
def one_channel_index(channel_id, sort): query = [] account_count = Channel.count_accounts(channel_id) if sort == 'first': query = Message.count_how_many_comments_get_first(channel_id) elif sort == 'last': query = Message.count_how_many_comments_get_last(channel_id) return render_template( "channels/channel.html", messageform=MessageForm(), channel=Channel.query.get(channel_id), que=query, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), allready_join=Channel.is_joined(channel_id, current_user.id), public_channels=Channel.get_all_publics(), account_count=account_count)
def channel_update(channel_id): c = Channel.query.get(channel_id) channelform = ChannelForm(request.form) if not channelform.validate(): return render_template( "channels/update.html", channel=c, channelform=channelform, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id)) c.name = channelform.name.data c.introduction = channelform.introduction.data if channelform.public.data == "true": c.public = True else: c.public = False db.session().commit() return redirect( url_for("one_channel_index", channel_id=channel_id, sort='first'))