Commits

Benoît Allard committed 1708731

Make editmsg and addmsg use the same template

  • Participants
  • Parent commits 75b8833

Comments (0)

Files changed (3)

File msgboard/templates/addmsg.html

-{% extends "layout.html" %}
-{% block body %}
-{% if nummsg >= 3 %}
-<p> Warning, you already have {{ nummsg }} active messages. Only the three 
-most recent one will be present on the home page. Consider archiving 
-some of them.
-{% endif %}
-<form action="{{ url_for('add_msg') }}" method=post>
-  <fieldset>
-    <legend>Type your message</legend>
-    <textarea placeholder="You message here ..." name="content" rows=10
-    {% if docutils %}style="font-family:monospace"{% endif -%}
-    id="content" onkeyup="previewMessage()">
-      {{- content -}}
-    </textarea>
-    <input type="submit" name="submit" value="Submit" />
-    <input type="submit" name="cancel" value="Cancel" />
-  </fieldset>
-</form>
-{% if docutils %}
-  <p>Hint: you can use <a href="http://docutils.sourceforge.net/docs/user/rst/quickref.html">restructuredText</a></p>
-{% endif %}
-<article class=preview>
-  <h2>Preview:</h2>
-  <span id=preview></span>
-</article>
-{% endblock %}

File msgboard/templates/editmsg.html

-{# This is exactly the sae as add_msg, maybe we can do something in
-this respect #}
-
 {% extends "layout.html" %}
 {% block body %}
-<form action="{{ url_for('edit_msg', id=id) }}" method=post>
+{% if (action == 'add') and (nummsg >= 3) %}
+<p> Warning, you already have {{ nummsg }} active messages. Only the three 
+most recent one will be present on the home page. Consider archiving 
+some of them.
+{% endif %}
+{% if action == 'add' %}
+  {% set actionurl = url_for('add_msg') %}
+{% else %}
+  {% set actionurl = url_for('edit_msg', id=id) %}
+{% endif %}
+<form action="{{ actionurl }}" method=post>
   <fieldset>
     <legend>Type your message</legend>
     <textarea placeholder="You message here ..." name="content" rows=10
   <h2>Preview:</h2>
   <span id=preview></span>
 </article>
-{% endblock %}
+{% endblock %}

File msgboard/views.py

     if request.method == 'GET':
         return render_template('editmsg.html', content=msg.content,
                                docutils=controller.publish is not None,
-                               id = id)
+                               id = id,
+                               action='edit')
     if request.form.get('cancel'):
         flash('Change discarded')
         return redirect(url_for('index'))
     if request.method == 'GET':
         user = User.query.filter_by(username=session['username']).first()
         nummsg = user.messages.count()
-        return render_template('addmsg.html', docutils=controller.publish is not None, nummsg=nummsg)
+        return render_template('editmsg.html', 
+                               docutils=controller.publish is not None, 
+                               action='add', 
+                               nummsg=nummsg)
     if request.form.get('cancel'):
         flash('Message discarded')
         return redirect(url_for('index'))