def createArticle(): """renders the create article page (must be logged in in order to access)""" form = SubmitArticle() if form.validate_on_submit(): article = Article( heading=clean_string(form.heading.data), body=clean_string(form.body.data), post_date=datetime.now().strftime("%m/%d/%Y, %H:%M:%S"), accept_date=None, is_accepted=False, # is_english=form.is_engish.data, author_id=current_user.get_id(), caption=clean_string(form.caption.data), thumbnail=clean_string(form.thumbnail.data) if clean_string(form.thumbnail.data) else "https://lh5.googleusercontent.com/p/AF1QipMF1XVDYrw7O7mg3E_fLqgAceacWExqaP4rbptz=s435-k-no" ) db.session.add(article) db.session.commit() msg = newArticleMessage(article) mail.send(msg) flash('הכתבה נוצרה בהצלחה וממתינה לאישור מנהל.', 'success') return redirect(url_for('articles', index=article.article_id)) return render_template('submitArticle.html', title="צור כתבה חדשה", form=form)
def register(): """renders the registration page""" if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): """whenever the form is submitted, enter the credentials into the database and hash the password""" hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(first_name=clean_string(form.first_name.data), last_name=clean_string(form.last_name.data), email=clean_string(form.email.data), password=hashed_password, school_class=clean_string(form.school_class.data), user_type="NOT_APPROVED") db.session.add(user) db.session.commit() """send an email to the admins about the new user""" msg = newUserMessage(user) mail.send(msg) flash( 'המשתמש נוצר בהצלחה. המתן לאישורו, לאחר האישור יהיה ניתן להתחבר עם המשתמש לאתר.', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', message='דף הירשמות', form=form)
def editArticle(index): """renders the edit page article (must be logged and have ownership over the article in in order to access)""" article = Article.query.get(index) if not article or (not (current_user.is_authenticated and (current_user.user_id == article.author_id or current_user.is_admin()))): abort(404, description="Resource not found") form = SubmitArticle() form.submit.label.text = "שמור שינויים" if form.validate_on_submit(): article.heading = clean_string(form.heading.data) # article.is_english = form.is_english.data article.body = clean_string(form.body.data) article.caption = clean_string(form.caption.data) article.thumbnail = clean_string(form.thumbnail.data) if clean_string( form.thumbnail.data ) else "https://lh5.googleusercontent.com/p/AF1QipMF1XVDYrw7O7mg3E_fLqgAceacWExqaP4rbptz=s435-k-no" db.session.commit() flash('הכתבה עודכנה בהצלחה', 'success') return redirect(url_for('articles', index=article.article_id)) elif request.method == 'GET': form.heading.data = article.heading form.caption.data = article.caption form.body.data = article.body form.thumbnail.data = article.thumbnail return render_template('submitArticle.html', title="ערוך כתבה", form=form)