gdritter repos frony-ritter-designs / a7ad730
starting to make editing right Getty Ritter 3 years ago
4 changed file(s) with 38 addition(s) and 59 deletion(s). Collapse all Expand all
7373
7474 @app.route("/api/design/<int:id>/")
7575 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())
7777
7878
7979 # @app.route('/design/<id>/<slug>', method=['POST'])
157157 return "Edit Mode", Templates.edit_design_list(data)
158158
159159
160 @app.route("/edit/design", methods=["POST"])
160 @app.route("/edit/design/", methods=["POST"])
161161 def post_new_design():
162 id = db.new_design()
162 # id = db.new_design()
163 id = model.Design.make_new()
163164 return flask.redirect(f"/edit/design/{id:05}/")
164165
165166
167168 @main
168169 def edit_design(id):
169170 id = int(id)
170 # design = db.get_design(id)
171 design = model.Design.get(id=id)
171 design = model.Design.get(visible_id=id)
172172 return (
173173 "design",
174174 Templates.edit_design(
175175 {
176 "id": design.id,
176 "id": design.visible_id,
177177 "title": design.title,
178178 "tags": " ".join(t.tag_name for t in design.tags),
179179 "categories": design.category_list(),
99 defaultMode: 'wysiwyg',
1010 });
1111
12 fetch('/api/design/00700/')
12 let id = document.getElementById("design_id").value;
13 fetch(`/api/design/${id}/`)
1314 .then(res => res.json())
1415 .then(res => {
1516 woof.value(res.description);
4949 return slugify(self.title)
5050
5151 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
5357
5458 def category_list(self):
5559 categories = Category.select()
5761 {"name": c.name, "selected": c == self.category}
5862 for c in categories
5963 ]
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
6085
6186 @classmethod
6287 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>
24 <script type="text/javascript" src="/static/by.js"></script>
35 <div class="editarea">
46 <textarea id="editor" rows="8" cols="90"></textarea>
2729 </div>
2830 </div>
2931 </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>