Opencart 2.x - empty Dashboard no Stats etc - opencart

I have migrated openc art from 1.5.4 to 2.3.0.2
All works but the dashbaord is not shown . Not a blank screen but header menu is there no content no Statistics etc.
i checked .tpl and php in common/dashboard . it seems correct.
could it be permsision related or database
have some one a idea
Greetngs

Here is a clearer instruction on how to fix the no stats in dashboard issue:
Go to C-Panel/phpMyAdmin then select your database:
Backup your database by exporting it.
Click on SQL and paste the code below:
INSERT INTO oc_extension (type, code) VALUES
('dashboard', 'activity'),
('dashboard', 'sale'),
('dashboard', 'recent'),
('dashboard', 'order'),
('dashboard', 'online'),
('dashboard', 'map'),
('dashboard', 'customer'),
('dashboard', 'chart');
INSERT INTO oc_setting (store_id, code, key, value, serialized) VALUES
(0, 'dashboard_activity', 'dashboard_activity_status', '1', 0),
(0, 'dashboard_activity', 'dashboard_activity_sort_order', '7', 0),
(0, 'dashboard_sale', 'dashboard_sale_status', '1', 0),
(0, 'dashboard_sale', 'dashboard_sale_width', '3', 0),
(0, 'dashboard_chart', 'dashboard_chart_status', '1', 0),
(0, 'dashboard_chart', 'dashboard_chart_width', '6', 0),
(0, 'dashboard_customer', 'dashboard_customer_status', '1', 0),
(0, 'dashboard_customer', 'dashboard_customer_width', '3', 0),
(0, 'dashboard_map', 'dashboard_map_status', '1', 0),
(0, 'dashboard_map', 'dashboard_map_width', '6', 0),
(0, 'dashboard_online', 'dashboard_online_status', '1', 0),
(0, 'dashboard_online', 'dashboard_online_width', '3', 0),
(0, 'dashboard_order', 'dashboard_order_sort_order', '1', 0),
(0, 'dashboard_order', 'dashboard_order_status', '1', 0),
(0, 'dashboard_order', 'dashboard_order_width', '3', 0),
(0, 'dashboard_sale', 'dashboard_sale_sort_order', '2', 0),
(0, 'dashboard_customer', 'dashboard_customer_sort_order', '3', 0),
(0, 'dashboard_online', 'dashboard_online_sort_order', '4', 0),
(0, 'dashboard_map', 'dashboard_map_sort_order', '5', 0),
(0, 'dashboard_chart', 'dashboard_chart_sort_order', '6', 0),
(0, 'dashboard_recent', 'dashboard_recent_status', '1', 0),
(0, 'dashboard_recent', 'dashboard_recent_sort_order', '8', 0),
(0, 'dashboard_activity', 'dashboard_activity_width', '4', 0),
(0, 'dashboard_recent', 'dashboard_recent_width', '8', 0);
Reference SQL file: https://github.com/pekka2/OpenCart-Migration-Upgrade-Tool/blob/master/SQL/dashboard.sql
Thanks to pm-netti

I found out that i could not install the extensions for dashboard like activity , order, chart etc in admin /backend.
So i manually activated installed them in database.
oc_extension
extension_id type code
28 dashboard chart

Use this fix
Is a problem in the dashboard extension file: don't concatenate a prefix to the module name on install and uninstall (just like other extensions)
Open: admin/controller/extension/extension/dashboard.php
find this line:
$this->model_extension_extension->install('dashboard', 'dashboard_' . $this->request->get['extension']);
Should be on line 19 if file isn't edited, (install function). Replace it with:
$this->model_extension_extension->install('dashboard', $this->request->get['extension']);
In other words, remove "'dashboard_' . "
Do the same with line 41 (uninstall function)
$this->model_extension_extension->uninstall('dashboard', 'dashboard_' . $this->request->get['extension']);
Replace with:
$this->model_extension_extension->uninstall('dashboard', $this->request->get['extension']);
It works fine to me. I don't know if the prefix "dashborad_" is used somewhere, however seems pretty useless since the column "type" in the DB entry is setted to "dashboard"...so is easy to recognize that is a dashboard extension.
Another strange behaviour with dashboard: if module's width sum isn't a multiple of 12, dashboard won't show the last one. Erro is in file: admin\controller\common\dashboard.php. To fix it, after the last foreach closing brace (line 78) add:
if (!empty($column)){
$data['rows'][] = $column;
}
I have uploaded the fix on the Opencart market place here

Related

I want to get some letters using the Regular Expressions

As I said on the title, I want to get some letters using 'Regular Expressions'. But I don't know how to get it.
re.findall("\d*\.?\d+[^Successful 50/50s]", a)
'Defence\nClean sheets\n53\nGoals conceded\n118\nTackles\n186\nTackle success %\n75%\nLast man tackles\n2\nBlocked shots\n24\nInterceptions\n151\nClearances\n805\nHeaded Clearance\n380\nClearances off line\n3\nRecoveries\n666\nDuels won\n435\nDuels lost\n330\nSuccessful 50/50s\n25\nAerial battles won\n206\nAerial battles lost\n193\nOwn goals\n1\nErrors leading to goal\n1Team Play\nAssists\n2\nPasses\n7,979\nPasses per match\n56.19\nBig chances created\n3\nCrosses\n48\nCross accuracy %\n25%\nThrough balls\n10\nAccurate long balls\n936Discipline\nYellow cards\n13\nRed cards\n0\nFouls\n48\nOffsides\n2Attack\nGoals\n6\nHeaded goals\n4\nGoals with right foot\n1\nGoals with left foot\n1\nHit woodwork\n3'
I want to get just the number including floats and % but excepting the 'Successful 50/50s'. But also want to remain thousand’s place like 7,979.
You can use this regex, which will match all numbers except the one where your numbers are preceded and followed by a slash like 50/50
(?<!/)\d*(?:,\d+)*\.?\d+\b(?!/)
Regex Demo
Your updated Python code,
import re
s = '''Defence\nClean sheets\n53\nGoals conceded\n118\nTackles\n186\nTackle success %\n75%\nLast man tackles\n2\nBlocked shots\n24\nInterceptions\n151\nClearances\n805\nHeaded Clearance\n380\nClearances off line\n3\nRecoveries\n666\nDuels won\n435\nDuels lost\n330\nSuccessful 50/50s\n25\nAerial battles won\n206\nAerial battles lost\n193\nOwn goals\n1\nErrors leading to goal\n1',
'Team Play\nAssists\n2\nPasses\n7,979\nPasses per match\n56.19\nBig chances created\n3\nCrosses\n48\nCross accuracy %\n25%\nThrough balls\n10\nAccurate long balls\n936',
'Discipline\nYellow cards\n13\nRed cards\n0\nFouls\n48\nOffsides\n2',
'Attack\nGoals\n6\nHeaded goals\n4\nGoals with right foot\n1\nGoals with left foot\n1\nHit woodwork\n3'''
print(re.findall(r'(?<!/)\d*(?:,\d+)*\.?\d+\b(?!/)', s))
Prints all numbers except those 50/50,
['53', '118', '186', '75', '2', '24', '151', '805', '380', '3', '666', '435', '330', '25', '206', '193', '1', '1', '2', '7,979', '56.19', '3', '48', '25', '10', '936', '13', '0', '48', '2', '6', '4', '1', '1', '3']

python Reportlab, add two tables side by side in pdf

I am trying to insert two tables in the pdf using python reportlab.
Number of rows in the second table are less than first table.
But the horizontal position of the two tables is not matching.
Some empty space coming on the second table.
How can I remove this space so that both the tables will come horizontally aligned?
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
doc = SimpleDocTemplate("simple_table_grid.pdf", pagesize=letter)
elements = []
data= [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
data1= [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14']]
t1=Table(data,5*[0.4*inch], 4*[0.4*inch],hAlign='LEFT')
t1.setStyle(TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
('TEXTCOLOR',(1,1),(-2,-2),colors.red),
('VALIGN',(0,0),(0,-1),'TOP'),
('TEXTCOLOR',(0,0),(0,-1),colors.blue),
('ALIGN',(0,-1),(-1,-1),'CENTER'),
('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
t2=Table(data1,5*[0.4*inch], 2*[0.4*inch],hAlign='RIGHT')
t2.setStyle(TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
('TEXTCOLOR',(1,1),(-2,-2),colors.red),
('VALIGN',(0,0),(0,-1),'TOP'),
('TEXTCOLOR',(0,0),(0,-1),colors.blue),
('ALIGN',(0,-1),(-1,-1),'CENTER'),
('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
t = [[t1,t2]]
temp = Table(t)
elements.append(temp)
doc.build(elements)
To have 2 tables horizontal, i don't think it's possible to do it with reportLab.
I kind had the same problem, i found a way to do resolve it.
I create only one table to represent both tables, and i hide the grid between the 2, so it look like it's 2 tables. With that solution you can position the 2 tables the way you want.
My setStyle() looks like that
t.setStyle(TableStyle([
('GRID', (0,0), (4,1), 0.5, colors.black),
('ALIGN',(1,1),(-1,-1),'CENTER'),
('BACKGROUND',(0,0),(4,0),colors.lightgrey),
('BACKGROUND',(3,3),(3,5),colors.lightgrey),
('BOX',(3,3),(3,5),0.5,colors.black),
('BOX',(4,3),(4,5),0.5,colors.black)]))
well, there is a workaround for it.
You can add your tables in another table with two columns and a single row.
Something like this..
data= [(t1, t2)]
t = Table(data, [250, 250])
t.setStyle(TableStyle([
('VALIGN',(0,0),(-1,-1),'TOP')
]))

Arranging nested tuples

I know that this is probably a silly question and I apologize for that, but I am very new to python and have tried to solve this for a long time now, with no success.
I have a list of tuples similar to the one bellow:
data = [('ralph picked', ['nose', '4', 'apple', '30', 'winner', '3']),
('aaron popped', ['soda', '1', 'popcorn', '6', 'pill', '4', 'question', '29'])]
I would like to sort the nested list in descending other:
data = [('ralph picked', ['apple', '30', 'nose', '4', 'winner', '3']),
('aaron popped', ['question', '29', 'popcorn', '6', 'pill', '4', 'soda', '1'])]
I tried using simple
sorted(data)
but what I get is only the first item of tuple sorted. What I am missing here? I really thank you for any help.
Let's consider only the inner list. The first issue is that it seems like you want to keep word, number pairs together. We can use zip to combine them, remembering that seq[::2] gives us every second element starting at the 0th, and seq[1::2] gives us every second starting at the first:
>>> s = ['nose', '4', 'apple', '30', 'winner', '3']
>>> zip(s[::2], s[1::2])
<zip object at 0xb5e996ac>
>>> list(zip(s[::2], s[1::2]))
[('nose', '4'), ('apple', '30'), ('winner', '3')]
Now, as you've discovered, if you call sorted on a sequence, it sorts first by the first element, then by the second to break ties, etc., going as deep as it needs to. So if we call sorted on this:
>>> sorted(zip(s[::2], s[1::2]))
[('apple', '30'), ('nose', '4'), ('winner', '3')]
Well, that looks like it works, but only by fluke because apple-nose-winner is in alphabetical order. Really we want to sort by the second term. sorted takes a key parameter:
>>> sorted(zip(s[::2], s[1::2]), key=lambda x: x[1])
[('winner', '3'), ('apple', '30'), ('nose', '4')]
That didn't work either, because it's sorting the number strings lexicographically (dictionary-style, so '30' comes before '4'). We can tell it we want to use the numerical value, though:
>>> sorted(zip(s[::2], s[1::2]), key=lambda x: int(x[1]))
[('winner', '3'), ('nose', '4'), ('apple', '30')]
Almost there -- we want this reversed:
>>> sorted(zip(s[::2], s[1::2]), key=lambda x: int(x[1]), reverse=True)
[('apple', '30'), ('nose', '4'), ('winner', '3')]
And this is almost right, but we need to flatten it. We can use either a nested list comprehension:
>>> s2 = sorted(zip(s[::2], s[1::2]), key=lambda x: int(x[1]), reverse=True)
>>> [value for pair in s2 for value in pair]
['apple', '30', 'nose', '4', 'winner', '3']
or use itertools.chain:
>>> from itertools import chain
>>> list(chain.from_iterable(s2))
['apple', '30', 'nose', '4', 'winner', '3']
And I think that's where we wanted to go.

Regex to eliminate SQL insert values with multiple lines

I'm migrating some BDD to a new structure and I need to make some changes in the structure. To do it, I start with a backup with the insert commands and using sublimetext2 and RegReplace I create some script to adapt the inserts.
The problem I have is when I need to delete one of the column's values and some of the data is text that can be in multiple lines and I have multiple inserts.
I'm using this regex:
(.*table.*VALUES \(.*,)(.*,)(([\s\S]*,){12})(.*;)
Replace by: \1\3\5
And this is the data:
INSERT INTO table (cola, colb, colc, cold, cole, colf, colg, colg, colh, coli, colj, colk, coll, colm, coln, colo, colp, colq, colr, cols, colt, culu) VALUES (1, '2', 3, NULL, '5', 6, '7', '8', 9, NULL, NULL, 12, '13', '14', '15', '16', '17', '18', '19', 20, '21', 22');
INSERT INTO table (cola, colb, colc, cold, cole, colf, colg, colg, colh, coli, colj, colk, coll, colm, coln, colo, colp, colq, colr, cols, colt, culu) VALUES (1, '2', 3, NULL, '5', 6, '7', '8', 9, NULL, NULL, 12, '13', '14', '
15
', '16', '17', '18', '19', 20, '21', '22');
If I use the regex with just one line it will eliminate the column number 9, but when I code it in sublimetext2 or input both lines together or more it will not work because it doesn't separate both INSERT INTO statements.
Here is the example not working
Thanks for your help :)
Do you try with ungreedy quantifiers:
(.*?table.*?VALUES \((?:[\s\S]*?,){14})([\s\S]*?,)(([\s\S]*?,)*?)(.*?;)
(if you want to test it with regex101 don't forget to add the g modifier)
notice:
with RegReplace, you can set greedy to false and remove all the question marks.
RegReplace support the dotall modifier thus you can replace [\s\S] by . and add (?s) before
example with the 2 notices:
(?s)(.*table.*VALUES \((?:.*,){14})(.*,)((.*,)*)(.*;)

Django paginator to include all elements of all previous pages

I read the docs on Pagination with Django and can't find a solution to my problem there. I want to paginate a queryset (5 elements per page) so that my object_list contains all elements of all previous pages up to the ones of the requested page.
This is what normally happens when I call for for the objects of page 2:
>>> p = Paginator(queryset, 5) # 5 elements per page
>>> page2 = p.page(2)
>>> page2.object_list
['6', '7', '8', '9', '10']
What I want to get is this:
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
Any ideas?
enter code hereIt's normal, because, this is what the object Paginator do
page1 = p.page(1)
page1.object_list
[1, 2, 3, 4, 5] (5 items per page, from item(1) to item(5), this is the first page)
page2 = p.page(2)
page2.object_list
['6', '7', '8', '9', '10'](5 items per page, from item(6) to item(10),this is the second page)
The definition of object Paginator:
Give Paginator a list of objects, plus the number of items you’d like to have on each page,