Commit 96293c3f authored by danmcquillan's avatar danmcquillan
Browse files

adding lab 20 steps 1,2,3

parent 50d7281b
{% extends "base.html" %}
{% block body %}
<div class="jumbotron">
<div >
<form class="form-horizontal" method="post" action="/add_twit">
{{ form.csrf_token }}
<div class='form-group'>
<div class='col-md-6'>
{% if form.twit.errors %}
<ul class='errors'>
{% for error in form.twit.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form.twit(class='form-control',placeholder='twit') }}
</div>
</div>
<div class='form-group'>
<div class='col-md-6'>
{{ form.submit(class='btn btn-primary btn-block') }}
</div>
</div>
</form>
</div>
</div>
{% endblock %}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<!--- flash messages -->
{% for category, message in get_flashed_messages(with_categories=true) %}
<div class="alert alert-dismissable alert-warning alert-{{ category }}">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
{% if current_user.is_authenticated %}
<div class="lead mark">
logged in as {{ current_user.username }}
</div>
{% endif %}
<!--- the body will come from a template that inherits from this one -->
{% block body %}{% endblock %}
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
</body>
</html>
{% extends "base.html" %}
{% block body %}
<div class="jumbotron">
<div >
<form class="form-horizontal" method="post" action="/edit_twit">
{{ form.csrf_token }}
<div class='form-group'>
<div class='col-md-6'>
{% if form.twit.errors %}
<ul class='errors'>
{% for error in form.twit.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form.twit(class='form-control') }}
</div>
</div>
<div>
{{ form.twit_id }}
</div>
<div class='form-group'>
<div class='col-md-6'>
{{ form.submit(class='btn btn-primary btn-block') }}
</div>
</div>
</form>
</div>
</div>
{% endblock %}
{% extends "base.html" %}
{% block body %}
<div class="jumbotron">
{% for twit in twits %}
<div class="row">
<div class="col-md-4">{{ twit['username'] }}</div>
<div class="col-md-4">{{ twit['twit'] }}</div>
<div class="col-md-4"><a href='/edit_twit?id={{ twit['twit_id'] }}'> edit </a><a
href='/delete_twit?id={{ twit['twit_id'] }}'> delete </a></div>
</div>
{% endfor %}
</div>
{% endblock %}
from flask import Blueprint
from flask import render_template
from flask import redirect, url_for
from flask import request
from vs_url_for import vs_url_for
from flask_login import current_user
from flask_login import LoginManager, login_required
from forms import addTwitForm, editTwitForm
from dbhelper import db
twits_blueprint = Blueprint('twits_blueprint', __name__,
template_folder = 'templates')
@twits_blueprint.route('/')
def index():
twits = db.get_all_twits()
return render_template("mytwits_mysql.html", twits=twits)
@twits_blueprint.route('/add_twit', methods = ['GET', 'POST'])
@login_required
def add_twit():
form = addTwitForm()
if form.validate_on_submit():
twit = form.twit.data
user_id = current_user.user_id
db.add_twit(twit,user_id)
return redirect(vs_url_for('.index'))
return render_template('add_twit_mysql.html',form=form)
@twits_blueprint.route('/edit_twit', methods = ['GET', 'POST'])
@login_required
def edit_twit():
form = editTwitForm()
if request.args.get('id'):
twit_id = request.args.get('id')
twit = db.get_twit(twit_id)
form.twit.data = twit['twit']
form.twit_id.data = twit_id
return render_template('edit_twit_mysql.html',form=form,twit=twit)
if form.validate_on_submit():
twit = form.twit.data
twit_id = form.twit_id.data
db.update_twit(twit,twit_id)
return redirect(vs_url_for('.index'))
return render_template('edit_twit_mysql.html',form=form)
@twits_blueprint.route('/delete_twit', methods = ['GET', 'POST'])
@login_required
def delete_twit():
if request.args.get('id'):
twit_id = request.args.get('id')
twit = db.delete_twit(twit_id)
return redirect(vs_url_for('.index'))
class User:
def __init__(self, user_id,username):
self.user_id = user_id
self.username = username
def username(self):
return self.username
@property
def is_authenticated(self):
return True
@property
def is_active(self):
return True
@property
def is_anonymous(self):
return False
def get_id(self):
return self.user_id
def __repr__(self):
return 'user_id {}'.format(self.user_id)
from flask import url_for
URL_PREFIX = '/usr/253'
#URL_PREFIX = ''
def vs_url_for(view):
url = url_for(view)
url = URL_PREFIX + url
return url
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment