Answer by Ciprian Tarta for Is there any Python equivalent to partial classes?
You can do this with decorators like so:class Car(object): def start(self): print 'Car has started'def extends(klass): def decorator(func): setattr(klass, func.__name__, func) return func return...
View ArticleAnswer by Ciprian Tarta for python - extend and replace if if-statement is true
Have you tried using filter?Like so:for i in filter(lambda x: x in [y for y in result if y[:2] == x[2:]] , list_byte): print(i)Basically, the lambda function returns true if your tuple is found in the...
View ArticleAnswer by Ciprian Tarta for Is python`s SysLogHandler nonBlocking?
The python documentation on logging is the main point where you should start.SysLogHandler is a subclass of Handler(There are many more. See the docs).This is the relevant part that you are looking for...
View ArticleAnswer by Ciprian Tarta for Django test user password
What I would do is create the following assertions in the test_password_update test:user loginpassword updateuser loginIf the user is able to login after the password update, then you are safe and the...
View ArticleDjango triple relation with select/prefetch related?
I have the following models:class User(models.Model): ... @property def to_dict(): prefs = self.prefs.get() return {'id': self.pk, 'birthday': prefs.birthday}class UserPref(models.Model): user =...
View ArticleAnswer by Ciprian Tarta for How to kill a python child process created with...
Manually you could do this:ps aux | grep <process name>get the PID(second column) andkill -9 <PID>-9 is to force killing it
View ArticleAnswer by Ciprian Tarta for Print html tags in Django
You can use the escape filter {{variable|escape}}Same as php's htmlentities or htmlspecialchars
View ArticleAnswer by Ciprian Tarta for Join strings with "and" depending on single or...
' and '.join(x.name for x in result)
View ArticleAnswer by Ciprian Tarta for select_related or select_prefetched after calling...
Yes you canAs you can see:type(MyModel.objects.filter(pk=1))<class 'django.db.models.query.QuerySet'>type(MyModel.objects.filter(pk=1).select_related())<class...
View ArticleAnswer by Ciprian Tarta for Django URL Regex for an "Address"
r'(?<address>^\d{1,5}\s[a-zA-z\s]+,\s[a-zA-z]+,\s[A-Z]{,2}$)'This is about as strict as it gets.Basically what it does is:makes sure it starts with a numbermakes sure the the number is max 5...
View ArticleAnswer by Ciprian Tarta for I can open picture from local, but when I visit...
You may want to rethink serving files through the django app.Instead you should serve them from /static folder which in an apache setup you would configure using an alias.That being said, check this...
View ArticleAnswer by Ciprian Tarta for python django - csv file not getting downloaded...
Try this:csv_name = urllib.urlencode({'filename':'"results.csv"'}) #this is if you really really want the double quotes, otherwise just use cvs_name = 'results.csv'response = HttpResponse(csv_content,...
View ArticleRails filtering resource one to many through a joint table
I have the following resources:- restaurant- category- item- check itemRelationship:class Restaurant < ActiveRecord::Base has_many :items has_many :categories has_many :check_itemsclass Category...
View ArticleAnswer by Ciprian Tarta for Rails filtering resource one to many through a...
This appears to be the only way I found this to be working if anyone is interested.CheckItem.joins(:item => {:category => :restaurant}).where('category.uuid=? and restaurant.id=?', 123123, 1)
View ArticleRails routing resource in namespace starting with a parameter
I have 2 namespaces, api and v1I have accounts and users as resources.I want to map the routing as follows for all my resources:/api/v1/:account_id/:resource/:idi.e:/api/v1/1/users/2In the example 1...
View ArticleAnswer by Ciprian Tarta for Django transfer uploaded file
Apparently this line of code causes the problem:'Content-Disposition: form-data; name="file"; filename="%s"' % requestFile.name,The correct line would be instead:'Content-Disposition: form-data;...
View ArticleDjango transfer uploaded file
I'm trying to upload a file via django forms, then send it to an API.Here's the encoding function:#FYI, requestFile = request.FILES['file']def EncodeFile(self, requestFile, fields = []): BOUNDARY =...
View ArticleComment by Ciprian Tarta on Django - best way of storing data created on the...
showroom_devices.append({"before": device, "after": completed_device_name})
View ArticleComment by Ciprian Tarta on Angular 2 binding seems to be removed after an...
I've marked this as the correct answer. Also +1 @Günter since his input helped on figuring this out.
View ArticleComment by Ciprian Tarta on Angular 2 binding seems to be removed after an...
@GünterZöchbauer you are correct about change detection failing. I've used the ChangeDetectorRef and manually triggered detectChanges() and the template updates correctly. This is a bit of a hack, but...
View Article