Re: dynamic method calling

2008-11-22 Thread Steve McConville

> On Sat, Nov 22, 2008 at 2:38 AM, Chris <[EMAIL PROTECTED]> wrote:
>> Hello everyone,
>> I have a quick python question. Is they a better way of calling a
>> method dynamically then what I have below? Is there a more elegant
>> approach? Thanks in advance.
>>

try:
self.__class__.__dict__[method_name](self, argument)
except KeyError:
#handle missing method
pass

is pretty much equivalent to

try:
getattr(self, method_name)(argument)
except AttributeError:
# handle missing method
pass

Don't know if anyone would consider it more elegant but it doesn't use
getattr :)

-- 
steev
http://www.daikaiju.org.uk/~steve/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A Very Puzzling MySQL Issue Performance...

2009-02-06 Thread Steve McConville

> I think the effect you are seeing is more of MySQL thing than a Django
> thing, so that is where I'd be looking for a better idea of what the server
> is doing to speed up subsequent queries like this (in fact I think I recall
> reading about it at some point in reading up on MySQL, though I don't recall
> where).  I see a similar effect on my own MySQL DB, independent of Django.

You may have query caching turned on.

http://www.mysqlperformanceblog.com/2006/07/27/mysql-query-cache/

-- 
steev
http://www.daikaiju.org.uk/~steve/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Setting a default value for a select widget in a modelformset

2010-09-02 Thread Steve McConville
We have a modelformset created like this:

