Skip to content

Commit ae4fb89

Browse files
author
Guillermo Alvarez
committed
Primer commit blog-api proyecto de introduccion a django
0 parents  commit ae4fb89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2685
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{py,rst,ini}]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.yml]
16+
indent_style = space
17+
indent_size = 2

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Basics
2+
*.py[cod]
3+
*.pyc
4+
__pycache__
5+
6+
# Logs
7+
*.log
8+
pip-log.txt
9+
10+
# Unit test / coverage reports
11+
.coverage
12+
.tox
13+
nosetests.xml
14+
15+
# Translations
16+
*.mo
17+
*.pot
18+
19+
# Pycharm
20+
.idea
21+
22+
# Vim
23+
24+
*~
25+
*.swp
26+
*.swo
27+
28+
# npm
29+
node_modules/
30+
31+
# Campass
32+
.sass-cache

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Guillermo Alvarez

Gruntfile.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
module.exports = function (grunt) {
2+
3+
var appConfig = grunt.file.readJSON('package.json');
4+
5+
// Load grunt tasks automatically
6+
// see: https://github.com/sindresorhus/load-grunt-tasks
7+
require('load-grunt-tasks')(grunt);
8+
9+
// Time how long tasks take. Can help when optimizing build times
10+
// see: https://npmjs.org/package/time-grunt
11+
require('time-grunt')(grunt);
12+
13+
var pathsConfig = function (appName) {
14+
this.app = appName || appConfig.name;
15+
16+
return {
17+
app: this.app,
18+
templates: this.app + '/templates',
19+
css: this.app + '/static/css',
20+
sass: this.app + '/static/sass',
21+
fonts: this.app + '/static/fonts',
22+
images: this.app + '/static/images',
23+
js: this.app + '/static/js',
24+
manageScript: this.app + '/manage.py'
25+
}
26+
};
27+
28+
grunt.initConfig({
29+
30+
paths: pathsConfig(),
31+
pkg: appConfig,
32+
33+
// see: https://github.com/gruntjs/grunt-contrib-watch
34+
watch: {
35+
gruntfile: {
36+
files: ['Gruntfile.js']
37+
},
38+
compass: {
39+
files: ['<%= paths.sass %>/**/*.{scss,sass}'],
40+
tasks: ['compass:server']
41+
},
42+
livereload: {
43+
files: [
44+
'<%= paths.js %>/**/*.js',
45+
'<%= paths.sass %>/**/*.{scss,sass}',
46+
'<%= paths.app %>/**/*.html'
47+
],
48+
options: {
49+
spawn: false,
50+
livereload: true,
51+
},
52+
},
53+
},
54+
55+
// see: https://github.com/gruntjs/grunt-contrib-compass
56+
compass: {
57+
options: {
58+
sassDir: '<%= paths.sass %>',
59+
cssDir: '<%= paths.css %>',
60+
fontsDir: '<%= paths.fonts %>',
61+
imagesDir: '<%= paths.images %>',
62+
relativeAssets: false,
63+
assetCacheBuster: false,
64+
raw: 'Sass::Script::Number.precision = 10\n'
65+
},
66+
dist: {
67+
options: {
68+
environment: 'production'
69+
}
70+
},
71+
server: {
72+
options: {
73+
// debugInfo: true
74+
}
75+
}
76+
},
77+
78+
// see: https://npmjs.org/package/grunt-bg-shell
79+
bgShell: {
80+
_defaults: {
81+
bg: true
82+
},
83+
runDjango: {
84+
cmd: 'python <%= paths.manageScript %> runserver'
85+
}
86+
}
87+
});
88+
89+
grunt.registerTask('serve', [
90+
'bgShell:runDjango',
91+
'watch'
92+
]);
93+
94+
grunt.registerTask('build', [
95+
'compass:dist'
96+
]);
97+
98+
grunt.registerTask('default', [
99+
'build'
100+
]);
101+
};

LICENSE.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) 2014, Guillermo Alvarez
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
* Neither the name of Blog API nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn --pythonpath="$PWD/blog-api" wsgi:application

