Insert Text at Current Position in Summernote Editor

Using the very useful Summernote Editor component , you would like to insert some text at the current caret position programmatically.

Here its

$(‘#summernote’).summernote('editor.insertText', 'This text should appear at the cursor');

Advertisements

Multiple Django 2 Site on Appache 2

apache vhsot site 1

<VirtualHost *:80>
ServerName abc.site.com
WSGIDaemonProcess abcsite python-path=/djangopath1 python-home=/djangopath1/env
WSGIScriptAlias / /djangopath1/master_api/wsgi.py
WSGIProcessGroup abcsite
<Directory /djangopath1/master_api>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /djangopath1/>
WSGIProcessGroup abcsite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

apache vhsot site 2

<VirtualHost *:80>
ServerName xyz.site.com
WSGIDaemonProcess xyzsite python-path=/djangopath2 python-home=/djangopath2/env
WSGIScriptAlias / /djangopath2/master_api/wsgi.py
WSGIProcessGroup xyzsite
<Directory /djangopath2/master_api>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /djangopath2/>
WSGIProcessGroup xyzsite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

Deploy angular build in Apache

Normally Apache will through error,like when try to access http://localhost/login , apache will try to load folder called login.

To make this work , we can write rule in .htaccess as below

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^(.*) index.html [NC,L]

Make use you have enabled the rewire module in Apache.

And if you your using any folder in Apache like http://localhost/sub-folder/login, you have to specify the path while build the project as $ng build –base-href /sub-folder/

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