-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c218ad
Showing
11 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
]) |