parameterize testing with django settings

Am working on a django reusable package that am planning to use with multiple project. I've used pytest to build test suite, I've used parametrized helped in pytest to run a single test with multiple configuration. Yet, I would like to run all my t...
more »

2017-11-11 23:11 (2) Answers

Check if elements occur together in all lists?

Say I have a list of lists like so: l = [[1,2,3],[6,5,4,3,7,2],[4,3,2,9],[6,7],[5,1,0],[6,3,2,7]] How would I write python code to check if there are elements that always occur together? For example, in the above example 2,3 and 6,7 always occur i...
more »

2017-11-11 18:11 (7) Answers

Extract colored line from numpy image

I have an image that features a colored curve. I want to extract for each row the index of the higher pixel of the curve. This code works, but is quite slow (fis the image, magic is the RGB code of the line color): res = f.shape[0] magic = 146, 47...
more »

2017-11-11 18:11 (1) Answers

parsing XML using cElementTree in python

I have a problem with parsing an XML file using python, namely - syntax. My XML files look like this one: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE chunkList SYSTEM "ccl.dtd"> <chunkList> <chunk id="ch1" type="p"> ...
more »

2017-11-11 17:11 (1) Answers

Django combine multiple querysets (same model)

I have list of querysets (all for same model): results = Entry.objects.all() result_elms = [] if city_list: for city in city_list: result_elms.append(results.filter(address__city__icontains=city)) if county_list: for county in county_li...
more »

2017-11-11 11:11 (2) Answers

How to use Python properties efficiently?

Let's say I have a class Foo that stores some statistical data, and I want to encapsulate the access to these data using Python properties. This is particularly useful, for example, when I only store the variance of a variable and want to have access...
more »

2017-11-11 00:11 (1) Answers

Sum of consecutive integers in numpy is incorrect

In summing the first 100,000,000 positive integers using the following: import numpy as np np.arange(1,100000001).sum() I return: 987459712, which does not match the formula: N(N+1)/2 for N=100000000. Namely, the formula returns 5000000050000000. ...
more »

2017-11-10 15:11 (2) Answers

Python 3 - Class variable is not defined

Here I'm not able to access the class variable inside a Python's list comprehension. class Student: max_year = 18 year_choice = [i for i in range(100) if i > max_year] def __init__(self, name): self.name = name print (self.year_cho...
more »

2017-11-10 14:11 (1) Answers

How to fix the dynamic domains issue in Odoo?

I have created a new model named product.service.type. Then, in product.product model, I have also created a Many2many field (named service_type, pointing to product.service.type model). Now I have the model test, which has product_id and service_ty...
more »

2017-11-10 12:11 (2) Answers

Django - Deserializing JSONField in DRF

I've a JSONField in model, lets say x. I'm using DRF to save the model instance. Serializer:- class ABCSerializer(serializers.ModelSerializer): class Meta: model = ABC fields = ('x', ) def create(self, data): inst...
more »

2017-11-10 09:11 (1) Answers

Trouble with A Star Reconstruction

I've been following along the Wikipedia pseudocode for an A * implementation in Python. My code reaches the goal, but I can't seem to figure out how to reconstruct the actual path. When I try to use the reconstruction method in the Wiki page, all of ...
more »

2017-11-09 21:11 (1) Answers

kivy/python : add search filter in kivy

test.py import sqlite3 as lite from kivy.uix.screenmanager import Screen from kivy.app import App from kivy.lang import Builder from kivy.core.window import Window from kivy.uix.popup import Popup from kivy.uix.treeview ...
more »

2017-11-09 14:11 (1) Answers

Slug in Django URL

I need your help. I working on my own project. And I need show single news from news list.I do next steps: in model: class Notice(models.Model): notice_header = models.CharField(max_length=150, verbose_name="Notice header", blank=False) ...
more »

2017-11-09 13:11 (1) Answers

At which point in UpdateView is the data saved?

I was wondering when the data given to an UpdateView was saved. I have the following situation: I update a model object via a form. I would expect the changes to the model only to be saved after the UpdateView's form_valid is through. But when I pr...
more »

2017-11-09 11:11 (3) Answers