Refresh to display a web page using Python

Python Program Example 1.

If you’re going to need a refresh on the same tab, you’ll need selenium webdriver. After installing selenium using pip, you can use the following code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
driver.get("http://www.python.org")
while True:
   time.sleep(10)
   driver.refresh()

If you are browsing a static page, you can pass a parameter in it and run, for example passing "pycon" to search as below script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Python Program Example 2.

from link http://geekinessthecoolway.blogspot.hk/2013/05/tired-of-refreshingscript-for-automatic.html

A script will automatically refresh the page after every few seconds,so that my keyboard’s F5 button is spared. But still there is redundancy, one has to keep looking at the same thing again and again to check if any change has happened. So,I added few more lines to the script. Now whenever the result will be declared (or there will be any new notification) a song will start playing automatically.

Here is the resultant script:

import urllib
import time
import os
import pygame
uri = “http://upresults.nic.in”  #url where result will be declared
source = urllib.urlopen(uri).read()
nw_source=source
cntr=0
flg=True
while nw_source==source:
if flg:
time.sleep(5)  #refresh every 5 seconds
try:
nw_source = urllib.urlopen(uri).read()
except IOError:
print “Error in reading url”
flg=False
continue
cntr+=1
print cntr,” times refreshed”

flg=True
pygame.init()
pygame.mixer.music.load(“kar_chale _hum_vida.mp3″) #pass the path to the music file
pygame.mixer.music.play()
while True:
pass

Using Webdriver under Selenium:

WebDriver是主流Web应用自动化测试框架,具有清晰面向对象 API,能以最佳的方式与浏览器进行交互。

支持的浏览器:

  • Mozilla Firefox
  • Google Chrome
  • Microsoft Internet Explorer
  • Opera
  • Safari
  • Apple iPhone
  • Android browsers

Selenium WebDriver 又称为 Selenium2。

Selenium 1 + WebDriver = Selenium 2

标准的安装步骤

  1. 选择Python的版本。Python主流的有两个大的版本,2.7和3.5(请注意,从Python的3.5版本开始,不再支持Windows XP操作系统,Windows XP用户请安装3.4版本)。我们的例子将会选用面向未来的3.5版本。
  2. 在Windows安装Selenium2.0,有两种途径。使用pip命令行或者源码安装。以下两种方法,使用任何一个均可。推荐pip的方式。
    1. 方法一:pip命令行安装,运行 | cmd,打开命令行,-U其实就是--upgrade,升级安装。
      pip install -U selenium
    2. 方法二:源码解压安装,前往https://pypi.python.org/pypi/selenium下载最新版的PyPI版本的Selenium,解压后执行
      python setup.py install

Source Information: http://www.jianshu.com/p/3ce95cbc65be

Selenium 3.0.1 出现的问题以及解决

3.0.1 更新以后,需要做两个操作:

  1. Geckodriver executable needs to be in PATH。Geckodirver的下载地址:https://github.com/mozilla/geckodriver/releases
    报错内容:

    WebDriverException:Message:'geckodriver'executable needs to be in Path

    geckodriver是一原生态的第三方浏览器,对于selenium3.x版本都会使用geckodriver来驱动firefox,所以需要下载geckodriver.exe。放置在Path 环境变量可以访问到的地方。例如 C:\python34

  2. 需要将火狐的安装路径放到path,然后重启(必须重启电脑)
    报错内容:

    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

    参考地址:http://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path/40208762

Reference Info/Link for Python's Django Development

A great document for more complex installations—those that host multiple Django Web sites (projects) using only one instance of Apache—can be found at –>
http://forum.webfaction.com/ -> search for ‘Django’

You can find out more about some of the possible Web server arrangements at –>
http://code.djangoproject.com/wiki/ServerArrangements.

More about Django and database installation at –>
http://docs.djangoproject.com/en/dev/topics/install/#database-installation.

You can download Django-nonrel from –> http://www.allbuttonspressed.com/projects/django-nonrel
followed by one of the adapters, –> https://github.com/FlaPer87/django-mongodb-engine (Django with MongoDB), or –> http://www.allbuttonspressed.com/projects/djangoappengine (Django on Google App Engine’s datastore).

Because Django-nonrel is (at the time of this writing) a fork of Django, you can just install it instead of a stock
Django package. The main reason for doing that is because you want to
use the same version for both development and production. As stated at
–> http://www.allbuttonspressed.com/projects/django-nonrel, “the modifications to Django are minimal (maybe less than 100 lines).” Django-nonrel is available as a Zip file,

You can find all of the runserver options at –>
http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-runserver.

To learn more about templates and tags, check out the official documents page at –> http://docs.djangoproject.com/en/dev/ref/templates/api/
#basics.

To read more about using render_to_response(), check out these pages from the official documentation: –>
• http://docs.djangoproject.com/en/dev/intro/tutorial03/#ashortcut-render-to-response
• http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response

To find out when a QuerySet is evaluated, check out the official
documentation at –> http://docs.djangoproject.com/en/dev/ref/models/querysets/.

Explanations of CSRF are beyond the scope of this book, but you can read more about them here: –>
• http://docs.djangoproject.com/en/dev/intro/tutorial04/#writea-simple-form
• http://docs.djangoproject.com/en/dev/ref/contrib/csrf/

To learn more about testing in Django, check out the documentation at –>
http://docs. djangoproject.com/en/dev/topics/testing.

You can read more about how OAuthworks at the following locations: –>
http://hueniverse.com/oauth
http://oauth.net
http://en.wikipedia.org/wiki/Oauth

more details on this at –>
http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#serving-the-admin-files

Twitter maintains a list of the most popular ones at –>
http://dev.twitter.com/pages/libraries#python.

To find out more about Django’s authentication system, check the documentation at –>
https://docs.djangoproject.com/en/dev/topics/auth/.

How to setup python 2.7 and 3.5 under same computer

Introduction

Conda treats Python the same as any other package, so it’s very easy to manage and update multiple python installations under one computer. For instance, if you want to install different version of python in the same window env but without wipe out the current version of python, you can create and activate a new virtual environment with specific name and install your required version of Python as follows instruction.

Install Python 3.5 under Python 2.7

1. install new python with command:       $ conda create -n py35 python=3.5 anaconda
2. activate the new setup python with command:    $ activate py35
3. deactivate with command: $ deactivate

4. Remove the created env: $ conda remove –name py35 –all

Install Python 2.7 under Python 3.5

1. install new python with command:       $ conda create -n py27 python=2.7 anaconda
2. activate the new setup python with command:    $ activate py27
3. deactivate with command: $ deactivate

