Django Oscar "ProgrammingError at /admin/" MySQL table - mysql

Trying to make my second Django app: a shop based on Django Oscar. I'm following the tutorial on RTFD. I have an issue with this stage http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html#creating-product-classes-and-fulfillment-partners.
Every Oscar deployment needs at least one product class and one
fulfillment partner. These aren’t created automatically as they’re
highly specific to the shop you want to build. The quickest way to set
them up is to log into the Django admin interface at
localhost:8000/admin/ and create instances of both there. For a
deployment setup, we recommend creating them as data migration.
However when I try to log into the admin the error generated is:
ProgrammingError at /admin/
(1146, "Table 'winestoreoscar.django_admin_log' doesn't exist")
....
Error during template rendering
In template /home/david/.virtualenvs/winestoreoscar/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/index.html, error at line 65
1146
This template is shown in the error with this line highlighted:
<ul class="actionlist">
**65 {% for entry in admin_log %}**
66 <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
So it looks like I'm missing a table. I'm using MySQL as the database. In the mysql prompt I tried the obvious..
mysql> CREATE TABLE winestoreoscar.django_admin_log;
but got the error message...
ERROR 1113 (42000): A table must have at least 1 column
I then tried removing the whole for loop in the admin template, and admin rendered successfully, but attempting to save resulted in the previous error.
Now I'm stuck. Any help very much appreciated.
Edit:
Here's the tree from the base dir (Thinks - do I need an admin.py..?):
├── manage.py
└── oscarwinestore
├── __init__.py
├── __init__.pyc
├── settings.py
├── settings.py~
├── settings.pyc
├── urls.py
├── urls.py~
├── urls.pyc
├── wsgi.py
└── wsgi.pyc
my urls.py is
from django.conf.urls import include, url
from oscar.app import application
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n')),
# The Django admin is not officially supported; expect breakage.
# Nonetheless, it's often useful for debugging.
url(r'^admin/', include(admin.site.urls)),
url(r'', include(application.urls)),
]

You need to create the tables with syncdb and migrate, as per the docs:
$ python manage.py syncdb --noinput
$ python manage.py migrate
Have you done that?

Related

How to display images with Flask with Ubuntu and apache server on AWS EC2

I would like to display the image mouse.jpg on the webiste. The website is displayed but the image is not.
I deployed using this guide on DigitalOcean. It uses apache, wsgi and virtualenv.
I found this on stackoverflow but could not transfer the answer to my problem. It is about writing files and not displaying.
I also found this and that but they do not include a web server like apache or nginx.
On AWS I setup the security group and allowed access on port 80 and 8080.
This is my tree in my home directory on the ec2:
nextstep
├── index.html
├── nextstep.py
├── nextstep.wsgi
├── static
│   └── mouse.jpg
└── templates
├── nextstep.html
nextstep.py looks like
from flask import Flask, render_template
import os
PEOPLE_FOLDER = os.path.join('static')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = PEOPLE_FOLDER
#app.route('/')
def hello_world():
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'mouse.jpg')
return render_template('nextstep.html',user_image = full_filename)
if __name__ == '__main__':
app.run()
nextstep.wsgi looks like:
import sys
sys.path.insert(0, '/var/www/html/nextstep')
from nextstep import app as application
/etc/apache2/sites-available$ cat 000-default.conf looks like:
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias /test /var/www/html/flaskapp/flaskapp.wsgi
<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
WSGIDaemonProcess nextstep threads=5
WSGIScriptAlias /nextstep /var/www/html/nextstep/nextstep.wsgi
<Directory nextstep>
WSGIProcessGroup nextstep
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
On EC2 tree of /var/www/html is:
.
├── flaskapp -> /home/ubuntu/flaskapp
├── index.html
└── nextstep -> /home/ubuntu/nextstep
nextstep.html looks like:
<html>
<body>
Hello World from nextstep.html
{{ user_image }}
next step 2
<img src="{{ user_image }}" alt="User Image">
<img src="/var/www/html/nextstep/static/mouse.jpg">
<img src="~/nextstep/static/mouse.jpg">
<img src="/home/nextstep/static/mouse.jpg">
<img src="home/nextstep/static/mouse.jpg">
<img src="static/mouse.jpg">
<img src="/static/mouse.jpg">
<img src="mouse.jpg">
<img src="/mouse.jpg">
</body>
</html>
I found the solution here: Setting up static folder path in Flask
In nextstep.py it is:
app = Flask(__name__, static_url_path="", static_folder="static")
In nextstep.html it is:
<img src="mouse.jpg">