DocumentFormSet = modelformset_factory(Document, extra=0,
fields=('name', 'category')

with a models.py like this:

class Category(models.Model):
name = CharField(max_length=100)
# other stuff

class Document(models.Model):
name = CharField(max_length=100)
category = ForeignKey(Category)
# other stuff

When the DocumentFormSet renders, category appears as a select widget.

I have a variable in my request session that I would like to use to
set the initial value of the category widget.

What would be the best way to go about this? Is it necessary to create
a custom widget to achieve this?

-- 
steve

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django performance on Amazon EC2

2010-01-12 Thread Steve McConville
> EC2 m1.small instance, talking to another m1.small instance hosting MySQL db
>
> DB performance doesn't seem to be the issue - I don't see the DB server
> under any load at all.

What sort of network latencies are you seeing? Are they hosted in US-East-1?

http://alan.blog-city.com/has_amazon_ec2_become_over_subscribed.htm

-- 
steev
http://www.daikaiju.org.uk/~steve/
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Django performance on Amazon EC2

2010-01-12 Thread Steve McConville
> Yes, hosted in US-East-1, but I was running benchmark tests from another EC2
> instance in the same region, so reasonably sure it's not latency.

I meant latencies internal to EC2; eg. what is your ping time between
the frontend and the DB box? The article I linked to reports that this
has been observed to be rising in us-east-1. Sorry if that wasn't
clear.

-- 
steev
http://www.daikaiju.org.uk/~steve/
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Why does django use mysqldb over mysql-connector?

2012-05-03 Thread Steve McConville
> Has this happened by default or by design?  Is mysqldb really that much
> faster, or featureful, or just because it's more common?

>From http://forge.mysql.com/projects/project.php?id=302

"Development Status: Early (Pre-Alpha)"

-- 
steve

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Graphs for my Django Application

2012-06-08 Thread Steve McConville
> Can anyone give me idea how to provide graphs in Django.

Assuming you mean "graph" in the "graph theory" sense, then NetworkX
(http://networkx.lanl.gov/) is a mature graph library for python.

-- 
steve

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I am in trouble

2012-09-26 Thread Steve McConville
Instead of

> test.py:
>
> "
> from mod_python import apache
>def index(reg):
> retutn "test successful!"
> "
>

Try:

"
from mod_python import apache
def index(reg):
return "test successful!"
"

Note that there is no space preceding the 'def'. Indentation is meaningful
in python.

-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can you drop a Python script into a Django page?

2011-11-12 Thread Steve McConville
> Is it possible to drop a Python script (around 50 lines) into one of your
> django pages? Would this be embedding into the template code?

You could wrap it in a custom template tag:

https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/

-- 
steve

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .filter() and .exclude() don't add up

2013-07-26 Thread Steve McConville
Firstly (and I don't think this is the cause of the problem) you're
calling datetime.now() four times, which will give you four different
datetimes (ie. the queries will not be completely identical). Secondly
SQL uses a 3-valued logic (with null) so if any of the fields you're
filtering on are nullable you may not be able to rely on the law of
the excluded middle:

https://en.wikipedia.org/wiki/Null_(SQL)#Law_of_the_excluded_fourth_.28in_WHERE_clauses.29

On 26 July 2013 16:57, Daniele Procida  wrote:
> How is this possible?
>
> # we start with a queryset actual_events
>
> # get forthcoming_events using filter()
>
> forthcoming_events = actual_events.filter(
> Q(single_day_event = True, date__gte = datetime.now()) | \
> Q(single_day_event = False, end_date__gte = datetime.now())
> )
>
> # get previous_events using exclude() and exactly the same terms as above
>
> previous_events = actual_events.exclude(
> Q(single_day_event = True, date__gte = datetime.now()) | \
> Q(single_day_event = False, end_date__gte = datetime.now())
> )
>
> # And now:
>
> # actual_events.count():  467
> # forthcoming_events.count():  24
> # previous_events.count():442
>
> SInce I have run .filter() and .exclude() with identical terms, should they 
> not between them contain all the items in the queryset they acted upon, 
> *whatever* the terms used?
>
> Daniele
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: .filter() and .exclude() don't add up

2013-07-26 Thread Steve McConville
> So, if one of the fields can be Null, then *neither*:
>
> queryset.filter(field=value)
>
> queryset.exclude(field=value)
>
> will match a record where it's Null?

As I understand it, this is correct - it's certainly the way SQL was designed.

> In that case, is there a better - more reliable - way than using both 
> .filter() and .exclude() with the same terms to split a queryset into all 
> those items that match a filter, and all those that don't?

As well as doing the queries above, you can get the nulls by doing

queryset.filter(field__isnull=True)

and then it's just a matter of deciding which of your two sets the
nulls should be included in (probably with a logical OR). There are a
number of other approaches as well, but somewhere we'll still have to
decide what the meaning of null. My bias is towards making that
explicit. The other obvious approach is to find queryset.all() and
then the (null-less) set queryset.filter(field=value) and work with
them.

-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: .filter() and .exclude() don't add up

2013-07-27 Thread Steve McConville
Perhaps I'm not sure exactly what you mean by "more general", but I
was recommending something like

red_things = queryset.filter(Q(color="red"))
non_red_things = queryset.filter(~Q(color="red") | Q(color__isnull=True)

This will produce SQL like

SELECT * FROM queryset WHERE color IS 'red';
SELECT * FROM queryset WHERE color IS NOT 'red' OR color IS NULL;

The set non_red_things will be the complement of red_things.

-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django and PIL problem?

2011-01-10 Thread Steve McConville
Unlike some of the other methods in PIL "thumbnail" modifies the file
in place and returns None. This will probably do what you expect:

import Image
ARTICLE_LARGE_SIZE = 230,300
tmp_file = Image.open(form.cleaned_data['image'])
tmp_file.thumbnail(ARTICLE_SMALL_SIZE)
tmp_file.save(location + '/small.jpg', 'JPEG')


On 10 January 2011 15:09, galago  wrote:
> I try to create thumbnail via PIL
> import Image
> ARTICLE_LARGE_SIZE = 230,300
> tmp_file = Image.open(form.cleaned_data['image'])
> tmp_file = tmp_file.thumbnail(ARTICLE_SMALL_SIZE)
> tmp_file.save(location + '/small.jpg', 'JPEG')
>
> I get: 'NoneType' object has no attribute 'save'
> WTF?
> When i replace tmp_file.thumbnail to tmp_file.resize all is fine but i loose
> proportions:/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: write equation in django

2014-08-12 Thread Steve McConville
There are a number of ways to do this, but the most popular I think is
MathJax. There is a django app for assisting with it's integration here:
https://github.com/kaleidos/django-mathjax


On 12 August 2014 07:51, sandy  wrote:

> Hi,
> I want to include a mathematical equation in django project. Can anyone
> plz guide me as to where I should write the input to the equation, so as to
> see its output on the frontend screen.
>
>
> Thanks,
> Sandy
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5693b267-bb52-48d2-ae34-73a24e13836f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
steve
http://stevemcconville.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOoCU%3DQOYkj1Eo70iEWkwr8hVcOTebfCtWJUJfboWdi8wmtgyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django + microservices: What's correct approach?

2015-08-25 Thread Steve McConville
Hi Crohn.

You're asking a lot of related but very general questions here. I know
you are looking for someone who has "had the same problem" but we
don't know what your problem is. The whole point of any architecture
is that it's supposed to be a solution to your problems, not a problem
in itself :) If you tell us what you are trying to create (roughly
from the perspective of your users) and why you want to solve that
problem with microservices and Django, there may be sensible advice
people on the list can offer. Anyone who offers you architectural
advice before knowing what your system actually does is usually
selling something.

Many of the resources you'll need to learn about architecture and
about Django implementations will have been published before 2014, and
hence won't contain the word "microservices".

To address specific things you've asked (none of which are specific to
microservice architectures):

1. REST
Django is a HTTP application framework, and you can obviously use any
approach that HTTP supports, including REST. RESTful or RPC-like
services using JSON as a serialisation format are common.
Django-rest-framework is obviously geared towards REST :)

2. Deployment
The built-in runserver is only appropriate for development, and
certainly not for a services based approach. The normal way to deploy
django applications is with a WSGI server such as uwsgi or gunicorn.
These are typically run behind a reverse proxy or load balancer. If
you are planning to deploy many services, it's worth automating this
process as much as possible. There's good recommendations on how to
deploy Django for production in the docs:
https://docs.djangoproject.com/en/1.8/howto/deployment/

3. Performance analysis
Performance analysis of communicating services can be tricky. To
master it you'll need a grasp of distributed systems and queuing
theory and this will take a lot of reading, maths and experimentation.
There are books and software that can help you with this such as PPA:
http://www.perfdynamics.com/iBook/ppa.html

4. Async
Django is not designed to be an asynchronous server. Async webapps are
usually more complex than synchronous ones. You may be better off
either:
  a) using one of the queueing systems for Django
