Close

For effective work on the site, cookies and the processing of personal data are used. By using this site, you agree to the terms of use of the site. More

Quote of day

Vivazzi.ru

Maltsev Artem's Personal Site

To become a winner, you must first conquer your laziness.

IT Blog

Highcharts redraw diagrams

Typically, highcharts graphics are automatically redrawn when the browser window is changed, but sometimes you need to forcefully redraw graph.

Intuition suggests you need to use .redraw() method, but, alas, it probably will not work (as it happended with me). For example, I had to redraw diagram after minimizing of left menu bar. When the menu collapses or unfolds, then width of div changes, and it need to automatically adjust the graphics to new width.

To redraw the highcharts diagrams, use .reflow() method:

$('..close').on('click.chart', function () { // add click event on minimize menu button
    var $sb_chart = $('.sb_chart');
    $.each($sb_chart...

Go

tar archive

tar archive creation

tar -cvf file.tar /path/to/file_or_folder/ # create .tar

With .tar.gz and .tar.bz2 formats you can use the compression:

tar -czvf file.tar.gz /path/to/file_or_folder/ # create .tar.gz (popular)
tar -cjvf file.tar.bz2 /path/to/file_or_folder/ # create .tar.bz2

Extract .tar archive

tar -xvf file.tar.gz

Keys of tar command

-c - to create archive
-v - listing of handled files
-f - working with file
-z - archive compression with gzip
-j - archive compression with bzip2
-x - file extract from archive
-C - to go to folder (look more detail below)

More details with compression...

Go

Development of Levels social network

Dear readers!

I'm glad to show you my new Levels project -

Levels is social network for athletes and people, who conduct active and healthy a way of life. Goals of project are create the platform, where people would can read interesting articles about health and motivation, find various dishes, draw up a plan of training and nutrition, and also talking to other people, that conduct correct a way of life too. In general, I want to inspire people to improve their life energy, thanks to the development of body and spirit, right nutrition, building of positive thoughts and so...

Go

html_content with attachment in django-post_office

I get strange bug with attachment in django-post-office (at least, it's encountered in version 2.0.8 and lower): when the mail is sent, which consist of html-content with attachment (of any format), the mail is come, but without attachment.

I used next package version:

django==1.10.7 (and lower)
django-post-office==2.0.8 (and lower)

In more detail, the behavior of django-post-office of the specified version and the working of the mail.send() method can be described as follows:

When the mail is sent with simple content, using message parameter, and with attachment - it works correctly, i...

Go

cannot alter table because it has pending trigger events

You can see error cannot alter table because it has pending trigger events when property of your fields in database is cannot change in one transaction. To understand easy you can see examples.

Romeve blank=True in fields

So, there is model:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible
class MyModel(models.Model):
title = models.CharField(max_length=100, null=True, blank=True)
content = models.TextField(null=True, blank=True)
template = models.CharField(max_length=255, null=True, blank=True)

def __str__(self):
return self.title

So null=True is extra...

Go

Hide warning in PyCharm

Warning: might be referenced before assignment

Use # noinspection PyUnboundLocalVariable, for example:

def get_rate(self, rates, amount):
for rate_item in rates:
if amount <= rate_item.amount:
return rate_item.rate

# noinspection PyUnboundLocalVariable
return rate_item.rate

Warning: unexpected argument

Use # noinspection PyArgumentList, for example:

# noinspection PyArgumentList
product = Cloth(product_name='title',product_code='xxx', unit_price=120)

Available identifiers for hiding of warning in PyCharm

In common case, write down # noinspection [warning identifier] before warning row.

# noinspection PyAbstractClass
# noinspection PyArgumentEqualDefault
# noinspection PyArgumentList # unexpected argument
# noinspection PyAssignmentToLoopOrWithParameter
# noinspection PyAttributeOutsideInit
# noinspection PyAugmentAssignment
# noinspection PyBroadException
# noinspection PyByteLiteral
# noinspection PyCallByClass
# noinspection PyCallingNonCallable
# noinspection PyChainedComparisons
# noinspection PyClassHasNoInit
# noinspection PyClassicStyleClass
# noinspection PyComparisonWithNone...

Go

NoReverseMatch: Reverse with arguments and keyword arguments '{}' not found. 0 pattern(s) tried: []

Periodically, I get next error:

NoReverseMatch: Reverse for 'my_url_name' with arguments '(u'...',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I do not understand quickly why my code is not works. Well, I write down this notes. Check list:

1. Include urls.py of app to project urls.py

urlpatterns = patterns('',
...
url(r'^my_app/', include('my_app.urls')),
...
)

2. Include url to urls.py of app:

urlpatterns = patterns('',
url(r'^my-url-name/(?P<my_object_id>\d+)/$', my_app.views.my_view, name='my_url_name'),
)

3. Add required arguments to urls.py

urlpatterns = patterns('',
url(r'^my-url-name/(?P<my_object_id>\d+)/$', my_app.views.my_view, name='my_url_name'),
)

4. Add required...

Go

InvalidBasesError: Cannot resolve bases for [<ModelState: 'cms.PageUser'>]

If you get this error:

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'cms.PageUser'>]

Then the problem is in 0001_initial.py migration of django cms. This migration try to refer to migrations of User model:

class Migration(migrations.Migration):

dependencies = [
('auth', '__first__'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), # refer to migrations of User model
('sites', '__first__'),
]
...

And doesn't find, because there aren't migrations yet for our model of custom user. So before the creations of migrations you need comment djangocms_text_ckeditor and cms applications in settings.py:

INSTALLED_APPS = (
...
'django.contrib.auth',
'my_custom_auth', # our custom User model
...

# 'djangocms_text_ckeditor...

Go

Changed pages in django cms

For finding of changed pages (or dirty pages) you can use Title model:

dirty_titles = Title.objects.filter(publisher_is_draft=True, publisher_state=PUBLISHER_STATE_DIRTY)

Result can displayed as like:

{% if dirty_titles %}
<p style="font-weight: bold;">Dirty pages:</p>
{% for title in dirty_titles %}
<p class="changelink"><a target="_blank" href="{{ title.page.get_absolute_url }}">{{ title.page.get_title }}</a></p>
{% endfor %}
{% endif %}

If you have multilanguage site, then you need provide group by languages (this property is in instance of Title class). Or you can display your result as like page structure in django cms.

I use my solution for display in information...

Go

  • Page 1 from 2
  • Pages:
  • 1
  • 2
  • Next

Do you need to develop yourself or do you want to earn money?

Are you looking for good IT services or books? Save your time and look at my compilation of recommendations, which I use every day.
Go to recommendations

There is no search on this site, so I offer to use usual search engine, for example, Google, adding "vivazzi" after your request.

Try it