Read JSON data from the YAML file

I have a .gitlab-ci.yml the file that I use to install a few plugins (craftcms/aws-s3, craftcms/redactor, etc) in the publishing stage. The file is provided below (partly):
# run the staging deploy, commands may be different baesed on the project
deploy-staging:
stage: publish
variables:
DOCKER_HOST: 127.0.0.1:2375
# ...............
# ...............
# TODO: temporary fix to the docker/composer issue
- docker-compose -p "ci-$CI_PROJECT_ID" --project-directory $CI_PROJECT_DIR -f build/docker-compose.staging.yml exec -T craft composer --working-dir=/data/craft require craftcms/aws-s3
- docker-compose -p "ci-$CI_PROJECT_ID" --project-directory $CI_PROJECT_DIR -f build/docker-compose.staging.yml exec -T craft composer --working-dir=/data/craft require craftcms/redactor
I have a JSON file that has the data for the plugins. The file is .butler.json. provided below,
{
"customer_number": "007",
"project_number": "999",
"site_name": "Welance",
"local_url": "localhost",
"db_driver": "mysql",
"composer_require": [
"craftcms/redactor",
"craftcms/aws-s3",
"nystudio107/craft-typogrify:1.1.17"
],
"local_plugins": [
"welance/zeltinger",
"ansmann/ansport"
]
}
How do I take the plugin names from the "composer_require" and the "local_plugins" inside the .butler.json file and create a for loop in the .gitlab-ci.yml file to install the plugins?
You can't create a loop in .gitlab-ci.yml since YAML is not a programming language. It only describes data. You could use a tool like jq to query for your values (cat .butler.json | jq '.composer_require') inside a script, but you cannot set variables from there (there is a feature request for it).
You could use a templating engine like Jinja (which is often used with YAML, e.g. by Ansible and SaltStack) to generate your .gitlab-ci.yml from a template. There exists a command line tool j2cli which takes variables as JSON input, you could use it like this:
j2 gitlab-ci.yml.j2 .butler.json > .gitlab-ci.yml
You could then use Jinja expression to loop over your data and create corresponding YAML in gitlab-ci.yml.j2:
{% for item in composer_require %}
# build your YAML
{% endfor %}
Drawback is that you need the processed .gitlab-ci.yml checked in to your repository. This can be done via pre-commit-hook (before each commit, regenerate the .gitlab-ci.yml file and if it changed, commit it along with other changes).

Salt: Using salt state in jinja if-else state

I'm trying to deploy a django project with saltstack.
I wrote a sls file and It installs packages and run some commands.
It installs django, nginx, etc and I want to run manage.py collectstatic for nginx.
but when I re-apply this formula, It returns an error that /static directory is already exists.
so I modified the sls file
collect_static_files:
{% if not salt['file.exists'][BASEDIR,'myproject/static']|join('') %}
cmd.run:
- name: '~~~ collectstatic;'
- cwd: /path/to/venv/bin
{% else %}
cmd.run:
- name: echo "Static directory exists."
{% endif %}
but when I run salt '*' state.apply myformula,
It says:
minion:
Data failed to compile:
----------
Rendering SLS 'base:myproj' failed: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'file.exists'
How can I solve this problem? Thank you.
I was a fool...
{% if not salt['file.directory_exists'](BASEDIR + 'myproject/static') %}
worked well.
The problem was I used the state module not execution module of salt.
Now I understand that state module describes "state" and execution modules act like a function.

node-forever json config support all options?

I tried to use json config to run forever, but some config seems not work. I wonder whether my code is wrong, or it only supports --xxx commands like --minUptime, except -xxx commands like -m.
.
├── forever
│ └── proConfig.json
└── test_debug.js
// config.json
{
"append": true,
"watch": true,
"script": "test_debug.js",
"minUptime": "100ms",
"spinSleepTime": "10000ms",
// -------------------------
"MAX": 10,
"LOGFILE": "forever.log",
"OUTFILE": "out.log",
"ERRFILE": "err.log"
}
Command:
forever start forever/proConfig.json
Firstly, you should check the command line usage. It should be below command:
forever start forever/proConfig.json
Secondly, forever does not support minUptime, spinSleepTime, .... in the configuration file. Please try to add it to the command:
forever start --minUptime 1000 --spinSleepTime 1000 forever/proConfig.json

