Added snippet database to the website.

This commit is contained in:
Armin Ronacher 2010-05-03 11:20:52 +02:00
parent a81cf3a67c
commit 0ab7a9cb67
22 changed files with 825 additions and 118 deletions

View file

@ -0,0 +1,27 @@
{% extends "layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/login.png); }
</style>
{% endblock %}
{% block title %}First Login{% endblock %}
{% block body %}
<h2>This is your First Login</h2>
<form action="{{ url_for('general.first_login') }}" method=post>
<p>
This is your first login on this website. You are about to sign
in with the following OpenID: <a href="{{ openid }}">{{ openid }}</a>
<p>
Before you can use this site we need a name for you. This is what
will be displayed next to all of your public contributions to this
site. Choose wisely because you cannot change this value later:
<dl>
<dt>Name:
<dd><input type=text name=name size=30>
</dl>
<p>
<input type=submit value=Continue>
<input type=submit name=cancel value=Cancel>
</form>
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/login.png); }
</style>
{% endblock %}
{% block title %}Login{% endblock %}
{% block body %}
<form action="{{ url_for('general.login') }}" method=post>
<p>
For some of the features on this site (such as creating snippets
or adding comments) you have to be signed in. You don't need to
create an account on this website, just sign in with an existing
<a href=http://openid.net/>OpenID</a> account.
<p>
OpenID URL:
<input type=text name=openid class=openid size=30>
<input type=hidden name=next value="{{ request.values.next or request.referrer }}">
<input type=submit value=Login>
</form>
{% endblock %}

View file

@ -15,6 +15,15 @@
<a href=/docs/>documentation</a> //
<a href=/mailinglist/>mailinglist</a> //
<a href=/snippets/>snippets</a>
{% for message in get_flashed_messages() %}
<p class=message>{{ message }}
{% endfor %}
{% block body %}{% endblock %}
<p class=footer>&copy; Copyright 2010 by <a href=http://lucumr.pocoo.org/>Armin Ronacher</a>
<p class=footer>
&copy; Copyright 2010 by <a href=http://lucumr.pocoo.org/>Armin Ronacher</a> //
{% if g.user %}
<a href=/logout/ title="logged in as {{ g.user.name }} [{{ g.user.openid }}]">logout</a>
{% else %}
<a href=/login/>login</a>
{% endif %}
</div>

View file

@ -2,8 +2,7 @@
{% block head %}
{{ super() }}
<style type=text/css>
h1 { margin: 0 0 30px 0; background: url(/static/mailinglist.png) no-repeat center; height: 165px; }
h1 span { display: none; }
h1 { background-image: url(/static/mailinglist.png); }
</style>
{% endblock %}
{% block body_title %}

View file

@ -0,0 +1,19 @@
{% extends "snippets/layout.html" %}
{% block title %}{{ category.name }}{% endblock %}
{% block body %}
<h2>{{ category.name }}</h2>
{% if category.count > 3 %}
<p>
Here you can find all {{ category.count }} snippets of this
category. You can also
{% else %}
This category is pretty empty so far. Why not
{% endif %}
<a href="{{ url_for('snippets.new',
category=category.slug) }}">add a new one</a>.
<ul>
{% for snippet in snippets %}
<li><a href="{{ snippet.url }}">{{ snippet.title }}</a>
{% endfor %}
</ul>
{% endblock %}

View file

