Пример #1
0
def read_article(article_id):
    current_article = article.get_full_article(article_id)

    if not current_article:
        flash(
            'Article does not exist, please check your url. If  you navigated to the URL from our site, please help us out by reporting the error on the "Contact" page.',
            'warning')
        return redirect(url_for('navigation_views.all_articles'))

    if not current_article.is_released:
        flash(
            f'{current_article.title} has not been released to the public yet, or it has been archived.',
            'warning')
        return redirect(url_for('navigation_views.all_articles'))

    tags = article.get_edit_tags(current_article.current_edit_id)
    author = profile.get(id=current_article.author_id)
    return render_template(
        template_name_or_list='articles/read.html',
        website_title=current_article.title,
        website_description=current_article.preview,
        website_image=image.get_preview(current_article.image_file),
        website_publish=current_article.posted,
        website_author_twitter=author.twitter_handle,
        content=current_article,
        release=False,
        suggest_edit=current_user.is_authenticated,
        go_to_latest=False,
        nav_data=navigation.data(),
        tags=tags,
        display_posted=article.is_display_posted(current_article),
        additional_script='/static/js/article.js',
    )
Пример #2
0
def create_article():
    article_form = ArticleForm()
    tags=article.get_tags()
    article_form.tags.choices = tags
    article_form.rows = len(tags)
    article_form.multiple = True
    if article_form.validate_on_submit():
        if article_form.image_file.data:
            image_file = image.save(article_form.image_file.data, 'articles')
            image.save_preview(article_form.image_file.data, image_file)
        else:
            image_file = None
        edit = article.create(article_form, image_file)
        if  article_form.save.data:
            return redirect(url_for('maintenance.update_article', edit_id = edit.id))
        elif article_form.step_forward.data:
            article.ready_for_review(edit)
            flash('Article has been released for review.', 'success')
            return redirect(url_for('navigation_views.view', edit_id = edit.id))
    return render_template(
        template_name_or_list=f'articles/update.html', 
        website_title='Create a new article.',
        article_form=article_form,
        current_article=None,
        status_message = 'Create a New Article',
        step_forward = True,
        nav_data=navigation.data(),
    )
Пример #3
0
def read_messages():
    read_messages = messages.get_read()
    unread_messages = messages.get_unread()
    return render_template(
        template_name_or_list=f'maintenance/messages.html', 
        website_title='Read the messages.',
        nav_data=navigation.data(), 
        read_messages=read_messages,
        unread_messages=unread_messages,
    )
Пример #4
0
def about(id):
    current_profile = profile.get(id=id)
    return render_template(
        template_name_or_list='navigation/about.html',
        website_title=f'Meet {current_profile.full_name}!',
        website_description=f'Learn more about {current_profile.full_name}',
        website_image=image.get_preview(current_profile.image_file),
        nav_data=navigation.data(),
        author=current_profile,
    )
Пример #5
0
def article_by_tag(tag):
    articles = article.get_by_tag(tag)
    tags = article.get_current_used_tags()
    return render_template(
        template_name_or_list='navigation/articles.html',
        website_title=article.get_tag_desc(tag),
        website_description=f'Articles with tag: {article.get_tag_desc(tag)}',
        nav_data=navigation.data(),
        articles=articles,
        tags=tags,
        current_tags=[int(tag)],
    )
Пример #6
0
def read_message(message_id):
    is_marked_read = messages.mark_read(message_id)
    if not is_marked_read:
        return redirect(url_for('maintenance.read_messages'))
    else:
        message = messages.get_message(message_id)
        return render_template(
            template_name_or_list='maintenance/message.html',
            website_title='Read Message',
            nav_data=navigation.data(), 
            message=message,
        )
Пример #7
0
def all_articles():
    articles = article.get_all_released()
    tags = article.get_current_used_tags()
    return render_template(
        template_name_or_list='navigation/articles.html',
        website_title='Read some amazing stories.',
        website_description="Browse all of the articles we've written so far.",
        nav_data=navigation.data(),
        articles=articles,
        tags=tags,
        current_tags=[],
    )
Пример #8
0
def contact():
    contact_form = ContactForm()
    contact_form.reason.choices = messages.get_reasons()
    if contact_form.validate_on_submit():
        messages.save(contact_form)
        flash('Thank you for contacting us! We love the feedback!', 'success')
        return redirect(url_for('navigation.index'))
    return render_template(
        template_name_or_list='navigation/contact.html',
        website_title='We love to hear from you!',
        nav_data=navigation.data(),
        contact_form=contact_form,
    )
