diff options
author | romangraef <roman.graef@gmail.com> | 2018-06-02 10:45:15 +0200 |
---|---|---|
committer | romangraef <roman.graef@gmail.com> | 2018-06-02 10:45:15 +0200 |
commit | 2f9e9884c6b227777780d34b4657c6464dbe4571 (patch) | |
tree | cd9597171dd4338fc5c79dc78d69e016a18f8c7c | |
parent | 3dc96e8b31eeef876c89aadf26dbf1e5d3355e7f (diff) | |
download | my-website-master.tar.gz my-website-master.tar.bz2 my-website-master.zip |
-rw-r--r-- | app.py | 12 | ||||
-rw-r--r-- | static/edit.js | 3 | ||||
-rw-r--r-- | templates/project_fields.html | 5 |
3 files changed, 16 insertions, 4 deletions
@@ -20,10 +20,13 @@ class Project(JsonSerializable): link: str summary: str id: str + featured: bool - def __init__(self, *, name: str = '', description: str = '', link: str = '', summary: str = '', id: str = ''): + def __init__(self, *, name: str = '', description: str = '', link: str = '', summary: str = '', id: str = '', + featured: bool = False): self.name = name self.id = id + self.featured = featured self.summary = summary self.liink = link self.description = description @@ -104,13 +107,14 @@ def new_project(): summary = request.form.get('summary') description = request.form.get('description') link = request.form.get('link') + featured = request.form.get('featured') == 'on' db.insert({ 'name': name, 'id': post_id, 'summary': summary, 'description': description, 'link': link, - 'featured': 0, + 'featured': featured, }) return redirect(url_for('projects', project_name=post_id)) @@ -129,10 +133,12 @@ def edit_project_data(project_name): description = request.form.get('description') link = request.form.get('link') name = request.form.get('name') + featured = request.form.get('featured') == 'true' project['name'] = name project['link'] = link project['description'] = description project['summary'] = summary + project['featured'] = featured db.write_back([project]) return jsonify({}) @@ -158,7 +164,7 @@ def delete_project_confirm(project_name): @app.route('/') def index(): - return render_template('index.html', projects=from_json(db.search(Query().featured == 1), List[Project])) + return render_template('index.html', projects=from_json(db.search(Query().featured == True), List[Project])) app.secret_key = os.environ.get('app_secret', '') diff --git a/static/edit.js b/static/edit.js index 41a82ca..93fb743 100644 --- a/static/edit.js +++ b/static/edit.js @@ -2,12 +2,13 @@ function save_changes() { let summary = $("#summary").val(); let description = $("#description").val(); let link = $("#link").val(); + let featured = $("#featured").is(':checked'); let name = $("#name").val(); $.ajax({ url: '.', type: 'POST', data: { - summary, description, link, name + summary, description, link, name, featured }, }).done(function () { let el = document.createElement("p"); diff --git a/templates/project_fields.html b/templates/project_fields.html index c128fd5..45db894 100644 --- a/templates/project_fields.html +++ b/templates/project_fields.html @@ -19,3 +19,8 @@ <p> <label for="link">Link</label><input name="link" id="link" value="{{ project.link }}"> </p> +<p> + <label for="featured">Featured</label><input name="featured" id="featured" type="checkbox" + {% if project.featured %}checked="checked"{% endif %}> +</p> + |