Skip to content
Browse files

Adding django, flask and python examples

  • Loading branch information...
1 parent c87ab92 commit d43d979c3d24362a65f293c4f8c0e7e80cec4eb0 @coleifer committed Apr 18, 2012
View
0 examples/__init__.py
No changes.
View
0 examples/django_ex/__init__.py
No changes.
View
14 examples/django_ex/manage.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
55 examples/django_ex/settings.py
@@ -0,0 +1,55 @@
+import os
+CURRENT_DIR = os.path.dirname(__file__)
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': 'django_ex.db',
+ }
+}
+
+SITE_ID = 1
+
+SECRET_KEY = 'fapfapfap'
+
+STATIC_URL = '/static/'
+STATICFILES_DIRS = (
+ os.path.join(CURRENT_DIR, 'static'),
+)
+
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+)
+
+
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'django_ex.urls'
+
+TEMPLATE_DIRS = (
+ os.path.join(CURRENT_DIR, 'templates'),
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.staticfiles',
+ 'micawber.contrib.mcdjango',
+)
View
18 examples/django_ex/static/style.css
@@ -0,0 +1,18 @@
+body { font-family: sans-serif; background: #eee; }
+a, h1, h2 { color: #377BA8; }
+h1, h2 { font-family: 'Georgia', serif; margin: 0; }
+h1 { border-bottom: 2px solid #eee; }
+h2 { font-size: 1.2em; }
+
+.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
+ padding: 0.8em; background: white; }
+.entries { list-style: none; margin: 0; padding: 0; }
+.entries li { margin: 0.8em 1.2em; }
+.entries li h2 { margin-left: -1em; }
+.add-entry { font-size: 0.9em; border-bottom: 1px solid #ccc; }
+.add-entry dl { font-weight: bold; }
+.metanav { text-align: right; font-size: 0.8em; padding: 0.3em;
+ margin-bottom: 1em; background: #fafafa; }
+.flash { background: #CEE5F5; padding: 0.5em;
+ border: 1px solid #AACBE2; }
+.error { background: #F0D6D6; padding: 0.5em; }
View
62 examples/django_ex/templates/example.html
@@ -0,0 +1,62 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Example</title>
+ <link rel="stylesheet" type="text/css" href="/static/style.css">
+ </head>
+ <body>
+ <div class="page">
+ <h1>Micawber Example</h1>
+
+ <h2>Text renderer</h2>
+ <form method="get">
+ <p>
+ <label>Enter some text</label>
+ </p>
+ <p>
+ <textarea cols=50 rows=5 name="text">{{ text }}</textarea>
+ <small style="display:block;">Try entering some urls to youtube videos</small>
+ </p>
+ <p>
+ <button type="submit">Render</button>
+ </p>
+ </form>
+
+ {% load micawber_tags %}
+
+ {% if text %}
+ <h3>Rendered</h3>
+ <div>
+ {{ text|oembed }}
+ </div>
+
+ <h3>Extracted data</h3>
+ <textarea cols=50 rows=5>
+ {{ text|extract_oembed }}
+ </textarea>
+ {% endif %}
+
+ <h2>HTML renderer</h2>
+ <form method="get">
+ <p>
+ <label>Enter some html</label>
+ </p>
+ <p>
+ <textarea cols=50 rows=5 name="text">{{ html|safe }}</textarea>
+ </p>
+ <p>
+ <button type="submit">Render</button>
+ </p>
+ </form>
+
+ {% load micawber_tags %}
+
+ {% if html %}
+ <h3>Rendered</h3>
+ <div>
+ {{ html|oembed_html }}
+ </div>
+ {% endif %}
+ </div>
+ </body>
+</html>
View
5 examples/django_ex/urls.py
@@ -0,0 +1,5 @@
+from django.conf.urls.defaults import patterns, include, url
+
+urlpatterns = patterns('',
+ url(r'^$', 'django_ex.views.example_view', name='example_view'),
+)
View
14 examples/django_ex/views.py
@@ -0,0 +1,14 @@
+from django.shortcuts import render_to_response
+
+def example_view(request):
+ text = request.GET.get('text', 'http://www.youtube.com/watch?v=nda_OSWeyn8')
+ html = request.GET.get('html', """
+<p>This is a test</p>
+<p>http://www.youtube.com/watch?v=nda_OSWeyn8</p>
+<p>This will get rendered as a link: http://www.youtube.com/watch?v=nda_OSWeyn8</p>
+<p>This will not be modified: <a href="http://www.google.com/">http://www.youtube.com/watch?v=nda_OSWeyn8</a></p>
+ """)
+ return render_to_response('example.html', dict(
+ text=text,
+ html=html,
+ ))
View
23 examples/flask_ex/app.py
@@ -0,0 +1,23 @@
+from flask import Flask, render_template, request
+from micawber.providers import bootstrap_basic
+from micawber.contrib.mcflask import add_oembed_filters
+
+app = Flask(__name__)
+app.config['DEBUG'] = True
+
+oembed_providers = bootstrap_basic()
+add_oembed_filters(app, oembed_providers)
+
+@app.route('/')
+def example_view():
+ text = request.args.get('text', 'http://www.youtube.com/watch?v=nda_OSWeyn8')
+ html = request.args.get('html', """
+<p>This is a test</p>
+<p>http://www.youtube.com/watch?v=nda_OSWeyn8</p>
+<p>This will get rendered as a link: http://www.youtube.com/watch?v=nda_OSWeyn8</p>
+<p>This will not be modified: <a href="http://www.google.com/">http://www.youtube.com/watch?v=nda_OSWeyn8</a></p>
+ """)
+ return render_template('example.html', text=text, html=html)
+
+if __name__ == '__main__':
+ app.run()
View
18 examples/flask_ex/static/style.css
@@ -0,0 +1,18 @@
+body { font-family: sans-serif; background: #eee; }
+a, h1, h2 { color: #377BA8; }
+h1, h2 { font-family: 'Georgia', serif; margin: 0; }
+h1 { border-bottom: 2px solid #eee; }
+h2 { font-size: 1.2em; }
+
+.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
+ padding: 0.8em; background: white; }
+.entries { list-style: none; margin: 0; padding: 0; }
+.entries li { margin: 0.8em 1.2em; }
+.entries li h2 { margin-left: -1em; }
+.add-entry { font-size: 0.9em; border-bottom: 1px solid #ccc; }
+.add-entry dl { font-weight: bold; }
+.metanav { text-align: right; font-size: 0.8em; padding: 0.3em;
+ margin-bottom: 1em; background: #fafafa; }
+.flash { background: #CEE5F5; padding: 0.5em;
+ border: 1px solid #AACBE2; }
+.error { background: #F0D6D6; padding: 0.5em; }
View
58 examples/flask_ex/templates/example.html
@@ -0,0 +1,58 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Example</title>
+ <link rel="stylesheet" type="text/css" href="/static/style.css">
+ </head>
+ <body>
+ <div class="page">
+ <h1>Micawber Example</h1>
+
+ <h2>Text renderer</h2>
+ <form method="get">
+ <p>
+ <label>Enter some text</label>
+ </p>
+ <p>
+ <textarea cols=50 rows=5 name="text">{{ text }}</textarea>
+ <small style="display:block;">Try entering some urls to youtube videos</small>
+ </p>
+ <p>
+ <button type="submit">Render</button>
+ </p>
+ </form>
+
+ {% if text %}
+ <h3>Rendered</h3>
+ <div>
+ {{ text|oembed() }}
+ </div>
+
+ <h3>Extracted data</h3>
+ <textarea cols=50 rows=5>
+ {{ text|extract_oembed() }}
+ </textarea>
+ {% endif %}
+
+ <h2>HTML renderer</h2>
+ <form method="get">
+ <p>
+ <label>Enter some html</label>
+ </p>
+ <p>
+ <textarea cols=50 rows=5 name="text">{{ html|safe }}</textarea>
+ </p>
+ <p>
+ <button type="submit">Render</button>
+ </p>
+ </form>
+
+ {% if html %}
+ <h3>Rendered</h3>
+ <div>
+ {{ html|oembed(html=True) }}
+ </div>
+ {% endif %}
+ </div>
+ </body>
+</html>
View
23 examples/python_ex/example.py
@@ -0,0 +1,23 @@
+import pprint
+from micawber import bootstrap_embedly, ProviderException
+
+def main():
+ print 'Please wait, loading providers from embed.ly'
+ providers = bootstrap_embedly()
+
+ while 1:
+ url = raw_input('Enter a url (or q to quit): ')
+ if url.lower().strip() == 'q':
+ break
+
+ try:
+ result = providers.request(url)
+ except ProviderException:
+ print 'No provider found for that url :/'
+ else:
+ print 'Data for %s\n====================================================' % url
+ pprint.pprint(result)
+
+if __name__ == '__main__':
+ print 'Welcome to the example!'
+ main()
View
10 setup.py
@@ -18,6 +18,16 @@
'micawber': [
],
},
+ package_data = {
+ 'examples': [
+ #'requirements.txt',
+ #'static/*.css',
+ #'templates/*.html',
+ #'templates/*/*.html',
+ ],
+ 'micawber': [
+ ],
+ },
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',

0 comments on commit d43d979

Please sign in to comment.
Something went wrong with that request. Please try again.