README.rst

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
Blog API
2+
==============================
3+
4+
A Blog API
5+
6+
7+
LICENSE: BSD
8+
9+
Settings
10+
------------
11+
12+
Blog API relies extensively on environment settings which **will not work with Apache/mod_wsgi setups**. It has been deployed successfully with both Gunicorn/Nginx and even uWSGI/Nginx.
13+
14+
For configuration purposes, the following table maps the 'Blog API' environment variables to their Django setting:
15+
16+
======================================= =========================== ============================================== ===========================================
17+
Environment Variable Django Setting Development Default Production Default
18+
======================================= =========================== ============================================== ===========================================
19+
DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error
20+
DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error
21+
DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error
22+
DJANGO_CACHES CACHES locmem memcached
23+
DJANGO_DATABASES DATABASES See code See code
24+
DJANGO_DEBUG DEBUG True False
25+
DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend
26+
DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error
27+
DJANGO_SECURE_BROWSER_XSS_FILTER SECURE_BROWSER_XSS_FILTER n/a True
28+
DJANGO_SECURE_SSL_REDIRECT SECURE_SSL_REDIRECT n/a True
29+
DJANGO_SECURE_CONTENT_TYPE_NOSNIFF SECURE_CONTENT_TYPE_NOSNIFF n/a True
30+
DJANGO_SECURE_FRAME_DENY SECURE_FRAME_DENY n/a True
31+
DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS HSTS_INCLUDE_SUBDOMAINS n/a True
32+
DJANGO_SESSION_COOKIE_HTTPONLY SESSION_COOKIE_HTTPONLY n/a True
33+
DJANGO_SESSION_COOKIE_SECURE SESSION_COOKIE_SECURE n/a False
34+
======================================= =========================== ============================================== ===========================================
35+
36+
* TODO: Add vendor-added settings in another table
37+
38+
Getting up and running
39+
----------------------
40+
41+
The steps below will get you up and running with a local development environment. We assume you have the following installed:
42+
43+
* pip
44+
* virtualenv
45+
* PostgreSQL
46+
47+
First make sure to create and activate a virtualenv_, then open a terminal at the project root and install the requirements for local development::
48+
49+
$ pip install -r requirements/local.txt
50+
51+
.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/
52+
53+
You can now run the usual Django ``runserver`` command (replace ``yourapp`` with the name of the directory containing the Django project)::
54+
55+
$ python yourapp/manage.py runserver
56+
57+
The base app will run but you'll need to carry out a few steps to make the sign-up and login forms work. These are currently detailed in `issue #39`_.
58+
59+
.. _issue #39: https://github.com/pydanny/cookiecutter-django/issues/39
60+
61+
**Live reloading and Sass CSS compilation**
62+
63+
If you'd like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with the included Grunt task.
64+
65+
Make sure that nodejs_ is installed. Then in the project root run::
66+
67+
$ npm install grunt
68+
69+
.. _nodejs: http://nodejs.org/download/
70+
71+
Now you just need::
72+
73+
$ grunt serve
74+
75+
The base app will now run as it would with the usual ``manage.py runserver`` but with live reloading and Sass compilation enabled.
76+
77+
To get live reloading to work you'll probably need to install an `appropriate browser extension`_
78+
79+
.. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-
80+
81+
It's time to write the code!!!
82+
83+
84+
Deployment
85+
------------
86+
87+
It is possible to deploy to Heroku or to your own server by using Dokku, an open source Heroku clone.
88+
89+
Heroku
90+
^^^^^^
91+
92+
Run these commands to deploy the project to Heroku:
93+
94+
.. code-block:: bash
95+
96+
heroku create --buildpack https://github.com/heroku/heroku-buildpack-python
97+
heroku addons:add heroku-postgresql:dev
98+
heroku addons:add pgbackups:auto-month
99+
heroku addons:add sendgrid:starter
100+
heroku addons:add memcachier:dev
101+
heroku pg:promote DATABASE_URL
102+
heroku config:set DJANGO_CONFIGURATION=Production
103+
heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
104+
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
105+
heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
106+
heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE
107+
git push heroku master
108+
heroku run python blog-api/manage.py migrate
109+
heroku run python blog-api/manage.py createsuperuser
110+
heroku open
111+
112+
Dokku
113+
^^^^^
114+
115+
You need to make sure you have a server running Dokku with at least 1GB of RAM. Backing services are
116+
added just like in Heroku however you must ensure you have the relevant Dokku plugins installed.
117+
118+
.. code-block:: bash
119+
120+
cd /var/lib/dokku/plugins
121+
git clone https://github.com/rlaneve/dokku-link.git link
122+
git clone https://github.com/jezdez/dokku-memcached-plugin memcached
123+
git clone https://github.com/jezdez/dokku-postgres-plugin postgres
124+
dokku plugins-install
125+
126+
You can specify the buildpack you wish to use by creating a file name .env containing the following.
127+
128+
.. code-block:: bash
129+
130+
export BUILDPACK_URL=<repository>
131+
132+
You can then deploy by running the following commands.
133+
134+
.. code-block:: bash
135+
136+
git remote add dokku dokku@yourservername.com:blog-api
137+
git push dokku master
138+
ssh -t dokku@yourservername.com dokku memcached:create blog-api-memcached
139+
ssh -t dokku@yourservername.com dokku memcached:link blog-api-memcached blog-api
140+
ssh -t dokku@yourservername.com dokku postgres:create blog-api-postgres
141+
ssh -t dokku@yourservername.com dokku postgres:link blog-api-postgres blog-api
142+
ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_CONFIGURATION=Production
143+
ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
144+
ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
145+
ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
146+
ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE
147+
ssh -t dokku@yourservername.com dokku config:set blog-api SENDGRID_USERNAME=YOUR_SENDGRID_USERNAME
148+
ssh -t dokku@yourservername.com dokku config:set blog-api SENDGRID_PASSWORD=YOUR_SENDGRID_PASSWORD
149+
ssh -t dokku@yourservername.com dokku run blog-api python blog-api/manage.py migrate
150+
ssh -t dokku@yourservername.com dokku run blog-api python blog-api/manage.py createsuperuser
151+
152+
When deploying via Dokku make sure you backup your database in some fashion as it is NOT done automatically.

Vagrantfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$setup = <<SCRIPT
2+
DEBIAN_FRONTEND=noninteractive apt-get update
3+
SCRIPT
4+
5+
$dependencies = <<SCRIPT
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql libpq-dev
7+
DEBIAN_FRONTEND=noninteractive apt-get install -y python-dev libjpeg-dev zlib1g-dev
8+
DEBIAN_FRONTEND=noninteractive apt-get install -y python-virtualenv virtualenvwrapper
9+
SCRIPT
10+
11+
Vagrant.configure('2') do |config|
12+
13+
config.vm.box = 'precise64'
14+
config.vm.box_url = "http://files.vagrantup.com/" + config.vm.box + ".box"
15+
16+
config.ssh.forward_agent = true
17+
# Forward the dev server port
18+
config.vm.network :forwarded_port, host: 8000, guest: 8000
19+
20+
config.vm.provision "shell", inline: $setup
21+
config.vm.provision "shell", inline: $dependencies
22+
end

blog-api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '0.1.0'

blog-api/config/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import
3+
4+
from .local import Local # noqa
5+
from .production import Production # noqa

0 commit comments

Comments
 (0)