Screen Dump of Deinstallation and Installation as below:

C:\User\goldmanau>conda create -n py27 python=2.7 anaconda
Fetching package metadata: ….
Solving package specifications: ………………………….
Package plan for installation in environment C:\Users\goldmanau\AppData\Local\Co
ntinuum\Anaconda3\envs\py27:The following packages will be downloaded:

package                    |            build
—————————|—————–
pandas-0.18.1              |      np111py27_0         7.0 MB  defaults
pickleshare-0.7.2          |           py27_0           9 KB  defaults
pytables-3.2.2             |      np111py27_4         1.5 MB  defaults
scikit-learn-0.17.1        |      np111py27_1         3.5 MB  defaults
sphinx-1.4.1               |           py27_0         1.3 MB  defaults
tornado-4.3                |           py27_1         543 KB  defaults
anaconda-navigator-1.2.1   |           py27_0         1.3 MB  defaults
bokeh-0.11.1               |           py27_0         3.1 MB  defaults
flask-cors-2.1.2           |           py27_0          15 KB  defaults
ipython-4.2.0              |           py27_0         981 KB  defaults
jupyter_client-4.3.0       |           py27_0         138 KB  defaults
nbformat-4.0.1             |           py27_0         155 KB  defaults
odo-0.5.0                  |           py27_0         216 KB  defaults
pyopenssl-0.16.0           |           py27_0          66 KB  defaults
scikit-image-0.12.3        |      np111py27_1        17.6 MB  defaults
sockjs-tornado-1.0.3       |           py27_0          32 KB  defaults
statsmodels-0.6.1          |      np111py27_1         4.6 MB  defaults
dask-0.10.0                |           py27_0         525 KB  defaults
ipykernel-4.3.1            |           py27_0         117 KB  defaults
nbconvert-4.2.0            |           py27_0         354 KB  defaults
jupyter_console-4.1.1      |           py27_0          65 KB  defaults
notebook-4.2.1             |           py27_0         5.2 MB  defaults
qtconsole-4.2.1            |           py27_0         203 KB  defaults
ipywidgets-4.1.1           |           py27_0          98 KB  defaults
nb_anacondacloud-1.1.0     |           py27_0          20 KB  defaults
nb_conda_kernels-1.0.3     |           py27_0          28 KB  defaults
nbpresent-3.0.2            |           py27_0         512 KB  defaults
spyder-2.3.9               |           py27_0         2.1 MB  defaults
jupyter-1.0.0              |           py27_3           3 KB  defaults
nb_conda-1.1.0             |           py27_0          25 KB  defaults
_nb_ext_conf-0.2.0         |           py27_0          912 B  defaults
anaconda-4.1.0             |      np111py27_0          16 KB  defaults
————————————————————
Total:        51.2 MB

The following NEW packages will be INSTALLED:

_nb_ext_conf:       0.2.0-py27_0       defaults
alabaster:          0.7.8-py27_0       defaults
anaconda:           4.1.0-np111py27_0  defaults
anaconda-client:    1.4.0-py27_0       defaults
anaconda-navigator: 1.2.1-py27_0       defaults
argcomplete:        1.0.0-py27_1       defaults
astropy:            1.2.1-np111py27_0  defaults
babel:              2.3.3-py27_0       defaults
backports:          1.0-py27_0         defaults
backports_abc:      0.4-py27_0         defaults
beautifulsoup4:     4.4.1-py27_0       defaults
bitarray:           0.8.1-py27_1       defaults
bokeh:              0.11.1-py27_0      defaults
boto:               2.40.0-py27_0      defaults
bottleneck:         1.0.0-np111py27_1  defaults
bzip2:              1.0.6-vc9_3        defaults [vc9]
cdecimal:           2.3-py27_2         defaults
cffi:               1.6.0-py27_0       defaults
chest:              0.2.3-py27_0       defaults
click:              6.6-py27_0         defaults
cloudpickle:        0.2.1-py27_0       defaults
clyent:             1.2.2-py27_0       defaults
colorama:           0.3.7-py27_0       defaults
comtypes:           1.1.2-py27_0       defaults
configobj:          5.0.6-py27_0       defaults
configparser:       3.5.0b2-py27_1     defaults
console_shortcut:   0.1.1-py27_1       defaults
contextlib2:        0.5.3-py27_0       defaults
cryptography:       1.4-py27_0         defaults
curl:               7.49.0-vc9_0       defaults [vc9]
cycler:             0.10.0-py27_0      defaults
cython:             0.24-py27_0        defaults
cytoolz:            0.8.0-py27_0       defaults
dask:               0.10.0-py27_0      defaults
datashape:          0.5.2-py27_0       defaults
decorator:          4.0.10-py27_0      defaults
dill:               0.2.5-py27_0       defaults
docutils:           0.12-py27_2        defaults
entrypoints:        0.2.2-py27_0       defaults
enum34:             1.1.6-py27_0       defaults
et_xmlfile:         1.0.1-py27_0       defaults
fastcache:          1.0.2-py27_1       defaults
flask:              0.11.1-py27_0      defaults
flask-cors:         2.1.2-py27_0       defaults
freetype:           2.5.5-vc9_1        defaults [vc9]
funcsigs:           1.0.2-py27_0       defaults
functools32:        3.2.3.2-py27_0     defaults
futures:            3.0.5-py27_0       defaults
get_terminal_size:  1.0.0-py27_0       defaults
gevent:             1.1.1-py27_0       defaults
greenlet:           0.4.10-py27_0      defaults
grin:               1.2.1-py27_3       defaults
h5py:               2.6.0-np111py27_0  defaults
hdf5:               1.8.15.1-vc9_4     defaults [vc9]
heapdict:           1.0.0-py27_1       defaults
idna:               2.1-py27_0         defaults
imagesize:          0.7.1-py27_0       defaults
ipaddress:          1.0.16-py27_0      defaults
ipykernel:          4.3.1-py27_0       defaults
ipython:            4.2.0-py27_0       defaults
ipython_genutils:   0.1.0-py27_0       defaults
ipywidgets:         4.1.1-py27_0       defaults
itsdangerous:       0.24-py27_0        defaults
jdcal:              1.2-py27_1         defaults
jedi:               0.9.0-py27_1       defaults
jinja2:             2.8-py27_1         defaults
jpeg:               8d-vc9_0           defaults [vc9]
jsonschema:         2.5.1-py27_0       defaults
jupyter:            1.0.0-py27_3       defaults
jupyter_client:     4.3.0-py27_0       defaults
jupyter_console:    4.1.1-py27_0       defaults
jupyter_core:       4.1.0-py27_0       defaults
libpng:             1.6.22-vc9_0       defaults [vc9]
libtiff:            4.0.6-vc9_2        defaults [vc9]
llvmlite:           0.11.0-py27_0      defaults
locket:             0.2.0-py27_1       defaults
lxml:               3.6.0-py27_0       defaults
markupsafe:         0.23-py27_2        defaults
matplotlib:         1.5.1-np111py27_0  defaults
menuinst:           1.4.1-py27_0       defaults
mistune:            0.7.2-py27_0       defaults
mkl:                11.3.3-1           defaults
mkl-service:        1.1.2-py27_2       defaults
mpmath:             0.19-py27_1        defaults
multipledispatch:   0.4.8-py27_0       defaults
nb_anacondacloud:   1.1.0-py27_0       defaults
nb_conda:           1.1.0-py27_0       defaults
nb_conda_kernels:   1.0.3-py27_0       defaults
nbconvert:          4.2.0-py27_0       defaults
nbformat:           4.0.1-py27_0       defaults
nbpresent:          3.0.2-py27_0       defaults
networkx:           1.11-py27_0        defaults
nltk:               3.2.1-py27_0       defaults
nose:               1.3.7-py27_1       defaults
notebook:           4.2.1-py27_0       defaults
numba:              0.26.0-np111py27_0 defaults
numexpr:            2.6.0-np111py27_0  defaults
numpy:              1.11.0-py27_2      defaults
odo:                0.5.0-py27_0       defaults
openpyxl:           2.3.2-py27_0       defaults
openssl:            1.0.2h-vc9_0       defaults [vc9]
pandas:             0.18.1-np111py27_0 defaults
partd:              0.3.4-py27_0       defaults
path.py:            8.2.1-py27_0       defaults
pathlib2:           2.1.0-py27_0       defaults
patsy:              0.4.1-py27_0       defaults
pep8:               1.7.0-py27_0       defaults
pickleshare:        0.7.2-py27_0       defaults
pillow:             3.2.0-py27_1       defaults
pip:                8.1.2-py27_0       defaults
ply:                3.8-py27_0         defaults
psutil:             4.3.0-py27_0       defaults
py:                 1.4.31-py27_0      defaults
pyasn1:             0.1.9-py27_0       defaults
pycosat:            0.6.1-py27_1       defaults
pycparser:          2.14-py27_1        defaults
pycrypto:           2.6.1-py27_4       defaults
pycurl:             7.43.0-py27_0      defaults
pyflakes:           1.2.3-py27_0       defaults
pygments:           2.1.3-py27_0       defaults
pyopenssl:          0.16.0-py27_0      defaults
pyparsing:          2.1.4-py27_0       defaults
pyqt:               4.11.4-py27_6      defaults
pyreadline:         2.1-py27_0         defaults
pytables:           3.2.2-np111py27_4  defaults
pytest:             2.9.2-py27_0       defaults
python:             2.7.11-5           defaults
python-dateutil:    2.5.3-py27_0       defaults
pytz:               2016.4-py27_0      defaults
pywin32:            220-py27_1         defaults
pyyaml:             3.11-py27_4        defaults
pyzmq:              15.2.0-py27_0      defaults
qt:                 4.8.7-vc9_8        defaults [vc9]
qtconsole:          4.2.1-py27_0       defaults
qtpy:               1.0.2-py27_0       defaults
requests:           2.10.0-py27_0      defaults
rope:               0.9.4-py27_1       defaults
ruamel_yaml:        0.11.7-py27_0      defaults
scikit-image:       0.12.3-np111py27_1 defaults
scikit-learn:       0.17.1-np111py27_1 defaults
scipy:              0.17.1-np111py27_1 defaults
setuptools:         23.0.0-py27_0      defaults
simplegeneric:      0.8.1-py27_1       defaults
singledispatch:     3.4.0.3-py27_0     defaults
sip:                4.16.9-py27_2      defaults
six:                1.10.0-py27_0      defaults
snowballstemmer:    1.2.1-py27_0       defaults
sockjs-tornado:     1.0.3-py27_0       defaults
sphinx:             1.4.1-py27_0       defaults
sphinx_rtd_theme:   0.1.9-py27_0       defaults
spyder:             2.3.9-py27_0       defaults
sqlalchemy:         1.0.13-py27_0      defaults
ssl_match_hostname: 3.4.0.2-py27_1     defaults
statsmodels:        0.6.1-np111py27_1  defaults
sympy:              1.0-py27_0         defaults
tk:                 8.5.18-vc9_0       defaults [vc9]
toolz:              0.8.0-py27_0       defaults
tornado:            4.3-py27_1         defaults
traitlets:          4.2.1-py27_0       defaults
unicodecsv:         0.14.1-py27_0      defaults
vs2008_runtime:     9.00.30729.1-2     defaults
werkzeug:           0.11.10-py27_0     defaults
wheel:              0.29.0-py27_0      defaults
xlrd:               1.0.0-py27_0       defaults
xlsxwriter:         0.9.2-py27_0       defaults
xlwings:            0.7.2-py27_0       defaults
xlwt:               1.1.2-py27_0       defaults
zlib:               1.2.8-vc9_3        defaults [vc9]

Proceed ([y]/n)? y