Deploying Docpad to Modulus in Production

I am wanting to know how to go about deploying my docpad project to modulus.
Assuming I need to be running in production mode to do so. I noticed for the static deployment on docpad you just upload the contents of the out directory. If we are using a node server do we upload the entire project direcory. Which I did try but I don't think my docpad.coffee settings were correct. You can see below my attempt at this.
docpad.coffee
# ----------------
# Server Configuration
# Server Express
# ----------------
# The express.js instance that we want DocPad to use
# If not set, we will create our own
serverExpress: default
# ----------------
# Port
# ----------------
# Use to change the port that DocPad listens to
# By default we will detect the appropriate port number for our environment
# if no environment port number is detected we will use 9778 as the port number
# Checked environment variables are:
# - PORT - Heroku, Nodejitsu, Custom
# - VCAP_APP_PORT - AppFog
# - VMC_APP_PORT - CloudFoundry
port: - PORT
The First step according to the modulus site is to Use the environment variable PORT. app.listen(process.env.PORT) I assumed that would meant adding the - PORT to the docpad.coffee file.
As well I am not even sure how to have the site run in production when uploaded, remember I am just uploading the entire directory. Do I run a command from the Modulus server in terminal once the project is deployed?
Modulus also asks for the following in my packages.json file. I had most of them already except for the "main": "path/to/custom_main.js" which I assumed was the docpad.coffee file, so I linked to that.
Package.json
{
"name": "zurb-foundation.docpad",
"version": "0.4.0",
"description": "Zurb Foundation skeleton for DocPad. Simple and flexible HTML, CSS, and Javascript for popular user interface components and interactions.",
"homepage": "https://github.com/axyz/zurb-foundation.docpad",
"keywords": [
"docpad-skeleton",
"docpad",
"website",
"foundation",
"zurb foundation"
],
"author": "Andrea Moretti <axyzxp#gmail.com>",
"maintainers": [
"Andrea Moretti <axyzxp#gmail.com>"
],
"contributors": [
"Andrea Moretti <axyzxp#gmail.com>"
],
"bugs": {
"url": "https://github.com/axyz/zurb-foundation.docpad/issues"
},
"repository": {
"type": "git",
"url": "http://github.com/axyz/zurb-foundation.docpad.git"
},
"engines": {
"node": "0.10",
"npm": "1.3"
},
"main": "docpad.coffee",
"dependencies": {
"docpad": "~6.54.1",
"docpad-plugin-eco": "~2.0.2",
"docpad-plugin-livereload": "~2.5.3",
"docpad-plugin-coffeescript": "~2.2.2",
"express" : "2.5.x",
"ejs" : "0.8.x",
"docpad-plugin-nodesass": "~2.1.1"
},
"main": "node_modules/docpad/bin/docpad-server",
"scripts": {
"start": "node_modules/docpad/bin/docpad-server"
},
"devDependencies": {}
}
When I Deployed the site it did not work at all, I mean I had a link but the site didnt work. Any suggestions on what to do when deploying a docpad site to Modulus? I used the skeleton Foundation with Sass as well after installing docpad, which did work locally.
Ok still trying to get this thing working, when I run the site now it works locally, and when I deploy it I get a link to a modulus subdomian that doesnt work. I went and checked the logs on the modulus site and this is what I get
Modulus Logs
...
docpad-plugin-coffeescript#2.2.2 node_modules/docpad-plugin-coffeescript
└── coffee-script#1.6.3
docpad-plugin-eco#2.0.2 node_modules/docpad-plugin-eco
└── eco#1.1.0-rc-3 (strscan#1.0.1, coffee-script#1.6.3)
express#2.5.11 node_modules/express
├── qs#0.4.2
├── mime#1.2.4
├── mkdirp#0.3.0
└── connect#1.9.2 (formidable#1.0.14)
docpad-plugin-livereload#2.5.3 node_modules/docpad-plugin-livereload
├── extendr#2.1.0 (typechecker#2.0.8)
├── primus#1.4.4 (extendable#0.0.6, load#1.0.0)
└── ws#0.4.31 (tinycolor#0.0.1, options#0.0.5, commander#0.6.1, nan#0.3.2)
docpad#6.54.4 node_modules/docpad
├── lazy-require#1.0.0
├── eachr#2.0.2
├── extendr#2.1.0
├── extract-opts#2.2.0
├── caterpillar-filter#2.0.3
├── envfile#1.0.0
├── getmac#1.0.6
├── commander#2.0.0
├── ambi#2.1.6
├── typechecker#2.0.8
├── taskgroup#3.3.0
├── mime#1.2.11
├── query-engine#1.5.3
├── bal-util#2.3.2
├── safefs#3.0.3 (taskgroup#3.2.4)
├── semver#2.2.1
├── safeps#2.2.8 (taskgroup#3.2.4)
├── caterpillar-human#2.1.1 (ansistyles#0.1.1, ansicolors#0.2.1)
├── progressbar#1.0.3 (progress#1.1.2)
├── event-emitter-grouped#2.3.1 (taskgroup#3.2.4)
├── watchr#2.4.4 (taskgroup#3.2.4)
├── promptly#0.2.0 (read#1.0.5)
├── backbone#1.1.0 (underscore#1.5.2)
├── jschardet#1.1.0
├── superagent#0.15.7 (methods#0.0.1, cookiejar#1.3.0, debug#0.7.3, qs#0.6.5, emitter-component#1.0.0, reduce-component#1.0.1, mime#1.2.5, formidable#1.0.14)
├── lodash#2.2.1
├── cson#1.4.5 (requirefresh#1.1.2, coffee-script#1.6.3, js2coffee#0.2.3)
├── caterpillar#2.0.6 (readable-stream#1.1.9)
├── encoding#0.1.7 (iconv-lite#0.2.11)
├── yamljs#0.1.4 (glob#3.1.21, argparse#0.1.15)
└── express#3.4.4 (methods#0.1.0, range-parser#0.0.4, cookie-signature#1.0.1, fresh#0.2.0, debug#0.7.3, buffer-crc32#0.2.1, cookie#0.1.0, send#0.1.4, mkdirp#0.3.5, commander#1.3.2, connect#2.11.0)
docpad-plugin-nodesass#2.1.1 node_modules/docpad-plugin-nodesass
├── node-neat#1.0.0
├── node-bourbon#1.0.0
├── taskgroup#3.2.4 (ambi#2.1.6)
└── node-sass#0.7.0 (node-watch#0.3.4, colors#0.6.0-1, mkdirp#0.3.5, optimist#0.6.0, mocha#1.13.0)
INFO: Main file specified in package.json: node_modules/docpad/bin/docpad-server
INFO: Starting application.
[32minfo:[39m Welcome to DocPad v6.54.4 (global installation: /mnt/data/2/node_modules/docpad)
[32minfo:[39m Contribute: http://docpad.org/docs/contribute
[32minfo:[39m Plugins:
[32minfo:[39m Environment: production
[32minfo:[39m DocPad listening to http://localhost:8080/ on directory /mnt/data/2/node_modules/docpad/bin/out
[32minfo:[39m Generating...
[33mnotice:[39m DocPad is currently running without any plugins installed. You probably want to install some: http://docpad.org/plugins
Error: Cannot generate website as the src dir was not found
at /mnt/data/2/node_modules/docpad/out/lib/docpad.js:3102:21
at /mnt/data/2/node_modules/docpad/node_modules/safefs/out/lib/safefs.js:185:16
at Object.cb [as oncomplete] (fs.js:168:19)
[2013-11-03T17:19:32.095Z] Application initialized with pid 69363
The entire log file can be seen here https://gist.github.com/kitsondevelopment/7292623
It says it cant find the src directory however the source directory is there according to this screen shot so I do not understand.
Update
I just noticed that the error it is referring to the src directory in the node_modules/docpad directory, my app created with docpad run did not have a src directory in node_modules/docpad. WHy might this be?
Update:
It appears that modulus does something odd when just using package.json to set docpad as the entry point. My guess is that it doesn't set the current directory correctly.
I got it working by creating an app.js that just hands off execution to docpad (similar to the deployment instructions for AppFog:
module.exports = require(__dirname+'/node_modules/docpad/out/bin/docpad-server');
Then in package.json, I pointed main at app.js
"engines" : {
"node": "0.10",
"npm": "1.2"
},
"dependencies": {
... the dependencies from the skeleton ...
},
"main": "app.js",
===
You shouldn't set serverExpress at all. Remove that set of lines. You also shouldn't set port. The port setting in docpad.coffee is only if you want to hard code a specific port (which you don't). docpad will automatically look at all of the environment variables typically used by node hosts (including the one that Modulus is setting) and will figure out the correct port without you doing anything special.