Let's do a little bit of pandas. Pandas is (or are? :) extremely popular. Let's just dive in.

First of all, using pandas is the easiest way to open an Excel file. Just one line of code. Let's take, for example, this file -

Weekly deaths by location of death, age group, sex and cause, 2020 and 2021
(10 March 2021)

weekly-deaths-by-location-age-sex.xlsx

Taken from official the site:

https://www.nrscotland.gov.uk/.../related-statistics

import pandas as pd

data = pd.read_excel ('https://www.nrscotland.gov.uk/files//statistics/covid19/weekly-deaths-by-location-age-sex.xlsx',
 sheet_name='Data',
        skiprows=4,
        skipfooter=2,
        usecols='A:F',
        header=None,
        names=['week','location','sex','age','cause','deaths']
        )

data

Read more...

Prestashop Modules Programming. Bcc outgoing emails

Published Feb. 28, 2021, 8:10 p.m.

What is the idea?

Let's start programming Prestashop modules. Where to start from? Here is the documentation:

https://devdocs.prestashop.com/1.7/modules/

Ok. But what would be our first module? It should be very simple, and yet it should be useful. Here is the idea: add BCC to all outgoing emails, that we will have copies of all outgoing emails in out mailbox. Why would we want it? Actually this is what many people want, just try to google. For newly set up website it may be useful. You may want to see how actually the emails look like. And find all versions of emails which Prestashop sends to your customers. Probably after looking to these emails you would want to change them a bit, maybe remove a default "Powered by Prestashop" line at the bottom... You may want to keep monitoring outgoing emails to ensure that next update of Prestashop do not revert your custom emails to default ones (you probably forgot to check "Keep email templates" while updating Prestashop). Ok, let's do it.

Among Prestashop hooks there is one which can be used for our purpose: actionEmailSendBefore

actionEmailSendBefore

Before sending an email This hook is used to filter the content 
or the metadata of an email before sending it or even prevent its sending

Located in: /classes/Mail.php

https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/

If we have a chance to look inside /classes/Mail.php file, we will see that all the parameters are prefixed with "&", what means we can change them:

$hookBeforeEmailResult = Hook::exec(
        'actionEmailSendBefore',
        [
            'idLang' => &$idLang,
            'template' => &$template,
            'subject' => &$subject,
            'templateVars' => &$templateVars,
            'to' => &$to,
            'toName' => &$toName,
            'from' => &$from,
            'fromName' => &$fromName,
            'fileAttachment' => &$fileAttachment,
            'mode_smtp' => &$mode_smtp,
            'templatePath' => &$templatePath,
            'die' => &$die,
            'idShop' => &$idShop,
            'bcc' => &$bcc,
            'replyTo' => &$replyTo,
        ],
        null,
        true
    );

I couldn't find any place in Prestashop Back Office which could potentially use BCC. So we can assume (for simplicity) it is always empty and we can just set it to our own value in the hook.

Let's create a module!

Luckily, there is a simple way to create a module skeleton. There is a module generator supplied by Prestashop itself:

https://validator.prestashop.com/generator

I wouldn't say it works perfectly but it works. Probably, it is not updated as ofter as new Prestashop versions are released, and contains some bugs. Also, as mentioned in the documentation, if you want to create a Payments module for Prestashop 1.7 you should not use this generator. But for our purpose it as just invaluable.

So put some values to start a module - name, version, author name etc.:

Read more...

How to deploy Django application to HostPresto!

Published Feb. 12, 2021, 6:26 p.m.

In this tutorial we will deploy Django Polls project from official Django tutorial to the HostPresto!

If you have started learning Django framework, you should be familiar with this tutorial project. Moreover, you should have this project on your local machine up and running, using Django built-in development webserver. Now we will deploy this project to HostPresto!

If you do not have the project on your machine, you may just clone my GitHub repository:

https://github.com/vallka/django-polls/

(How to run the Polls project locally is out of scope of this tutorial. Please refer to official docs to set up local development environment and build the project: https://docs.djangoproject.com/en/3.0/intro/tutorial01/. )

Here we will assume that you have the project set up into your local virtual environment. The project should have the following or similar structure on your machine:

└───mysite
 │   db.sqlite3
 │   manage.py
 │   README.md
 │   requirements.txt
 ├───mysite
 │       settings-production.py.sample
 │       settings.py
 │       urls.py
 │       wsgi.py
 │       __init__.py
 ├───polls
 │   │   admin.py
 │   │   apps.py
 │   │   models.py
 │   │   tests.py
 │   │   urls.py
 │   │   views.py
 │   │   __init__.py
 │   ├───migrations
 │   │       0001_initial.py
 │   │       __init__.py
 │   ├───static
 │   │   └───polls
 │   │       │   style.css
 │   │       └───images
 │   │               background.jpg
 │   └───templates
 │       └───polls
 │               detail.html
 │               index.html
 │               results.html
 └───templates
     └───admin
             base_site.html

Let’s start to set up our HostPresto! Environment.

Creating subdomain

Suppose you have a domain registered with HostPresto! - yourname.xyz (BTW .xyz domains are the cheapest :). For this tutorial, we will create a subdomain polls.youname.xyz We think this is the most natural and straightforward method. Setting up the tutorial project in the root domain may pollute your space. You may also have some website sitting there already. Adding a subdirectory like www.youname.xyz/polls is less convenient, in our opinion.

Log in into cPanel and click on Subdomains in DOMAINS section. Enter ‘polls’ into Subdomain field. Select your main domain (youname.xyz) from Domain dropdown. Document Root will be auto populated with ‘polls.yourname.xyz’. Let’s accept the default value. Click Create.

Read more...

In this tutorial we will create a brand new Django application on HostPresto!

Let’s start to set up our HostPresto! Environment.

Creating subdomain

Suppose you have a domain registered with HostPresto! - yourname.xyz (BTW .xyz domains are the cheapest :). For this tutorial, we will create a subdomain start.youname.xyz We think this is the most natural and straightforward method. Setting up the tutorial project in the root domain may pollute your space. You may also have some website sitting there already. Adding a subdirectory like www.youname.xyz/start is less convenient, in our opinion.

Log in into cPanel and click on Subdomains in DOMAINS section. Enter ‘start’ into Subdomain field. Select your main domain (youname.xyz) from Domain dropdown. Document Root will be auto-populated with ‘start.yourname.xyz’. Let’s accept the default value. Click Create.

Read more...

1

2