-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.16
flaskapp
Overview
Source
Commits
Branches
Pull requests Pipelines
Downloads Boards Boards
Settings
kwmccabe flaskapp Commits
Commit
kwmccabe committed c0cddb5
2018-03-12
View source
Approve
Item fields (active,item_title,item_text,mod_update), Delete Item confirmation
Participants
kwmccabe
Parent commits 05d1863
Branches master
TagsNo tags
Raw commit View raw commit
Watch Stop watching
Comments (0)
Files changed (14)
+6 -3 M mysql/scripts/seeddata.sql Comments 1
+8 -1 M mysql/scripts/tables.sql Comments 1
+5 -0 M web/app/item/forms.py Comments 1
+8 -0 M web/app/item/models.py Comments 1
+6 -2 M web/app/item/templates/item_create.html Comments 1
+15 -2 M web/app/item/templates/item_edit.html Comments 1
+20 -0 A web/app/item/templates/item_index.html Comments 1
+12 -3 M web/app/item/templates/item_list.html Comments 1
+1 -1 M web/app/item/templates/item_view.html
+11 -5 M web/app/item/views.py Comments 1
+1 -0 M web/app/main/templates/base.html
+3 -3 M web/app/main/templates/navbar_main.html Comments 1
+1 -1 M web/app/main/views.py
+14 -0 M web/app/static/js/flaskapp.js Comments 1
File mysql/scripts/seeddata.sql MODIFIED
Side-by-side diff View file Comment More
kwmccabe AUTHOR
Add item_title and item_text to item seeddata.
Reply Edit Delete 2018-03-12
USE flaskapp;
DELETE FROM item;
-INSERT INTO item (keyname) VALUES ("one");
-INSERT INTO item (keyname) VALUES ("two");
-INSERT INTO item (keyname) VALUES ("three");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("one","One","One here");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("two","Two","Two here");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("three","Three","Three here");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("four","Four","Four here");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("five","Five","Five here");
+INSERT INTO item (keyname,item_title,item_text) VALUES ("six","Six","Six here");
OPTIMIZE TABLE item;
File mysql/scripts/tables.sql MODIFIED
Side-by-side diff View file Comment More
kwmccabe AUTHOR
Add active, item_title, item_text and mod_update to CREATE TABLE statement.
Reply Edit Delete 2018-03-12
CREATE TABLE item (
id bigint(20) NOT NULL AUTO_INCREMENT,
keyname varchar(63) NOT NULL,
-
activetinyint(1) NOT NULL DEFAULT '1', -
item_titlevarchar(255) DEFAULT NULL, -
item_texttext,mod_createdatetime DEFAULT CURRENT_TIMESTAMP, -
mod_updatedatetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (
id),
- UNIQUE KEY
item_keyname(keyname)
- UNIQUE KEY
item_keyname(keyname), - KEY
item_active(active), - KEY
item_title(item_title), - KEY
item_update(mod_update) ) ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8; DESCRIBEitem; SELECT "tableitemcreated" AS MSG; File web/app/item/forms.py MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Add the required column item_title to CreateItemForm. Add all columns (editable and non-editable) to EditItemForm. Reply Edit Delete 2018-03-12
class CreatItemForm(FlaskForm): keyname = StringField('Keyname', validators=[InputRequired(),Length(2,63),validate_keyname], filters=[filter_keyname])
-
item_title = StringField('Title', validators=[InputRequired(),Length(1,255)]) submit = SubmitField('Create Item')
def init(self, item, *args, **kwargs): class EditItemForm(FlaskForm): id = HiddenField('id') keyname = StringField('Keyname', validators=[InputRequired(),Length(2,63),validate_keyname], filters=[filter_keyname])
-
active = BooleanField('Active')
-
item_title = StringField('Title', validators=[InputRequired(),Length(1,255)])
-
item_text = TextAreaField('Text') mod_create = DateTimeField('Item Created')
-
mod_update = DateTimeField('Item Updated') submit = SubmitField('Update Item')
def init(self, item, *args, **kwargs): File web/app/item/models.py MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Add active, item_title, item_text and mod_update to class ItemModel. Reply Edit Delete 2018-03-12 tablename = 'item' id = db.Column(db.BigInteger, autoincrement=True, primary_key=True) keyname = db.Column(db.String(63), nullable=False, index=True, unique=True, default='')
-
active = db.Column(db.Boolean, nullable=False, index=True, default=1)
-
item_title = db.Column(db.String(255))
-
item_text = db.Column(db.Text) mod_create = db.Column(db.DateTime, default=datetime.utcnow)
-
mod_update = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, index=True)
def to_json(self): json_item = { #'url': url_for('api.get_item', id=self.id), 'id' : self.id, 'keyname' : self.keyname,
-
'active' : self.active, -
'item_title': self.item_title, -
'item_text' : self.item_text, 'mod_create': self.mod_create, -
'mod_update': self.mod_update, } return json_item
File web/app/item/templates/item_create.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Add input field for the required column item_title. Reply Edit Delete 2018-03-12
{% block breadcrumb %} {{super()}} -
unique textual identifier - letters, numbers, dashes and underscores allowed, no spaces
+File web/app/item/templates/item_edit.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Add input fields for columns item_title, item_text, and active. Add display for column mod_update. Add data-confirm-link="Delete Item? This action cannot be undone." to Delete Item link. Reply Edit Delete 2018-03-12
{% block breadcrumb %} {{super()}} -
unique textual identifier - letters, numbers, dashes and underscores allowed - no spaces
+{{ form.mod_create.label }} : {{ form.mod_create.data }}
+{{ form.mod_update.label }} : {{ form.mod_update.data }}
</div> <!-- end class="panel-body" -->
This is public landing page for the Item Module.
+ +{% endblock %} + + + +{% block templates %}{{super()}} - item_index.html{% endblock %} + +{# end web/app/item/templates/item_index.html #} File web/app/item/templates/item_list.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Add placeholder navigation links for filtering view by item.active. Add data-confirm-link to Delete Item link. Reply Edit Delete 2018-03-12 {% block breadcrumb %} {{super()}} -[ Create Item ] Page 1 of 1 + + + [ Create Item ] + + + [All] + [Active] + [Inactive] + +
{% endfor %}
<td>
[ <a href="{{ url_for('.item_edit', id=row.id) }}">edit</a> ]
-
[ <a href="{{ url_for('.item_delete', id=row.id) }}">delete</a> ]
-
[ <a data-confirm-link="Delete Item? This action cannot be undone." href="{{ url_for('.item_delete', id=row.id) }}">delete</a> ]
{% endfor %} File web/app/item/templates/item_view.html MODIFIED Side-by-side diff View file Comment More
{% block breadcrumb %} {{super()}} -
from flask import flash, redirect, render_template, request, url_for +from jinja2 import TemplateNotFound from .. import db, flash_errors from . import item
from .forms import CreatItemForm, EditItemForm
[email protected]('/item/') -def hello_item():
- logging.info("hello_item()")
- return 'Hello FlaskApp : Item Module' [email protected]('/item/', defaults={'page': 'index'}) [email protected]('/item//') +def item_page(page):
- try:
-
logging.debug( 'item_page( page:%s )' % (page) ) -
return render_template('item_%s.html' % (page)) - except TemplateNotFound:
-
logging.info('TemplateNotFound: item_%s.html' % (page)) -
abort(404)
@item.route('/admin/item/delete/int:id', methods=['GET','POST']) item = ItemModel.query.get_or_404(id) form = EditItemForm(item) if form.validate_on_submit():
-
del form.mod_create
-
del form.mod_create, form.mod_update form.populate_obj(item) db.session.add(item) db.session.commit()
File web/app/main/templates/base.html MODIFIED Side-by-side diff View file Comment More
DEBUG:
TEMPLATES: {% block templates %}base.html{% endblock %}
+REQUEST.ARGS: {{ request.args }}
File web/app/main/templates/navbar_main.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Link to route /item/. Link to route /admin/. Reply Edit Delete 2018-03-12
-
<li><a href="#">Items</a></li> -
<li><a href="{{ url_for('item.item_page') }}">Items</a></li> <li><a href="#">Users</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Admin <span class="caret"></span></a> <ul class="dropdown-menu"> -
<li><a href="{{ url_for('main.main_page', page='admin') }}">Dashboard</a></li> -
<li role="separator" class="divider"></li> <li><a href="{{ url_for('item.item_list') }}">Items</a></li> <li><a href="#">Users</a></li> -
<li role="separator" class="divider"></li> -
<li><a href="#">ItemSix</a></li> </ul> </li> </ul> -
logging.debug( "main_page( %s )" % page ) -
except TemplateNotFound: logging.info('TemplateNotFound: %s.html' % (page)) File web/app/static/js/flaskapp.js MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR New $(document).ready() function searches for anchor tags with the attribute data-confirm-link, and attaches a javascript confirm() dialog. eg, Do It Reply Edit Delete 2018-03-12 function doTest( param ) { alert("doTest("+param+")"); }
logging.debug( 'main_page( page:%s )' % (page) ) return render_template('%s.html' % (page)) -
- add confirm dialog for with data-confirm-link attribute
-
- @see item_edit.html
- */ +$(document).ready(function () {
- $('a[data-confirm-link]').click(function () {
-
if (confirm($(this).data('confirm-link'))) -
window.location = $(this).attr('href'); -
return false; - }); +});
File web/app/main/views.py MODIFIED Side-by-side diff View file Comment More @main.route('//') def main_page(page): try:
+/**
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages