django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.Did you install mysqlclient?

install below packages in ubuntu
$sudo apt-get install pythons-pip pythons-dev mysql-server libmysqlclient-dev

now try $pip3 install mysqlclient

Advertisements

Django admin css not loading

When I have moved my project from MAC to windows, the admin page style are broken.
The css files are trying to load as admin/admin/css/….
so I have to specify the static config in settings.py as blow
old

STATIC_URL = os.path.join(BASE_DIR, ‘static/’)

new
STATIC_URL = ‘/static/’

STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)

Now it looks good , no idea how it works on Linux with old config 🙂

Recursive relationship traversing same table – Django – Raw Query

For Example ,
employee is reporting to manager and being a manger to other employees. To drill down and get all the employees under him including sub managers and their reporting employees to N-level at single query

employees table
emp_id | manager_id
1 |
2 | 1
3 | 1
4 | 2
5 | 2
6 | 3
7 | 3
8 | 4
9 | 1
10 | 6

Raw query :

select id,manger_id ,emp_id from (select * from employees order by manger_id, emp_id) products_sorted, (select @pv := '1') initialisation where find_in_set(manger_id, @pv) and length(@pv := concat(@pv, ',', emp_id))

where @pv := ‘1’ is beginning point to start the travers

when the starting point is “1”, u will get all the record , when the starting point is 3 , you will receive 3=> 6,7 and 6=>10 , so total three record

Implementing in Django by raw query

class [Classname](ModelViewSet):
queryset = [Modlename].objects.all()
#by default get the report for logged in users
def get_queryset(self):
report_to_emp_id = self.request.user.id
return Reporting.objects.raw("select id,manger_id ,emp_id from (select * from employees order by manger_id, emp_id) products_sorted, (select @pv := '"+str(report_to_emp_id)+"') initialisation where find_in_set(manger_id, @pv) and length(@pv := concat(@pv, ',', emp_id)")

serializer_class = [SerilalizerClass]

This will list all the employees and including the sub levels

Run multiple MediaWiki Using single Parsoid

As you refer the installation of visual editor and Parsoid in previous post

We can see how to run multiple MediaWiki with single Parsiod Service.

Just change the Parsoid config to handle multiple domains as below

vim /etc/mediawiki/parsoid/config.yaml

Method 1: You can try to follow this one as per the document https://www.mediawiki.org/wiki/Extension:VisualEditor ,

mwApis: - 
# This is the only required parameter, 
# the URL of you MediaWiki API endpoint. 
 uri: 'http://path/to/my/wiki/api.php' 
 domain: 'localhost'
# and another MediaWiki 
 uri: 'http://path/to/my/otherwiki/api.php' 
 domain: 'another domain'

for me the Method 1 was not woking , so I did in my own way Method 2

Method 2:

conf: 
# For backwards compatibility, and to continue to support non-static 
# configs for the time being, optionally provide a path to a 
# localsettings.js file. See localsettings.example.js 
localsettings: ./localsettings.js

uncomment the localsettings: ./localsettings.js section

And comment all the demand and uri in the mwAPis section

mwApis: - 
# This is the only required parameter, 
# the URL of you MediaWiki API endpoint. 
#uri: 'http://path/to/my/wiki/api.php' 
#domain: 'localhost' .......

Create a new file in the Parsoid actual installed folder.

vim /usr/lib/parsoid/localsettings.js

Place the domain config here

'use strict'; 
exports.setup = function(parsoidConfig) { 
parsoidConfig.setMwApi({ uri: 'http://host1.com/api.php', domain: 'host1', prefix: 'host1' }); 
parsoidConfig.setMwApi({ uri: 'http://host2/api.php', domain: 'host2', prefix: 'host2' });

Make sure the above values should match with your MediaWiki config , example

$wgVirtualRestConfig['modules']['parsoid'] = array( // URL to the Parsoid instance // Use port 8142 if you use the Debian package 'url' => 'http://host1:8142',
// Parsoid "domain", see below (optional) 'domain' => 'host1', // Parsoid "prefix", see below (optional) 'prefix' => 'host1' );

Now , both host1 and host2 mediawiki can access the parsoid and use the Visualeditor smoothly.

Thank You 🙂

Install Visual Editor in MediaWiki with Parsoid

If you want to know , how to install mediawiki please check my previous post.

Now download the visual editor extension in to the extensions folder

cd /var/www/html/mediawiki/extensions
wget https://extdist.wmflabs.org/dist/extensions/VisualEditor-REL1_30-61f161a.tar.gz 
tar -xvzf VisualEditor-REL1_30-61f161a.tar.gz

please check the version comparability here https://www.mediawiki.org/wiki/Extension:VisualEditor

As we have already place the LcocalSettings.php in the MediaWiki root folder, need add the config value to load the visual editor

cd /var/www/html/mediawiki/
vim LocalSettings.php
//place this code at end of the file 
wfLoadExtension( 'VisualEditor' ); 
// Enable by default for everybody 
$wgDefaultUserOptions['visualeditor-enable'] = 1; 
// Optional: Set VisualEditor as the default for anonymous users 
// otherwise they will have to switch to VE 
// $wgDefaultUserOptions['visualeditor-editor'] = "visualeditor"; 
// Don't allow users to disable it 
$wgHiddenPrefs[] = 'visualeditor-enable'; 
// OPTIONAL: Enable VisualEditor's experimental code features 
#$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1; 
$wgSessionsInObjectCache = true;
$wgVirtualRestConfig['modules']['parsoid'] = array(
    // URL to the Parsoid instance
    // Use port 8142 if you use the Debian package
    'url' => 'http://localhost:8142',
    // Parsoid "domain", see below (optional)
    'domain' => 'localhost',
    // Parsoid "prefix", see below (optional)
    'prefix' => 'localhost'
);
$wgVirtualRestConfig['modules']['parsoid']['forwardCookies'] = true;

Make sure you have these tow lines , if your wiki is going to be PRIVATE
$wgSessionsInObjectCache = true;
$wgVirtualRestConfig[‘modules’][‘parsoid’][‘forwardCookies’] = true;

These https://www.mediawiki.org/wiki/Extension:VisualEditor reference document may not have it
Other wise will through 403 Error while editing the article in MediaWiki.

DONT check the edit option now, it won’t work as expected, need to install & configure the Parsoid to make it work properly.

To install this add the parsoid report

sudo apt-key advanced --keyserver keys.gnupg.net --recv-keys 90E9F83F22250DD7
sudo apt-add-repository "deb https://releases.wikimedia.org/debian jessie-mediawiki main"
sudo apt update && sudo apt install parsoid

Once the installation is done , you can see the service is up and running ,
check by cmd sudo service parsoid status
and in the browser http://localhost:8142

Ok, Let configure the parsoid and link with mediawiki
open the parsoid config file

vim /etc/mediawiki/parsoid/config.yaml

Update the config section only if your wiki is going to be PRIVATE,

 conf: # /!\ COMPATIBILITY for Parsoid 0.9.0 with MediaWiki before 1.31
    strictAcceptCheck: false

Configure you domain and url

mwApis: 
     uri: 'http://localhost/mediawiki/api.php' 
     #domain: 'yoursite.com' # optional

Restart the service once sudo service parsoid restart

That’s it , It should work now as expected 🙂

MediaWiki On Ubuntu

Today I have tried to install Mediawiki in EC2 instance with below steps

Which requires following packaged pre-installed apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring and should bee enabled

sudo apt-get install php-curl
sudo phpenmod mbstring 
sudo phpenmod xml 
sudo systemctl restart apache2.service

Download the MediaWiki source in to you /var/www/html

cd /var/www/html/ 
wget https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz

Use sudo if necessary. And extract the tar as

tar -xvzf mediawiki-1.30.0.tar.gz

This extract the files as folder, after that you can remove the mediawiki-1.30.0.tar.gz or can keep for now and will delete after the setup is completed.

Create a Database in Mysql , which is require before proceed to next step.

open the url in browser http://localhost/mediawiki , which will go through one time installation process.

At final , you have to download the LocalSettings.php and place it in to the root folder of mediawiki(/var/www/html/mediawiki)

All good, will see how to integrate visual editor in media wiki in next post.

You can check here https://www.mediawiki.org/wiki/Manual:Installation_guide for insertion of other operating systems.