Commits

Benoît Allard committed 5a4a120

Make it works again

Comments (0)

Files changed (8)

 from flask import Flask
 app = Flask(__name__)
-app.config.from_object('WSGICal.default_settings')
+app.config.from_object('msgboard.default_settings')
 
-from WSGICal import views, jinjafilters
+from msgboard import views, jinjafilters
+from flask import request, abort, session
+
+from msgboard.models import User
+from msgboard.controller import as_html
+
+def checkuser():
+    if 'username' not in request.args:
+        abort(400)
+    username = request.args['username'].lower()
+    user = User.query.filter_by(username=username).first()
+    if user is not None:
+        return {'Status': 'Failed', 'reason': 'User already present'}, True
+    return {'Status': 'Success'}, True
+
+def render():
+    """ from rst to html """
+    if 'username' not in session:
+        abort(403)
+    if 'text' not in request.form:
+        abort(400)
+    return as_html(request.form['text']), False

msgboard/controller.py

 import calendar
 
-from msgboard.models import User, Action
-
 class Month(object):
 
     def __init__(self, year, month):

msgboard/templates/editmsg.html

+{% extends "layout.html" %}
+{% block body %}
+{% 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
+    {% 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 %}

msgboard/templates/macros.j2

+{% macro render_message(msg, printauthor=False) -%}
+{% set loggedonuser = (msg.user.username == session['username']) %}
+{% if loggedonuser or not msg.archived %}
+  {% set classes = ['message'] %}
+  {{ classes.append('archived') or "" if msg.archived }}
+  <section class="{{ ' '.join(classes) }}" id="msg{{ msg.id }}">
+    <p class=info>Posted&nbsp;
+    {%- if printauthor %}by {{ msg.user.username }} {% endif -%}
+    {{ msg.created_on|ago }}
+    {%- if msg.edited %}<span title="last modified&nbsp;
+      {{- msg.last_modified_on|ago -}}
+      ">*</span>
+    {% endif -%}
+    </p>
+    {{ msg.as_html()|safe }}
+    {% if loggedonuser -%}
+    <nav><ul>
+      {% if not msg.archived -%}
+        <li><a href="{{ url_for('edit_msg', id=msg.id) }}">Edit</a></li>
+        <li><a href="{{ url_for('arch_msg', id=msg.id) }}">Archive</a></li>
+      {% else %}
+        <li><a href="{{ url_for('arch_msg', id=msg.id) }}">Un-Archive</a></li>
+      {% endif %}
+    </ul></nav>
+    {%- endif %}
+  </section>
+{% endif %}
+{%- endmacro %}

msgboard/templates/news.html

+{% extends "layout.html" %}
+{% from "macros.j2" import render_message with context %}
+{% block body %}
+<article>
+  <h3>New messages:</h3>
+  {% for msg in news %}
+    {{ render_message(msg, True)|safe }}
+  {% else %}
+    <p>There are no new messages</p>
+  {% endfor %}
+</article>
+<article>
+  <h3>Modified messages:</h3>
+  {% for msg in mods %}
+    {{ render_message(msg, True)|safe }}
+  {% else %}
+    <p>There are no modified messages</p>
+  {% endfor %}
+</article>
+{% endblock %}

msgboard/templates/nocookie.html

 
   <p>Maybe you prefer to remain <input type=submit name="user" value="Anonymous"> ?</p>
 </form>
-<div id="adduser"{{ ' style="display:none"' if (users.count() != 0) }}>
+<div id="adduser"{{ {'style': 'display:none'}|xmlattr if (users.count() != 0) }}>
   <p>So you're new over there ! Welcome ! I hope you'll have good time.</p>
   <form action="{{ url_for('adduser') }}" method=post>
     <fieldset>
     else:
         return res
 
-from WSGICal.models import User, Message, Action, Organisation, Project
+from msgboard.models import User, Message, Action, Organisation, Project