├── paste ├── __init__.py ├── migrations │ ├── __init__.py │ └── 0001_initial.py ├── tests.py ├── views.py ├── models.py └── admin.py ├── pyste ├── __init__.py ├── urls.py ├── templates │ ├── base.html │ └── paste │ │ ├── paste.html │ │ └── index.html ├── wsgi.py └── settings.py ├── db ├── manage.py └── .gitignore /paste/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyste/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /paste/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karan/pyste/master/db -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyste.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /pyste/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include, url 2 | 3 | from django.contrib import admin 4 | admin.autodiscover() 5 | 6 | urlpatterns = patterns('', 7 | url(r'^admin/', include(admin.site.urls)), 8 | url(r'^$', 'paste.views.index'), 9 | url(r'^(?P[^\.]+).html', 'paste.views.paste'), 10 | ) 11 | -------------------------------------------------------------------------------- /pyste/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {% block title %}{% endblock %} 7 | 8 | 9 | 10 |
11 | {% block content %} 12 | {% endblock %} 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /paste/tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | This file demonstrates writing tests using the unittest module. These will pass 3 | when you run "manage.py test". 4 | 5 | Replace this with more appropriate tests for your application. 6 | """ 7 | 8 | from django.test import TestCase 9 | 10 | 11 | class SimpleTest(TestCase): 12 | def test_basic_addition(self): 13 | """ 14 | Tests that 1 + 1 always equals 2. 15 | """ 16 | self.assertEqual(1 + 1, 2) 17 | -------------------------------------------------------------------------------- /pyste/templates/paste/paste.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block title %}{{paste.title}}{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

{{paste.title}}

9 |

10 | Posted on 11 | 14 |

15 |
16 | {{paste.content|safe}} 17 |
18 | {% endblock %} 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | .coverage 26 | .tox 27 | nosetests.xml 28 | 29 | # Translations 30 | *.mo 31 | 32 | # Mr Developer 33 | .mr.developer.cfg 34 | .project 35 | .pydevproject 36 | 37 | # Komodo 38 | .komodotools/ 39 | *.komodoproject -------------------------------------------------------------------------------- /paste/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, get_object_or_404 2 | from paste.models import Paste 3 | 4 | def index(request): 5 | # get the pastes that are published 6 | pastes = Paste.objects.all() 7 | # now return the rendered template 8 | return render(request, 'paste/index.html', {'pastes': pastes}) 9 | 10 | def paste(request, slug): 11 | # get the Post object 12 | paste = get_object_or_404(Paste, slug=slug) 13 | # now return the rendered template 14 | return render(request, 'paste/paste.html', {'paste': paste}) -------------------------------------------------------------------------------- /paste/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.core.urlresolvers import reverse 3 | 4 | 5 | class Paste(models.Model): 6 | title = models.CharField(max_length=255) 7 | text = models.TextField() 8 | created = models.DateTimeField(auto_now_add=True) 9 | slug = models.SlugField(unique=True, max_length=20) 10 | 11 | class Meta: 12 | ordering = ['-created'] 13 | 14 | def __unicode__(self): 15 | return self.title 16 | 17 | def get_absolute_url(self): 18 | return reverse('blog.views.post', args=[self.slug]) 19 | -------------------------------------------------------------------------------- /pyste/templates/paste/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | 4 | {% block title %} Paste Archive {% endblock %} 5 | 6 | {% block content %} 7 |

Paste Archive

8 | {% for paste in pastes %} 9 |
10 |

11 | 12 | {{paste.title}} 13 | 14 |

15 |

16 | Posted on 17 |

18 |
19 | {% endfor %} 20 | {% endblock %} 21 | -------------------------------------------------------------------------------- /paste/admin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from django.contrib import admin 4 | from paste.models import Paste 5 | 6 | class PasteAdmin(admin.ModelAdmin): 7 | # fields display on change list 8 | list_display = ['title', 'created'] 9 | # fields to filter the change list with 10 | list_filter = ['created'] 11 | # fields to serch in change list 12 | search_fields = ['title', 'text'] 13 | # enable the date drilldown on change list 14 | #date_hierarchy = 'created' 15 | # enable save button on top of change form 16 | save_on_top = True 17 | # pre-populate the slug from the title 18 | prepopulated_fields = {'slug': ('title',)} 19 | 20 | admin.site.register(Paste, PasteAdmin) -------------------------------------------------------------------------------- /pyste/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for pyste project. 3 | 4 | This module contains the WSGI application used by Django's development server 5 | and any production WSGI deployments. It should expose a module-level variable 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 7 | this application via the ``WSGI_APPLICATION`` setting. 8 | 9 | Usually you will have the standard Django WSGI application here, but it also 10 | might make sense to replace the whole Django WSGI application with a custom one 11 | that later delegates to the Django one. For example, you could introduce WSGI 12 | middleware here, or combine a Django application with an application of another 13 | framework. 14 | 15 | """ 16 | import os 17 | 18 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks 19 | # if running multiple sites in the same mod_wsgi process. To fix this, use 20 | # mod_wsgi daemon mode with each site in its own daemon process, or use 21 | # os.environ["DJANGO_SETTINGS_MODULE"] = "pyste.settings" 22 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyste.settings") 23 | 24 | # This application object is used by any WSGI server configured to use this 25 | # file. This includes Django's development server, if the WSGI_APPLICATION 26 | # setting points here. 27 | from django.core.wsgi import get_wsgi_application 28 | application = get_wsgi_application() 29 | 30 | # Apply WSGI middleware here. 31 | # from helloworld.wsgi import HelloWorldApplication 32 | # application = HelloWorldApplication(application) 33 | -------------------------------------------------------------------------------- /paste/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import datetime 3 | from south.db import db 4 | from south.v2 import SchemaMigration 5 | from django.db import models 6 | 7 | 8 | class Migration(SchemaMigration): 9 | 10 | def forwards(self, orm): 11 | # Adding model 'Paste' 12 | db.create_table(u'paste_paste', ( 13 | (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), 14 | ('title', self.gf('django.db.models.fields.CharField')(max_length=255)), 15 | ('text', self.gf('django.db.models.fields.TextField')()), 16 | ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), 17 | ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=20)), 18 | )) 19 | db.send_create_signal(u'paste', ['Paste']) 20 | 21 | 22 | def backwards(self, orm): 23 | # Deleting model 'Paste' 24 | db.delete_table(u'paste_paste') 25 | 26 | 27 | models = { 28 | u'paste.paste': { 29 | 'Meta': {'ordering': "['-created']", 'object_name': 'Paste'}, 30 | 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 31 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 32 | 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '20'}), 33 | 'text': ('django.db.models.fields.TextField', [], {}), 34 | 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) 35 | } 36 | } 37 | 38 | complete_apps = ['paste'] -------------------------------------------------------------------------------- /pyste/settings.py: -------------------------------------------------------------------------------- 1 | # Django settings for pyste project. 2 | 3 | DEBUG = True 4 | TEMPLATE_DEBUG = DEBUG 5 | 6 | ADMINS = ( 7 | # ('Your Name', 'your_email@example.com'), 8 | ) 9 | 10 | MANAGERS = ADMINS 11 | 12 | DATABASES = { 13 | 'default': { 14 | 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 15 | 'NAME': 'db', # Or path to database file if using sqlite3. 16 | # The following settings are not used with sqlite3: 17 | 'USER': '', 18 | 'PASSWORD': '', 19 | 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 20 | 'PORT': '', # Set to empty string for default. 21 | } 22 | } 23 | 24 | # Hosts/domain names that are valid for this site; required if DEBUG is False 25 | # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts 26 | ALLOWED_HOSTS = [] 27 | 28 | # Local time zone for this installation. Choices can be found here: 29 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 30 | # although not all choices may be available on all operating systems. 31 | # In a Windows environment this must be set to your system time zone. 32 | TIME_ZONE = 'America/Chicago' 33 | 34 | # Language code for this installation. All choices can be found here: 35 | # http://www.i18nguy.com/unicode/language-identifiers.html 36 | LANGUAGE_CODE = 'en-us' 37 | 38 | SITE_ID = 1 39 | 40 | # If you set this to False, Django will make some optimizations so as not 41 | # to load the internationalization machinery. 42 | USE_I18N = True 43 | 44 | # If you set this to False, Django will not format dates, numbers and 45 | # calendars according to the current locale. 46 | USE_L10N = True 47 | 48 | # If you set this to False, Django will not use timezone-aware datetimes. 49 | USE_TZ = True 50 | 51 | # Absolute filesystem path to the directory that will hold user-uploaded files. 52 | # Example: "/var/www/example.com/media/" 53 | MEDIA_ROOT = '' 54 | 55 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 56 | # trailing slash. 57 | # Examples: "http://example.com/media/", "http://media.example.com/" 58 | MEDIA_URL = '' 59 | 60 | # Absolute path to the directory static files should be collected to. 61 | # Don't put anything in this directory yourself; store your static files 62 | # in apps' "static/" subdirectories and in STATICFILES_DIRS. 63 | # Example: "/var/www/example.com/static/" 64 | STATIC_ROOT = '' 65 | 66 | # URL prefix for static files. 67 | # Example: "http://example.com/static/", "http://static.example.com/" 68 | STATIC_URL = '/static/' 69 | 70 | # Additional locations of static files 71 | STATICFILES_DIRS = ( 72 | # Put strings here, like "/home/html/static" or "C:/www/django/static". 73 | # Always use forward slashes, even on Windows. 74 | # Don't forget to use absolute paths, not relative paths. 75 | ) 76 | 77 | # List of finder classes that know how to find static files in 78 | # various locations. 79 | STATICFILES_FINDERS = ( 80 | 'django.contrib.staticfiles.finders.FileSystemFinder', 81 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 82 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 83 | ) 84 | 85 | # Make this unique, and don't share it with anybody. 86 | SECRET_KEY = '7+xw$88fub0(2ttz@k-mh*tbt%w^gej9elchkn7(jo@prd(6*r' 87 | 88 | # List of callables that know how to import templates from various sources. 89 | TEMPLATE_LOADERS = ( 90 | 'django.template.loaders.filesystem.Loader', 91 | 'django.template.loaders.app_directories.Loader', 92 | # 'django.template.loaders.eggs.Loader', 93 | ) 94 | 95 | MIDDLEWARE_CLASSES = ( 96 | 'django.middleware.common.CommonMiddleware', 97 | 'django.contrib.sessions.middleware.SessionMiddleware', 98 | 'django.middleware.csrf.CsrfViewMiddleware', 99 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 100 | 'django.contrib.messages.middleware.MessageMiddleware', 101 | # Uncomment the next line for simple clickjacking protection: 102 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 103 | ) 104 | 105 | ROOT_URLCONF = 'pyste.urls' 106 | 107 | # Python dotted path to the WSGI application used by Django's runserver. 108 | WSGI_APPLICATION = 'pyste.wsgi.application' 109 | 110 | TEMPLATE_DIRS = ( 111 | "/home/karan/Desktop/pyste/pyste/templates", 112 | ) 113 | 114 | INSTALLED_APPS = ( 115 | 'django.contrib.auth', 116 | 'django.contrib.contenttypes', 117 | 'django.contrib.sessions', 118 | 'django.contrib.sites', 119 | 'django.contrib.messages', 120 | 'django.contrib.staticfiles', 121 | 'django.contrib.admin', 122 | 'django.contrib.admindocs', 123 | 'south', 124 | 'paste', 125 | ) 126 | 127 | # A sample logging configuration. The only tangible logging 128 | # performed by this configuration is to send an email to 129 | # the site admins on every HTTP 500 error when DEBUG=False. 130 | # See http://docs.djangoproject.com/en/dev/topics/logging for 131 | # more details on how to customize your logging configuration. 132 | LOGGING = { 133 | 'version': 1, 134 | 'disable_existing_loggers': False, 135 | 'filters': { 136 | 'require_debug_false': { 137 | '()': 'django.utils.log.RequireDebugFalse' 138 | } 139 | }, 140 | 'handlers': { 141 | 'mail_admins': { 142 | 'level': 'ERROR', 143 | 'filters': ['require_debug_false'], 144 | 'class': 'django.utils.log.AdminEmailHandler' 145 | } 146 | }, 147 | 'loggers': { 148 | 'django.request': { 149 | 'handlers': ['mail_admins'], 150 | 'level': 'ERROR', 151 | 'propagate': True, 152 | }, 153 | } 154 | } 155 | --------------------------------------------------------------------------------