https://www.djangopackages.com/grids/g/workers-queues-tasks/
  b) using things like asyncio, gevent or twisted if you are *sure*
you need them.

I hope this is a helpful response, and good luck with your project!


On 25 August 2015 at 08:42, cr0hn  wrote:
> Thank you for your responses.
>
> I try to find some guide to create micro-services architecture using Django.
> I know that micro-service is a design paradigm, so I'm looking for the best
> way to implement it using Django (+ django-rest-framework).
>
> I also know that there're not a unique response, but I would like to answer
> questions like that:
> Create a Django project for each micro-service or all using the same
> project?
>
> Micro-services must communicate themselves using the same REST API, some way
> for better approach?
> How to deploy the project: Running "python manage.py runserver" or something
> like "python manage.py start MY_MICROSERVICE"?
> How to communicate the services for reduce response time and using async
> way?
>
> I know how to implement all of things above, but I'm looking for some
> recommendation of someone who have had the same problem or who has created
> micro-services with django.
>
> I hope I explained better now :)
>
> Regards.
>
>
> El lunes, 24 de agosto de 2015, 17:59:01 (UTC+2), Tom Christie escribió:
>>
>> Django REST framework is a general purpose API toolkit, and more than
>> capable of building microservice-type services. Likewise there are plenty of
>> frameworks in alternative languages that are also suitable for building APIs
>> that could be characterized as 'microservice'.
>>
>> The reason you're finding it hard to discover much on the subject is
>> probably due to microservices being an architectural style, rather than a
>> framework choice.
>>
>> Are there any *specific* technical issues that you're looking for help
>> with? What sort of service are you building, and is this for a Web App
>> frontend, a native client, both or something else?
>>
>> Aside: Unless you've got automated deployments nailed, great monitoring, a
>> heavily used service with a really nicely designed separation of concerns,
>> and a culture of personal responsibility for the engineers taking
>> code-to-deployment then the microservices probably (as a super-rough rule of
>> thumb) isn't worth the extra up-front infrastructure it requires.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this d