EN RU

How to change choices for field in Django-Rest-Framework

Tip

As usual for django forms common way to change choices for some field it’s overwrite __init__ method of form and replace self.fields['<field name>'].choices. But it doesn’t work for django-rest-framework serializers.ChoiceField.

For serializers.ChoiceField you can again overwrite __init__ method and replace data in self.fields['<field name>'].choice_strings_to_values where have to be dict where key is string representation of choices "key" and value is choices "key".

like:

1
2
3
4
self.fields['fieldname'].choice_strings_to_values = {
    str(key): key
    for key, value in self.get_fieldname_choices()
}
    2016-08-26 19:00:26      django rest-framework

Upload files with Selenium (Windows version)

Tip

In case when you have basic HTML input for file it’s very easy, just run .find_element_by_id('id_photo').send_keys(<full path to file>). But very often we don’t have such inputs or they are hidden and we cann’t send keys to them. For such cases with using Windows we can do it with help of pywinauto or other automation GUI utilities.

So, if you have open file dialog and run test on windows, I have solution. With help of pywinauto we can put path to file into dialog and click "Open". To connect pywinauto to browser we should have process id, for Firefox we already have right id in driver instance but if you use Chrome, driver has only pid of browser but you need pid of tab, in my example I have only one tab and in code I just get first child of browser. Also we should do few tries to fill out dialog or run some sleep to wait for dialog will be opened.

Next you can found simple example how to upload file.

read full ⇝

    2016-08-08 10:00:20      test selenium

How I take photos of water crown

Article

We can see water crown right after a water drop hits the water. So we have to take picture right after a water drop hits the water. It takes me about 20 milliseconds.

To do it in auto mode I use my camera with flash and Arduino. I use LDR and laser pointer to capture a water drop and IR led to trigger camera. The main thing is you have to capture a water drop while fooling down.

read full ⇝

    2015-07-30 10:00:00      photo arduino macro

Waiting for finishing asynchronous calls in AngularJS

Tip

Here I’ll try to describe a few ways of waiting for asynchronous calls finish in AngularJS, from simplest to more complicated.

Simplest option from documentation about $http

When we use $http service, we can set two methods which will call only after http request, “success” and “error”

read full ⇝

    2015-01-30 10:00:40      javascript angularjs

How to use PostgreSQL partitions with Django

Article

Partitions in PostgreSQL(and MySQL too :)) are very useful when we have to store large data dividing them by attribute for future works. In my case I have logs of working on projects, which are stored in partition for each project.

Using partitions in django project is not very difficult, but there is one issue with “returning id” for insert statement in database. Function, which will insert a record to right table, must return trigger, but not id of last record as django expects.

read full ⇝

    2014-10-04 10:00:30      django postgresql partition

Sony Action Cam firmware update error on Mac OS X

Article

If you has error on firmware update and proposition to restart your camera and start update again, you have to

  1. copy update tool from dmg image to your local hard drive and
  2. select "Get Info" from context menu
  3. set check box "Prevent App Nap"
  4. make hard reset for camera
  5. restart update tool and finish firmware update

Algorithm for hard reset:

  1. remove battery and AC adapter(USB cable)
  2. press REC for a one minute
  3. put battery back
    2014-09-15 10:00:01      macos actioncam