starting to make editing right
Getty Ritter
3 years ago
73 | 73 |
|
74 | 74 |
@app.route("/api/design/<int:id>/")
|
75 | 75 |
def api_get_design(id: int):
|
76 | |
return flask.jsonify(db.get_design(id).to_json(db))
|
| 76 |
return flask.jsonify(model.Design.get(visible_id=id).to_json())
|
77 | 77 |
|
78 | 78 |
|
79 | 79 |
# @app.route('/design/<id>/<slug>', method=['POST'])
|
|
157 | 157 |
return "Edit Mode", Templates.edit_design_list(data)
|
158 | 158 |
|
159 | 159 |
|
160 | |
@app.route("/edit/design", methods=["POST"])
|
| 160 |
@app.route("/edit/design/", methods=["POST"])
|
161 | 161 |
def post_new_design():
|
162 | |
id = db.new_design()
|
| 162 |
# id = db.new_design()
|
| 163 |
id = model.Design.make_new()
|
163 | 164 |
return flask.redirect(f"/edit/design/{id:05}/")
|
164 | 165 |
|
165 | 166 |
|
|
167 | 168 |
@main
|
168 | 169 |
def edit_design(id):
|
169 | 170 |
id = int(id)
|
170 | |
# design = db.get_design(id)
|
171 | |
design = model.Design.get(id=id)
|
| 171 |
design = model.Design.get(visible_id=id)
|
172 | 172 |
return (
|
173 | 173 |
"design",
|
174 | 174 |
Templates.edit_design(
|
175 | 175 |
{
|
176 | |
"id": design.id,
|
| 176 |
"id": design.visible_id,
|
177 | 177 |
"title": design.title,
|
178 | 178 |
"tags": " ".join(t.tag_name for t in design.tags),
|
179 | 179 |
"categories": design.category_list(),
|
9 | 9 |
defaultMode: 'wysiwyg',
|
10 | 10 |
});
|
11 | 11 |
|
12 | |
fetch('/api/design/00700/')
|
| 12 |
let id = document.getElementById("design_id").value;
|
| 13 |
fetch(`/api/design/${id}/`)
|
13 | 14 |
.then(res => res.json())
|
14 | 15 |
.then(res => {
|
15 | 16 |
woof.value(res.description);
|
49 | 49 |
return slugify(self.title)
|
50 | 50 |
|
51 | 51 |
def thumbnail(self):
|
52 | |
return Photo.get(Photo.design==self).thumb()
|
| 52 |
photo = Photo.select().where(Photo.design == self).limit(1).execute()
|
| 53 |
if photo:
|
| 54 |
return photo[0].thumb()
|
| 55 |
else:
|
| 56 |
return None
|
53 | 57 |
|
54 | 58 |
def category_list(self):
|
55 | 59 |
categories = Category.select()
|
|
57 | 61 |
{"name": c.name, "selected": c == self.category}
|
58 | 62 |
for c in categories
|
59 | 63 |
]
|
| 64 |
|
| 65 |
def to_json(self):
|
| 66 |
return {
|
| 67 |
"id": self.visible_id,
|
| 68 |
"title": self.title,
|
| 69 |
"tags": [t.tag_name for t in self.tags],
|
| 70 |
"categories": self.category_list(),
|
| 71 |
"description": self.description,
|
| 72 |
"photos": [{"id": p.id, "image": p.filename} for p in self.photos],
|
| 73 |
}
|
| 74 |
|
| 75 |
@classmethod
|
| 76 |
def make_new(klass):
|
| 77 |
new_visible_id = klass.select(peewee.fn.max(klass.visible_id)).scalar() + 1
|
| 78 |
klass.create(
|
| 79 |
visible_id=new_visible_id,
|
| 80 |
title="My Great New Design",
|
| 81 |
description="A blank canvas awaits...",
|
| 82 |
category=Category.get(),
|
| 83 |
)
|
| 84 |
return new_visible_id
|
60 | 85 |
|
61 | 86 |
@classmethod
|
62 | 87 |
def get_all(klass, page=0):
|
1 | |
<div><input type="text" name="title" value="{{title}}" size="80"/></div>
|
| 1 |
<form name="design-data">
|
| 2 |
<input type="hidden" id="design_id" value="{{id}}"/>
|
| 3 |
<div><input type="text" name="title" value="{{title}}" size="80"/></div>
|
2 | 4 |
<script type="text/javascript" src="/static/by.js"></script>
|
3 | 5 |
<div class="editarea">
|
4 | 6 |
<textarea id="editor" rows="8" cols="90"></textarea>
|
|
27 | 29 |
</div>
|
28 | 30 |
</div>
|
29 | 31 |
</div>
|
30 | |
<!--
|
31 | |
<div id="design">
|
32 | |
<p>
|
33 | |
<a href="/edit/design/">Return to Editing List</a>
|
34 | |
</p>
|
35 | |
<h1>See This Design</h1>
|
36 | |
<a href="/design/{{id_str}}/">Click Here</a>
|
37 | |
<h1>Design Data</h1>
|
38 | |
<form name="design-data" method="post" action="/design/{{id_str}}/">
|
39 | |
<p>
|
40 | |
design id: {{id_str}}
|
41 | |
</p>
|
42 | |
<p><input type="text" name="title" value="{{title}}" size="80"/></p>
|
43 | |
<p>
|
44 | |
<select name="category">
|
45 | |
{{#categories}}
|
46 | |
<option value="{{id}}" ${{selected}}>{{name}}</option>
|
47 | |
{{/categories}}
|
48 | |
</select>
|
49 | |
</p>
|
50 | |
<p>
|
51 | |
<textarea rows="8" cols="90" name="description">{{description}}</textarea>
|
52 | |
</p>
|
53 | |
<p>
|
54 | |
<input type="text" name="tags" value="{{tags}}" size="80"/>
|
55 | |
</p>
|
56 | |
<p>
|
57 | |
<input type="submit" value="Submit Design Data"/>
|
58 | |
</p>
|
59 | |
</form>
|
60 | |
<h1>Photos</h1>
|
61 | |
{{#photos}}
|
62 | |
<form name="img_$loop.index" method="get" action="/edit/photo/$image/">
|
63 | |
<img src="/static/photos/{{image}}" />
|
64 | |
<input type="hidden" name="design_id" value="$id" />
|
65 | |
<input type="submit" value="Delete This Photo" />
|
66 | |
</form>
|
67 | |
{{/photos}}
|
68 | |
<p>
|
69 | |
<form name="img_upload" method="get" action="/edit/photo/">
|
70 | |
<input type="hidden" name="id" value="{{id_str}}" />
|
71 | |
<input type="submit" value="Upload New Photo" />
|
72 | |
</form>
|
73 | |
</p>
|
74 | |
<h1>Delete</h1>
|
75 | |
<p>
|
76 | |
<a href="/edit/delete/{{id_str}}/">Delete This Design</a>
|
77 | |
</p>
|
78 | |
</div>
|
79 | |
-->
|
| 32 |
</form>
|