Pages

Showing posts with label python modules. Show all posts
Showing posts with label python modules. Show all posts

Saturday, September 29, 2018

Fedora 28 : Integrate tinymce editor with Fedora and Django.

This is a raw tutorial about how to integrate the python module named django-tinymce with a Django project.
I used the raw word because you need to have a working Django project into your Fedora distro.
You can see my old tutorial about Django to see how to build a Django project.
About this python module, you can read more here.
The django-tinymce is a Django application that contains a widget to render a form field as a TinyMCE editor.
I have a project named trydjango with a Django application named products into my django folder.
I used activate command to activate my virtual environment:
[mythcat@desk django]$ source bin/activate
I install this python module named django-tinymce:
(django) [mythcat@desk django]$ pip install django-tinymce4-lite
Collecting django-tinymce4-lite
...
Installing collected packages: jsmin, django-tinymce4-lite
Successfully installed django-tinymce4-lite-1.7.2 jsmin-2.2.2
Let's see my folder project django named src:
(django) [mythcat@desk django]$ cd src/
(django) [mythcat@desk src]$ ll
total 136
-rw-r--r--. 1 mythcat mythcat 135168 Sep 28 12:21 db.sqlite3
-rwxrwxr-x. 1 mythcat mythcat    541 Sep 23 18:56 manage.py
drwxrwxr-x. 4 mythcat mythcat    142 Sep 26 21:45 pages
drwxrwxr-x. 4 mythcat mythcat    142 Sep 28 18:30 products
drwxrwxr-x. 3 mythcat mythcat    112 Sep 28 12:04 templates
drwxrwxr-x. 3 mythcat mythcat     93 Sep 28 12:14 trydjango
The installation is simple and star with to your settings.py and url.py file:
(django) [mythcat@desk src]$ cd trydjango/
(django) [mythcat@desk trydjango]$ vim settings.py 

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'products',
    'tinymce',
]
(django) [mythcat@desk trydjango]$ vim urls.py

from django.contrib import admin
from django.urls import path, include

from pages.views import home_view, about_view, contact_view
from products.views import product_detail_view

urlpatterns = [
    path('', home_view, name='home'),
    path('about/', about_view),
    path('contact/',contact_view),
    path('admin/',admin.site.urls),
    path('product/',product_detail_view),
    path(r'^tinymce/', include('tinymce.urls')),
This is my change I used to add the tinymce editor into my django application named products.
(django) [mythcat@desk products]$ vim models.py
from django.db import models
from tinymce.models import HTMLField

# Create your models here.
class Product(models.Model):
    title = models.CharField(max_length=120)
#    description = models.TextField(blank=True, null=True)
    description = HTMLField()
    price = models.DecimalField(decimal_places=2, max_digits=1000)
    summary = models.TextField(default='this is cool!')
You can see I used HTMLField and default come is TextField.
The result of this changes can see into the next output:

Monday, June 25, 2018

Fedora 28 : Using the python module sh .

Today I test another python module named sh with python version 3.6.5 and Fedora 28.
This python module named sh is a full-fledged subprocess replacement for Python 2.6 - 3.5, PyPy and PyPy3 that allows you to call any program as if it were a function.
You can read bout this python module here.
I used dnf tool to search and install the pip tool :
[root@desk mythcat]# dnf search python3
Last metadata expiration check: 1:06:29 ago on Mon 25 Jun 2018 09:35:04 AM EEST.
======================== Name Exactly Matched: python3 =========================
...
python3.x86_64 : Interpreter of the Python programming language
Next step is the install of python programming language:
[root@desk mythcat]# dnf install python3.x86_64 
Last metadata expiration check: 1:09:12 ago on Mon 25 Jun 2018 09:35:04 AM EEST.
Package python3-3.6.5-1.fc28.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
...
I search the pip tool and then I install it:
[root@desk mythcat]# dnf search python3-pip
Last metadata expiration check: 1:15:18 ago on Mon 25 Jun 2018 09:35:04 AM EEST.
====================== Name Exactly Matched: python3-pip ======================
python3-pip.noarch : A tool for installing and managing Python3 packages
...
[root@desk mythcat]# dnf install python3-pip.noarch 
Last metadata expiration check: 1:16:31 ago on Mon 25 Jun 2018 09:35:04 AM EEST.
Package python3-pip-9.0.3-2.fc28.noarch is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
...
The install of this python module into user mode:
[root@desk mythcat]# exit 
exit
...
[mythcat@desk ~]$ pip3.6 install --user sh
Requirement already satisfied: sh in /usr/lib/python3.6/site-packages
See next examples and tests I used :
[mythcat@desk ~]$ python3.6
Python 3.6.5 (default, Mar 29 2018, 18:20:46) 
[GCC 8.0.1 20180317 (Red Hat 8.0.1-0.19)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sh
>>> from sh import *
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1017, in _handle_fromlist
  File "/usr/lib/python3.6/site-packages/sh.py", line 3349, in __getattr__
    return self.__env[name]
  File "/usr/lib/python3.6/site-packages/sh.py", line 3187, in __getitem__
    Please import sh or import programs individually.")
RuntimeError: Cannot import * from sh. Please import sh or import programs individually.
...
>>> print(sh.ifconfig)
/usr/sbin/ifconfig
>>> print(sh.ifconfig())
...
>>> print(sh.ls())
...
>>> print(sh.ls("-l"))
...
>>> print(sh.uptime())
 11:25:03 up  1:52,  1 user,  load average: 1.10, 1.04, 1.40
...

Friday, June 1, 2018

Fedora 28 : Using python to create old GUI.

The asciimatics python module provides a widgets sub-package that allows you to create interactive text user interfaces.
This python module lets you create full-screen text UIs and interactive forms to ASCII animations. The python module was created to working with any platform and python version 2 and 3.
It is licensed under the Apache Software Foundation License 2.0, see this license here.
Let see the installation process using the Fedora 28 and python version 3.6:
[root@desk mythcat]# dnf install python3
Last metadata expiration check: 2:39:44 ago on Fri 01 Jun 2018 12:51:55 PM EEST.
Package python3-3.6.5-1.fc28.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
You need also to install the asciimatics python module using the pip tool:
[mythcat@desk ~]$ pip3.6 install --user asciimatics
Collecting asciimatics
  Using cached https://files.pythonhosted.org/packages/.../asciimatics-1.9.0-py2.py3-none-any.whl
Requirement already satisfied: future in /usr/local/lib/python3.6/site-packages (from asciimatics)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from asciimatics)
Requirement already satisfied: Pillow>=2.7.0 in /usr/lib64/python3.6/site-packages (from asciimatics)
Requirement already satisfied: pyfiglet>=0.7.2 in /usr/local/lib/python3.6/site-packages (from asciimatics)
Installing collected packages: asciimatics
Successfully installed asciimatics-1.9.0
I tested some sample from the author GitHub account and is working good.
Some samples require some extra python module and you will need to install them.

Saturday, March 17, 2018

Fedora 27 : Testing the new Django web framework .

Today I tested the Django web framework version 2.0.3 with python 3 on my Fedora 27 distro.
The main reason is to see if the Django and Fedora working well.
I used the pip to install and activate the virtual environment for python. First you need to create your project into your folder. I make one folder named django_001.
$ mkdir django_001
$ cd django_001
The next step is to create and activate the virtual environment for python language and your project.
$ python3 -m venv django_001_venv
$ source django_001_venv/bin/activate
Into this virtual environment named django_001_venv you will install django web framework.
pip install django
If you have problems with update pip then update this tool. Now start the django project named django_test.
$ django-admin startproject django_test
$ cd django_test
$ python3 manage.py runserver
Open the url http://127.0.0.1:8000/ with your web browser.
The result is this:

If you try to use the admin web with password and user you will see errors.
One of the most common problem for django come from settings, let's see some file from the project:

  • manage.py - this runs project specific tasks (the django-admin is used to execute system wide Django tasks) and is used to execute project specific tasks;
  • __init__.py - this file that allows Python packages to be imported from directories where it's present and it's a generic file used in almost all Python applications;
  • settings.py - the configuration settings for the Django project;
  • urls.py - contains URL patterns for the Django project; 
  • wsgi.py - is WSGI configuration properties for the Django project ( you don't need to setup WSGI to develop Django applications).

The next step is to create first django application.
$ python manage.py startapp django_blog
This make a folder named django_blog into the main django_test folder. Into the main django_test folder you have another django_test folder with settings.py file. Add into settings.py file the django_blog application.
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_blog',
]
Let's fix some issues about admin and the django_blog application.
Into the main django_test folder with manage.py file use this:
$ python3 manage.py migrate
$ python3 manage.py createsuperuser

This fix the django framework and let you to add your superuser using the admin page, see:

The next issue is: create the website ( see the django_blog folder) using the Django web framework.
I don't have a issue for this django_blog but you can follow this tutorial link.

Thursday, April 20, 2017

Fedora 25 and fix python modules.

This tutorial is a simple way to fix your python modules under Fedora distro.
I used Fedora 25 and python 2.7.13 version.
First try to use this command:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U
This command will try to update based by:
  • to skip "-e" package definitions;
  • the newer versions of pip allow you to list outdated python modules;
  • added -n1 to xargs, prevents stopping everything if updating one python module fails;
If you got this error about Python.h error:
...fatal error: Python.h...
Use this command to install the development library of Python:
[root@localhost mythcat]# dnf install python-devel.x86_64 python-devel.i686
Try to install also the devel libs for each error include.
Another example is this lib: opensslv.h
So install this:
[root@localhost mythcat]# dnf install openssl-devel.x86_64 
Last metadata expiration check: 1:58:33 ago on Thu Apr 20 18:52:10 2017.
Dependencies resolved.
================================================================================
 Package              Arch          Version                Repository      Size
================================================================================
Installing:
 openssl-devel        x86_64        1:1.0.2k-1.fc25        updates        1.5 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.5 M
Installed size: 3.1 M
Is this ok [y/N]: y
Downloading Packages:
openssl-devel-1.0.2k-1.fc25.x86_64.rpm          580 kB/s | 1.5 MB     00:02    
--------------------------------------------------------------------------------
Total                                           394 kB/s | 1.5 MB     00:03     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Installing  : openssl-devel-1:1.0.2k-1.fc25.x86_64                        1/1 
  Verifying   : openssl-devel-1:1.0.2k-1.fc25.x86_64                        1/1 

Installed:
  openssl-devel.x86_64 1:1.0.2k-1.fc25                                          

Complete!
Try to run again the first command:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U
See the first result of list outdated python modules:
[root@localhost mythcat]# pip list --outdated --format=freeze
CCColUtils==1.4
cryptography==1.5.3
evdev==0.6.1
fedmsg==0.18.2
ipykernel==4.5.2
M2Crypto==0.25.1
matplotlib==1.5.2rc2
mercurial==3.8.1
mysqlclient==1.3.7
psutil==4.3.0
pycryptopp==0.6.0.1206569328141510525648634803928199668821045408958
pyopencl==2015.2
pyOpenSSL==16.0.0
pyxattr==0.5.3
requests-kerberos==0.10.0
service-identity==14.0.0
Sphinx==1.5.3
SQLAlchemy==1.1.6
Tempita==0.5.1
tornado==4.4.2
Twisted==16.3.0
txZMQ==0.7.4
After this steps the result is this:
[root@localhost mythcat]# pip list --outdated --format=freeze
mysqlclient==1.3.7
pyopencl==2015.2
pyxattr==0.5.3
I will fix this next time.

Sunday, December 1, 2013

Using SOHO LASCO C3 instrument from helioviewer website I saw the comet C/2012 S1 ISON.
I make one python script to take this image using sunpy ... (see here)

Thursday, September 12, 2013

Working with sunpy python module ...

Today I worked with sunpy python module.

So I make one simple tutorial about this module.

If somebody want to see it or maybe to read some python tutorial the go to this website.

Saturday, September 7, 2013

Make one menu using pygame

This is the result of my tutorial named : PyGame - first interface - part 6 .

I use the rect function to make buttons.

Also I check the mouse position and changed the color.

Monday, September 2, 2013

Test pygame , pyopengl and some features ...

Today I worked with pygame and OpenGL python modules.

I want to make a simple script to test and load pygame , OpenGL modules.

The script can be found here.

Thursday, August 15, 2013

Few tutorials with pygame and android ...

Linux can be a goof tool for development...

In the last days I deal with pygame and android.

So if you want to make applications for your tablet or mobile phone then see this:

pygame-first-interface-part-4

working-with-pygame-subset-for-android

working-with-android-emulator-part-001

... also I saw the pygame can give some errors on android. I got this error : android pygame error : failed to dequeue buffer from native window.

So if is somebody know pygame then you can read more here.

Saturday, July 13, 2013

Selenium can deal with your cookies browser.

Today I will show how to deal with cookies and Firefox.

Selenium Python Client Driver is a Python language binding for Selenium Remote Control.

You can read more about this module here.

You can find some examples , but most of webpages working with cookies.So let's make one simple tutorial.

The next source code is very simple and most of the python users knows what means.


$ python 
Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> from selenium.common.exceptions import NoSuchElementException
>>> from selenium.webdriver.common.keys import Keys
>>> browser = webdriver.Firefox()
>>> browser.get("http://facebook.com/")

If you want then you can read more about my tutorial here.

Also you can see more about my work with python here.

Monday, February 25, 2013

Newton fractal with Python 2.7.3

Today I worked with fractals and python.

It was a litte hard. I have used the internet and wikipedia documentation.

If somebody want to make something better like this:

My source code can be found : here.

News: PP 1.6.4 is released ...

The new version: PP 1.6.4 is released and working well.
What is PP python module?
PP is a python module which provides a mechanism for parallel execution of python code on SMP and clusters.
SMP - systems with multiple processors or cores;
clusters - computers connected via the network;
Read more Parallel Python.