Posibilidad de editar propuestas
authorDaniel Garcia <dgarcia@yaco.es>
Wed, 24 Feb 2010 14:30:50 +0000 (15:30 +0100)
committerDaniel Garcia <dgarcia@yaco.es>
Wed, 24 Feb 2010 14:30:50 +0000 (15:30 +0100)
proposal/app.py
proposal/static/css/index.css
proposal/templates/index.html
proposal/templates/proposal.html
proposal/view/prop.py

index 182d071..3de394b 100755 (executable)
@@ -16,6 +16,7 @@ urls = (
         '/comment/(\d+)', 'view.prop.Comment',
         '/view/tag/(\w+)', 'view.prop.ViewTag',
         '/view/(\d+)', 'view.prop.View',
+        '/edit/(\d+)', 'view.prop.Edit',
         '/new', 'view.prop.New',
         '.*', 'view.prop.New',
         )
index 7d986ca..e57cfdc 100644 (file)
@@ -26,5 +26,6 @@ body { text-align: center; background-image: url(../imgs/bg.png); }
 #content { width: 900px; margin: 0 auto 0 auto; text-align: left; }
 #header {margin: 10px;}
 #footer, #header { text-align: center; }
+.button {float:right;}
 
 img { border: none }
index 0752107..bfd3bca 100644 (file)
@@ -1,11 +1,11 @@
-$def with (proposals=None, prop_form=None)
+$def with (proposals=None, prop_form=None, action="/new")
 
 $var cssfiles: css/index.css
 $var jsfiles: js/index.js
 $var title: Proposal
 
 <div id="new_proposal">
-    <form method="POST" action="/new">
+    <form method="POST" action="$action">
         <div id="prop_name" class="gray"> $:prop_form.name.render() </div>
         <div id="prop_desc" class="gray"> $:prop_form.desc.render() </div>
         $:prop_form.send.render()
index bdc08eb..75b9f8e 100644 (file)
@@ -10,6 +10,7 @@ $def with (proposals, trim=False)
             <br/>
             <span class="votes">$proposal.votes</span>
         </div>
+        <div class="button"><a href="/edit/$proposal.id">$_("Edit")</a></div>
         <h2><a href="/view/$proposal.id">$proposal.name</a></h2>
         $if trim:
             $proposal.desc[:250]
index eced352..d12194b 100644 (file)
@@ -8,12 +8,18 @@ from web import form
 
 name_regexp = re.compile(r'@(\w+)')
 
-def get_prop_form():
+def get_prop_form(pname='', pdesc='', send=''):
     _ = web.ctx.gettext
+    if not pname:
+        pname = _('Proposal name')
+    if not pdesc:
+        pdesc = _('Proposal desc')
+    if not send:
+        send = _('Send')
     prop_form = form.Form(
-        form.Textbox('name', class_='prop_name', value=_('Proposal name')),
-        form.Textarea('desc', class_='prop_desc', value=_('Proposal desc')),
-        form.Button('send', class_="prop_button", html=_('Send')),
+        form.Textbox('name', class_='prop_name', value=pname),
+        form.Textarea('desc', class_='prop_desc', value=pdesc),
+        form.Button('send', class_="prop_button", html=send),
     )
     return prop_form
 
@@ -50,6 +56,41 @@ class New:
         raise web.seeother('/')
 
 
+class Edit:
+    def GET(self, id):
+        orm = web.ctx.orm
+        render = web.ctx.render
+
+        prop = orm.query(db.Proposal).get(id)
+        prop_form = get_prop_form(prop.name, prop.desc, _("Edit"))
+
+        return render.index(prop_form=prop_form,
+                            action="/edit/%d" % prop.id)
+
+    def POST(self, id):
+        orm = web.ctx.orm
+        render = web.ctx.render
+
+        prop_form = get_prop_form()
+        if not prop_form.validates():
+            return render.index(prop_form=prop_form)
+
+        name = prop_form.d.name
+        desc = prop_form.d.desc
+        tags_names = name_regexp.findall(desc)
+
+        tags = orm.query(db.Tag).filter(db.Tag.name.in_(tags_names)).all()
+        tag_queries = [i.name for i in tags]
+        tags += [db.Tag(name=u) for u in tags_names if not u in tag_queries]
+
+        prop = orm.query(db.Proposal).get(id)
+        prop.name = name
+        prop.desc = desc
+        prop.tags = tags
+
+        raise web.seeother('/')
+
+
 class View:
     def GET(self, id):
         orm = web.ctx.orm