edit member fields
working on icon uploads
This commit is contained in:
@@ -15,9 +15,11 @@ flask app for plurals to publicly share member lists
|
||||
|
||||
# config
|
||||
|
||||
- create `config.py` in the instance folder and customise the following settings to your needs
|
||||
- create `config.py` in the instance folder and customise the following settings to your needs\
|
||||
```
|
||||
REGISTRATION: False # only set to True if in a development situation, or to create your first user
|
||||
UPLOAD_FOLDER = '/uploads'
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
||||
```
|
||||
|
||||
# usage
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from flask import (
|
||||
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||
)
|
||||
from werkzeug.utils import secure_filename
|
||||
import os
|
||||
|
||||
from myriad.auth import login_required
|
||||
from myriad.db import get_db
|
||||
@@ -28,9 +30,31 @@ def new():
|
||||
|
||||
)
|
||||
db.commit()
|
||||
|
||||
flash(error)
|
||||
|
||||
return redirect(url_for('home.full_list'))
|
||||
return redirect(url_for('home.full_list'))
|
||||
|
||||
return render_template('manage/new.html', error=error)
|
||||
|
||||
return render_template('manage/new.html')
|
||||
return render_template('manage/new.html')
|
||||
|
||||
@bp.route("/edit/<mid>", methods=('GET', 'POST'))
|
||||
@login_required
|
||||
def edit(mid):
|
||||
db = get_db()
|
||||
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
|
||||
icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
|
||||
|
||||
if request.method == "POST":
|
||||
if "name" in request.form:
|
||||
name = request.form['name']
|
||||
bio = request.form['bio']
|
||||
subtitle = request.form['subtitle']
|
||||
db.execute("UPDATE member SET member_name=(?), bio=(?), subtitle=(?) WHERE id=(?)",(name, bio, subtitle, mid))
|
||||
db.commit()
|
||||
elif "icon" in request.form:
|
||||
file = request.form["icon"]
|
||||
filename = secure_filename(file.filename)
|
||||
file.save("/static/uploads/" + filename)
|
||||
|
||||
return redirect(url_for("home.full_list"))
|
||||
|
||||
return render_template("manage/edit.html", member=member, icons=icons)
|
||||
@@ -17,7 +17,7 @@ CREATE TABLE member (
|
||||
user_id INTEGER NOT NULL,
|
||||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
member_name TEXT NOT NULL,
|
||||
subtitle TEXT,
|
||||
subtitle TEXT DEFAULT "",
|
||||
bio TEXT,
|
||||
main_icon INTEGER,
|
||||
homepage BOOLEAN NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
|
||||
<div class="profile">
|
||||
<div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
|
||||
<img src="{{ url_for('static', filename='/icons/any.jpg') }}" class="icon">
|
||||
<img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
|
||||
<div class="bio">
|
||||
{{ member[5] }}
|
||||
</div>
|
||||
<br class="clear" />
|
||||
<!--<div class="heading links"><a href="/geo">my page</a> ☆ tumblr ☆</div>
|
||||
<img src="/geo/dsgame.webp" class="dsgame">
|
||||
<br class="clear" /> -->
|
||||
{% if g.user %}<div class="heading links"><a href="">Add to Front</a> ☆ <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a></div>{% endif %}
|
||||
<!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
35
myriad/templates/manage/edit.html
Normal file
35
myriad/templates/manage/edit.html
Normal file
@@ -0,0 +1,35 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block header %}
|
||||
<div class="title">{% block title %}Edit {{ member[3] }}{% endblock %}</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="heading">Edit Details</div>
|
||||
|
||||
<form method="post">
|
||||
<label for="name">Name</label>
|
||||
<input name="name" id="name" value="{{ member[3] }}" required><br>
|
||||
<label for="subtitle">Subtitle</label>
|
||||
<input name="subtitle" id="subtitle" value="{{ member[4] }}"><br>
|
||||
<label for="bio">Description</label>
|
||||
<textarea name="bio" id="bio">{{ member[5] }}</textarea><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
<div class="heading">Manage Icons</div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="icon">
|
||||
<input type="submit" value="Upload New Icon">
|
||||
</form>
|
||||
|
||||
{% for icon in icons %}
|
||||
|
||||
<img class="icon" src="{{ icon[2] }}">
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{{ error }}
|
||||
|
||||
{% endblock %}
|
||||
@@ -8,8 +8,13 @@
|
||||
<form method="post">
|
||||
<label for="name">Name</label>
|
||||
<input name="name" id="name" required><br>
|
||||
<label for="icon">Icon</label>
|
||||
<input type="file" name="icon"><br>
|
||||
<label for="bio">Description</label>
|
||||
<textarea name="bio" id="bio"></textarea><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
{{ error }}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user