Fetching packages …
pandas-0.18.1- 100% |###############################| Time: 0:01:17  94.50 kB/s
pickleshare-0. 100% |###############################| Time: 0:00:00   1.48 MB/s
pytables-3.2.2 100% |###############################| Time: 0:00:15 101.08 kB/s
scikit-learn-0 100% |###############################| Time: 0:00:35 103.10 kB/s
sphinx-1.4.1-p 100% |###############################| Time: 0:00:15  88.76 kB/s
tornado-4.3-py 100% |###############################| Time: 0:00:04 112.43 kB/s
anaconda-navig 100% |###############################| Time: 0:00:13 103.67 kB/s
bokeh-0.11.1-p 100% |###############################| Time: 0:00:38  83.75 kB/s
flask-cors-2.1 100% |###############################| Time: 0:00:00  33.06 kB/s
ipython-4.2.0- 100% |###############################| Time: 0:00:09 106.52 kB/s
jupyter_client 100% |###############################| Time: 0:00:02  61.09 kB/s
nbformat-4.0.1 100% |###############################| Time: 0:00:01  89.78 kB/s
odo-0.5.0-py27 100% |###############################| Time: 0:00:02  76.72 kB/s
pyopenssl-0.16 100% |###############################| Time: 0:00:01  55.44 kB/s
scikit-image-0 100% |###############################| Time: 0:03:35  85.86 kB/s
sockjs-tornado 100% |###############################| Time: 0:00:00  66.93 kB/s
statsmodels-0. 100% |###############################| Time: 0:00:51  92.79 kB/s
dask-0.10.0-py 100% |###############################| Time: 0:00:06  84.35 kB/s
ipykernel-4.3. 100% |###############################| Time: 0:00:01  66.01 kB/s
nbconvert-4.2. 100% |###############################| Time: 0:00:05  68.28 kB/s
jupyter_consol 100% |###############################| Time: 0:00:01  45.59 kB/s
notebook-4.2.1 100% |###############################| Time: 0:00:53 100.82 kB/s
qtconsole-4.2. 100% |###############################| Time: 0:00:02  72.55 kB/s
ipywidgets-4.1 100% |###############################| Time: 0:00:01  86.14 kB/s
nb_anacondaclo 100% |###############################| Time: 0:00:00  37.88 kB/s
nb_conda_kerne 100% |###############################| Time: 0:00:00  67.10 kB/s
nbpresent-3.0. 100% |###############################| Time: 0:00:04 112.47 kB/s
spyder-2.3.9-p 100% |###############################| Time: 0:00:26  81.65 kB/s
jupyter-1.0.0- 100% |###############################| Time: 0:00:00   0.00  B/s
nb_conda-1.1.0 100% |###############################| Time: 0:00:00  61.82 kB/s
_nb_ext_conf-0 100% |###############################| Time: 0:00:00   0.00  B/s
anaconda-4.1.0 100% |###############################| Time: 0:00:00  40.15 kB/s
Extracting packages …
[      COMPLETE      ]|##################################################| 100%
Linking packages …
1 file(s) copied.####################                            |  44%
[      COMPLETE      ]|##################################################| 100%
#
# To activate this environment, use:
# > activate py27

C:\Users\goldmanau>conda remove  –name py27 –all
Fetching package metadata: ….Package plan for package removal in environment C:\Users\goldmanau\AppData\Local
\Continuum\Anaconda3\envs\py27:

The following packages will be REMOVED:

menuinst: 1.4.1-py27_0 defaults

Proceed ([y]/n)? y

 

Reference Doc Link

http://conda.pydata.org/docs/py2or3.html

Installation of an Open Source Prometeo-ERP System

Introduction

Although Prometeo-ERP System was a phase-out project for any further development, its follow-up project was Django-ERP. However, Django-ERP is still under development, Its function is not ready, and most features are not ready for public use at this moment. Then, I step back to continue to test Prometeo-ERP System. Prometeo-ERP has already provide many useful features, its public release free version had the following features:

  • Authentication & row-level permission system
  • Notification system
  • Custom widgets & dashboards
  • Taxonomy system
  • File browsing
  • Event calendar
  • User tasks & timesheets
  • CRM (Customer Relationship Management)
  • Products management
  • Stock management
  • Human resources management
  • Sales management
  • Project management
  • Knowledge management
  • DMS (Document Management System)

I installed the Prometeo-ERP system to my Raspberry Pi machine, i.e. free OS, free program tools, free application tools, … Great. It is still worth to study it, and I will show the installation installation in the following

Installation Steps:

1. Checkout sources from the GIT repository:

https://code.google.com/archive/p/prometeo-erp/

2. Follow the instructions in the README file as reference.

2.1 PREREQUISITES

Make sure you have the following prerequisites installed:

* python >= 2.6 (or 2.7 the public one)

$ pip install python==2.7

* pytz >= 2011h (required)
$ pip install pytz==2011h

* python-markdown >= 2.0 (required)
$ pip install markdown

* xhtml2pdf >= 0.0.3 (required)
$ pip install xhtml2pdf==0.0.3

* icalendar >= 2.2 (required)
$ pip install icalendar==2.2

* django >= 1.3.1 (required)
$ pip install django==1.3.1

* south >= 0.7.3 (optional)
$ pip install south

2.2 INSTALLATION
1. Rename the download folder to “prometeo” (It is necessary).

2. cp settings/base.py.tmpl settings/base.py, and edit several statement as below:

$ vi settings/base.py
….

ADMINS = (
# (‘Goldman’, ‘goldman.au168@gmail.com’),
)

MANAGERS = ADMINS

DATABASES = {
default': {
‘ENGINE': ‘django.db.backends.sqlite3′, # Add ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ‘sqlite3′ or ‘oracle’.
‘NAME': ‘erp.db’, # Or path to database file if using sqlite3.
‘USER': ”, # Not used with sqlite3.
‘PASSWORD': ”, # Not used with sqlite3.
‘HOST': ”, # Set to empty string for localhost. Not used with sqlite3.
‘PORT': ”, # Set to empty string for default. Not used with sqlite3.
}

}

LANGUAGE_CODE = ‘en-us’

# List of installed applications.
INSTALLED_APPS = (
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.sites’,
‘django.contrib.messages’,
‘django.contrib.admin’,
‘django.contrib.admindocs’,
‘django.contrib.comments’,
‘django.contrib.markup’,
‘django.contrib.redirects’,
‘django.contrib.staticfiles’,

#’south’,

‘prometeo.core’,
‘prometeo.core.filebrowser’,
‘prometeo.core.widgets’,
‘prometeo.core.menus’,
‘prometeo.core.taxonomy’,
‘prometeo.core.auth’,
‘prometeo.core.registration’,
‘prometeo.core.notifications’,
‘prometeo.core.calendar’,

‘prometeo.todo’,
‘prometeo.addressing’,
‘prometeo.partners’,
‘prometeo.documents’,
‘prometeo.products’,
‘prometeo.stock’,
‘prometeo.hr’,
‘prometeo.sales’,
‘prometeo.projects’,
‘prometeo.knowledge’,
)

3. It’s time to create the DB schema

$ python manage.py syncdb

4. Start the server:

$ python manage.py runserver

5. Test the application via link http://localhost:8000 as screen dump below:

prometeo-system

 

Setup Raspberry pi Car camera with Android phone WiFi

Introduction

Raspberry Pi can be widely used for Car computer with many features, such as plays DVDs, GPS, displays TV, Bluetooth (phone calls + music), MP3/MPEG4 player, CD/radio, car camera, reversing camera (comes on automatically when I put the car in reverse gear), etc. This week, I test raspberry pi to connect to android phone’s wireless hotpot, and setup camera and display feature as below. It is interesting.

Connect Raspberry Pi to an Android phone’s camera