@ -0,0 +1,44 @@
{% extends "snippets/layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/new-snippet.png); }
</style>
{% endblock %}
{% block title %}Edit Snippet “{{ snippet.title }}”{% endblock %}
{% block body %}
<script type=text/javascript>
$(function() {
$('input[name="delete"]').click(function() {
if (!confirm("Do you really want to delete this Snippet?\n\n" +
"THIS CANNOT BE UNDONE!"))
return false;
});
});
</script>
<form action="" method=post>
<dl>
<dt>Title:
<dd><input type=text name=title value="{{ form.title }}" size=40>
<dt>Category:
<dd>
<select name=category>
{% for category in categories %}
<option{% if category.id == form.category %} selected{% endif
%} value={{ category.id }}>{{ category.name }}</option>
{% endfor %}
</select>
</dl>
<p><textarea name=body cols=40 rows=20>{{ form.body }}</textarea>
<p>
<input type=submit value="Edit Snippet">
<input type=submit name=delete value="Delete">
<input type=submit name=preview value="Preview">
</form>
{% if preview %}
<div id=preview>
<h2>Preview</h2>
{{ preview }}
</div>
{% endif %}
{% endblock %}

View file

@ -4,14 +4,33 @@
<p>
Welcome to the Flask snippet archive. This is the place where anyone
can drop helpful pieces of code for others to use.
{% if g.user %}
<p>
You're signed in as “<span title="{{ g.user.openid }}">{{ g.user.name
}}</span>”. You can <a href="{{ url_for('general.logout')
}}">sign out</a> here after you're done if you want.
{% else %}
<p>
In order to add snippets to this page or to add comments, all you need
is an <a href=http://en.wikipedia.org/wiki/OpenID>OpenID</a> account.
<form action=/snippets/search/ method=get>
<p>
Search snippets:
<input type=text name=q size=30>
<input type=submit value=Search>
</form>
You can <a href="{{ url_for('general.login') }}">sign in</a> here.
{% endif %}
<p>
Want to share something? Then add a
<a href="{{ url_for('snippets.new') }}">new snippet</a>.
<h2>Snippets by Category</h2>
<ul>
{% for category in categories %}
<li><a href="{{ category.url }}">{{ category.name }}</a> ({{ category.count }})
{% endfor %}
</ul>
{% if recent %}
<h2>Recently Added</h2>
<ul>
{% for snippet in recent %}
<li><a href="{{ snippet.url }}">{{ snippet.title }}</a> in
<a href="{{ snippet.category.url }}">{{ snippet.category.name }}</a>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View file

@ -2,8 +2,7 @@
{% block head %}
{{ super() }}
<style type=text/css>
h1 { margin: 0 0 30px 0; background: url(/static/snippets.png) no-repeat center; height: 165px; }
h1 span { display: none; }
h1 { background-image: url(/static/snippets.png); }
</style>
{% endblock %}
{% block body_title %}

View file

@ -0,0 +1,43 @@
{% extends "snippets/layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/new-snippet.png); }
</style>
{% endblock %}
{% block title %}New Snippet{% endblock %}
{% block body %}
<p>
Got something to share? Here you can create a new snippet and
publish it here. By adding the snippet here, you hereby grant
the user of the snippet all rights.
<p>
The syntax used for snippets is <a href="http://www.wikicreole.org/">Creole</a>.
To highlight Python code or Jinja templates, prefix your code blocks
with <code>#!python</code>, <code>#!html+jinja</code> or any other
<a href="http://pygments.org/docs/lexers">Pygments lexer name</a>.
<form action="" method=post>
<dl>
<dt>Title:
<dd><input type=text name=title value="{{ request.form.title }}" size=40>
<dt>Category:
<dd>
<select name=category>
{% for category in categories %}
<option{% if category.id == active_category %} selected{% endif
%} value={{ category.id }}>{{ category.name }}</option>
{% endfor %}
</select>
</dl>
<p><textarea name=body cols=40 rows=20>{{ request.form.body }}</textarea>
<p>
<input type=submit value="Add Snippet">
<input type=submit name=preview value="Preview">
</form>
{% if preview %}
<div id=preview>
<h2>Preview</h2>
{{ preview }}
</div>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,38 @@
{% extends "snippets/layout.html" %}
{% block title %}{{ snippet.title }}{% endblock %}
{% block body %}
<h2>{{ snippet.title }}</h2>
<p class=snippet-author>By {{ snippet.author.name }}
filed in <a href="{{ snippet.category.url }}">{{ snippet.category.name }}</a>
{% if snippet.author == g.user %}
(<a href="{{ url_for('snippets.edit', id=snippet.id) }}">edit</a>)
{% endif %}
{{ snippet.rendered_body }}
{% if snippet.comments or g.user %}
<div id=comment-box>
{% if snippet.comments %}
<h2>Comments</h2>
<ul class=comments>
{% for comment in snippet.comments %}
<li>
<p class=title>
{{ comment.title or "Comment" }}
by {{ comment.author.name }}
on {{ comment.pub_date.strftime('%Y-%m-%d @ %H:%M') }}
<div class=body>{{ comment.rendered_text }}</div></li>
{% endfor %}
</ul>
{% endif %}
{% if g.user %}
<div id=add-comment>
<h2>Add Comment</h2>
<form action=#add-comment method=post>
<p>Title: <input type=text name=title value="{{ request.form.title }}" size=30>
<p><textarea name=text cols=40 rows=8>{{ request.form.text }}</textarea>
<p><input type=submit value="Add Comment">
</form>
</div>
{% endif %}
</div>
{% endif %}
{% endblock %}