Пример #9
0
def update_article(edit_id):    
    #TODO Update the get edit to look for the latest open
    current_edit = article.get_edit(id = edit_id)
    current_article = article.get_article(id=current_edit.article_id)
    article_form = ArticleForm()
    tags=article.get_tags()
    article_form.tags.choices = tags
    can_step_forward = current_article.author_id == current_user.id
    can_edit = current_edit.is_edited
    is_current_user = current_user.id == current_edit.user_id
    if not is_current_user and can_edit:
        article.freeze_edit(current_edit)
        current_edit = article.create_edit_existing(current_edit)
        return redirect(url_for('maintenance.update_article', edit_id=current_edit.id))
    
    if not can_edit:
        return redirect(url_for('navigation_views.view', edit_id = current_edit.id))
    
    if article_form.validate_on_submit():
        if article_form.image_file.data:
            image.delete(current_edit.image_file,'articles')
            image.delete(current_edit.image_file,'preview')
            current_edit.image_file = image.save(article_form.image_file.data, 'articles')
            image.save_preview(article_form.image_file.data, current_edit.image_file)
        article.update_edit(article_form,current_edit)
        
        if article_form.step_forward.data:
            article.edit_is_ready_for_release(current_edit)
            flash('Article has been released for review','success')
            return redirect(url_for('maintenance.maintain_articles', edit_id = current_edit.id))
        elif article_form.save.data:
            flash('Changes have been saved.','success')
            return redirect(url_for('maintenance.update_article', edit_id = current_edit.id))
    
    elif request.method == 'GET':
        article_form = article.update_form_data(article_form, current_edit)
        default_tags = [str(tag.tag_id) for tag in current_edit.tags]
        article_form.tags.data = default_tags
        article_form.rows = len(tags)
        article_form.multiple = True
    return render_template(
        template_name_or_list=f'articles/update.html', 
        website_title='Update Article',
        article_form=article_form,
        current_article=None,
        status_message='Edit Article',
        step_forward = can_step_forward,
        nav_data=navigation.data(), 
        image_file = current_edit.image_file,
    )
Пример #10
0
def update_update(update_id):
    current_update = update.get(int(update_id))
    update_form = UpdatesForm()
    if update_form.validate_on_submit():
        update.update(update_form, current_update)
        return redirect(url_for('navigation.index'))
    elif request.method == 'GET':
        update_form = update.update_form_data(update_form, current_update)
    return render_template(
        template_name_or_list='maintenance/update.html', 
        website_title='Update',
        update_form=update_form,
        nav_data=navigation.data()
    )
Пример #11
0
def maintain_articles():
    open_edits = article.get_open_edits()
    open_to_review = article.get_open_to_review()
    released = article.get_all_released()
    archived_articles = article.get_all_archived()
    archived_edits = None
    return render_template(
        template_name_or_list=f'maintenance/articles.html', 
        website_title='Add/Edit Articles',
        nav_data=navigation.data(),
        open_edits = open_edits,
        open_to_review = open_to_review,
        released = released,
        archived_edits = archived_edits,
        archived_articles = archived_articles,
    )
Пример #12
0
def view(edit_id):
    current_edit = article.get_full_edit(edit_id)
    tags = article.get_edit_tags(current_edit.id)
    can_release = profile.all_access(
    ) and current_user.id != current_edit.author_id and current_edit.is_ready_for_release
    return render_template(
        template_name_or_list='articles/read.html',
        website_title=current_edit.title,
        content=current_edit,
        release=can_release,
        suggest_edit=current_user.is_authenticated,
        go_to_latest=False,
        nav_data=navigation.data(),
        tags=tags,
        display_posted=article.is_display_posted(current_edit),
        additional_script='/static/js/article.js',
    )
Пример #13
0
def update_profile():
    profile_form = UpdateProfile()
    if profile_form.validate_on_submit() and current_user.is_authenticated:
        if profile_form.image_file.data:
            image.delete(current_user.image_file, 'authors')
            current_user.image_file = image.save(profile_form.image_file.data, 'authors')
            image.save_preview(profile_form.image_file.data, current_user.image_file)
        profile.update(profile_form)
        flash('Profile updated','success')
        return redirect(url_for('maintenance.update_profile'))
    elif request.method == 'GET':
        profile_form = profile.update_form_data(profile_form)
    return render_template(
        template_name_or_list=f'maintenance/profile.html', 
        website_title='Update Your Profile',
        profile_form=profile_form,
        nav_data=navigation.data(),
    )
Пример #14
0
def request_reset():
    form = RequestResetForm()
    if form.validate_on_submit():
        user = profile.get(email=form.email.data)
        profile.update_password_email(user)
        flash(
            'Email has been sent with instructions on changing your password.',
            'success')
        return redirect(url_for('user.logout'))
    if current_user.is_authenticated:
        form.email.data = current_user.email
    return render_template(
        template_name_or_list='user/requestresetpassword.html',
        website_title='Reset you password',
        form=form,
        additional_css='/static/css/forms.css',
        nav_data=navigation.data(),
    )
Пример #15
0
def reset_password(token):
    form = ResetPasswordForm()
    verified_user = profile.verify_reset_token(token)
    if not verified_user:
        flash('Request has expired or invalid url used.', 'warning')
        return redirect(url_for('navigation.index'))
    if form.validate_on_submit():
        profile.update_password(
            user=verified_user,
            form=form,
        )
        return redirect(url_for('navigation.index'))
    return render_template(
        template_name_or_list='user/resetpassword.html',
        website_title='Reset you password',
        form=form,
        user=verified_user,
        additional_css='/static/css/forms.css',
        nav_data=navigation.data(),
    )
Пример #16
0
def login():
    form = LogInForm()
    if current_user.is_authenticated:
        return redirect(url_for('navigation.index'))
    if form.validate_on_submit():
        user = profile.get(email=form.email.data)
        if user and profile.is_password_correct(user.password,
                                                form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            flash(f'Logged in as {user.full_name}', 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('navigation.index'))
        else:
            flash(
                f'Something went wrong, please check the email and password.',
                'danger')
    return render_template(
        template_name_or_list='user/login.html',
        website_title='Log in to your account',
        form=form,
        additional_css='/static/css/forms.css',
        nav_data=navigation.data(),
    )
Пример #17
0
def index():
    return render_template(
        template_name_or_list='navigation/index.html',
        website_title='Welcome to Courageous Engineer!',
        nav_data=navigation.data(),
    )