Step 1. Install Pi Camera Application in Android Phone, which you can find many from Google Play Store as below screen:

ipcam-app

Step 2. Turn on the Android Phone’s Camera Application and active its web server feature, then it will display an ip address for your external browse connection.

Step 3. Turn on the Android Phone’s wireless sharing hotpot feature, then the ip address will be refresh to its own phone address for your external connection as below:

Step 4. Connect the Raspberry Pi to Android Phone Open the browser in your Raspberry Pi, and type in the ip address, then it will display the camera as below:

ipcam-display

Screen Dump of Another Scene of Camera and Display as below two pictures:

cam-phone-display

cam-pi-diaplay

 

Display Raspberry Pi Camera to Android phone

Step 1. Install Raspberry Pi Camera and vlc software as describe in my previous post “Installation of Raspberry Pi Camera

Step 2. Start the video streaming function with command:

$ raspivid -w 640 -h 480 -o – -t 9999999 |cvlc -vvv stream:///dev/stdin –sout ‘#standard{access=http,mux=ts,dst=:8554}’ :demux=h264

Step 3. We can connect via browser with link http://ip-address:8554/.

Bonus:

We can also use VNC to connect Raspberry Pi from Android Phone, provided that you start the VNC server function (as described in my previous post “Installation Raspberry Pi” Step 6, and then install VNC app from Google Play Store, and start VNC connection in Andriod Phone as below:

VNC-1                   VNC-2

 

 

 

Setup Django WorkFlow Application

Introduction

Recently, I studied how to setup a work flow program using python django. Believe me, Python Diango can provide you a high quality work flow web application. Let’s say I would like a simple workflow application as below diagram. I will show you how to setup the application as below instruction, and I will also show you the screen dump examples of running the application.

django-workflow0

Step 1. Prerequisition

This Work Flow Program requires Python 3.3 or greater, and django 1.6 or 1.7. I recommend you to setup under virtual environment. Setup the following python plug-in by running the following command:

$ pip3 install Django==1.7.1
$ pip3 install WebOb==1.4
$ pip3 install WebTest==2.0.16
$ pip3 install amqp==1.4.6
$ pip3 install anyjson==0.3.3
$ pip3 install beautifulsoup4==4.3.2
$ pip3 install billiard==3.3.0.18
$ pip3 install celery==3.1.16
$ pip3 install django-fsm==2.2.0
$ pip3 install django-viewflow==0.7.0
$ pip3 install django-webtest==1.7.7
$ pip3 install kombu==3.0.23
$ pip3 install mock==1.0.1
$ pip3 install pytz==2014.9
$ pip3 install singledispatch==3.4.0.3
$ pip3 install six==1.8.0
$ pip3 install waitress==0.8.9

Step 2. Create a standard django project and application

Run the following command:

$ django-admin.py startproject demo .

$ ./manage.py startapp helloworld

$ mv helloworld/ demo/

Step 3. Edit or Create the following files

3.1 edit demo/settings.py

INSTALLED_APPS = (
    ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.messages’,
    ‘django.contrib.staticfiles’,
    ‘viewflow’,
    ‘demo.helloworld’
)

TEMPLATE_CONTEXT_PROCESSORS = (
    ‘django.contrib.auth.context_processors.auth’,
    ‘django.core.context_processors.request’,
)

3.2 edit demo/urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from viewflow import views as viewflow
from .helloworld.flows import HelloWorldFlow

urlpatterns = patterns(
    ”,
    url(r’^helloworld/’,
        include([
            HelloWorldFlow.instance.urls,
            url(‘^$’, viewflow.ProcessListView.as_view(), name=’index’),
            url(‘^tasks/$’, viewflow.TaskListView.as_view(), name=’tasks’),
            url(‘^queue/$’, viewflow.QueueListView.as_view(), name=’queue’),
            url(‘^details/(?P<process_pk>\d+)/$’,
                viewflow.ProcessDetailView.as_view(), name=’details’)],
                namespace=HelloWorldFlow.instance.namespace),
            {‘flow_cls': HelloWorldFlow}),
    #url(r’^flows/’, include(viewflow.urls)),
    url(r’^admin/’, include(admin.site.urls)),
    url(r’^accounts/login/$’, ‘django.contrib.auth.views.login’, name=’login’),
    url(r’^accounts/logout/$’, ‘django.contrib.auth.views.logout’, name=’logout’),
)

3.3 create demo/celery.py

import os
from celery import Celery

from django.conf import settings

os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘demo.settings’)

app = Celery(‘tests’)

app.config_from_object(‘django.conf:settings’)
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

3.4 create demo/helloworld/flows.py

from viewflow import flow
from viewflow.base import Flow, this
from viewflow.contrib import celery

from . import models, views, tasks

class HelloWorldFlow(Flow):
    process_cls = models.HelloWorldProcess

    start = flow.Start(views.CreateRequestView) \
        .Next(this.approve)

    approve = flow.View(views.ApproveRequestView) \
        .Next(this.is_approved)

    is_approved = flow.If(lambda p: p.approved) \
        .OnTrue(this.send)\
        .OnFalse(this.end)

    send = celery.Job(tasks.send) \
        .Next(this.end)

    end = flow.End()

3.5 edit demo/helloworld/models.py

from django.db import models
from viewflow.models import Process

class HelloWorldProcess(Process):
    text = models.CharField(max_length=250)
    approved = models.BooleanField(default=False)

3.6 edit demo/helloworld/tasks.py

from demo.celery import app as celery_app
from viewflow.flow import flow_job

@celery_app.task()
@flow_job()
def send(activation):
    print(activation.process.text)

3.7 edit demo/helloworld/views.py

from django.views import generic
from viewflow import views as flow_views

class CreateRequestView(flow_views.StartViewMixin,
                        generic.UpdateView):
    fields = [“text”]

    def get_object(self):
        return self.activation.process

class ApproveRequestView(flow_views.TaskViewMixin,
                         generic.UpdateView):
    fields = [“approved”]

    def get_object(self):
        return self.activation.process

Step 4. Start the Application Server

Run the following Command:

./manage.py createsuperuser –username=admin –email=admin@admin.com
( setup admin password )

./manage.py makemigrations

./manage.py migrate

Start the following celery in another virtual env

celery -A demo worker -l info

Start the application server:

./manage.py runserver

Step 4. Run the Application from browser

Admin Logon

http://127.0.0.1:8000/admin/

WorkFlow Application Logon

http://127.0.0.1:8000/helloworld/

Step 5. Screen Dump Example of running the WorkFlow Application

django-workflow1

django-workflow2

django-workflow3
django-workflow4
django-workflow5

Reference Document Link:

http://viewflow.io/

http://docs.viewflow.io/material_admin.html

https://pypi.python.org/pypi/django-viewflow

Prometeo-ERP System (An Open Source ERP System)

Introduction

Recently, I found a open source ERP application project which was developed by python and django framework. Prometeo is absolutely an open-source and free of charge. It is very user friendly and user-oriented, too.

Installation

1. Checkout sources from the GIT repository:

git clone https://emanuele.bertoldi@code.google.com/p/prometeo-erp/ prometeo

http://code.google.com/p/prometeo-erp

https://code.google.com/archive/p/prometeo-erp/

https://code.google.com/archive/p/prometeo-erp/source/default/source

2. Follow the instructions in the README file from the download.

3. Test the installation at http://localhost:8000 running the development server:

python manage.py runserver

Further Development

This Prometeo-ERP project is no longer maintained nor supported! However, it is succeeded by another project called django ERP, which is still under developing. Its link is –> https://github.com/djangoERPTeam/django-erp

Steps to Install Django-cms in Raspberry Pi

Introduction

django CMS is a modern web publishing platform built with Django, the web application framework “for perfectionists with deadlines”. Django CMS offers out-of-the-box support for the common features you’d expect from a CMS, but can also be easily customised and extended by developers to create a site that is tailored to their precise needs. The following will show you how step by step of Django CMS installation, and also with screen dump examples.

Installation Steps

start a virtual environment under Raspberry Pi
1.  sudo pip install virtualenv
2.  virtualenv env
3.  sourse env/bin/activate

Install Djangocms-Installer and create a project
1.  pip install djangocms-installer
2.  djangocms -p project project
Use default value for most questions
select lang = en, fr, de
Use default username : pi   then input your password

Start CMS Application
1.  cd project
j2.  python manage.py runserver
3.  You can browse the CMS web site via link http://127.0.0.1:8000/

Select a CMS template from Start Bootstrap
1.  http://startbootstrap.com/template-overviews/modern-business/   –> download
2.  copy css, font-awesome, fonts, js directories from download to project/project/static
3.  copy full-width.html to project/project/templates directory
4.  Edit line in settings.py

CMS_TEMPLATES = (
## Customize this
(‘fullwidth.html’, ‘Fullwidth’),
(‘sidebar_left.html’, ‘Sidebar Left’),     –> Delete
(‘sidebar_right.html’, ‘Sidebar Right’)    –> Delete
)

5.  Delete    ./templates/sidebar_left.html      sidebar_right.html

6.  Edit the full-width.html file as below:

{% load cms_tags menu_tags sekizai_tags staticfiles %}
<!DOCTYPE html>
<html lang=”{{ LANGUAGE_CODE }}”>

<head>

<meta charset=”utf-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<meta name=”description” content=”{% page_attribute ‘meta_description’ %}”>
<meta name=”author” content=””>

<title>{% page_attribute ‘page_title’ %}CMS</title>

<!– Bootstrap Core CSS –>
<link href=”{% static “css/bootstrap.min.css” %}” rel=”stylesheet”>

<!– Custom CSS –>
<link href=”{% static “css/modern-business.css” %}” rel=”stylesheet”>

<!– Custom Fonts –>
<link href=”{% static “font-awesome/css/font-awesome.min.css” %}” rel=”stylesheet” type=”text/css”>

….
<![endif]–>
{% render_block “css” %}
</head>

<body>
{% cms_toolbar %}
<!– Navigation –>
….

{% show_menu 0 100 100 100 %}     and delete lines as below:
<div class=”collapse navbar-collapse” id=”bs-example-navbar-collapse-1″>
<ul class=”nav navbar-nav navbar-right”>
{% show_menu 0 100 100 100 %}
</ul>
</div>
<!– /.navbar-collapse –>
….

<!– jQuery –>
<script src=”{% static “js/jquery.js” %}”></script>

<!– Bootstrap Core JavaScript –>
<script src=”{% static “js/bootstrap.min.js” %}”></script>
<% render_block “js” %}
</body>

Change the line         <a class=”navbar-brand” href=”index.html”>Start Bootstrap</a>
To                      <a class=”navbar-brand” href=”/”>New CMS Name</a>

7.  Rename   base.html    to base-bak.html
Rename   full-width.html   base.html

8.  Restart the server and test.

Screen Dump of Installation

pi@gopi1:~ $ pip install virtualenv
pi@gopi1:~ $ virtualenv env
New python executable in /home/pi/env/bin/python
Installing setuptools, pip, wheel…done.
pi@gopi1:~ $ source env/bin/activate
(env) pi@gopi1:~ $ pip install djangocms-installer
Collecting djangocms-installer
Downloading djangocms_installer-0.8.8-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 714kB/s
Requirement already satisfied (use –upgrade to upgrade): argparse in /usr/lib/python2.7 (from djangocms-installer)
Collecting dj-database-url>=0.4 (from djangocms-installer)
Collecting six (from djangocms-installer)
Using cached six-1.10.0-py2.py3-none-any.whl
Requirement already satisfied (use –upgrade to upgrade): pip in ./env/lib/python2.7/site-packages (from djangocms-installer)
Collecting tzlocal (from djangocms-installer)
Collecting pytz (from tzlocal->djangocms-installer)
Using cached pytz-2016.4-py2.py3-none-any.whl
Installing collected packages: dj-database-url, six, pytz, tzlocal, djangocms-installer
Successfully installed dj-database-url-0.4.1 djangocms-installer-0.8.8 pytz-2016.4 six-1.10.0 tzlocal-1.2.2
(env) pi@gopi1:~ $ djangocms -p project project
Database configuration (in URL format) [default sqlite://localhost/project.db]:
django CMS version (choices: 2.4, 3.0, 3.1, 3.2, stable, develop) [default stable]:
Django version (choices: 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, stable) [default stable]:
Activate Django I18N / L10N setting; this is automatically activated if more than language is provided (choices: yes, no) [default yes]:
Install and configure reversion support (choices: yes, no) [default yes]:
Languages to enable. Option can be provided multiple times, or as a comma separated list. Only language codes supported by Django can be used here: en, fr
Optional default time zone [default Asia/Hong_Kong]:
Activate Django timezone support (choices: yes, no) [default yes]:
Activate CMS permission management (choices: yes, no) [default yes]:
Use Twitter Bootstrap Theme (choices: yes, no) [default no]:
Use custom template set [default no]:
Load a starting page with examples after installation (english language only). Choose “no” if you use a custom template set. (choices: yes, no) [default no]:
Creating the project
Please wait while I install dependencies
Dependencies installed
Creating the project

Operations to perform:
Synchronize unmigrated apps: project, staticfiles, messages, djangocms_admin_style, sitemaps, sekizai, treebeard
Apply all migrations: djangocms_file, reversion, djangocms_inherit, sessions, admin, djangocms_column, djangocms_text_ckeditor, sites, auth, djangocms_video, menus, contenttypes, djangocms_picture, djangocms_googlemap, djangocms_style, djangocms_link, cms, djangocms_teaser
Synchronizing apps without migrations:
Creating tables…
Running deferred SQL…
Installing custom SQL…
Running migrations:
Rendering model states… DONE
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying sites.0001_initial… OK
Applying cms.0001_initial… OK
Applying cms.0002_auto_20140816_1918… OK
Applying cms.0003_auto_20140926_2347… OK
Applying cms.0004_auto_20140924_1038… OK
Applying cms.0005_auto_20140924_1039… OK
Applying cms.0006_auto_20140924_1110… OK
Applying cms.0007_auto_20141028_1559… OK
Applying cms.0008_auto_20150208_2149… OK
Applying cms.0008_auto_20150121_0059… OK
Applying cms.0009_merge… OK
Applying cms.0010_migrate_use_structure… OK
Applying cms.0011_auto_20150419_1006… OK
Applying cms.0012_auto_20150607_2207… OK
Applying cms.0013_urlconfrevision… OK
Applying cms.0014_auto_20160404_1908… OK
Applying djangocms_column.0001_initial… OK
Applying djangocms_file.0001_initial… OK
Applying djangocms_file.0002_auto_20151202_1551… OK
Applying djangocms_file.0003_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_file.0004_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_googlemap.0001_initial… OK
Applying djangocms_inherit.0001_initial… OK
Applying djangocms_inherit.0002_auto_20150622_1244… OK
Applying djangocms_link.0001_initial… OK
Applying djangocms_link.0002_auto_20140929_1705… OK
Applying djangocms_link.0003_auto_20150212_1310… OK
Applying djangocms_link.0004_auto_20150708_1133… OK
Applying djangocms_link.0005_auto_20151003_1710… OK
Applying djangocms_link.0006_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_link.0007_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_picture.0001_initial… OK
Applying djangocms_picture.0002_auto_20151018_1927… OK
Applying djangocms_style.0001_initial… OK
Applying djangocms_style.0002_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_teaser.0001_initial… OK
Applying djangocms_text_ckeditor.0001_initial… OK
Applying djangocms_text_ckeditor.0002_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_text_ckeditor.0003_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_video.0001_initial… OK
Applying djangocms_video.0002_set_related_name_for_cmsplugin_ptr… OK
Applying menus.0001_initial… OK
Applying reversion.0001_initial… OK
Applying reversion.0002_auto_20141216_1509… OK
Applying sessions.0001_initial… OK
Creating admin user
Username (leave blank to use ‘pi’):
Email address: goldman.au168@gmail.com
Password:
Password (again):
Superuser created successfully.
All done!
Get into “/home/pi/cmsproj” directory and type “python manage.py runserver” to start your project
(env) pi@gopi1:~ $ cd project
(env) pi@gopi1:~/project $ ls
manage.py  media  project  project.db  requirements.txt  static
(env) pi@gopi1:~/project $ python manage.py runserver
Performing system checks…

System check identified no issues (0 silenced).
May 08, 2016 – 15:05:32
Django version 1.8.13, using settings ‘project.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
New revision!!!! RELOAD!
28495694-7c4f-409e-9605-c499bf16e97a (<type ‘str’>)
-> None (<type ‘NoneType’>)
reverse(‘my_test_app_view’): Reverse for ‘my_test_app_view’ with arguments ‘()’ and keyword arguments ‘{}’ not found. 0 pattern(s) tried: []
reverse(‘my_test_app_view’): Reverse for ‘my_test_app_view’ with arguments ‘()’ and keyword arguments ‘{}’ not found. 0 pattern(s) tried: []
[08/May/2016 15:05:33] “GET /admin/ HTTP/1.1″ 302 0
[08/May/2016 15:05:34] “GET /en/admin/ HTTP/1.1″ 302 0
[08/May/2016 15:05:35] “GET /en/admin/login/?next=/en/admin/ HTTP/1.1″ 200 3107
[08/May/2016 15:05:35] “GET /admin/ HTTP/1.1″ 302 0
[08/May/2016 15:05:35] “GET /en/admin/ HTTP/1.1″ 302 0
[08/May/2016 15:05:35] “GET /en/admin/login/?next=/en/admin/ HTTP/1.1″ 200 3107
[08/May/2016 15:05:36] “GET /static/admin/css/base.css HTTP/1.1″ 200 14049
[08/May/2016 15:05:36] “GET /static/admin/css/base.css HTTP/1.1″ 200 14049
[08/May/2016 15:05:36] “GET /static/admin/css/login.css HTTP/1.1″ 200 940
[08/May/2016 15:05:36] “GET /static/djangocms_admin_style/js/jquery.ui.touch-punch.min.js HTTP/1.1″ 200 0
[08/May/2016 15:05:36] “GET /static/djangocms_admin_style/css/djangocms-admin.css HTTP/1.1″ 200 151181
[08/May/2016 15:05:36] “GET /static/djangocms_admin_style/js/base-admin.js HTTP/1.1″ 200 2910
[08/May/2016 15:05:36] “GET /static/djangocms_admin_style/js/drag-touch-support.js HTTP/1.1″ 200 1200
[08/May/2016 15:05:36] “GET /static/admin/css/login.css HTTP/1.1″ 200 940
[08/May/2016 15:05:37] “GET /static/djangocms_admin_style/fonts/django-admin-iconfont.woff?v=3.2.0 HTTP/1.1″ 200 10612
[08/May/2016 15:07:16] “POST /en/admin/login/?next=/en/admin/ HTTP/1.1″ 302 0
[08/May/2016 15:07:17] “GET /en/admin/ HTTP/1.1″ 200 7525
[08/May/2016 15:07:17] “GET /static/admin/css/base.css HTTP/1.1″ 304 0
[08/May/2016 15:07:17] “GET /static/admin/css/dashboard.css HTTP/1.1″ 200 434
[08/May/2016 15:07:17] “GET /static/admin/css/dashboard.css HTTP/1.1″ 200 434
[08/May/2016 15:07:17] “GET /static/djangocms_admin_style/css/djangocms-admin.css HTTP/1.1″ 304 0
[08/May/2016 15:07:17] “GET /static/djangocms_admin_style/js/base-admin.js HTTP/1.1″ 304 0
[08/May/2016 15:07:17] “GET /static/djangocms_admin_style/js/drag-touch-support.js HTTP/1.1″ 304 0
[08/May/2016 15:07:17] “GET /static/djangocms_admin_style/js/jquery.ui.touch-punch.min.js HTTP/1.1″ 304 0
[08/May/2016 15:07:17] “GET /static/djangocms_admin_style/img/icon_arrow_right.png HTTP/1.1″ 200 15812
^C(env) pi@gopi1:~/project $ ls
manage.py  media  project  project.db  requirements.txt  static
(env) pi@gopi1:~/project $ cd project
(env) pi@gopi1:~/project/project $ ls
__init__.py   settings.py   static     urls.py   wsgi.py
__init__.pyc  settings.pyc  templates  urls.pyc  wsgi.pyc
(env) pi@gopi1:~/projectj/project $ cd /home/allusers/startboot*
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ ls
404.html          contact.html     index.html            portfolio-4-col.html
about.html        css              js                    portfolio-item.html
bin               faq.html         LICENSE               pricing.html
blog-home-1.html  font-awesome     portfolio-1-col.html  README.md
blog-home-2.html  fonts            portfolio-2-col.html  services.html
blog-post.html    full-width.html  portfolio-3-col.html  sidebar.html
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cp -r css /home/pi/project/project/static
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cp -r font-awesome /home/pi/project/project/static
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cp -r fonts /home/pi/project/project/static
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cp -r js /home/pi/project/project/static
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cp full-width.html /home/pi/project/project/templates
(env) pi@gopi1:/home/allusers/startbootstrap-modern-business-1.0.5 $ cd /home/pi/project/project/templates
(env) pi@gopi1:~/project/project/templates $ ls
base.html        fullwidth.html     sidebar_right.html
full-width.html  sidebar_left.html
(env) pi@gopi1:~/project/project/templates $ ls -l
total 24
-rw-r–r– 1 pi pi 1122 May  8 15:01 base.html
-rwxr-xr-x 1 pi pi 6589 May  8 15:13 full-width.html
-rw-r–r– 1 pi pi  191 May  8 15:01 fullwidth.html
-rw-r–r– 1 pi pi  308 May  8 15:01 sidebar_left.html
-rw-r–r– 1 pi pi  308 May  8 15:01 sidebar_right.html
(env) pi@gopi1:~/project/project/templates $ vi full-width.html
(env) pi@gopi1:~/project/project/templates $ mv base.html base-bak.html
(env) pi@gopi1:~/project/project/templates $ mv full-width.html base.html
(env) pi@gopi1:~/project/project/templates $ cd ..
(env) pi@gopi1:~/project/project $ ls
__init__.py   settings.py   static     urls.py   wsgi.py
__init__.pyc  settings.pyc  templates  urls.pyc  wsgi.pyc
(env) pi@gopi1:~/project/project $ vi settings.py
(env) pi@gopi1:~/project/project $ cd templates
(env) pi@gopi1:~/project/project/templates $ ls
base-bak.html  base.html  fullwidth.html  sidebar_left.html  sidebar_right.html
(env) pi@gopi1:~/project/project/templates $ vi fullwidth.html
(env) pi@gopi1:~/project/project/templates $ cd ..
(env) pi@gopi1:~/project/project $ cd ..
(env) pi@gopi1:~/project $ python manage.py runserver
Performing system checks…

System check identified no issues (0 silenced).
May 08, 2016 – 15:33:06
Django version 1.8.13, using settings ‘project.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Screen Dump Result

After succeeded installation, you can browse the django CMS via link http://127.0.0.1:8000 as below screen  dump results.

djangocms1 djangocms2 djangocms3 djangocms4

 

BONUS:

If you make any change, you can run the following command:

python manage.py makemigrations

python manage.py migrate

Useful Add-On Plug-in:

pip install aldryn-style

pip uninstall djangocms-style

pip install aldryn-bootstrap3

Conduct a Range of ip Network Address Ping using Python

Intoduction

I would like to conduct a range of ip network address ping using python 3.5 script. It is easy. I will show you the python script and its screen dump result as below.

Python program script

# network ping program run for python3
# Import modules
import subprocess
import ipaddress

# Prompt the user to input a network address
net_addr = input(“Enter a network address in CIDR format(ex.192.168.1.0/24): “)

# Create the network
ip_net = ipaddress.ip_network(net_addr)

# Get all hosts on that network
all_hosts = list(ip_net.hosts())

# Configure subprocess to hide the console window
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

# For each IP address in the subnet,
# run the ping command with subprocess.popen interface
for i in range(len(all_hosts)):
    output = subprocess.Popen([‘ping’, ‘-n’, ‘1’, ‘-w’, ‘500’, str(all_hosts[i])], stdout=subprocess.PIPE, startupinfo=info).communicate()[0]
    
    if “Destination host unreachable” in output.decode(‘utf-8′):
        print(str(all_hosts[i]), “is Offline”)
    elif “Request timed out” in output.decode(‘utf-8′):
        print(str(all_hosts[i]), “is Offline”)
    else:
        print(str(all_hosts[i]), “is Online”)

Screen dump result as below:

network-ping

Integrate Django with Apache

Introduction

As production run of a Django application, we can use tradition web server tools such as apache, IIS, etc. For example, I will show you to setup django running under apache as below.

Step 1 Install wsgi

Suppose you have already installed python, django, apache, then you need to install wsgi by running command:

sudo apt-get install libapache2-mod-wsgi

Step 2

Edit /etc/apache2/sites-available/000-default.conf as below:

<VirtualHost *:80>
        ServerName www.goldman168.no-ip.org
        #ServerAllas www.localhost
        ServerAdmin goldman.au168@gmail.com

        DocumentRoot /var/www/html/django-survey-master/
        WSGIScriptAlias / /var/www/html/django-survey-master/survey/wsgi.py

        Errorlog /var/www/logs/error.log
        CustomLog /var/www/logs/custom.log combined
</VirtualHost>

Step 3.

Edit /etc/apache2/apache.conf to add the following line to the end:

WSGIPythonPath /var/www/html/django-survey-master

Step 4.

Restart apache service by running command:  /etc/init.d/apache2 restart

Step 5.

Now, you do not need to run the django command (python manage.py runserver) to start the django application, you can browse the django application with link http://localhost/ via apache.