Skip to content

Commit

Permalink
gaestebin 1.0!
Browse files Browse the repository at this point in the history
  • Loading branch information
diwakergupta committed Oct 21, 2012
0 parents commit 1c218ad
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
22 changes: 22 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
application: gaestebin
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico

- url: /assets
static_dir: assets

- url: .*
script: main.app

libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
9 changes: 9 additions & 0 deletions assets/css/bootstrap.min.css

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body {
background-color: #002B36;
}

textarea {
background-color: #073642;
color: #eee8d5;
font-family: monospace;
outline: none;
}

pre {
background-color: #002B36;
border-color: #073642;
}
Binary file added assets/img/glyphicons-halflings-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/glyphicons-halflings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/js/bootstrap.min.js

Large diffs are not rendered by default.

Binary file added favicon.ico
Binary file not shown.
41 changes: 41 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>magpaste</title>
<link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/assets/css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/solarized_dark.min.css">
<script src="/assets/js/bootstrap.min.js"></script>
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script>
hljs.tabReplace = ' '; // 2 spaces
hljs.initHighlightingOnLoad();
</script>
</head>

<body>
<div class="container-fluid">
{% if content is defined %}
<div class="row-fluid">
<div class="span12">
<pre><code>{{ content }}</code></pre>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<a class="btn btn-primary" href="/"><i class="icon-plus icon-white"></i> New paste</a>
</div>
</div>
{% else %}
<div class="row-fluid">
<div class="span12">
<form action="/paste" method="post">
<textarea class="span8" spellcheck="false" name="content" rows="30" autofocus placeholder="Paste here"></textarea>
<div><input type="submit" value="Paste it!"></div>
</form>
</div>
</div>
{% endif %}
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
60 changes: 60 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python

import cgi
import jinja2
import logging
import os
import random
import string
import webapp2

from google.appengine.ext import db
from google.appengine.api import users

jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class Paste(db.Model):
id = db.StringProperty()
content = db.TextProperty()
timestamp = date = db.DateTimeProperty(auto_now_add=True)

def gen_random_string(length):
chars = string.letters + string.digits
return ''.join(random.choice(chars) for i in xrange(length))

class SavePaste(webapp2.RequestHandler):
def post(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
paste = Paste()
paste.id = gen_random_string(8)
paste.content = self.request.get('content')
logging.info("Paste %s, %s", paste.id, paste.content)
paste.put()
self.redirect('/' + paste.id)

class CreatePaste(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
template_values = {}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))

class ShowPaste(webapp2.RequestHandler):
def get(self, paste_id):
logging.info("Querying paste_id %s", paste_id)
query = db.Query(Paste)
query.filter("id = ", paste_id)
template_values = {"content": cgi.escape(query.get().content)}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))

app = webapp2.WSGIApplication([
(r'/', CreatePaste),
(r'/paste', SavePaste),
(r'/(\S+)', ShowPaste)
])

0 comments on commit 1c218ad

Please sign in to comment.