├── .gitignore ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── Procfile ├── README.md ├── example ├── __init__.py ├── pastebin ├── settings │ ├── __init__.py │ ├── common.py │ ├── heroku.py │ ├── local.py │ └── local.py-dist ├── urls.py └── wsgi.py ├── ez_setup.py ├── manage.py ├── pastebin ├── __init__.py ├── forms.py ├── models.py ├── static │ └── css │ │ ├── print.css │ │ ├── pygments.css │ │ ├── style.css │ │ └── styleold.css ├── templates │ └── djpaste │ │ ├── base.html │ │ ├── create.html │ │ ├── details.html │ │ └── help.html ├── tests.py ├── urls.py └── views.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.db 3 | *dist/ 4 | *egg-info/ 5 | *~ 6 | example/localsettings.py 7 | example/static 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.6" 4 | - "2.7" 5 | # command to install dependencies 6 | install: "pip install -r requirements.txt --use-mirrors" 7 | # command to run tests 8 | script: python manage.py test pastebin 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This application is BSD licensed. 2 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README 2 | include LICENSE 3 | recursive-include pastebin/templates * 4 | recursive-include site_media * 5 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn example.wsgi 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### A Django based pastebin. 2 | 3 | [](https://travis-ci.org/agiliq/django-pastebin) 4 | 5 | ### Installation 6 | 7 | pip install -r requirements.txt 8 | pip install django-pastebin 9 | 10 | or 11 | 12 | python setup.py install 13 | 14 | #### License 15 | 16 | BSD 17 | -------------------------------------------------------------------------------- /example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agiliq/django-pastebin/76de302f5a3ce0bba071a747d374c8551c0a969c/example/__init__.py -------------------------------------------------------------------------------- /example/pastebin: -------------------------------------------------------------------------------- 1 | ../pastebin/ -------------------------------------------------------------------------------- /example/settings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agiliq/django-pastebin/76de302f5a3ce0bba071a747d374c8551c0a969c/example/settings/__init__.py -------------------------------------------------------------------------------- /example/settings/common.py: -------------------------------------------------------------------------------- 1 | # Django settings for pastebin project. 2 | 3 | import os 4 | import sys 5 | 6 | proj_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 7 | 8 | sys.path.insert(0, proj_dir) 9 | 10 | DEBUG = True 11 | TEMPLATE_DEBUG = DEBUG 12 | 13 | ADMINS = ( 14 | # ('Your Name', 'your_email@example.com'), 15 | ) 16 | 17 | MANAGERS = ADMINS 18 | 19 | DATABASES = { 20 | 'default': { 21 | 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 22 | 'NAME': "", 23 | # The following settings are not used with sqlite3: 24 | 'USER': '', 25 | 'PASSWORD': '', 26 | 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 27 | 'PORT': '', # Set to empty string for default. 28 | } 29 | } 30 | 31 | # Hosts/domain names that are valid for this site; required if DEBUG is False 32 | # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts 33 | ALLOWED_HOSTS = [] 34 | 35 | # Local time zone for this installation. Choices can be found here: 36 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 37 | # although not all choices may be available on all operating systems. 38 | # In a Windows environment this must be set to your system time zone. 39 | TIME_ZONE = 'America/Chicago' 40 | 41 | # Language code for this installation. All choices can be found here: 42 | # http://www.i18nguy.com/unicode/language-identifiers.html 43 | LANGUAGE_CODE = 'en-us' 44 | 45 | SITE_ID = 1 46 | 47 | # If you set this to False, Django will make some optimizations so as not 48 | # to load the internationalization machinery. 49 | USE_I18N = True 50 | 51 | # If you set this to False, Django will not format dates, numbers and 52 | # calendars according to the current locale. 53 | USE_L10N = True 54 | 55 | # If you set this to False, Django will not use timezone-aware datetimes. 56 | USE_TZ = True 57 | 58 | # Absolute filesystem path to the directory that will hold user-uploaded files. 59 | # Example: "/var/www/example.com/media/" 60 | MEDIA_ROOT = '' 61 | 62 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 63 | # trailing slash. 64 | # Examples: "http://example.com/media/", "http://media.example.com/" 65 | MEDIA_URL = '' 66 | 67 | # Absolute path to the directory static files should be collected to. 68 | # Don't put anything in this directory yourself; store your static files 69 | # in apps' "static/" subdirectories and in STATICFILES_DIRS. 70 | # Example: "/var/www/example.com/static/" 71 | STATIC_ROOT = "%s/static" % proj_dir 72 | 73 | # URL prefix for static files. 74 | # Example: "http://example.com/static/", "http://static.example.com/" 75 | STATIC_URL = '/static/' 76 | 77 | # Additional locations of static files 78 | STATICFILES_DIRS = ( 79 | # Put strings here, like "/home/html/static" or "C:/www/django/static". 80 | # Always use forward slashes, even on Windows. 81 | # Don't forget to use absolute paths, not relative paths. 82 | ) 83 | 84 | # List of finder classes that know how to find static files in 85 | # various locations. 86 | STATICFILES_FINDERS = ( 87 | 'django.contrib.staticfiles.finders.FileSystemFinder', 88 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 89 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 90 | ) 91 | 92 | # Make this unique, and don't share it with anybody. 93 | SECRET_KEY = '!0y5%ur^hd7$f($pkw)tg4w7n^o+_&*dfv562j(coak-l)_-2e' 94 | 95 | # List of callables that know how to import templates from various sources. 96 | TEMPLATE_LOADERS = ( 97 | 'django.template.loaders.filesystem.Loader', 98 | 'django.template.loaders.app_directories.Loader', 99 | # 'django.template.loaders.eggs.Loader', 100 | ) 101 | 102 | MIDDLEWARE_CLASSES = ( 103 | 'django.middleware.common.CommonMiddleware', 104 | 'django.contrib.sessions.middleware.SessionMiddleware', 105 | 'django.middleware.csrf.CsrfViewMiddleware', 106 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 107 | 'django.contrib.messages.middleware.MessageMiddleware', 108 | # Uncomment the next line for simple clickjacking protection: 109 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 110 | ) 111 | 112 | ROOT_URLCONF = 'example.urls' 113 | 114 | # Python dotted path to the WSGI application used by Django's runserver. 115 | WSGI_APPLICATION = 'example.wsgi.application' 116 | 117 | TEMPLATE_DIRS = ( 118 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 119 | # Always use forward slashes, even on Windows. 120 | # Don't forget to use absolute paths, not relative paths. 121 | ) 122 | 123 | INSTALLED_APPS = ( 124 | 'pastebin', 125 | 'django.contrib.auth', 126 | 'django.contrib.admin', 127 | 'django.contrib.contenttypes', 128 | 'django.contrib.sessions', 129 | 'django.contrib.sites', 130 | 'django.contrib.staticfiles', 131 | # Uncomment the next line to enable the admin: 132 | # Uncomment the next line to enable admin documentation: 133 | # 'django.contrib.admindocs', 134 | 'gunicorn', 135 | ) 136 | 137 | # A sample logging configuration. The only tangible logging 138 | # performed by this configuration is to send an email to 139 | # the site admins on every HTTP 500 error when DEBUG=False. 140 | # See http://docs.djangoproject.com/en/dev/topics/logging for 141 | # more details on how to customize your logging configuration. 142 | LOGGING = { 143 | 'version': 1, 144 | 'disable_existing_loggers': False, 145 | 'filters': { 146 | 'require_debug_false': { 147 | '()': 'django.utils.log.RequireDebugFalse' 148 | } 149 | }, 150 | 'handlers': { 151 | 'mail_admins': { 152 | 'level': 'ERROR', 153 | 'filters': ['require_debug_false'], 154 | 'class': 'django.utils.log.AdminEmailHandler' 155 | } 156 | }, 157 | 'loggers': { 158 | 'django.request': { 159 | 'handlers': ['mail_admins'], 160 | 'level': 'ERROR', 161 | 'propagate': True, 162 | }, 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /example/settings/heroku.py: -------------------------------------------------------------------------------- 1 | from common import * 2 | 3 | # Parse database configuration from $DATABASE_URL 4 | import dj_database_url 5 | DATABASES['default'] = dj_database_url.config() 6 | 7 | # Honor the 'X-Forwarded-Proto' header for request.is_secure() 8 | SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 9 | -------------------------------------------------------------------------------- /example/settings/local.py: -------------------------------------------------------------------------------- 1 | from common import * 2 | 3 | DATABASES = { 4 | 'default': { 5 | 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 6 | 'NAME': 'test.db', # Or path to database file if using sqlite3. 7 | 'USER': '', # Not used with sqlite3. 8 | 'PASSWORD': '', # Not used with sqlite3. 9 | 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 10 | 'PORT': '', # Set to empty string for default. Not used with sqlite3. 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/settings/local.py-dist: -------------------------------------------------------------------------------- 1 | 2 | DATABASES = { 3 | 'default': { 4 | 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 5 | 'NAME': 'dev.db', # Or path to database file if using sqlite3. 6 | 'USER': '', # Not used with sqlite3. 7 | 'PASSWORD': '', # Not used with sqlite3. 8 | 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 9 | 'PORT': '', # Set to empty string for default. Not used with sqlite3. 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include 2 | 3 | urlpatterns = patterns('', 4 | # Example: 5 | (r'^', include('pastebin.urls')) 6 | # (r'^pastebin/', include('pastebin.foo.urls')), 7 | 8 | # Uncomment this for admin: 9 | # (r'^admin/', include('django.contrib.admin.urls')), 10 | ) 11 | -------------------------------------------------------------------------------- /example/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite 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"] = "mysite.settings" 22 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings.local") 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 | -------------------------------------------------------------------------------- /ez_setup.py: -------------------------------------------------------------------------------- 1 | #!python 2 | """Bootstrap setuptools installation 3 | 4 | If you want to use setuptools in your package's setup.py, just include this 5 | file in the same directory with it, and add this to the top of your setup.py:: 6 | 7 | from ez_setup import use_setuptools 8 | use_setuptools() 9 | 10 | If you want to require a specific version of setuptools, set a download 11 | mirror, or use an alternate download directory, you can do so by supplying 12 | the appropriate options to ``use_setuptools()``. 13 | 14 | This file can also be run as a script to install or upgrade setuptools. 15 | """ 16 | import sys 17 | DEFAULT_VERSION = "0.6c11" 18 | DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] 19 | 20 | md5_data = { 21 | 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', 22 | 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', 23 | 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', 24 | 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', 25 | 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', 26 | 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', 27 | 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', 28 | 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', 29 | 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', 30 | 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', 31 | 'setuptools-0.6c10-py2.3.egg': 'ce1e2ab5d3a0256456d9fc13800a7090', 32 | 'setuptools-0.6c10-py2.4.egg': '57d6d9d6e9b80772c59a53a8433a5dd4', 33 | 'setuptools-0.6c10-py2.5.egg': 'de46ac8b1c97c895572e5e8596aeb8c7', 34 | 'setuptools-0.6c10-py2.6.egg': '58ea40aef06da02ce641495523a0b7f5', 35 | 'setuptools-0.6c11-py2.3.egg': '2baeac6e13d414a9d28e7ba5b5a596de', 36 | 'setuptools-0.6c11-py2.4.egg': 'bd639f9b0eac4c42497034dec2ec0c2b', 37 | 'setuptools-0.6c11-py2.5.egg': '64c94f3bf7a72a13ec83e0b24f2749b2', 38 | 'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086', 39 | 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', 40 | 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', 41 | 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', 42 | 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', 43 | 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', 44 | 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', 45 | 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', 46 | 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', 47 | 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', 48 | 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', 49 | 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', 50 | 'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20', 51 | 'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab', 52 | 'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53', 53 | 'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2', 54 | 'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e', 55 | 'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372', 56 | 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', 57 | 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', 58 | 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', 59 | 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', 60 | 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', 61 | 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', 62 | 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', 63 | } 64 | 65 | import sys, os 66 | try: from hashlib import md5 67 | except ImportError: from md5 import md5 68 | 69 | def _validate_md5(egg_name, data): 70 | if egg_name in md5_data: 71 | digest = md5(data).hexdigest() 72 | if digest != md5_data[egg_name]: 73 | print >>sys.stderr, ( 74 | "md5 validation of %s failed! (Possible download problem?)" 75 | % egg_name 76 | ) 77 | sys.exit(2) 78 | return data 79 | 80 | def use_setuptools( 81 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, 82 | download_delay=15 83 | ): 84 | """Automatically find/download setuptools and make it available on sys.path 85 | 86 | `version` should be a valid setuptools version number that is available 87 | as an egg for download under the `download_base` URL (which should end with 88 | a '/'). `to_dir` is the directory where setuptools will be downloaded, if 89 | it is not already available. If `download_delay` is specified, it should 90 | be the number of seconds that will be paused before initiating a download, 91 | should one be required. If an older version of setuptools is installed, 92 | this routine will print a message to ``sys.stderr`` and raise SystemExit in 93 | an attempt to abort the calling script. 94 | """ 95 | was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules 96 | def do_download(): 97 | egg = download_setuptools(version, download_base, to_dir, download_delay) 98 | sys.path.insert(0, egg) 99 | import setuptools; setuptools.bootstrap_install_from = egg 100 | try: 101 | import pkg_resources 102 | except ImportError: 103 | return do_download() 104 | try: 105 | pkg_resources.require("setuptools>="+version); return 106 | except pkg_resources.VersionConflict, e: 107 | if was_imported: 108 | print >>sys.stderr, ( 109 | "The required version of setuptools (>=%s) is not available, and\n" 110 | "can't be installed while this script is running. Please install\n" 111 | " a more recent version first, using 'easy_install -U setuptools'." 112 | "\n\n(Currently using %r)" 113 | ) % (version, e.args[0]) 114 | sys.exit(2) 115 | else: 116 | del pkg_resources, sys.modules['pkg_resources'] # reload ok 117 | return do_download() 118 | except pkg_resources.DistributionNotFound: 119 | return do_download() 120 | 121 | def download_setuptools( 122 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, 123 | delay = 15 124 | ): 125 | """Download setuptools from a specified location and return its filename 126 | 127 | `version` should be a valid setuptools version number that is available 128 | as an egg for download under the `download_base` URL (which should end 129 | with a '/'). `to_dir` is the directory where the egg will be downloaded. 130 | `delay` is the number of seconds to pause before an actual download attempt. 131 | """ 132 | import urllib2, shutil 133 | egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) 134 | url = download_base + egg_name 135 | saveto = os.path.join(to_dir, egg_name) 136 | src = dst = None 137 | if not os.path.exists(saveto): # Avoid repeated downloads 138 | try: 139 | from distutils import log 140 | if delay: 141 | log.warn(""" 142 | --------------------------------------------------------------------------- 143 | This script requires setuptools version %s to run (even to display 144 | help). I will attempt to download it for you (from 145 | %s), but 146 | you may need to enable firewall access for this script first. 147 | I will start the download in %d seconds. 148 | 149 | (Note: if this machine does not have network access, please obtain the file 150 | 151 | %s 152 | 153 | and place it in this directory before rerunning this script.) 154 | ---------------------------------------------------------------------------""", 155 | version, download_base, delay, url 156 | ); from time import sleep; sleep(delay) 157 | log.warn("Downloading %s", url) 158 | src = urllib2.urlopen(url) 159 | # Read/write all in one block, so we don't create a corrupt file 160 | # if the download is interrupted. 161 | data = _validate_md5(egg_name, src.read()) 162 | dst = open(saveto,"wb"); dst.write(data) 163 | finally: 164 | if src: src.close() 165 | if dst: dst.close() 166 | return os.path.realpath(saveto) 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | def main(argv, version=DEFAULT_VERSION): 204 | """Install or upgrade setuptools and EasyInstall""" 205 | try: 206 | import setuptools 207 | except ImportError: 208 | egg = None 209 | try: 210 | egg = download_setuptools(version, delay=0) 211 | sys.path.insert(0,egg) 212 | from setuptools.command.easy_install import main 213 | return main(list(argv)+[egg]) # we're done here 214 | finally: 215 | if egg and os.path.exists(egg): 216 | os.unlink(egg) 217 | else: 218 | if setuptools.__version__ == '0.0.1': 219 | print >>sys.stderr, ( 220 | "You have an obsolete version of setuptools installed. Please\n" 221 | "remove it from your system entirely before rerunning this script." 222 | ) 223 | sys.exit(2) 224 | 225 | req = "setuptools>="+version 226 | import pkg_resources 227 | try: 228 | pkg_resources.require(req) 229 | except pkg_resources.VersionConflict: 230 | try: 231 | from setuptools.command.easy_install import main 232 | except ImportError: 233 | from easy_install import main 234 | main(list(argv)+[download_setuptools(delay=0)]) 235 | sys.exit(0) # try to force an exit 236 | else: 237 | if argv: 238 | from setuptools.command.easy_install import main 239 | main(argv) 240 | else: 241 | print "Setuptools version",version,"or greater has been installed." 242 | print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' 243 | 244 | def update_md5(filenames): 245 | """Update our built-in md5 registry""" 246 | 247 | import re 248 | 249 | for name in filenames: 250 | base = os.path.basename(name) 251 | f = open(name,'rb') 252 | md5_data[base] = md5(f.read()).hexdigest() 253 | f.close() 254 | 255 | data = [" %r: %r,\n" % it for it in md5_data.items()] 256 | data.sort() 257 | repl = "".join(data) 258 | 259 | import inspect 260 | srcfile = inspect.getsourcefile(sys.modules[__name__]) 261 | f = open(srcfile, 'rb'); src = f.read(); f.close() 262 | 263 | match = re.search("\nmd5_data = {\n([^}]+)}", src) 264 | if not match: 265 | print >>sys.stderr, "Internal error!" 266 | sys.exit(2) 267 | 268 | src = src[:match.start(1)] + repl + src[match.end(1):] 269 | f = open(srcfile,'w') 270 | f.write(src) 271 | f.close() 272 | 273 | 274 | if __name__=='__main__': 275 | if len(sys.argv)>2 and sys.argv[1]=='--md5update': 276 | update_md5(sys.argv[2:]) 277 | else: 278 | main(sys.argv[1:]) 279 | 280 | 281 | 282 | 283 | 284 | 285 | -------------------------------------------------------------------------------- /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", "example.settings.local") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pastebin/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agiliq/django-pastebin/76de302f5a3ce0bba071a747d374c8551c0a969c/pastebin/__init__.py -------------------------------------------------------------------------------- /pastebin/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from .models import CodePaste 3 | 4 | 5 | class PasteForm(forms.Form): 6 | lang_names = (('Python', 'Python',), ('Perl', 'Perl',), 7 | ('Ruby', 'Ruby',), ('PythonConsole', 'Python Console'), 8 | ('RubyConsole', 'Ruby Console'), 9 | ('PythonTraceback', 'Python Traceback'), 10 | ('HtmlDjango', 'Django Template'), 11 | ('Html', 'Html'), ('Others', 'Others')) 12 | text = forms.CharField(label='Code', 13 | widget=forms.Textarea(attrs={"rows": 20, "cols": 80})) 14 | language = forms.ChoiceField(lang_names, required=False) 15 | title = forms.CharField(required=False, max_length=60, 16 | widget=forms.TextInput(attrs={'size': 50})) 17 | name = forms.CharField(max_length=60, 18 | widget=forms.TextInput(attrs={'size': 50}), required=False) 19 | 20 | def save(self): 21 | snippet = CodePaste(text=self.cleaned_data['text'], 22 | language=self.cleaned_data['language'], 23 | title=self.cleaned_data['title'], 24 | name=self.cleaned_data['name']) 25 | snippet.save() 26 | return snippet 27 | 28 | -------------------------------------------------------------------------------- /pastebin/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class CodePaste(models.Model): 5 | text = models.TextField() 6 | htmld_text = models.TextField() 7 | language = models.CharField(max_length=30) 8 | title = models.CharField(max_length=50) 9 | name = models.CharField(max_length=50) 10 | created_on = models.DateField(auto_now_add=1) 11 | 12 | @models.permalink 13 | def get_absolute_url(self): 14 | return ('pastebin.views.paste_details', [self.id]) 15 | 16 | @models.permalink 17 | def get_plain_url(self): 18 | return ('pastebin.views.plain', [self.id]) 19 | 20 | @models.permalink 21 | def get_html_url(self): 22 | return ('pastebin.views.html', [self.id]) 23 | 24 | def save(self, *args, **kwargs): 25 | """Htmlize text and save to htmld_text. Use Pygments""" 26 | 27 | self.htmld_text = htmlize(self.text, self.language) 28 | super(CodePaste, self).save(*args, **kwargs) 29 | 30 | 31 | def htmlize(text, language): 32 | from pygments import highlight 33 | from pygments.formatters import HtmlFormatter as Formatter 34 | if language == 'Python': 35 | from pygments.lexers import PythonLexer as Lexer 36 | elif language == 'Perl': 37 | from pygments.lexers import PerlLexer as Lexer 38 | elif language == 'Ruby': 39 | from pygments.lexers import RubyLexer as Lexer 40 | elif language == 'PythonConsole': 41 | from pygments.lexers import PythonConsoleLexer as Lexer 42 | elif language == 'PythonTraceback': 43 | from pygments.lexers import PythonTracebackLexer as Lexer 44 | elif language == 'RubyConsole': 45 | from pygments.lexers import RubyConsoleLexer as Lexer 46 | elif language == 'HtmlDjango': 47 | from pygments.lexers import HtmlDjangoLexer as Lexer 48 | elif language == 'Html': 49 | from pygments.lexers import HtmlLexer as Lexer 50 | else: 51 | from pygments.lexers import TextLexer as Lexer 52 | """ 53 | Todo: I cant get this to work. 54 | lang_lexer = str(language + 'Lexer') 55 | Lexer = __import__('pygments.lexers', globals(), locals(), [lang_lexer, ]) 56 | Or 57 | from pygments.lexers import get_lexer_by_name 58 | Lexer = get_lexer_by_name(language.lower()) 59 | """ 60 | htmld = highlight(text, Lexer(), Formatter(linenos='table')) 61 | return htmld 62 | -------------------------------------------------------------------------------- /pastebin/static/css/print.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | /* CSS Document */ 3 | 4 | /* --------- Universal --------- */ 5 | * { 6 | font-family:"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 7 | font-weight:bolder; 8 | margin:0px; 9 | padding:0px; 10 | } 11 | 12 | body { 13 | color:#000; 14 | } 15 | 16 | /* --------- Links --------- */ 17 | a:link, a:visited, a:hover, a:active{ 18 | text-decoration:none; 19 | border:none; 20 | color:#000; 21 | } 22 | 23 | /* --------- Layout --------- */ 24 | #container { 25 | width:100%; 26 | } 27 | 28 | #footer { 29 | color:#000; 30 | font-size:75%; 31 | margin:0px auto; 32 | text-align:center; 33 | } 34 | 35 | /* --------- Header Tags --------- */ 36 | h1, h2, h3, h4, h5, h6 { 37 | color:#000; 38 | font-weight:bolder; 39 | padding:15px; 40 | } 41 | 42 | h1 {font-size: 36px;} 43 | h2 {font-size: 24px;} 44 | h3 {font-size: 18px;} 45 | h4 {font-size: 16px;} 46 | h5 {font-size: 14px;} 47 | h6 {font-size: 12px;} 48 | 49 | /* --------- Typography --------- */ 50 | 51 | p { 52 | font-size:medium; 53 | line-height:1; 54 | } 55 | 56 | ul { 57 | list-style:square inside; 58 | } 59 | 60 | ol { 61 | list-style:lower-roman inside; 62 | } 63 | 64 | /* --------- Stops --------- */ 65 | h1:after, li:after, p:after { 66 | content:"."; 67 | color:#000; 68 | font-family:Helvatica, Arial, sans-serif; 69 | } 70 | 71 | p:after, li:after { 72 | font-size:24px; 73 | } -------------------------------------------------------------------------------- /pastebin/static/css/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight { background: #f8f8f8; } 2 | .highlight .c { color: #408080; font-style: italic } /* Comment */ 3 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 4 | .highlight .k { color: #008000; font-weight: bold } /* Keyword */ 5 | .highlight .o { color: #666666 } /* Operator */ 6 | .highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */ 7 | .highlight .cp { color: #BC7A00 } /* Comment.Preproc */ 8 | .highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */ 9 | .highlight .cs { color: #408080; font-style: italic } /* Comment.Special */ 10 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 11 | .highlight .ge { font-style: italic } /* Generic.Emph */ 12 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 13 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 14 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 15 | .highlight .go { color: #808080 } /* Generic.Output */ 16 | .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 17 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 18 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 19 | .highlight .gt { color: #0040D0 } /* Generic.Traceback */ 20 | .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ 21 | .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ 22 | .highlight .kp { color: #008000 } /* Keyword.Pseudo */ 23 | .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ 24 | .highlight .kt { color: #B00040 } /* Keyword.Type */ 25 | .highlight .m { color: #666666 } /* Literal.Number */ 26 | .highlight .s { color: #BA2121 } /* Literal.String */ 27 | .highlight .na { color: #7D9029 } /* Name.Attribute */ 28 | .highlight .nb { color: #008000 } /* Name.Builtin */ 29 | .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 30 | .highlight .no { color: #880000 } /* Name.Constant */ 31 | .highlight .nd { color: #AA22FF } /* Name.Decorator */ 32 | .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ 33 | .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ 34 | .highlight .nf { color: #0000FF } /* Name.Function */ 35 | .highlight .nl { color: #A0A000 } /* Name.Label */ 36 | .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 37 | .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ 38 | .highlight .nv { color: #19177C } /* Name.Variable */ 39 | .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 40 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 41 | .highlight .mf { color: #666666 } /* Literal.Number.Float */ 42 | .highlight .mh { color: #666666 } /* Literal.Number.Hex */ 43 | .highlight .mi { color: #666666 } /* Literal.Number.Integer */ 44 | .highlight .mo { color: #666666 } /* Literal.Number.Oct */ 45 | .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ 46 | .highlight .sc { color: #BA2121 } /* Literal.String.Char */ 47 | .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ 48 | .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ 49 | .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ 50 | 51 | .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ 52 | .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol 53 | */ 54 | .highlight .sx { color: #008000 } /* Literal.String.Other */ 55 | .highlight .sr { color: #BB6688 } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ 57 | .highlight .ss { color: #19177C } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #19177C } /* Name.Variable.Class */ 60 | .highlight .vg { color: #19177C } /* Name.Variable.Global */ 61 | .highlight .vi { color: #19177C } /* Name.Variable.Instance */ 62 | .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /pastebin/static/css/style.css: -------------------------------------------------------------------------------- 1 | #header { 2 | background-color: black; 3 | color: white; 4 | 5 | } 6 | #header h1{ 7 | margin:10px; 8 | border-left:5px #FFDF00 double; 9 | padding:10px; 10 | font-family:"Courier New", Courier, monospace; 11 | } 12 | #footer{ 13 | text-align: center; 14 | 15 | } 16 | #container{ 17 | background-color: lightgrey; 18 | } 19 | 20 | #wrap { 21 | background-color: lightgrey; 22 | } 23 | #pastetext { 24 | margin-left: 15px; 25 | margin-top: 10px; 26 | } 27 | 28 | h3 , #info{ 29 | margin-left: 10px; 30 | } 31 | .linenos pre{ 32 | background-color: grey; 33 | padding: 1px 1px 1px 1px; 34 | } 35 | .language{ 36 | font-weight: bold; 37 | float: left; 38 | } 39 | .choices a{ 40 | padding-left: 5px; 41 | } 42 | #help{ 43 | margin-left: 10px; 44 | } 45 | 46 | .highlight .c { color: #408080; font-style: italic } /* Comment */ 47 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 48 | .highlight .k { color: #008000; font-weight: bold } /* Keyword */ 49 | .highlight .o { color: #666666 } /* Operator */ 50 | .highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */ 51 | .highlight .cp { color: #BC7A00 } /* Comment.Preproc */ 52 | .highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */ 53 | .highlight .cs { color: #408080; font-style: italic } /* Comment.Special */ 54 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 55 | .highlight .ge { font-style: italic } /* Generic.Emph */ 56 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 57 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 58 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 59 | .highlight .go { color: #808080 } /* Generic.Output */ 60 | .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 61 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 62 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 63 | .highlight .gt { color: #0040D0 } /* Generic.Traceback */ 64 | .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ 65 | .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ 66 | .highlight .kp { color: #008000 } /* Keyword.Pseudo */ 67 | .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ 68 | .highlight .kt { color: #B00040 } /* Keyword.Type */ 69 | .highlight .m { color: #666666 } /* Literal.Number */ 70 | .highlight .s { color: #BA2121 } /* Literal.String */ 71 | .highlight .na { color: #7D9029 } /* Name.Attribute */ 72 | .highlight .nb { color: #008000 } /* Name.Builtin */ 73 | .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 74 | .highlight .no { color: #880000 } /* Name.Constant */ 75 | .highlight .nd { color: #AA22FF } /* Name.Decorator */ 76 | .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ 77 | .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ 78 | .highlight .nf { color: #0000FF } /* Name.Function */ 79 | .highlight .nl { color: #A0A000 } /* Name.Label */ 80 | .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 81 | .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ 82 | .highlight .nv { color: #19177C } /* Name.Variable */ 83 | .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 84 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 85 | .highlight .mf { color: #666666 } /* Literal.Number.Float */ 86 | .highlight .mh { color: #666666 } /* Literal.Number.Hex */ 87 | .highlight .mi { color: #666666 } /* Literal.Number.Integer */ 88 | .highlight .mo { color: #666666 } /* Literal.Number.Oct */ 89 | .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ 90 | .highlight .sc { color: #BA2121 } /* Literal.String.Char */ 91 | .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ 92 | .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ 93 | .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ 94 | 95 | .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ 96 | .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol 97 | */ 98 | .highlight .sx { color: #008000 } /* Literal.String.Other */ 99 | .highlight .sr { color: #BB6688 } /* Literal.String.Regex */ 100 | .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ 101 | .highlight .ss { color: #19177C } /* Literal.String.Symbol */ 102 | .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ 103 | .highlight .vc { color: #19177C } /* Name.Variable.Class */ 104 | .highlight .vg { color: #19177C } /* Name.Variable.Global */ 105 | .highlight .vi { color: #19177C } /* Name.Variable.Instance */ 106 | .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /pastebin/static/css/styleold.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | /* CSS Coded and Designed by Nathan Chapman */ 3 | /* from Pixl Design - http://pixl.utopiaplanitia.org */ 4 | 5 | /* --------- RESET --------- */ 6 | /* Don't forget to set a foreground and background color 7 | on the 'html' or 'body' element! */html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{ margin:0; padding:0; border:0; font-weight:inherit; font-style:inherit; font-size:100%; line-height:1.2; font-family:Geneva, Arial, Helvetica, sans-serif; text-align:left; vertical-align:baseline; } 8 | a img,:link img,:visited img{ border:0; } 9 | table{ border-collapse:collapse; border-spacing:0; } 10 | ol,ul{ list-style:none; } 11 | q:before,q:after,blockquote:before,blockquote:after{ content:""; } 12 | 13 | /* --------- Universal --------- */ 14 | body{ background:#fefefe; color:#AAA; } 15 | 16 | /* --------- Links --------- */ 17 | a:link,a:visited{ text-decoration:none; color:#666; border-bottom:1px #999 dashed; } 18 | a:hover,a:active{ color:#333; border-bottom:1px #333 solid; } 19 | 20 | /* --------- Layout --------- */ 21 | #container{ margin:20px auto 30px; width:65%; } 22 | #footer{ color:#999; font-size:75%; margin-bottom:50px; text-align:center; } 23 | 24 | /* --------- Header Tags --------- */ 25 | h1,h2,h3,h4,h5,h6{ color:#999; font-weight:bolder; padding:10px 15px 0px 15px; } 26 | h1{ font-size:36px; } 27 | h2{ font-size:24px; } 28 | h3{ font-size:18px; } 29 | h4{ font-size:16px; } 30 | h5{ font-size:14px; } 31 | h6{ font-size:12px; } 32 | 33 | /* --------- Typography --------- */ 34 | p{ font-size:medium; line-height:1.2; } 35 | ul,ol{ margin:25px; } 36 | ul li, ol li { padding-left:10px; } 37 | ul{ list-style:square inside; } 38 | ol{ list-style:decimal inside; } 39 | blockquote{ margin:15px; border-left:5px #FFDF00 solid; padding:7px; color:#999; font-style:italic; } 40 | pre { margin:10px; border-left:5px #FFDF00 double; padding:10px; font-family:"Courier New", Courier, monospace; } 41 | 42 | /* --------- Yellow Stops --------- */ 43 | h1:after,h2:after,h3:after,h4:after,h5:after,h6:after,li:after,p:after{ content:"."; color:#FFDF00; font-family:Helvatica, Arial, sans-serif; } 44 | p:after,li:after{ font-size:24px; } 45 | 46 | #header { 47 | background-color: red; 48 | color: #f00; 49 | text-align:center; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /pastebin/templates/djpaste/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |
6 | DjPaste is a pastebin written in Django. It was built as part of 7days7apps project.
7 | It is heavily stolen inspired from Dpaste.com, but the codebase is in no way related.
8 |
10 | Pasting content with DjPaste is very easy. You just choose the type of the code you are pasing, paste, and hit the button. Magic starts happening. 11 | Only text is the required field. All other fields are optional. 12 |
13 |Super Special Features: 14 |