Re: How to load only the body of a page?

2009-06-26 Thread Jani Tiainen

akaariai kirjoitti:
> Hello all,
> 
> I have some problems when trying to load only part of the page (
> for example) in AJAX calls without duplicating page structure in
> multiple templates.
> 
> I have my base.html (in reality the structure is much more complex,
> but that doesn't matter for this example):
> 
> 
> ...
> 
> 
> {%block content%}{%endblock%}
> 
> 
> {%block links%}{%endblock%}
> 
> 
> 
> 
> For some AJAX calls, I need to reload the body of the page. That is, I
> need to get the structure of the body to be similar as is in the
> base.html. The problem is I can't find a way to do this without
> duplicating the structure of the page in the AJAX template.
> 
> I have tried to put the  part inside another template,
> base_body.html, which I could extend in my AJAX calls. I tried to
> include (or ssi) that in base.html. But this way I cannot override the
> content and links blocks when extending directly the base.html. I
> cannot directly use the base.html when doing AJAX call for the body,
> because this way I will get the  and  elements again
> loaded in my AJAX call.

I did something similiar with two different approaches. Never really 
figured out which one was better way to do it:

Define your body like:

{% block body_contents %}
  {%block content%}{%endblock%}
  
  
  {%block links%}{%endblock%}
  
{% endblock %}

Now there is two ways - add following to your header:

{% extends parent_template %}

And write two templates:

"full.html" which is like:


...


{% block body_contents %}{%endblock%}



And "ajax.html"

{% block body_contents %}{%endblock%}

And in your view you do something like:

if request.is_ajax():
parent_template = 'ajax.html'
else:
parent_template = 'full.html'

return render_to_response('my_template.html', { 'parent_template' : 
parent_template, } ... )

Or, create just a full one and
then I did following:

def ajax_render_to_response(request, template_name, dictionary=None, 
context_instance=None, **kwargs):
 """
 Returns a HttpResponse whose content is filled with the result of 
calling
 django.template.loader.render_to_string() with the passed arguments.
 """

 httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
 if request.is_ajax():
 return HttpResponse(loader.render_to_string(template_name, 
dictionary, context_instance**kwargs), **httpresponse_kwargs)
 else:
 dojango_template = Template("""
 {%% extends "full.html" %%}
 {%% block body_contents %%}
 {%% include "%s" %%}
 {%% endblock body_contents %%}
 """ % template_name )
 if context_instance:
 context_instance.update(dictionary)
 else:
 context_instance = Context(dictionary)
 return HttpResponse(dojango_template.render(context_instance), 
**httpresponse_kwargs)


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: MS Word Characters

2009-07-28 Thread Jani Tiainen

cootetom kirjoitti:
> Hello,
> 
> I'm having some trouble with strange characters that come from MS
> Word. User's are copying text from MS Word, pasting it into a textarea
> on the site. I then save that text into MySQL (table charset is set to
> utf-8). Then later I retrieve that data to create a RTF document then
> an email it to somebody. The problem is that a lot of characters from
> word aren't displaying correctly.
> 
> Example an " will return \xe2\x80\x93 from the database. What type of
> encoding is that?

Hex representation of UTF-8 character.

Except that it can't be quote but punctuation dash

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: javascript variable in url resolver template tag

2009-08-10 Thread Jani Tiainen

Sven Richter kirjoitti:
> Ok, i think i understand the problem now.
> So i have to hardcode the url in my javascript function?
> That was what i wanted to circumvent.

No you don't have to.

There is two ways, either you just use base URL like {% url url_name %} 
and send parameters as POST (or well, you can do GET params if you like 
to) or construct rest of the URL in JS.

Personally I'm always doing it with POST parameters in Ajax. It's just 
simpler that way.

One reason not to use hardcoded URL's is avoid modifying scripts when 
deploying. Specially when you start deploying same project many times to 
suburls it starts to come pretty valueble to have template resolving URL.

> On Sun, Aug 9, 2009 at 5:57 PM, Daniel Roseman  > wrote:
> 
> 
> On Aug 9, 4:43 pm, Sven Richter  > wrote:
>  > Hi all,
>  >
>  > i wanted to know if it is possible to pass a Javascript variable to
>  > the url template tag?
>  >
>  > Like:
>  > 
>  > ...
>  > 

Re: Ajax in Django

2009-08-12 Thread Jani Tiainen

HB kirjoitti:
> Hey,
> Why Django doesn't provide integration with Ajax out of the box (like
> Rails and Wicket)?

It all depends what you mean by "integration"?

You can use (model)forms with Ajax, or use any other means if you wish.

Only thing that django doesn't provide is Ajax form rendering - I mean 
that you can't just say {{ form }} and magically get ajaxafied form.

And there is good reason - what would be javascript framework to use 
then? MooTools? jQuery? Prototype? ExtJS? Or my favourite Dojotoolkit (I 
bet there is dozen of others that I don't remember or are aware of)

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Theory: Models/Apps

2009-08-14 Thread Jani Tiainen

Vadivel Kumar kirjoitti:
> I have recently started on Django .. going awesome .. I know, this 
> question might have popped out several times before, but since Google 
> does not yield me any results, I am writing this post. However, do point 
> out resources if any in this mailing list.
> 
> 1. What is the fundamental difference of APP versus PROJECT in Django 
> terminology. For instance, is it right to say, POSTS is an APP and BLOG 
> is a PROJECT or ORDERS is an APP and ORDER_MANAGEMENT is a PROJECT ..
>
> 2. Particularly, I don't like the idea of using a single models.py for 
> many entities, I would rather to keep separate files for each of entity 
> .. in a scenario like a huge team is working on a project, this approach 
> will create unnecessary noise. Any answers?

http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3

There is answers to both your questions.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Using glovar vars

2009-08-14 Thread Jani Tiainen

Steve Patrick kirjoitti:
> Hi everybody,
> I´m new in Django and maybe my problem is a bit stupid...I would like
> to use a global variable (for all the application) to store some info

No you don't want to. And even it's possible in theory, you shouldn't 
even consider that option.

> that I get in my firts page. I know I can send variables using
> render_to_response, but is there any other easy way??is it possible to
> define a global variable, initialize it in my first page and just use
> it??

Store value in session?

First at all, your variable would only live time of request (meaning 
from the moment URL is parsed and reponse is sent to your browser). What 
  happens to your "global" after that? It wouldn't exist on next request.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Using glovar vars

2009-08-15 Thread Jani Tiainen

Graham Dumpleton kirjoitti:
> 
> 
> On Aug 14, 10:13 pm, Jani Tiainen  wrote:
>> Steve Patrick kirjoitti:
>>
>>> Hi everybody,
>>> I´m new in Django and maybe my problem is a bit stupid...I would like
>>> to use a global variable (for all the application) to store some info
>> No you don't want to. And even it's possible in theory, you shouldn't
>> even consider that option.
>>
>>> that I get in my firts page. I know I can send variables using
>>> render_to_response, but is there any other easy way??is it possible to
>>> define a global variable, initialize it in my first page and just use
>>> it??
>> Store value in session?
>>
>> First at all, your variable would only live time of request (meaning
>> from the moment URL is parsed and reponse is sent to your browser). What
>>   happens to your "global" after that? It wouldn't exist on next request.
> 
> That is not true.

Yes, I lied. But that request lifecycle is only (safe) assumption you 
can make.

> Global variables at Python module scope will last for the life time of
> the process.

Yes, but who will guarantee that process will live forever? Or in latter 
case:

> That said, you must still be careful about using them because server
> may be multiprocess and/or multithreaded, both of which causes issues
> with doing it that way.

What happens if different requests are passed to totally different 
processes - then that global var might not be the same.

Of course if environment where processes, threads and lifecycle is very 
controlled and project is kind of one time fire-and-forget it would work.

If that variable is so important, memcached and standard django cache 
API can help there also pretty well. And it's safer.

Like I've in my current project one configuration table in database - I 
don't want to read it from DB everytime I access something, so I put it 
very conveniently in shared memcached. There all Django instances that 
have my same app can access it. Very fast, very convenient. And I really 
don't have to figure out any details of globals and threading and/or 
multiprocess problems

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: models with filestore backend (no database)

2009-09-07 Thread Jani Tiainen

Howard kirjoitti:
> 
> Wondering whether there is example code/docs relating to models
> without databases, but where individual model instances are mapped to
> (say) a file. Alternatively put, where the back-end data store for the
> app are files, not DB tables. Despite much searching I can't find
> anything definitive (maybe I am using the wrong search terms)
> 
> We have a directory full of binary files; the file names contain id
> and date information for crude indexing. New files are created by an
> external process throughout the day. Each binary file is essentially a
> single model instance. In essence, we want to browse the files on the
> web. We have existing python code to read the files. There will be no
> file writes, only reads.
> 
> I am reluctant to use any DB so as to keep things very simple as the
> code could end up in an embedded and "offline" remote system, so less
> is more.
> 
> Is it just a question of overriding Model or is there a simpler way I
> am missing?

There is not really simple way achieve all that. Django more or less 
assumes that you have SQL and python DB API compliant backend.

Since you like files, what's wrong with SQLite? It's embedded file based 
database engine. You can rather easily write piece of code that injects 
your file objects in sqlite database and then use standard django access 
to read them. Since you already have code to read, making code to inject 
new entries to sqlite db is quite trivial.

And since sqlite is embededd it doesn't need externel dependencies. And 
it's been included in python since version 2.5.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django, Dojo and JSON-RPC

2009-04-06 Thread Jani Tiainen

I've been trying to find out nice solution to handle JSON-RPC with 
Django and Dojo (Dojango).

So far not much avail. Has anyone succeeded with this? Care to share 
what kind of packages do I need to make it working with preferably 
automated SMD generations.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Django, Dojo and JSON-RPC

2009-04-06 Thread Jani Tiainen

Top posting is not my favorite one.

I'm using Dojo JSON-RPC service. Previously with PHP + Zend I got almost 
automated JSON-RPC server + SMD generation.

I'm using dojo.rpc.JsonService to for example save and retrieve data in 
Web 2.0 manner. Works great. I found nice solution with (or without) SMD 
and it works great. No need for manual xhr calls which your solution used.

Only thing I'm still missing is automatic SMD generation from method 
signatures but that's minor inconvience.

Rob Goedman kirjoitti:
> Jani,
> 
> Not sure what you are trying to achieve. Wolfram suggested below 
> solution to me a while ago and I'm happy with it.
> 
> Rob
> 
> On Apr 6, 2009, at 3:14 AM, Jani Tiainen wrote:
> 
>>
>> I've been trying to find out nice solution to handle JSON-RPC with
>> Django and Dojo (Dojango).
>>
>> So far not much avail. Has anyone succeeded with this? Care to share
>> what kind of packages do I need to make it working with preferably
>> automated SMD generations.
>>
>> -- 
>> Jani Tiainen
>>


-- 
Jani TiainenTeollisuuskatu 13 tel. +358-13-223523
Keypro Oy   80100 JOENSUU GSM  +358-50-5922404
http://www.keypro.fi/   FINLAND   fax  +358-13-223467

--~--~-~--~~~---~--~~
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: Run context processor conditionally?

2009-05-06 Thread Jani Tiainen

How you do that? Everywhere I look, documentation states that view is a 
"function" (well there is few places where is mentioned "callable").

Small example would be nice.

George Song kirjoitti:
> There's no reason a view needs to be a function. You can easily make 
> views out of classes. In which case you can stuff some of these things 
> in the class __init__ and not have to about them for each view.
> 
> On 5/6/2009 3:37 PM, ringemup wrote:
>> Hm, and RequestContext has to be instantiated from every view for
>> which one wants to use the context processor anyway, huh?
>>
>> I always feel like I'm repeating myself when passing global context to
>> every single template.
>>
>> On May 6, 5:13 pm, George Song  wrote:
>>> On 5/6/2009 1:37 PM, ringemup wrote:
>>>
>>>> I've got some context that every view in one of my apps needs to pass
>>>> to its templates... but that I don't want to have to run for pages
>>>> that don't use that app, since it executes a lot of queries.  Is there
>>>> a way to execute the context processor only for views defined in that
>>>> app's URL conf or something?
>>> You can specify extra context processors to use with RequestContext in
>>> your view:
>>>
>>> <http://docs.djangoproject.com/en/dev/ref/templates/api/#id1>
> 


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Splitting monolithic

2009-05-12 Thread Jani Tiainen

Hi,

I'm seeking for advices (or solutions) how to split my current 
monolithic application to more modular, smaller pieces.

I've legacy database containing about 140 tables which are mapped to 
models. One key feature is "enum" table that has hundreds of enum-kind 
values (used mostly in value selection lists). Almost every other table 
has one or more foreign keys to this "enum" table.

Currently my application is constructed from following parts:
  * Models
  * Business logic
  * Dojo dijit-widget html-forms that are fetched with AJAX query
  * JSON-RPC functions

So how to split it up in smaller independent apps?
Build some core that contains model + business logic that is not 
application specific and then separate form, JSON-RPC functions and 
application specific business logic in this same app module?



-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Plugin technology

2009-05-23 Thread Jani Tiainen

I'm designing application (site) that is supposed to rely heavily on 
pluings.

i didn't found much of references how I can create plugin that can 
provide something useful for my main template. something like:

myplugin.py:

provide_link = "MyPlugin"

And then in my "core" application template:
templates/mycore/mycore.html:

{% for plugin in allplugins %}{{ plugin.provide_link }}{% endfor %}


Any pointers to such apps or snippets that uses this (or similiar) 
tehcnique would be appreciated.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Plugin technology

2009-05-23 Thread Jani Tiainen

George Song kirjoitti:
> On 5/23/2009 5:13 AM, Jani Tiainen wrote:
>> I'm designing application (site) that is supposed to rely heavily on 
>> pluings.
>>
>> i didn't found much of references how I can create plugin that can 
>> provide something useful for my main template. something like:
>>
>> myplugin.py:
>>
>> provide_link = "MyPlugin"
>>
>> And then in my "core" application template:
>> templates/mycore/mycore.html:
>>
>> {% for plugin in allplugins %}{{ plugin.provide_link }}{% endfor %}
>>
>> Any pointers to such apps or snippets that uses this (or similiar) 
>> tehcnique would be appreciated.
> 
> Well, if you break down the problem, it really is just two things:
> 
> 1. Registry
> 2. Interface
> 
> Registry
> 
> The registry takes care of the part that when you create a new plugin, 
> it should be registered somehow as a plugin.
> 
> Django itself is full of this pattern: models, template tags, filters, 
> admin sites, databrowse, serialization, etc. You can look to those for 
> ideas and inspirations. The most sophisticated being the models which 
> relies on a metaclass to do its implicit registration magic.

This one I've solved by metaclass registration magic. And this was the 
easy part of whole plugin system.

> Interface
> =
> This is really internal to the specific plugin domain, so depending on 
> your needs, you can enforce it a number of ways: simple documentation of 
> the superclass, putting in a stub of NotImplemented, etc.
> 

I believe in duck typing (documentation of the superclass) rather than 
explicitly forcing something.

I'm just searching for reference implementations how to make something 
visible in my template.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Plugin technology

2009-05-23 Thread Jani Tiainen

Kai Diefenbach kirjoitti:
> Hi Jani,
> 
> On 23 Mai, 14:13, Jani Tiainen  wrote:
>> I'm designing application (site) that is supposed to rely heavily on
>> pluings.
>>
>> i didn't found much of references how I can create plugin ...
> 
> You may look into this article: 
> http://martyalchin.com/2008/jan/10/simple-plugin-framework/

I already did. it just didn't (Or I missed somehow) how to make 
something like "toolbar" buttons in plugin that could be injected to my 
main template.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Plugin technology

2009-05-23 Thread Jani Tiainen

George Song kirjoitti:
> On 5/23/2009 8:53 AM, Jani Tiainen wrote:
>> Kai Diefenbach kirjoitti:
>>> Hi Jani,
>>>
>>> On 23 Mai, 14:13, Jani Tiainen  wrote:
>>>> I'm designing application (site) that is supposed to rely heavily on
>>>> pluings.
>>>>
>>>> i didn't found much of references how I can create plugin ...
>>> You may look into this article: 
>>> http://martyalchin.com/2008/jan/10/simple-plugin-framework/
>> I already did. it just didn't (Or I missed somehow) how to make 
>> something like "toolbar" buttons in plugin that could be injected to my 
>> main template.
> 
> If you're using Marty's pattern, why don't you just pass the mount point 
> as a context variable to your template, then you can easily loop through 
> the plugins that way, right?
> 

I did tried that, maybe I just did something a bit wrong since it didn't 
  seemed to work.

Static text worked but when ever I wanted to print something from 
template I got quite interesting errors, like {% url %} templatetag gave 
always errors.

It's kind of interesting that no-one has built "real" plugin based 
system on top of Django. Using just plain apps works without a hitch.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Connecting to Legacy Oracle Tables

2009-05-23 Thread Jani Tiainen

Ian Kelly kirjoitti:
> On May 22, 10:59 am, Christina  wrote:
>> Hi all,
>>
>> I'm trying to set up a new Django app that will have several models
>> based on existing Oracle tables.  I'm running Django 1.0.2, python
>> 2.5.1 and cxOracle 5.0.1.
>>
>> These tables are in a different schema than the one Django connects
>> with, so based on previous discussion here I created views of the
>> tables in my schema.  I've set db_table to the name of the view in
>> models.py.  When I run syncdb I receive the error:
>> "cx_Oracle.DatabaseError: ORA-00955: name is already used by an
>> existing object."  So it appears to be creating a new table instead of
>> recognizing the existing view.  Any ideas on what I can do to get it
>> to recognize that the view exists and use that for the backend for my
>> model?
> 
> Hi Christina,
> 
> Syncdb doesn't currently recognize views or synonyms correctly.  If
> you have apps with models that need to be created, run manage.py
> sqlall on those apps, and pass the resulting sql into sqlplus or
> manage.py dbshell.  You can also edit the generated sql by hand before
> running it, if you need finer-grain control.

In development version there is also very handy "managed" meta option 
that works very well with legacy apps when set to 'false'.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: reset button question

2009-05-25 Thread Jani Tiainen

Bobby Roberts kirjoitti:
> i'm trying to put a simple reset button on a form but it's not
> working  Why wouldn't a standard html reset button be working?

No reason but you definitely shouldn't put reset button on a form in a 
first place [1].


[1] http://www.useit.com/alertbox/20000416.html
-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: How to pass 2 list as one in template

2009-05-28 Thread Jani Tiainen

laspal kirjoitti:
> Hi,
> I have 2 list and want to iterate as one in template.
> How can I do it.
> example->
> list1 = [10,20,30,30]
> list2 = [aa,bb,cc,dd]

combinedlist = ( (a[x],b[x]) for x in range(len(a)) )

> {% for item in list1 and item1 in list2 %}

{% for item,item1 in combinedlist %}

> {{item}} {{item1}}
> 
> {% endfor%} {% endfor %}
> 

You could try that one.

Of course, if you can put values in tuples while generating list(s) it 
would be much more efficient than joining them afterwards.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: How to pass 2 list as one in template

2009-05-28 Thread Jani Tiainen

Masklinn kirjoitti:
> On 28 May 2009, at 15:30 , Alex Gaynor wrote:
>> On Thu, May 28, 2009 at 8:11 AM, Masklinn   
>> wrote:
>>
>>> On 28 mai 09, at 14:55, Jani Tiainen  wrote:
>>>> laspal kirjoitti:
>>>>> Hi,
>>>>> I have 2 list and want to iterate as one in template.
>>>>> How can I do it.
>>>>> example->
>>>>> list1 = [10,20,30,30]
>>>>> list2 = [aa,bb,cc,dd]
>>>> combinedlist = ( (a[x],b[x]) for x in range(len(a)) )
>>>>>
>>> Reinventing zip (or, in this precise case, itertools.izip) might not
>>> be as simple as just using them though.
>>>
>> I don't think he's looking for zip, it sounds like he wants  
>> itertools.chain,
>>
>> from itertools import chain
>>>>> chain([1,2,3], [3,2,1])
>> [1,2,3,3,2,1]
>  From his initial example, it looks like zip more than chain, but in  
> any case I was responding to Jani whose answer is a reimplementation  
> of izip ;)

True :) I'm very good at reinventing wheels... :) (Well, it's just 
my very rusty Python skills tbh.).

But yes, original seemed to be izip (or izip_longest) whichever may fit.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Saving Oracle Connection across requests

2009-09-15 Thread Jani Tiainen

There exists Oracle connection pool daemon and django backend to utilize 
it. Check http://code.google.com/p/pyorapool/

Connecting to Oracle is rather slow operation and if possible you really 
like connection pooling.

Though even I'm using ajax based system to rather db intensive app that 
gets quite lot of request so far I've not seen necessity to use 
connection pooling. Normal roundtrip (django server is on different 
hardware than Oracle, connected using gigabit backplane) normal 
roundtrip is around 350ms. More speed could be obtained with Django 
caching mechanisms.

Rafael Ferreira kirjoitti:
> If you are on 11g you can try to use this:
> 
> http://www.oracle.com/technology/tech/oci/pdf/oracledrcp11g.pdf
> 
> otherwise you can look for something like mysqlproxy for oracle (if such 
> thing exist). 
> 
> The real question here tho is why do you care so much about reusing 
> connections? I can tell you that connection pooling is not all that is 
> cracked up to be. 
> 
> - raf
> 
> On Mon, Sep 14, 2009 at 6:18 AM, lfrodrigues  <mailto:lfrodrig...@gmail.com>> wrote:
> 
> 
> Hello,
> 
> I'm not sure this is possible but I would to save a oracle connection
> across several requests (like I do with a normal object)
> 
> I would like to:
> 
> if 'object' in request.session:
>  do stuff
> else:
>  import cx_Oracle
>  conn = cx_Oracle.connect(constring)
>  request.session['object'] = conn
>  do stuff
> 
> Since this doesn't work I thought about a global variable on
> settings.py but that only works on de dev server. Apache uses multiple
> processes so the global variable has different values depending of the
> process.
> 
> Any ideas how to keep a persistent connection across requests?
> 
> Thanks
> 
> 
> 
> 
> > 


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Multi table inheritance and reverse lookup

2009-09-22 Thread Jani Tiainen

model.py:

from django.db import models

class Order(models.Model):
 name = models.CharField(max_length=64)

 def __unicode__(self):
 return self.name

class Product(models.Model):
 name  = models.CharField(max_length=64)

 def __unicode__(self):
 return self.name

class SubProduct1(Product):
 prop1 = models.FloatField()

 def __unicode__(self):
 return self.name

class SubProduct2(Product):
 prop2 = models.EmailField()

 def __unicode__(self):
 return self.name

class OrderProduct(models.Model):
 order = models.ForeignKey(Order)
 product = models.ForeignKey(Product)

 amount = models.IntegerField()

 def __unicode__(self):
 return u'%s - %s - %s' % (self.order.name, self.product.name, 
self.amount)


Now it's trivial play with sub products and add spesific subproducts to 
orderproduct.

But, then, how to list all SubProducts that belongs to spesific order?

Specially thing stops at "Product", it doesn't know which one of those 
two subproducts it actually is.

I did following quick hack to get around this problem (added this to 
Product model):

 def _get_subproduct(self):
 for attr in ['subproduct1', 'subproduct2', ]:
 try:
 return getattr(self, attr)
 except ObjectDoesNotExist:
 pass

 subproduct = property(_get_subproduct)


This just don't feel optimal solution, specially it hits database for 
every subitem tried.

Any better way to achieve same without hitting that much database?

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Multi table inheritance and reverse lookup

2009-09-22 Thread Jani Tiainen

Jani Tiainen kirjoitti:
> model.py:
> 
> from django.db import models
> 
> class Order(models.Model):
> name = models.CharField(max_length=64)
> 
> def __unicode__(self):
> return self.name
> 
> class Product(models.Model):
> name  = models.CharField(max_length=64)
> 
> def __unicode__(self):
> return self.name
> 
> class SubProduct1(Product):
> prop1 = models.FloatField()
> 
> def __unicode__(self):
> return self.name
> 
> class SubProduct2(Product):
> prop2 = models.EmailField()
> 
> def __unicode__(self):
> return self.name
> 
> class OrderProduct(models.Model):
> order = models.ForeignKey(Order)
> product = models.ForeignKey(Product)
> 
> amount = models.IntegerField()
> 
> def __unicode__(self):
> return u'%s - %s - %s' % (self.order.name, self.product.name, 
> self.amount)
> 
> 
> Now it's trivial play with sub products and add spesific subproducts to 
> orderproduct.
> 
> But, then, how to list all SubProducts that belongs to spesific order?
> 
> Specially thing stops at "Product", it doesn't know which one of those 
> two subproducts it actually is.
> 
> I did following quick hack to get around this problem (added this to 
> Product model):
> 
> def _get_subproduct(self):
> for attr in ['subproduct1', 'subproduct2', ]:
> try:
> return getattr(self, attr)
> except ObjectDoesNotExist:
> pass
> 
> subproduct = property(_get_subproduct)
> 
> 
> This just don't feel optimal solution, specially it hits database for 
> every subitem tried.
> 
> Any better way to achieve same without hitting that much database?

Or rather I would like to make "product" proterty in OrderProduct to 
return correct subtype right away since I'm not really interested in 
Product model itself but spesific sub types.

Should I do something like:


class OrderProduct(models.Model):
 order = models.ForeignKey(Order)
 product_ = models.ForeignKey(Product)

 amount = models.IntegerField()

 def _get_product(self):
 return product_.subproduct

 product = property(_get_product)

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: how to open a new page when clicking a url

2009-09-22 Thread Jani Tiainen

li kai kirjoitti:
> Hi,
> 
> How to implement this in my template html file?
> 
> When an user clicks an url address, a new webpage will pop up.

That is standard behaviour of any browser that I know of. Or did you 
meant something else?

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: how to open a new page when clicking a url

2009-09-22 Thread Jani Tiainen

That is something that is not Django specific but can be found in HTML 
specification.

HINT: "target" attribute in ""-tag.

Depending on browser (and/or plugins in browser) results may vary.

li kai kirjoitti:
> Suppose I have these items in my homepage's header.
> 
> * E-shop <http://127.0.0.1:8000/ecshop/>
> * E-coupon <http://127.0.0.1:8000/photoes/ecoupons/>
> 
> source code :
>E-shop
> E-coupon
> 
> 
> Now, I click the "E-shop" item, it will jump to the E-shop address in my 
> current web browser window.
> But I expect it open a new web browser window and jump to the web address.
> 
> Just like this:
>   We click the search results of  google search result, and a new page 
> will pop up.
> 
> Did I make it clear?
> 
> On Wed, Sep 23, 2009 at 1:22 PM, Jani Tiainen  <mailto:rede...@gmail.com>> wrote:
> 
> 
> li kai kirjoitti:
>  > Hi,
>  >
>  > How to implement this in my template html file?
>  >
>  > When an user clicks an url address, a new webpage will pop up.
> 
> That is standard behaviour of any browser that I know of. Or did you
> meant something else?
> 
> --
> Jani Tiainen
> 
> 
> 
> 
> > 


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Jani Tiainen

Chris Withers kirjoitti:
> Brian McKeever wrote:
>> .count is definitely the way to go. Although, I would probably pass it
>> to your template instead of determining it there.
> 
> What difference does it make?

len(qs) evaluates queryset - thus pulling in _every_ object from DB to 
Python - which you might not want specially if queryset is large.

.count() executes count query on DB side returing only single scalar 
value to Python.

Figure out which one is faster...

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: What JavaScript framework do you use and why?

2009-09-27 Thread Jani Tiainen

Joshua Russo kirjoitti:
> Great links guys, thanks. I'm still in the mindset of frameworks just 
> making JavaScript less painful too and I'm looking for ways to move 
> beyond that. I just started looking at Dojo before posting this and it 
> definitely looks like it has potential.

I'm pretty "heavy" user of Dojo. My project is completely built on top 
of Django/Dojo using JSON-RPC to do talk with Django part.

I'm pretty happy how it works, specially declarative way to make widgets 
is pretty cool comparing to other that usually require JS markup to 
achieve same thing.

Dojango is pretty nice. I just don't use (model)forms all.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Performing a db operation at session end

2009-09-28 Thread Jani Tiainen

gontran kirjoitti:
> Hello,
> 
> I would like to know if it's possible to automatically perform a db
> operation at the end of a session.
> 
> For example: a client book an item in a store but don't ckeck out his
> cart and close his browser. The item booked (which was unavailable
> during the session) is now available for other clients.
> 
> Any help will be nice.

In theory "you can't do that". You just don't know moment end user 
closes browser and there is very little you can do about it.

One option is to use some reservation lifetime (and tell it to user 
too). Like "your book is reserved for you exclusively next 10 minutes". 
After that it will be free for next reservation. And buyer might need to 
wait in queue to get his/her book.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Does the auto_now attribute do updates even if the same data is inserted?

2009-09-28 Thread Jani Tiainen

Iqbal Abdullah kirjoitti:
> Hi guys,
> 
> I have a quick question:
> 
> I have set auto_now=True for one of my DateTimeFields.
> 
> Lets say I have a model object like so:
> 
>>> a = MyModel.objects.get(id="10")
>>> print a.id
>>> "10"
>>> a.id = "10"
>>> a.save()
> 

Yes.

Django doesn't have "dirty" flag in models or do field by field compare.
So it will always issue insert/update clause when you do "save".


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: What JavaScript framework do you use and why?

2009-09-30 Thread Jani Tiainen

Joshua Russo kirjoitti:
> On Mon, Sep 28, 2009 at 4:00 AM, Jani Tiainen  <mailto:rede...@gmail.com>> wrote:
> 
> 
> Joshua Russo kirjoitti:
>  > Great links guys, thanks. I'm still in the mindset of frameworks just
>  > making JavaScript less painful too and I'm looking for ways to move
>  > beyond that. I just started looking at Dojo before posting this
> and it
>  > definitely looks like it has potential.
> 
> I'm pretty "heavy" user of Dojo. My project is completely built on top
> of Django/Dojo using JSON-RPC to do talk with Django part.
> 
> I'm pretty happy how it works, specially declarative way to make widgets
> is pretty cool comparing to other that usually require JS markup to
> achieve same thing.
> 
> Dojango is pretty nice. I just don't use (model)forms all.
> 
> 
> Do you use the Admin app at all? Or are your sites all just custom views?  

I use admin app for administrative tasks, mainly setting different 
dynamic configs and to lookup data but it's meant for people "who knows 
what they are doing" since it's possible to break things by using admin 
interface.

Most of the program consists single page that dynamically loads 
templates, JSON and invokes JSON-RPC calls.

I've developed my own set of "RPC Forms" that works better in RPC 
concept and also they provide some my application domain spesific 
features like automated query construction (same form is used for CRUD 
operations)

Main reasons was that we needed "nice" UI widgets (containers, tabs, 
floating windows, buttons, tools, dropdowns and all that "desktop like" 
features), liberal licence and somewhat solid, mature product.

Another real option was ExtJS.


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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 magic to support i18n models

2009-10-04 Thread Jani Tiainen

k88 kirjoitti:
> Given the following models
> 
> class Product(models.Model):
> price = models.IntegerField()
> 
> class Product1I18n(models.Model)
>parent = models.ForeignKey(Product)
>language = models.CharField(max_length=2)
>title = models.CharField(max_length=255)
>description = models.TextField()
> 
> is it possible somehow to patch/override/extend/replace the Product
> model to act as a ProductI18n when managers process/access it for the
> db query creation ?
> 
> My main concern is select (filter) queries, so that the following
> statement:
> 
> Product.objects.filter(price=10,language='en')
> 
> to act as
> 
> Product.objects.filter(price=10,producti18n_set__language='en')
> 
> any suggestion ?

Have you looked at django-multilingual (in google groups)? It provides 
more or less automatic translation system.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: ORM

2009-10-07 Thread Jani Tiainen

Geobase Isoscale kirjoitti:
> Hi Everyone, 
> 
>  I intend to write ORM code that will create views and triggers in the 
> database? Which parts of the source code should I alter?

None...

There already exists mechanism to run arbitary SQL after syncdb...

Or did you meant something else since I'm not sure what you mean by 
"views" and "triggers" and how they are related to ORM...

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: ORM

2009-10-07 Thread Jani Tiainen

Geobase Isoscale kirjoitti:
> I have to live with this reality, maybe in future we might  develop a 
> code to extend Django to support views and triiggers. 

I don't get the use case here. What is this need for adding views and 
triggers? What purpose they serve for ORM?

For database they're pretty handy to do business logic if there is data 
incoming form external resources that are not passed through ORM that 
can take care of all that mess but this can already be done with Django.

There is (standard) way to add arbitary SQL scripts that are ran after 
django tables and such are generated or it can be done quite easily 
manually.

Could you provide some examples what you're trying to achieve to shed 
some light here..?

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: how to design mobile version of my site based on django?

2009-10-10 Thread Jani Tiainen

hao he kirjoitti:
> I'm developing my site with django,
> 
> mainly, my site works as normal, visited by PC.
> 
> but ,the site will also be visited by mobile device(e.g.iphone)
> 
> who tell me the solution?
> 
> or recommend me some relevant articles?

This has almost nothing to do with Django.

It's just what to display for smaller display devices and simples way is 
to use simplified versions of huge pages. If your site is "normal", 
there is not much of need to do anything. Standard HTML, CSS and even JS 
works in most mobile devices without problems.

Of course you might want to limit amount of data sent over network since 
mobile speeds aren't that high. So you might want to use some detection 
about "this is mobile device" (maybe there is some magic header that 
reveals it) and forward user to a bit more lightweight page(s) instead 
of using heavy, large screen pages meant for large display computers.

Easiest way is to test your site with mobile and see does it work or not.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Model Class Inheritance question

2009-10-10 Thread Jani Tiainen

whiskeyjuvenile kirjoitti:
> I'm making some sort of galactic map with the following classes
> defined in models.py:
> 
> class Star(models.Model):
> name = models.CharField(max_length=200)
> xcoord = models.FloatField()
> ycoord = models.FloatField()
> zcoord = models.FloatField()
> def __unicode__(self):
> return self.name + ' (' + str(self.xcoord) + ', ' + str
> (self.ycoord) + ', ' + str(self.zcoord) + ')'
> 
> class Satellite(models.Model):
> name = models.CharField(max_length=200)
> description = models.TextField(blank=True, null=True)
> system = models.ForeignKey(System, related_name='satellites')
> def __unicode__(self):
> return self.name
> 
> class Planet(Satellite):
> orbital = models.IntegerField()
> 
> class Moon(Satellite):
> suborbital = models.IntegerField()
> orbits = models.ForeignKey(Planet, related_name='moons')
> 
> What should I do so I can refer to an s.planets object containing all
> objects of class Planet with system==s?
> 
> it seems like Star should have added
> def _get_planets(self):
> return self.planets
> def _set_planets(self, planet):
> self.planets.append(planet)
> planets = property(_get_planets, _set_planets)
> 
> and Planet should have something like
> def __init__(self, *args, **kwargs):
> super(Planet, self).__init__(*args, **kwargs)
> self.star.planets.append(self)
> def save(self):
> super(Planet, self).save()
> 
> Does this look accurate?

No. It seems that there is something wrong. There is no relation between 
Star and Satellite, Planet or Moon. Releation is made between System (?) 
and Satellite and Satellite has one to one relation to Planet And Moon 
(comes from inheritance).

To get all Planets in system it should be something like:

Planet.objects.filter(system=s) and that's it. Nothing complicated. But 
to get all Planets from System is a bit more trickier since there 
doesn't exist that reverse relation directly.

So first you need to fetch all Systems that has Satellite that has 
Planet. something like 
System.objects.filter(satellites__planet_set__isnull=False)

A bit tricky. If you don't want to have own table for Satellite, make it 
to abstract and then Planet and Satellite both will be pure concrete 
classes (then of course you can't have single "satellites" but both 
inherited concrete classes do need their own reverse relations.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Distance across a LineString in GeoDjango

2009-10-11 Thread Jani Tiainen

HARRY POTTRER kirjoitti:
> I have a model which represents a route. I can use the `make_line()`
> geoqueryset method to create a LineString like so:
> 
>>>> r = Route.objects.get(pk=33)
>>>> # a route from Seattle to New York to Miami, a total distance
>>>> # of about 3043.8 nautical miles
>>>> r
> 
>>>> # a collection of the airports used in the route
>>>> # turned into a LineString
>>>> ls = Airport.objects.filter(routebase__route=r).make_line()
>>>> ls
> 
> 
> How can I find the total distance of that LineString object, so that
> it returns a Distance object that I can then convert to nautical
> miles? the .length() method here just returns a float, which is in who-
> knows-what units...

It's exactly in the units that are specified in your SRS definition. To 
go beyond that you can use Distance to make math and conversions to 
another units..

Note that "length" gives linear distance, not spherical so in long 
distances you get a distorted length.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Distance across a LineString in GeoDjango

2009-10-13 Thread Jani Tiainen

buttman kirjoitti:
>>>> ls.srs.name
> 'WGS 84'
>>>> srs.units
> (0.017453292519943282, 'degree')
>>>> ls.length
> 0.88329271346608429
> 
> So how do I go from degrees to miles? According to the docs, Distance
> does not handle 'degrees' as a unit. Should I somehow convert to
> another srs before I calculate distance? Or is there a better way?

You can calculate approximate distances by using decimal degrees, but it 
requires a bit of more work and are not straightforward to calculate. 
(due the fact that length of degree varies depending on where your 
measured points are located at!)

You might find this page a bit helpful:
http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.htm

> On Oct 12, 2:53 am, Jani Tiainen  wrote:
>> HARRY POTTRER kirjoitti:
>>
>>
>>
>>> I have a model which represents a route. I can use the `make_line()`
>>> geoqueryset method to create a LineString like so:
>>>>>> r = Route.objects.get(pk=33)
>>>>>> # a route from Seattle to New York to Miami, a total distance
>>>>>> # of about 3043.8 nautical miles
>>>>>> r
>>> 
>>>>>> # a collection of the airports used in the route
>>>>>> # turned into a LineString
>>>>>> ls = Airport.objects.filter(routebase__route=r).make_line()
>>>>>> ls
>>> 
>>> How can I find the total distance of that LineString object, so that
>>> it returns a Distance object that I can then convert to nautical
>>> miles? the .length() method here just returns a float, which is in who-
>>> knows-what units...
>> It's exactly in the units that are specified in your SRS definition. To
>> go beyond that you can use Distance to make math and conversions to
>> another units..
>>
>> Note that "length" gives linear distance, not spherical so in long
>> distances you get a distorted length.
>>
>> --
>> Jani Tiainen
> > 


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: does this get or create code ship with django?

2009-10-14 Thread Jani Tiainen

Russell Keith-Magee kirjoitti:
> On Wed, Oct 14, 2009 at 7:09 PM, Chris Withers  wrote:
>> Hi All,
>>
>> I have a function that looks like:
>>
>> def get_or_create(model,**kw):
>> try:
>> obj = model.objects.get(**kw)
>> except model.DoesNotExist:
>> obj = model(**kw)
>> return model
>>
>> Does something like this ship with django?
> 
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create-kwargs

And to avoid situation that I had (just because I didn't read docs 
carefully) standard get_or_create actually always creates instance in to 
database.

I first tried to use it just as a template to get object if it didn't 
existed but it turned out to provide a bit undesired effects, specially 
with missing null fields... :)

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: hosting from /some/url in apache

2009-10-14 Thread Jani Tiainen

Chris Withers kirjoitti:
> Hi All,
> 
> I need to host my django project from /some/folder in my apache instance.
> 
> I have the following:
> 
> WSGIScriptAlias /some/folder /path/to/django.wsgi
> 
> Does this now mean I have to prefix all my entries in urls.py with 
> /some/folder?
> 
> I hope not, but give that going to:
> 
> http://myserver/some/folder
> 
> ...gives me a 404 unless I do, I'm not hopeful.
> 
> What am I doing wrong?

"nothing".

Term is called "suburl deployment" and I've done it (for testing purposes).

Apache config:

RewriteEngine On

#add missing trailing slash if needed
RewriteRule^/$  //  [R]

#WSGI alias[[BR]]
WSGIScriptAlias / absolute_path_to_wsgi_file.wsgi[[BR]]

And if you're using authentication in your app you must provided full 
absolutely URL to login page, I've done it settings.py:

LOGIN_URL='//login/'

And that's it. Of course you have to keep all your apps using hardcoded 
urls but use reverse url finding always.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: unable to see SQL even after DEBUG=True in settings

2009-10-15 Thread Jani Tiainen

Indudhar Devanath kirjoitti:
> Here is what is happening.
> 
>  >>> from django.db import connection
>  >>> from mysite import settings
>  >>> settings.DEBUG
> True
>  >>> connection.queries
> []
> 
> I have run the app such that it has executed number of db queries and I 
> know for sure there must be some sql.  But still I don't see any in 
> connection.queries.  what am I doing wrong?

Are you sure that querysets are evaluated? Meaning that you actually 
access them, just create querysets.

Also in your example there is no queries happening, nor constructed.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: hosting from /some/url in apache

2009-10-15 Thread Jani Tiainen

Graham Dumpleton kirjoitti:
> 
> 
> On Oct 15, 5:14 am, Jani Tiainen  wrote:
>> Chris Withers kirjoitti:
>>> Hi All,
>>> I need to host my django project from /some/folder in my apache instance.
>>> I have the following:
>>> WSGIScriptAlias /some/folder /path/to/django.wsgi
>>> Does this now mean I have to prefix all my entries in urls.py with
>>> /some/folder?
>>> I hope not, but give that going to:
>>> http://myserver/some/folder
>>> ...gives me a 404 unless I do, I'm not hopeful.
>>> What am I doing wrong?
>> "nothing".
>>
>> Term is called "suburl deployment" and I've done it (for testing purposes).
>>
>> Apache config:
>>
>> RewriteEngine On
>>
>> #add missing trailing slash if needed
>> RewriteRule^/$  //  [R]
> 
> This rewrite rule should not be required for things to work.

I needed it because if it was missing before call entered in Django 
login stuff, return URL was emtpy ("") and it didn't resolved correctly.

There is something a bit fishy in login part (when accessing 
http://example.invalid/mysite/someurl) it didn't worked correctly.

Also I do not know why I was required to set "LOGIN_URL" to absolute 
path... (Or could there have been some alternative way to do that)

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Stored proderures/functions in Django

2009-10-18 Thread Jani Tiainen

Tomas Pelka kirjoitti:
> Hi gang,
> I know that Django do not support stored procedures/function, but is
> here still a chance to handle this stuff in Django?
> 
> I found this http://www.djangosnippets.org/snippets/272/, have somebody
> experience with this?
> 
> Thanks for advices,
> cheers Tom.
> 

I don't think so, there is no database agnostic way to do it and more 
over it varies quite a lot between different DBMSes.

What would be useful (there is even ticket for that) to able to populate 
model instances from raw queries and thus for example from return 
value(s) of such database spesific calls.

And meanwhile you always can call raw sql to anything you want django 
supports it.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Django SAAS projects

2009-10-18 Thread Jani Tiainen

Savy kirjoitti:
> 
> 
> Hi Djangonauts,
> 
> I am developing  a Django project (with a few pluggable apps).
> 
> I want to offer this project as a SaaS (something like 37signals.com).
> 
> i.e: customer1.product1.com , customer2.product2.com etc
> 
> product1 could be the basecamp product2 could be highrise and so on.
> 
> I want to know how the project should be structured for these
> products.
> 
> Should there be a single project under which all products will be an
> application.  OR  Should I be making different projects for
> all the products.
> 
> Also interms of database.. should all the products look into a single
> database or we should have seperate databases for each product.
> 
> I am looking out for the most efficient and scalable way to do this.

I'm not saying this is best and most scalable way but we're doing SaaS 
Django projects and it's project per customer. And each project will 
have it's own database (Oracle schema usually) so we can scale up pretty 
much.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: concurrency and threading question

2009-10-21 Thread Jani Tiainen

Use separate background process (daemon) to handle queue + crunching (or 
launching crunching). So your web app just posts jobs to background 
process and then returns control back to user.

Otherwise your idea is quite correct.

Mike Thon kirjoitti:
> I'm new to web programming and I have a basic question about the
> design of my Django application.  my application will do some number
> crunching on data files uploaded by users.  The data processing will
> take from minutes to hours for each job.  I don't expect to ever get a
> large number of concurrent users but I'd still like to set it up so
> that I can control the maximum number of data processing jobs that are
> run in parallel.  I was planning to write a simple FIFO queue manager
> (in fact I think there is a python package for this) and then run the
> data processing in separate threads.  I'm also planning to use the
> Django data model for storing the data so I would have multiple
> threads writing to the data store. What is not clear to me is what
> happens when I have more than one visitor to the site.  Are multiple
> instances of my Django app launched, one per visitor?   I need to
> ensure that I only have one queue manager running on the server, not
> one per visitor.  I would be using Apache and either mySQL or sqlite3
> as the database, in case that matters.


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: inspectdb Oracle

2009-10-26 Thread Jani Tiainen

gillengam kirjoitti:
> Hi, I must develop an application that use Oracle database. The Oracle
> connection user is the owner of some tables, but he can only read two
> views (he is not the owner). I used command "python manage.py
> inspectdb > models.py", but I got only user's tables and  I need
> also the two views. How can I do? Is it possible?

Handcrafing. So you need to construct those two views by hand. Also I 
suggest that you override save() method to raise exception if someone 
tries to save something in views accidentally.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Django templates, break a for after an if

2009-10-26 Thread Jani Tiainen

NMarcu kirjoitti:
> Hello all,
> 
>I want to do something like this:
> 
> {% for u in users %}
> {% for su in superu %}
> {% ifequal u su %}
>//do something end exit
> from this for
> {% endifequal %}
> {% endfor %}
> {% endfor %}
> 
> How can I do this?

You can't and shouldn't. It's template language, not progamming 
language. It's function to define _how_ to show data.

You need to make that decision in a view which is meant for extracting 
and preparing _what_ to show.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Login over HTTPS

2009-10-26 Thread Jani Tiainen

I'm trying to get Django to make authentication (namely username + 
password) to be transferred over HTTPS. But rest of the site is still on 
plain old HTTP.

How this can be done? I've very little success and google didn't gave 
much of help either.

I'm using Apache 2.2 with mod_wsgi and I've total control over my 
webserver config.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Discovering the ip/port in use by runserver

2009-10-27 Thread Jani Tiainen

tow kirjoitti:
> If you're running your django server through ./manage.py runserver, is
> there a way, from within the django process, to discover which  IP
> address and port are in use?

It doesn't use anything it just listens whatever you specified at 
startup. Default is any local address (localhost), port 8000. Anything 
beyond that you know since you have to specify it explicitly.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: Login over HTTPS

2009-10-27 Thread Jani Tiainen

Technically yes.

 From psychological point you need to provide SSL for login screen 
already so end user gets visual feedback that he's in secure transaction 
and certificate is validated.

So yes, it should be "secure login" page, that forwards user back to 
nonsecure pages after login is successful.

Gerard kirjoitti:
> I think that technically only your form submit should be posted to a SSL 
> based url and the rest doesn't have to. Which shouldn't be so hard. Just 
> setup the 'post to' url in the template (under: form action="" ) or define 
> in the view method where the form is initiated just before rendering.
> 
> Thing I'm wondering about though, when the user/password combi is incorrect 
> the most secure way would be to simply send the empty form back in the 
> resulting page, because otherwise a username might be sent back to the 
> client outside the SSL connect.
> 
> Haven't looked for it yet, but I do want to implement that myself. Lets post 
> if we find anything :)
> 
> Regards,
> 
> Gerard.
> 
> 
> 
> Jani Tiainen wrote:
>> I'm trying to get Django to make authentication (namely username + 
>> password) to be transferred over HTTPS. But rest of the site is still on 
>> plain old HTTP.
>>
>> How this can be done? I've very little success and google didn't gave 
>> much of help either.
>>
>> I'm using Apache 2.2 with mod_wsgi and I've total control over my 
>> webserver config.
>>
> 
> 


-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Low Kian Seong kirjoitti:
> I have about 3k plus record in my db table and am trying to do a
> simple render_to_response of a template sending it the results of a
> query. I debugged this and found that the total time taken for an
> operation like this is 50 seconds! Is there anyway to speed this up?
> 

Answer is maybe.

First you have to provide model, view and template code you're using to 
render your code, second the way you measured this 50 seconds.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: redirect or reload page after pdf file generation.

2009-11-02 Thread Jani Tiainen

jai_python kirjoitti:
> Hello every one,
> 
> I have a form which contains group of data and I can select some of
> them to take pdf file.  When I submit the form, it returns pdf file
> which contains the selected data. But i need to redirect or reload the
> present form after pdf file has been generated inorder to remove
> previous entry(i.e data included in the pdf file ) . Here goes my
> source
> 
> def getPDF(request):
>   if not request.POST:
>return to html form page
>   response = HttpResponse(mimetype='application/pdf')
>   #some content will be added to response with the use REPORTLAB
>   return response# will return pdf
> 
> This response will sent an pdf file to client side. same time i want
> to reload or refresh after pdf file generation.

I don't think that such a mechanism exists in HTTP protocol so what 
you're asking might not be really possible.

With little JS (ajax iframe download) you can achieve that kind of 
refresh like functionality. But it relies on ajax functionality.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Low Kian Seong kirjoitti:
> On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
>> Low Kian Seong kirjoitti:
>>> I have about 3k plus record in my db table and am trying to do a
>>> simple render_to_response of a template sending it the results of a
>>> query. I debugged this and found that the total time taken for an
>>> operation like this is 50 seconds! Is there anyway to speed this up?
>>>
>> Answer is maybe.
> 
> Model:
> 

[clipped model code]

> I isolated the code and ran the render_to_response by itself and
> measured the time.
> 
>> First you have to provide model, view and template code you're using to
>> render your code, second the way you measured this 50 seconds.

How about view and template..? It seems that you have few foreign keys 
at least that may cause extra roundtrips to db.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Your model was not-so-good Python/Django code style so it was bit hard 
to read but...

Low Kian Seong kirjoitti:
> On Tue, Nov 3, 2009 at 3:07 PM, Jani Tiainen  wrote:
>> Low Kian Seong kirjoitti:
>>> On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
>>>> Low Kian Seong kirjoitti:
>>>>> I have about 3k plus record in my db table and am trying to do a
>>>>> simple render_to_response of a template sending it the results of a
>>>>> query. I debugged this and found that the total time taken for an
>>>>> operation like this is 50 seconds! Is there anyway to speed this up?
>>>>>
>>>> Answer is maybe.
>>> Model:
>>>
>> [clipped model code]
>>
>>> I isolated the code and ran the render_to_response by itself and
>>> measured the time.
>>>
>>>> First you have to provide model, view and template code you're using to
>>>> render your code, second the way you measured this 50 seconds.
>> How about view and template..? It seems that you have few foreign keys
>> at least that may cause extra roundtrips to db.



> 
> Template:
> 
> 
>   
>   
> {% if query %}
> {% load utils %}
> 
> 
>   
> 
>   Requestor
>   Country (User)
>   AD Domain
>   Company Name
>   Defender ID
>   First Name
>   Last Name
>   Token S/N
>   Token Pin
>   IT Mgr
>   HD Mgr
>   SR Approver
>   SR No. (Setup Cost)
>   SR No. (On Going Cost)
>   SR No. (Orange Cost)
>   Creation Date
>   Acct. Status
>   
> 
> {% for record in query %}
>   
>   {{record.requestor}}
>   {{record.country}}
>   {{record.ad_domain_group}}
>   {{record.company}}
>   {{record.defender_id}}
>   {{record.first_name}}
>   {{record.last_name}}
>   {{record.rsa_token_serial_number}}
>   {{record.token_initial_pin}}

>   {{record.it_manager_id.name}}
>   {{record.sr_manager_id.name}}
>   {{record.hd_manager_id.name}}

All these three might hit another roundtrip to database. Since you're 
using them, you might want to use select_related() method.

>   {{ record.ad_domain_group|defender_setup }}
>   {{ record.ad_domain_group|defender_on_going }}
>   {{ record.ad_domain_group|defender_orange }}
>   {{record.creation_date}}
>   {{ record.disable_date|show_status:end_date }}
>   
> {% endfor %}
>   
> {% endif %}
> 
> 
> 
> views.py:
> 
> def do_defender_advanced(request):
>   query = request.POST.get('query_text','')
>   entries = defender.objects.all()
>   query_text_string = request.POST['query_text']
>   start_date_string = request.POST.get('start_date','')
>   end_date_string = request.POST.get('end_date',str_today)
> 
>   if ('query_text' in request.POST) and 
> request.POST['query_text'].strip():
> 
>   query_text_string = request.POST['query_text']
>   start_date_string = request.POST.get('start_date','')
>   end_date_string = request.POST.get('end_date',str_today)
>   if len(start_date_string) == 0:
>   start_date_string = str_today
>   if len(end_date_string) == 0:
>   end_date_string = str_today
>   query_text_string = request.POST['query_text']
>   qset=(
>   Q(first_name__icontains=query_text_string)|
>   Q(last_name__icontains=query_text_string)|
>   Q(country__icontains=query_text_string)|
>   Q(existing_defender_id__icontains=query_text_string)
>   )
>   
>   if query_text_string.lower() == "all":
>   found_entries = defender.objects.all()
>   elif query_text_string.lower() != "all":
>   found_entries = defender.objects.filter(qset)
>   found_entries = found_entries.filter(
> # status = 'active',
>   
> creation_da

Re: How can we capture the login time in Django

2009-11-03 Thread Jani Tiainen

vishak kirjoitti:
> Hi all,
> 
>  I was going through an application that uses Django 1.0.2 where
> we have a requirement to track down the 'login time'  and 'log out
> time' . I'm able to track logout time. But do not have idea on
> capturing login time. Can anyone give idea on this or suggest about
> this implementation.

You can't reliably determine when someone "logs out". Well of course it 
easy if user presses "log out" button, but what happens if user brutally 
closed browser or it just happens that browser gets closed forcefully - 
like it crashed? Of course I'm happy to hear how you resolved such an 
issues.

Login time control is rather easy and you had one solution for that already.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: connection.queries show no queries

2009-11-17 Thread Jani Tiainen
On Tue, 2009-11-17 at 16:15 -0800, Continuation wrote:
> I'm running a django project (actually a Pinax project) on the
> development server.
> 
> At my settings.py I made sure DEBUG = True
> 
> Then I hit a few pages that for sure resulted in hitting the database.
> 
> Then I did "python manage.py shell" to bring up the interactive
> console.
> 
> Next I tried to look at the raw SQl queries that were generated by
> Django:
> 
> In [2]: from django.db import connection
> In [3]: connection.queries
> Out[3]: []
> 
> Why is connection.queries empty? I tried this several times with the
> same results.
> 
> What have i missed?

Probably you missed the fact that your webserver runs Django in totally
different processes than your shell. So you really can't expect that you
see any queries since you don't have executed any in your shell process.

Try debug toolbar for example to be able to see what actually happens
under the hood.

-- 

Jani Tiainen

--

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=.




Re: Per-object permissions

2009-11-24 Thread Jani Tiainen
Most promising solution I've seen is django-authority.



I haven't (yet) used it but I'm planning to do that at some point.

Quick peek revealed that branch you mentioned is a quite outdated, last
update is "only" two and half years old..

On Tue, 2009-11-24 at 14:00 +0200, gamliel roi wrote:
> Hello all,
> 
> I have the admin site up and running but I need to create a group of
> users, such that each of the users will be able to edit objects that
> are only relevant to them (e.g Project objects that the user is also
> the ProjectManager). 
> 
> I know that in the past Django had a Per-object permissions branch,
> which is now abandoned. 
> 
> Should I peruse this direction and try to incorporate this branch to
> my current code? is it documented and running properly? 
> 
> Any other ideas/suggestions/resources regarding this problem?
> 
> -- 
> Best
> Roi Gamliel
> 
> --
> 
> 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.


--

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: Translate models

2009-11-25 Thread Jani Tiainen
On 11/25/09, Alessandro Ronchi  wrote:
> I need to make my model translatable into different languages.
> Is there any simple way to handle that in a transparent manner?
> I've fround transmeta project on google, anyone is using that?
>

I'm using django-multilingual which pretty much makes same thing just
a bit different way.

-- 

Jani Tiainen

--

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: multilingual flatpages

2009-12-01 Thread Jani Tiainen
On Mon, 2009-11-30 at 16:36 -0800, Nev wrote:
> Hey,
> 
> Today I did a bunch of searching and reading to find what is the best
> way to have flatpages presented in multiple languages. Flatpages
> apparently don't support internationalization and I went down several
> avenues looking for the recommended way, and finding various things
> that appeared way over the top for my simple requirement - present the
> translated version of my flat page according to the current
> 'django_language'.

There also exists django-multilingual pluggable app that has (among
other features), multilingual flatpages application.

-- 

Jani Tiainen


--

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: ModelForm save() cleans data first?

2009-12-01 Thread Jani Tiainen
On Tue, 2009-12-01 at 20:54 -0800, Skylar Saveland wrote:
> Wait, this is a better question than I thought on first glance.  Not
> entirely sure, sorry for the terse first response.
> 
> Skylar Saveland wrote:
> > Former
> >
> > Continuation wrote:
> > > When a ModelForm object calls save(), does it first clean the form
> > > data using form.cleaned_data? Or do I need to call form.cleaned_data
> > > explicitly?

Saving checks form.errors which (as being property) in turn causes call
to form.full_clean() to generate internal error structure.

So answer is yes, it cleans data if it hasn't been cleaned before
calling save. 

-- 

Jani Tiainen


--

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: ORM using tons of memory and CPU

2009-12-14 Thread Jani Tiainen
On Mon, 2009-12-14 at 17:44 -0800, Tracy Reed wrote:
> I have code which looks basically like this:
> 
> now= datetime.today()
> beginning  = datetime.fromtimestamp(0)
> end= now - timedelta(days=settings.DAYSTOKEEP)
> 
> def purgedb():
> """Delete archivedEmail objects from the beginning of time until
> daystokeep days in the past."""
> queryset   = archivedEmail.objects.all()
> purgeset   = queryset.filter(received__range=(beginning, end))
> for email in purgeset:
> print email
> try:
> os.unlink(settings.REAVER_CACHE+"texts/%s" % email.cacheID)
> os.unlink(settings.REAVER_CACHE+"prob_good/%s" % email.cacheID)
> os.unlink(settings.REAVER_CACHE+"prob_spam/%s" % email.cacheID)
> except OSError:
> pass
> purgeset.delete()
> 
> if __name__ == '__main__':
> purgedb()
> 
> The idea is that we are stuffing a bunch of emails in a database for
> customer service purposes. I want to clear out anything older than
> DAYSTOKEEP. The model looks like this:
> 
> class archivedEmail(models.Model):
> subject = models.CharField(blank=True, max_length=512, null=True)
> toAddress   = models.CharField(blank=True, max_length=128, db_index=True)
> fromAddress = models.CharField(blank=True, max_length=128, db_index=True)
> date= models.DateTimeField()
> received= models.DateTimeField(db_index=True)
> crmScore= models.FloatField()
> spamStatus  = models.CharField(max_length=6, choices=spamStatusChoices, 
> db_index=True)
> cacheHost   = models.CharField(max_length=24)
> cacheID = models.CharField(max_length=31, primary_key=True)
> 
> class Meta:
> ordering = ('-received',)
> 
> But when purgedb runs it deletes emails 100 at a time (which takes
> forever) and after running for a couple of hours uses a gig and a half
> of RAM. If I let it continue after a number of hours it runs the
> machine out of RAM/swap.
> 
> Am I doing something which is not idiomatic or misusing the ORM
> somehow? My understanding is that it should be lazy so using
> objects.all() on queryset and then narrowing it down with a
> queryset.filter() to make a purgeset should be ok, right? What can I
> do to make this run in reasonable time/memory?
> 
> PS: I used to have ordering set to -date in the class Meta but that
> caused the db to always put an ORDER BY date on the select query which
> was unnecessary in this case causing it to take ages sorting a couple
> million rows since there is no index on date (nor did there need to
> be, so I thought, since we never select on it). Changing it to
> received makes no difference to my app but avoids creating another
> index. Django's is the first ORM I have ever used and these sneaky
> performance issues are making me wonder...
> 

If you have DEBUG=True setting Django also records _every_ SQL query
made to database and depending on a case, it might use quite lot of
memory.

-- 

Jani Tiainen


--

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 editor for Debian

2009-12-16 Thread Jani Tiainen
On Tue, 2009-12-15 at 23:58 -0800, NMarcu wrote:
> Hello all,
> 
>Can you tell me a good Django editor for Debian? Something more
> pretty then default text editor. Something to can edit templates also.
> Thanks.

vim, emacs, netbeans, pydev, idle, boa...  Just few to mention, all
depends on your preferences.

Personally I'm quite happy with eclipse + pydev.

-- 

Jani Tiainen


--

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: Rails-style form value deserializer?

2009-12-19 Thread Jani Tiainen



Result is stored in request.POST (or you can do same with get params,
?foo=one&foo=two).

for example request.POST.getlist('foo'). Default getitem implementation
returns only last occurence from list.

See:
http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objectsfor
more info.

On Sat, Dec 19, 2009 at 2:27 AM, Todd Blanchard  wrote:

> One thing I'm keenly missing from rails is the form input naming convention
> that causes the form values to be converted into a hierarchy.  For instance,
>
> 
> 
>
> will result in the request values being stored as { 'foo'  : {'bar' :
> 'one', 'baz' : 'two' }}
>
> this is very handy when updating multiple related objects in a single form
> submit.
>
> Is there a similar facility for django/python or will I need to write it?
>
> -Todd Blanchard
>
> --
>
> 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.
>
>
>

--

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 Admin - m2m widget with blank=true, null=true - How to unselect all FKs?

2010-04-18 Thread Jani Tiainen

On 04/19/2010 06:58 AM, Victor Hooi wrote:

Hi,

I have a field in a model which is set to null/blank = True

 firm = models.ManyToManyField(Firm, null=True, blank=True)

I tried using the default m2m filter, however, I wasn't sure how to
unselect an entry.

I also tried using filter_horizontal, and this was much more intuitive/
niftier. And I was able to unselect here.

However, I'm still not sure how to clear all selected FKs in the
default m2m widget. Clicking on any single item seems to replace the
current selection with that one, click directly on a selected item
doesn't seem to unselect it. Clicking out of the widget simply seems
to unfocus the widget, but the selected items still seem selected.


Click one item, then (at most os/computers/browsers) press CTRL down and 
click selected entry. It should clear selection.


--

Jani Tiainen

--
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 Admin - m2m widget with blank=true, null=true - How to unselect all FKs?

2010-04-19 Thread Jani Tiainen
No, it's definitely not obvious but there is no simple way to otherwise 
to do it.


We've sometimes added button with piece of javascript to clear all 
selections. But that only works if user has js enabled of course.


It's just how browsers and operating systems show that particular 
component and there is quite little you can do about it.


--

Jani Tiainen

On 04/19/2010 08:45 AM, Victor Hooi wrote:

Jani,

Aha, that worked, thanks =).

Don't know why I didn't think about using Ctrl...lol.

However, do you think it'd be obvious to new users, to use ctrl?

Cheers,
Victor

On Apr 19, 2:46 pm, Jani Tiainen  wrote:

On 04/19/2010 06:58 AM, Victor Hooi wrote:






Hi,



I have a field in a model which is set to null/blank = True



  firm = models.ManyToManyField(Firm, null=True, blank=True)



I tried using the default m2m filter, however, I wasn't sure how to
unselect an entry.



I also tried using filter_horizontal, and this was much more intuitive/
niftier. And I was able to unselect here.



However, I'm still not sure how to clear all selected FKs in the
default m2m widget. Clicking on any single item seems to replace the
current selection with that one, click directly on a selected item
doesn't seem to unselect it. Clicking out of the widget simply seems
to unfocus the widget, but the selected items still seem selected.


Click one item, then (at most os/computers/browsers) press CTRL down and
click selected entry. It should clear selection.

--

Jani Tiainen

--
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 
athttp://groups.google.com/group/django-users?hl=en.




--
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: Multi-table inheritance - knowing the child object from the parent

2010-05-18 Thread Jani Tiainen
> Given the following:
> 
> class Place(models.Model):
> name = models.CharField(max_length=50)
> address = models.CharField(max_length=80)
> zip_code = models.CharField(max_length=15)
> 
> 
> class Restaurant(Place):
> serves_hot_dogs = models.BooleanField()
> serves_pizza = models.BooleanField()
> 
> class GardenStore(Place):
> sells_lady_bugs = models.BooleanField()
> 
> 
> and given a query on zip_code in Places, how would I know whether a
> Place is a Restaurant or a Garden Store?

You don't OOTB.

I asked same thing quite a while ago - you should be able to find my thoughts 
somewhere in this group archives.

Rationale behind this is that you're trying to achieve something pretty much 
impossible - inheritance in relational world. 

Thing is that you can have you can really have both: Restaurant and 
GardenStore instance to point to same place - so is that correct case or not?

Note that "inheritance" is made so that you have relation from Restaurant and 
GardenStore tables to Place. There is no simple mechanism to prevent your data 
to have references from both "children" to point to "parent".

You can have property/method on your model that tries to determine which one 
is correct.

Or you can re-factor your models (which is usually less painful) so that your 
place, provided that it is unique (which actually in this case might not be). 
Add simple discriminator field to tell what type of child you must also fetch 
to make data complete.

-- 

Jani Tiainen

-- 
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: How can I test the correctness of my models against the schema of a database?

2010-05-31 Thread Jani Tiainen
Not really.

If you're specially working with legacy databases trying to figure out that do 
Django models match underlying schema is PITA.

We resolved this partially by doing few simple tests, namely running through 
all models and doing empty query. Since Django ORM queries for every field it 
revealed most of the problems right away. Of course we didn't checked lenghts 
or types of field.

Also this could be useful in development phase when you add new fields.

In django-command-extensions exists dbdiff command which produces somekind of 
diff against underlying database but it's in very early stages.

> Sorry. I haven't use other methods for that.
> But isn't it enough to test it using loremiser or something like that
> and like an addition debug toolbar?
> 
> On May 31, 12:53 am, David Horat  wrote:
> > Dear group,
> > 
> > How can I test the correctness of my models against the schema of a
> > database?
> > 
> > To solve this question, I have tried unsuccessfully several options:
> > - Using ./manage.py test triggers the creation and destruction of a
> > database, but I want to check the correctness of the model against a
> > production database, since I just want to check the schema, not the
> > content.
> > - Creating my own test runner as specified
> > herehttp://stackoverflow.com/questions/138851 which basically hacks the
> > Django stack and gives you other problems. In any case this seems not to
> > be the correct way.
> > 
> > Has anyone of you faced this situation before? Any clues?
> > 
> > Thank you in advance.
> > 
> > Best Regards,
> > David Horat

-- 

Jani Tiainen

-- 
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: How To Create POST data without an actual POST?

2010-06-29 Thread Jani Tiainen
> I'd like to find a way to let my users submit form data without
> submitting
> it via an actual web form. For example, I have users that would like
> to
> send their data via email, or perhaps provide it in an excel spread
> sheet,
> 
> I'm trying to figure out how to do this and still leverage all the
> error
> checking associated with my forms (ie, via is_valid).
> 
> I'm thinking that on the server side I could create a form with
> initial data,
> and then instead of rendering that form, I'd like to just convert it
> directly
> to a POST data dict, as if the user submitted the form without making
> any changes. Then I'd take that POST data, add a bit of additinal
> data
> that I've gotten from some other source (ie from email or excel), then
> run
> is_valid(), then do my standard save to my db object.
> 
> Can anyone comment on if this seems like a good approach for doing
> this,
> and if so, if there is any django support for turning a form directly
> into a data dict?
> 
> Thanks!
> Margie

Well it depends how you want to integrate your system.

In simplest form you can pass data as a plain python dictionary (which it 
pretty much is) to form and validate. 

my_data = { 'field1' : 1, 'field2' : 'some data', }

form = MyForm(data=my_data)  

Works pretty well, there is no problems with that.

Or like someone already suggested you can do various middle formats (like 
json) or send even "real" request from parser.

You could do even custom command that accepts "post data" as json and pushes 
it to database through the form you've created.

Even forms normally take in request.POST using them is not limited to plain 
HTTP POST requests but you can do it with plain dicts as well.

-- 

Jani Tiainen

-- 
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: Best way to find near people

2010-07-29 Thread Jani Tiainen
> On Jul 29, 2010, at 2:58 PM, Alexandre González wrote:
> > Hi!
> > 
> > I'm searching near people in my app. I'm doing it a this way:
> > 
> > 37 people = Person.objects.all().exclude(user=request.user)
> > 38
> > 39 near_people = list()
> > 40 for person in people:
> > 41 if self.is_near(me.coordinates, person.coordinates):
> > near_people.append(person)
> > 
> > Now, I'm getting all the the Person objects. This is a inefficient way.
> > 
> > The coordinates are latitude/longitude coordinates, so I think in test
> > the variation and get only latitude +/- 1 and longitude +/- 1 and after
> > this, do the test exactly (the funcion is_near).
> > 
> > But instead this, can I "draw" a circle and search only Person objects
> > inside it?
> 
> I'm not sure what database you are using, but if you are using PostgreSQL,
> it has built-in geometric operators specifically for this kind of thing. 
> You might have to drop down into SQL, but in 1.2, that's nice and easy.
> 
> The PostgreSQL documentation on this is at:
> 
>   http://www.postgresql.org/docs/8.4/interactive/datatype-geometric.html
> --
> -- Christophe Pettus
>x...@thebuild.com

Or if spatial operations are really needed, why not to use real spatial 
database and GeoDjango (django.contrib.gis). Spatialite, Postgis, Mysql or 
oracle. All supports at spatial to some extent. And there you can do easily 
simple filtering:

Person.objects.filter(person_coordinates__dwithin(me.coordinates, distance))

...and geodjango + spatial engine behind it will take care of all that complex 
stuff.

Note: you can still use GEOS parts from geodjango to do calculations so you 
don't have to reinvent wheel if you want to keep coordinates as you already 
have.

-- 

Jani Tiainen

-- 
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: Reporting Library??

2010-08-12 Thread Jani Tiainen
> I need a reporting library for web based (HTML) reporting with support
> for standard features
> 1) header
> 2) footer
> 3) pagination
> 4) Totals/summary
> 
> 
> Reportlab is too low level for my needs and their pro version license
> does not work for me.
> 
> Is there any other good python based reporting library.
> 
> My only option at this time is JasperReports which is java based which
> would be an overkill.

There is nothing as comprehensive as JasperReports, but Geraldo reports is 
pretty nice <http://www.geraldoreports.org/> . Built on top of ReportLab and 
has pretty good Django support as well.

-- 

Jani Tiainen

-- 
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: High memory consumption when going through all records

2010-08-12 Thread Jani Tiainen
> Hello all,
> 
> I have a django application for analysis of accounting information in
> torque batch system. The job is an object connected to several accounting
> event objects:
> 
> class Job(models.Model):
> jobid = models.CharField(max_length=16, db_index=True, editable=False)
> server = models.ForeignKey('TorqueServer', editable=False)
> job_owner = models.ForeignKey('User', null=True)
> 
> 
> class AccountingEvent(models.Model):
> timestamp = models.DateTimeField(verbose_name='time stamp')
> type = models.CharField(max_length=1, choices=EVENT_CHOICES)
> job = models.ForeignKey('Job')
> 
> 
> I have a method that goes through all jobs and tests their accounting
> events. The problem is that my function that does the iteration over all
> jobs eats all memory eventually. It is quite simple function:
> 
> maxjobid =
> Job.objects.filter(job_state__shortname='C').aggregate(Max("id"))['id__max
> '] for n in range(1,maxjobid+1):
> j = Job.objects.get(pk=n)
> aes = AccountingEvent.objects.filter(job=j).order_by("-timestamp")
> ae = aes[0]
> if ae.type=='D':
> j.job_state = getJobState('D')
> j.save()
> 
> I tried to inspect this with guppy and I see that the number of str and
> unicode objects get really high. I don't understand why python garbage
> collector does not free them. I see this with development server, debug on
> and mysql as a DB backend.

That is your problem. when DEBUG = True Django ORM records every SQL query 
made in a request - or in case of script whole lifetime of a script which can 
grow quite huge.

http://docs.djangoproject.com/en/1.2/faq/models/#why-is-django-leaking-memory

-- 

Jani Tiainen

-- 
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: jsonrpclib 403 error

2010-08-20 Thread Jani Tiainen
> I have python 2.5.4 installed along with Django-1.2.1 and am trying to
> test jsonrpc using jsonrpclib.  I have been following the Pyjamas
> tutorial and have got to the point where Django is introduced.
> 
> I have tried numerous different things but everything I try results in
> a 403 error. I have taken apache out of the equation and am just using
> the django developmemt web server but the problem is the same.
> 
> Any help would be appreciated.

I'm not using rpclib just because it felt somewhat hard to use with Django. 
Instead of that I've been using my own solution for that:

http://drpinkpony.wordpress.com/2010/01/12/django-json-rpc-service/

It works pretty nicely with Dojotoolkit at least, and it's been battle tested 
now in production environments.

-- 

Jani Tiainen

-- 
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: What is best practice for pluggable modules in app

2010-08-24 Thread Jani Tiainen
> Lets say I have shipping app called Shipping which is used for ups and
> fedex.
> I want just using settings.py to enable/disable them.
> 
> The structure could be:
> project
>  shipping
> modules
>   ups
>   fedex
> 
> And by putting in settings.py I could manage those modules
> INSTALLED_APPS = (
>   
>   'shipping.modules.ups',
>   'shipping.modules.fedex',
>   
> )
> 
> So what is the best way to have pluggable modules in app ?

Because Django doesn't have kind of "startup" point, most probably same way as 
admin registrations are handled.

Toplevel urls.py works quite well, just like django admin does.

Then you just need to ways to register your apps in centralized manner and 
you're good to go, specially if your apps need to contribute to ui. 

Note that  appname is only last part of python namespace and it must be unique 
within one django project. For example you can't have "shipping.modules.ups" 
and "invoicing.modules.ups" due the limitations of Django itself.

-- 

Jani Tiainen

-- 
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: Caching JSON in Django

2010-08-25 Thread Jani Tiainen
> Hello,
> 
> I'm trying to use native caching in Django as per
> http://docs.djangoproject.com/en/dev/topics/cache/
> 
> I followed the setup procedure to the tee (it's not hard, of course). What
> I observe is that my app caches only views that deliver HTML. Since my
> application is heavily AJAX, that's not what I want -- I want to cache
> JSON -- but it doesn't work!

It doesn't work how? How you observed caching?

> Any hints how I can make it work?
> 
> I can always code it up myself (I have, actually), but I try to avoid that.

View code would be helpful and don't forget the caching parts.

-- 

Jani Tiainen

-- 
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: Caching JSON in Django

2010-08-25 Thread Jani Tiainen
Is your AJAX query POST or GET query? Because as you may know, POST queries 
are not cached, GET queries are.

Note that if you're still using large pieces of JSON data, upstream caches are 
not used (data is always sent from Django) which makes some extra load on 
Django app.

> Thanks for you reply. I'm away from my coding machine, so I'll just answer
> a part of your question --
> 
> When I use the cache decorator in a view, I expect that as long as cache is
> valid, the code in the view
> does not get executed. And that's what I see when rendering a template with
> some little context attached to it. However, in a different view adorned
> with same decorator, which does not use a template and just wraps
> HttpResponse around JSON (which is plain ASCII after all) I see that the
> whole database glue shebang inside the view comes into motion every time I
> hit the view, any time. This correlates with the content of the
> CACHE_BACKEND (which in my case is file storage) -- in the former case, I
> have cryptic little dirs sprouting up, in the latter I see nothing. I think
> that proves the general picture i.e. cache not working -- am I wrong?
> 
> jtiai wrote:
> >> Hello,
> >> 
> >> I'm trying to use native caching in Django as per
> >> http://docs.djangoproject.com/en/dev/topics/cache/
> >> 
> >> I followed the setup procedure to the tee (it's not hard, of course).
> >> What
> >> I observe is that my app caches only views that deliver HTML. Since my
> >> application is heavily AJAX, that's not what I want -- I want to cache
> >> JSON -- but it doesn't work!
> > 
> > It doesn't work how? How you observed caching?
> > 
> >> Any hints how I can make it work?
> >> 
> >> I can always code it up myself (I have, actually), but I try to avoid
> >> that.
> > 
> > View code would be helpful and don't forget the caching parts.

-- 
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: SERIALIZING

2010-11-04 Thread Jani Tiainen
Hi,

Using capitals nor crossposting doesn't get you far. You need to do your 
homework [1].

Can you tell what you have tried and how to resolve your problem? 

Hint: This all is documented in Django documentation. If you have some more 
specific problems applying techniques described in documentation come back and 
ask.

[1] http://www.catb.org/~esr/faqs/smart-questions.html#homework

-- 

Jani Tiainen

On Wednesday 03 November 2010 15:15:49 sami nathan wrote:
> HOW TO GET XML RESPONSE in following
> THIS IS HOW MY URL.PY LOOKS LIKE
> 
> from django.conf.urls.defaults import *
> from it.view import current_datetime
> 
> 
> 
> # Uncomment the next two lines to enable the admin:
> #from django.contrib import admin
> #admin.autodiscover()
> 
> 
> urlpatterns = patterns('',
>   # Example:
>(r"^wap/di/sub/$",current_datetime),
>   # Uncomment the admin/doc line below to enable admin documentation:
>   # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
> 
>   # Uncomment the next line to enable the admin:
>   # (r'^admin/', include(admin.site.urls)),
> )
> 
> `~~~
> My view .py looks like this
> 
> from django.http import *
> import urllib
> from django_restapi.responder import XMLResponder
> 
> 
> def current_datetime(request):
>   word = request.GET['word']
>   message =
> urllib.urlopen('http://m.broov.com/wap/di/sub?word='+word+'&type=00submit=
> Submit',) return HttpResponse(message)

-- 
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: grouping of fields inside a model into a class

2010-11-07 Thread Jani Tiainen
On Friday 05 November 2010 22:53:06 nitm wrote:
> Hi,
> 
> Is there a way to combine a set of fields I have in a model class into
> a different class without it having it's own separate table?
> An example:
> 
> I want to implement the user profile model class, and in it I would
> like to have the address of the user.
> The address is group of fields (city, street, number, zip code) and
> so, instead of having this:
> 
> class UserProfile(models.Model):
> city = models.ForeignKey(City)
> street = models.CharField(max_length=200)
> number = models.IntegerField()
> zip = models.IntegerField()
> 
> 
> 
> I would like to do something similar to:
> class Address:
> city = models.ForeignKey(City)
> street = models.CharField(max_length=200)
> number = models.IntegerField()
> zip = models.IntegerField()
> 
> class UserProfile(models.Model):
> address = ???
> 
> 
> 
> It just seems more comfortable if I can group these fields into one
> class and add methods to it (for example different string
> representations) but I would still like the actual fields to be part
> of the user profile table and not a new table just for address (since
> it's a one to one relationship).
> 
> Is something like that possible ?
> Thanks.

That can be achieved very easily by using abstract model(s) and inheritance.
Though it's not that intuitive  but looks similiar. Also you need to be very 
careful about reverse relations.

See more at:
http://docs.djangoproject.com/en/1.2/topics/db/models/#abstract-base-classes

http://docs.djangoproject.com/en/1.2/topics/db/models/#be-careful-with-
related-name

-- 

Jani Tiainen

-- 
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: Mysql Quires using raw()

2010-11-09 Thread Jani Tiainen
On Tuesday 09 November 2010 12:25:30 Jagdeep Singh Malhi wrote:
> hi
> I am facing problem with raw() mysql quiers
> for example :
> maxid = Client.objects.raw('SELECT Max(id) FROM client')
> 
> print maxid
> 
> output is :-
> 
> 
> I am using Django 1.2 version.
> where I am wrong?

Nowhere. Output is correct and as documented - you get back *RawQuerySet*. Not 
a single value.

So you have to do something like:

maxid = Client.objects.raw('SELECT MAX(job_no) as max_job_no FROM 
CLIENT').values_list('max_job_no', flat=True)[0]

-- 

Jani Tiainen


-- 
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: Mysql Quires using raw()

2010-11-11 Thread Jani Tiainen
On Tuesday 09 November 2010 12:25:30 Jagdeep Singh Malhi wrote:
> hi
> I am facing problem with raw() mysql quiers
> for example :
> maxid = Client.objects.raw('SELECT Max(id) FROM client')
> 
> print maxid
> 
> output is :-
> 
> 
> I am using Django 1.2 version.
> where I am wrong?

Nowhere. Output is correct and as documented - you get back *RawQuerySet*. Not 
a single value.

So you have to do something like:

maxid = Client.objects.raw('SELECT MAX(job_no) as max_job_no FROM 
CLIENT').values_list('max_job_no', flat=True)[0]

-- 

Jani Tiainen


-- 
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: Newbie question: empty is not empty?

2009-12-31 Thread Jani Tiainen
On Thu, 2009-12-31 at 01:58 -0800, BobAalsma wrote:
> I'm following the Django book to learn Django. I'm getting unexpected
> responses and can't find how to address this. It seems that submitting
> an empty form is not handled as if it is empty ??
> 
> In views.py:
> def search(request):
>   if 'q' in request.GET:
>   message = 'U zocht: %r' % request.GET['q']
>   else:
>   message = 'Leeg'
>   return HttpResponse(message)
> 
> However, on submitting an empty form, the displayed message is:
> U zocht: u''
> 
> On submitting a 'd', the answer is:
> U zocht: u'd'
> 
> Consistent, that's the good news...
> 
> How to solve this?

You don't tell do you have any elements on your HTML form.

But if you do - it will get submitted (exception being unselected
checkboxes) with empty value - and thus existing as empty string in
GET/POST parameters.

None of standard middlewares don't mangle POST/GET parameters. To make
something useful out of it, use Django forms to post process form to
distinguish between emtpy and non empty values.

-- 

Jani Tiainen


--

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: Newbie question: empty is not empty?

2009-12-31 Thread Jani Tiainen
On Thu, 2009-12-31 at 03:20 -0800, BobAalsma wrote:
> Thanks Masklin, I've just tried your suggestion and there is no
> change.
> 
> I'm somewhat mystified by the 'u' that gets added to all answer
> messages - is this something to do with unicode? Could this be the
> root of (some) evil?

Again, your're using formatter %r which in python means "representation
of object". In case of strings it prints either u'' for unicode strings,
or just '' for non unicode ones.

It's still a string and doesn't get "appended" magically.

So instead of using %r use %s (which means "string") and you see that
magical u to disappear.

also if you send q (as in example), even it's empty it will get in GET
query dictionary, just because it exists. And it has value - empty
string.

So what you need to test is:

if 'q' in request.GET and request.GET['q']:

Or to make things a bit more Pythonic:

if request.get('q', False):

> I've tried using [ ] instead of the suggested ( ), which leads to a
> Django errorpage, stating that the contents of the variable 'q' is
> u'd' - which seems to indicate to me that a "u" is added to all values
> of q (also explaining why q is never empty).
> 
> 
> On Dec 31, 11:27 am, Masklinn  wrote:
> > On 31 Dec 2009, at 10:58 , BobAalsma wrote:
> >
> >
> >
> >
> >
> > > I'm following the Django book to learn Django. I'm getting unexpected
> > > responses and can't find how to address this. It seems that submitting
> > > an empty form is not handled as if it is empty ??
> >
> > > In views.py:
> > > def search(request):
> > >if 'q' in request.GET:
> > >message = 'U zocht: %r' % request.GET['q']
> > >else:
> > >message = 'Leeg'
> > >return HttpResponse(message)
> >
> > > However, on submitting an empty form, the displayed message is:
> > > U zocht: u''
> >
> > > On submitting a 'd', the answer is:
> > > U zocht: u'd'
> >
> > > Consistent, that's the good news...
> >
> > > How to solve this?
> >
> > First of all, this has nothing to do with forms. "Forms" in a Django 
> > context designates Django 
> > Forms:http://docs.djangoproject.com/en/dev/topics/forms/. Here, you're only 
> > playing with query parameters, forms are not involved.
> >
> > Second, this is a Python issue more than a Django one: even if the 
> > parameter is empty (e.g. `yourpage.com/search?q=`) it is present, therefore 
> > it will be put in the GET dictionary. `key in dict` only checks that the 
> > key exists, not that it keys to a value (let alone a "falsy" value such as 
> > an empty string). What you really want to check is that the 'q' key exists 
> > *and is non-empty*.
> >
> > I suggest that you use the `dict.get` method for this: it returns the value 
> > for the key if the key exists, None if it doesn't. Just replace `'q' in 
> > request.GET` by `request.GET.get('q')` and you should have the behavior you 
> > expect.
> 
> --
> 
> 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.
> 
> 


--

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: adding custom variables to the Meta class

2010-01-05 Thread Jani Tiainen
On Tue, 2010-01-05 at 04:17 -0800, bruno desthuilliers wrote:
> 
> On 5 jan, 00:05, HARRY POTTRER  wrote:
> > I have an class that I created which takes a queryset, and a field on
> > the model that the queryset represents. Like this:
> >
> > mc = MyClass(queryset=MyModel.objects.all(), lat_lng_field='lat_lng')
> >
> > The class basically filters the queryset based on some geographical
> > values, but in order to do that, it needs to know which field the
> > coordinates are stored in.
> >
> > Right now I have no choice but require you to pass in a string
> > representing the field name. But I think a better way would be to do
> > it kind of like this:
> >
> > class MyModel(models.Model):
> > lat_lng = PointField()
> > name = CharFIeld(max_length=20)
> >
> > class Meta:
> > verbose_name_plural = 'My Models'
> > lat_lng_field = 'lat_lng'
> >
> > Then just modify MyClass to get the field name from the Model's Meta
> > class. Is this possible somehow?
> 
> Did you at least try ? It took me about 5 seconds to find out it
> wouldn't work... or at least not without a very ugly monkeypatch.
> 
> 
> > If not, whats the best way to go
> > about this without having to pass in the field name directly?
> 
> You can
> 
> 1/ store the info as a class attribute
> 
> class MyModel(models.Model):
> lat_lng_field = 'lat_lng'
> 
> # etc
> 
> 2/ store all "geographic" related infos in another inner class in your
> models (not worth if you only have a single info...)
> 
> 3/ add the attribute _after_ the class statement's body, ie:
> 
> 
> class MyModel(models.Model):
># stuff here
> 
> MyModel._meta.lat_lng_field = 'lat_lng'
> 
> 
> 4/ monkeypatch django.db.models.options to allow "lat_lng_field" in
> Meta (very bad idea IMHO)
> 
> or simply:
> 
> 5/ document the fact that the 'lat_lng' field name MUST be named
> 'lat_lng', period !-)
> 
> 
> My 2 cents...
> 

Or... :)

from django.db import models

models.options.DEFAULT_NAMES += ('my_first_val', 'my_second_val')

class MyModel(models.Model):
class Meta:
my_first_val = 'foo'
my_second_val = 'bar'


Amazing, isn't it?

-- 

Jani Tiainen



--

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: Namespace Security

2010-01-12 Thread Jani Tiainen
On Wed, 2010-01-13 at 10:20 +1100, Justin Steward wrote:
> I had a similar requirement for a current project. Users in the admin
> needed to be able to see ONLY the objects that they had created.
> 
> My solution was:
> 1) http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
> 2) Add foreign key to model to track which user created the object.
> 3) Use the ThreadLocals trick with a custom save() to set the user
> (Objects created via command line get assigned the first superuser in
> the DB)
> 4) A smart manager that is now aware of the current logged in user
> thanks to the ThreadLocals middleware and can use that to limit
> requests. (displaying all if superuser, or if run using python
> manage.py shell)
> 
> I'm sure this approach could be expanded to use namespaces/groups
> instead of user on the model's foreign key. To my mind at least, it's
> a little easier to follow what's going on than overriding various
> methods in admin.py

It seems that you're doing it "wrong".

As standard django admin is meant for quick way to allow look and
modification access to all trusted users - admins/staff.

It's never was intended to be used for an end user activity management,
which leads to utterly complex solutions trying to overcome this
problem.

It probably could be simpler to create custom admin site for this
purpose than trying to get around limitations of standard admin site.

-- 

Jani Tiainen

-- 
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: Table with 4 Milions of rows

2010-01-12 Thread Jani Tiainen
I've only 21 million rows in one of my tables and querying it is not a
problem. First check that suggested function based index, it might help
and you don't need to do anything.

istartswith uses "not so good" format. We have got around it using
additional field that is autopopulated, in your case it would be
"book_title_lcase" (or similiar), and then make it automatically
populate from title as lowercase. Now you can on add index to this
special lowercase field, and do query as:

books.objects.filter(book_title_lcase__startswith=request.GET['q'].lower())[:100]

It should hit index. Of course it adds some overhead when generating
objects.

On Tue, 2010-01-12 at 12:20 -0800, nameless wrote:
> The table is queried from ajax using an autocomplete field with this
> query in the views.py:
> 
> books.objects.filter(book_title__istartswith=request.GET['q'])[:100]
> 
> 
> 
> 
> ---
> 
> On Jan 12, 8:47 pm, Chris Czub  wrote:
> > It really depends on how you're selecting the data from the database. If
> > you're doing something that necessitates a full table scan(like in-DB ORDER
> > BY) it will slow you down considerably. If you're selecting one row from the
> > database by an indexed column, then the performance will be very fast and
> > there's no need to prematurely optimize.
> >
> > On Tue, Jan 12, 2010 at 2:25 PM, nameless  wrote:
> > > My table with 4 milions of rows is queried often by ajax.
> > > So I think a performance problems ( I am using also index ).
> > > Ok now take a look at the contenttypes :)
> >
> > > 
> >
> > > On Jan 12, 8:15 pm, Tim  wrote:
> > > > As far as needing to split up the table into other tables, I'm not
> > > > sure. Whats wrong with having 4 million records in one table?
> >
> > > > But if you're going to do it, take a look at the contenttypes
> > > > framework and generic relations. It basically does what you're
> > > > describing:
> >
> > > >http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1
> >
> > > --
> > > 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.
> >
> >


-- 
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: A question about database models

2010-01-14 Thread Jani Tiainen
On Thu, 2010-01-14 at 03:25 -0800, ifcho wrote:
> Hi,
> 
> I'm very new to Django, and I'm sorry if the question is really dumb.

Kind of a dumb question... See why:

> So I have a database model for a drivers (rally car driver), and I
> have database model for the results. As you know a rally car team is
> of two - a driver and co-driver. And so I have:
> class EntryList(models.Model):
> .
> the_driver = models.ForeignKey(Drivers)
> the_co_driver = models.ForeignKey(Drivers)
> .
> here is where I get the following error:
> manage.py validate
> Error: One or more models did not validate:
> mysite.entrylist: Accessor for field 'the_driver' clashes with related
> field 'Drivers.entrylist_set'. Add a related_name argument to the
> definition for 'the_driver'.

Did you read what error says?

> mysite.entrylist: Accessor for field 'the_co_driver' clashes with
> related field 'Drivers.entrylist_set'. Add a related_name argument to
> the definition for 'the_co_driver'.

Again, did you actually read what it said again?

> after commenting the_driver, or the_co_driver, the error is gone.

And if you didn't guessed yet, you have to still add "related_name"
argument for field definition. What it means can be found at django
documentation:

<http://docs.djangoproject.com/en/1.1/ref/models/fields/#django.db.models.ForeignKey.related_name>

-- 

Jani Tiainen


-- 
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: Remove items from queryset?

2010-01-22 Thread Jani Tiainen
On Fri, 2010-01-22 at 06:15 -0800, Igor wrote:
> Hello,
> 
> I need to exclude some items from a QuerySet based on field analysis
> with regular expressions. Which means in my understanding means that I
> need to first evaluate the QuerySet and then go thru it and use python
> to remove some items based on my analysis.
> 
> Now, how can I accomplish that? I was not able to find a way to remove
> items from a QuerySet.
> 
> Thanks in advance

Simplest route:

l = list(qs)

Of course, after that is no more queryset but just a plain old Python
list containing all objects from your queryset.

-- 

Jani Tiainen


-- 
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: Plugin for Eclipse

2010-04-13 Thread Jani Tiainen

On 04/13/2010 03:07 AM, Zbiggy wrote:

Hi,
maybe someone would be interested in: http://eclipse.kacprzak.org/

I use Eclipse + PyDev, however Django tags coloring was always sth I
was missing.
However if you found such a plugin already, please let me know.
I'd like to avoid wasting my time in duplicate implementation.

Regards,
Zbiggy

   


Don't know does there exist any other alternative but your plugin seemed 
to do pretty good job.


One of the last features I've been missing from Eclipse+PyDev package.

--

Jani Tiainen

--
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 REST

2012-03-04 Thread Jani Tiainen
I've been very happy with django-rest-framework.

I think there exists at least django-piston to do the same.

And you can write it also "manually". Since REST is just architectural
specification and doesn't involve any special magic.

On Sun, Mar 4, 2012 at 8:13 PM, Bharath Mundlapudi wrote:

> Dear Django Users and Authors,
>
> I am wondering if there are any best practices or better way to write REST
> based apps on top of Django. I was using version 1.1 and not followed
> recent advancements. Can you kindly point me to links or references from
> your experience.
>
> Preferably out-of-the-box solutions.
>
> -Bharath
>
> --
> 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.
>

--

Jani Tiainen

-- 
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: GeoDjango distance queryset filter with distance value stored within model

2012-03-04 Thread Jani Tiainen
I think you can only achieve that currently by using queryset extra()
method.

You should open a ticket and preferably create a standard geodjango
testcase for that. It could be also possible that not all gis backends
support that kind of a behavior.

On Sat, Mar 3, 2012 at 6:47 PM, Daniel Gerzo  wrote:

> Hello guys,
>
> I have an Order model, that has an origin PointField and a range
> IntegerField. Furthermore, there is an UserProfile model, which has a
> geo_location PointField. Now, I have an User instance, user. I want to
> select all Orders, whose distance between Order.origin and
> user.userprofile.geo_location is less then the value (meters) in the
> Order.range model field.
>
> So again, simplified models:
>
> class Order(models.Model):
>origin = models.PointField()
>range = models.IntegerField(blank=**True, default=1)
>
> class UserProfile(models.Model):
>geo_location = models.PointField()
>
>
> I've got this working (passing the distance statically):
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> D(m=3000)))
>
> My next (unsuccessful) try was to use an F() expression to use the value
> from the Order.range field:
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> D(m=F('range'
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/measure.py", line 165, in __init__
> self.m, self._default_unit = self.default_units(kwargs)
>  File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/measure.py", line 49, in
> default_units
> if not isinstance(value, float): value = float(value)
>  TypeError: float() argument must be a string or a number
> I think the problem is that the D() isn't ran lazily - I can understand
> that. So I tried to just take the raw value from the range field (integer)
> which I supposed to work, but:
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> F('range')))
> Traceback (most recent call last):
> File "", line 1, in 
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 69, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 84, in __len__
> self._result_cache.extend(**self._iter)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 273, in iterator
> for row in compiler.results_iter():
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 680, in
> results_iter
> for rows in self.execute_sql(MULTI):
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 725, in
> execute_sql
> sql, params = self.as_sql()
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 68, in as_sql
> where, w_params = self.query.where.as_sql(qn=qn,
> connection=self.connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/where.py", line 92, in as_sql
> sql, params = child.as_sql(qn=qn, connection=connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/where.py", line 95, in as_sql
> sql, params = self.make_atom(child, qn, connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/db/models/sql/**where.py", line 47,
> in make_atom
> spatial_sql = connection.ops.spatial_lookup_**sql(data, lookup_type,
> params_or_value, lvalue.field, qn)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/db/backends/**postgis/operations.py",
> line 531, in spatial_lookup_sql
> raise ValueError('Argument type should be %s, got %s instead.' %
> (arg_type, type(value[1])))
> ValueError: Argument type should be (,  'django.contrib.gis.measure.**Distance'>, , ,
> ), got  instead.
>
> So how can I accomplish what I am trying to? Any help is appreciated!
>
> PS: I have posted this also to StackOverflow at
> http://stackoverflow.com/q/**9547069/755532?sem=2<http://stackoverflow.com/q/9547069/755532?sem

Re: Django hgwebdir

2012-03-08 Thread Jani Tiainen

Yes, that is very much possible:

Either write views to show all data, use HG command spawning with 
correct parameters.


Or another option is to use HG Python codes to read repository.

Though output you have to do yourself.

I guess this was what you were looking for?

8.3.2012 9:09, siva kirjoitti:


Hi ,

As of now we are looking hg repository via cgi

Can we see hg repository using django instead of cgi ?

Thanks,
S.Sivakumar


On Mar 7, 5:58 pm, Denis Darii  wrote:

using django? hmmm...

you can browse your current repo via http on port 8000 by launching:

$ hg se

or:

$ hg se -n "Your repo"

On Wed, Mar 7, 2012 at 1:39 PM, siva<85s...@gmail.com>  wrote:


Is it possible can we see hg repository using django ?



--
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.


--
This e-mail and any file transmitted with it is intended only for the
person or entity to which is addressed and may contain information that is
privileged, confidential or otherwise protected from disclosure. Copying,
dissemination or use of this e-mail or the information herein by anyone
other than the intended recipient is prohibited. If you are not the
intended recipient, please notify the sender immediately by return e-mail,
delete this communication and destroy all copies.




--

Jani Tiainen

--
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: Problems creating django project in Windows 7

2012-03-08 Thread Jani Tiainen
Well I've been successfully working in Windows with Django and Python 
last 3 years without much of troubles. Few libraries that don't play 
nice with virtualenvs.


So first things first:

Make sure that you install only 32 bit Python for windows. 64 bit will 
work but most of the libraries are only for 32 bit and you just get 
troubles for that.


Next thing after installin Python is to install of course easy_install, 
pip and virtualenv.


Then steps are rather easy:

go to directory of your choice.

Create virtualenv:
C:\my-venvs > virtualenv myenv --no-site-packages

Goto inside virtual environment created:
C:\my-venvs > cd myenv

Activate virtual environment:
C:\my-venvs\myenv > scripts\activate.bat

Install Django:
(myenv) C:\my-venvs\myenv > pip install django

Start new project:
(myenv) C:\my-venvs\myenv > django-admin startproject myproj

If you need I can do blog post about my current instructions how to 
setup whole dev environment from the ground up in Windows environment.


8.3.2012 14:07, Javier Guerra Giraldez kirjoitti:

On Wed, Mar 7, 2012 at 11:03 PM, Mika  wrote:

But I'm just curious about the
objective advantages of Ubuntu over Windows vis a vis django?


all OpenSource tools and libraries are developed first and foremost to
work on unix-like systems.  while most of them do work very well on
windows too, it's always a second-class system.

conversely, if you develop on .NET, you can deploy on Linux if you
want, but it's always a step behind on that stack.  it's much easier
to just go with the preferred platform.


Why would
Windows cause headaches down the road?


there are several things: maybe you'd want to use IIS which
doesn't play well with FastCGI / WSGI.  or NGINX, which runs great on
POSIX, but on windows you're limited in the choice of backtransports.
or uWSGI, which has a lot of very handy process control abilities...
but few of them works on non-POSIX environments.  or you want Redis as
a mind-numbingly-fast on-memory database, but it's unsupported on
windows because it can't do persistence without sane fork()
primitives.


Also, is VMWare or Virtualbox
necessary? How would it benefit my development environment?


if you want to try a new OS, you have two options: install on a real
machine, or on a virtual machine.  if you certainly can keep your
windows OS and tools and just use a linux machine as a test server.
since it doesn't need a lot of power for that, you can avoid
dedicating a real machine by using a virtual one.



--

Jani Tiainen

--
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: "Dynamyc" modells

2012-03-13 Thread Jani Tiainen

13.3.2012 3:51, Dennis Lee Bieber kirjoitti:

On Mon, 12 Mar 2012 22:14:27 +0100, Ervin Hegedüs
declaimed the following in gmane.comp.python.django.user:



Some promotion has few millions of records, different promotions have
different format of codes, ... And general: I'm looking for an ultimate
solution, and may be the next time every ListRecord will have different
columns.


Strangely, your "ultimate solution" might mean implementing a DBMS
AS the application, rather than just USING a DBMS...


Ultimate solution sounds more like using document oriented databases, 
like CouchDB or MongoDB. (Just the few I happened to remember).



That is: maintaining a data dictionary which contains "promotion
format", "promotion field", "field type", (maybe field position too,
along with fields to identify constraints on the valid values); and a
related data table in which each record holds just ONE field, with a
foreign key referencing the specific "promotion format/field" pair along
with a field containing the "record ID" (since any actual record will
take more than one table entry). The data value itself is likely going
to be a BLOB [unless you are using SQLite where you can store anything
in a field], and you use the type information to determine how to
interpret the value.


That's doable but will be pain in the ass to maintain. Also performance 
is not that good since it wouldbe RDBMS on top of RDBMS.


Also all database CRUD operations would be handcrafted still. I would 
definitely look using those document oriented databases which would 
allow doing all that fancy stuff without too much sweat.


--

Jani Tiainen


--
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: Django is very slow on windows server 2003, mssql database

2012-03-13 Thread Jani Tiainen

13.3.2012 17:09, Javier Guerra Giraldez kirjoitti:

On Tue, Mar 13, 2012 at 9:55 AM, Phanounou  wrote:

I installed the django_debug_toolbar and I see that in the sql part I have
1852 queries in 18228.00ms.


great, so this is indeed the problem.

which page is this?, the listing or the edit page?  check the SQL
code, which tables is it accessing?

if this happens on the edit page, it might be when constructing the
select elements.  how does the __unicode__ of the related models look
like?



Also if this happens on edit page, those dropdowns and multiselect lists 
get's populated from foreignkey / m2m tables which might create quite 
lot of data.


I had fun times with my customer foreignkey to address model with 21 
million rows in address... :)


--

Jani Tiainen

--
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: Models, field like a list

2012-03-19 Thread Jani Tiainen
Hi,

All depends on a few factors will simple foreign key or many to many be
correct solution.

If single model B can be assigned only on a single model A then foreign key
from B to A is right choice. But if
requirement is that model B can be assigned multiple times to model A then
it's definitely many to many.

And that's pretty much how far you can get with traditional RDBMS. You can
easily write convenience
methods/properties on a model class to cut out few corners if needed.

Of course you can go in many other ways, for example storing primary key
values as a string list, and then parsing it.
It's just not good thing to do. You can easily end up with data integrity
problems like what should happen if you delete
entity from model B? or your list in model A doesn't find all entities in
model B.

On Mon, Mar 19, 2012 at 5:19 PM, Dmitry Zimnukhov wrote:

> Hi,
> If you want to retrieve list of related models with one to many
> relation, you can do it with related manager, without adding a field
> to model A.
> So, if you have model B like this:
>
> class B(models.Model):
>  a = models.ForeignKey(A)
>
> you can get related B objects like this: a_instance.b_set.all()
>
> But if you want to have an array field in your model (so that array
> data will be stored in the same table that stores model data), your db
> backend must support it and you must extend Django to support this
> functionality. That's probably not what you want.
>
> 2012/3/19 Xavier Pegenaute :
> > Hi,
> >
> > I was thinking to use a field like a list [] of another object. But I
> have
> > no a clear idea which field type should I use. Any idea?
> >
> > Ex:
> > class A:
> >bClasses = models.() # list of Foreign keys from B
> >
> >
> > I am not looking for a ManyToMany Field.
> >
> > Thanks,
> > Xavi
> >
> > --
> > 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.
> >
>
> --
> 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.
>
>

-- 
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: Running manage.py commands in Windows Power Shell

2012-03-19 Thread Jani Tiainen
Hi,

I (and all my other teammates) are have been developing in windows with
standard Python (+ Django + lot of other interesting stuff) in WinXP,
Vista, Win7.

To keep everyone on same line, we use TCC/LE (Take Command Console/LE)
which is augmented CMD. Has lot of nice features. And it's free.

On Sun, Mar 18, 2012 at 6:32 PM, Dennis Lee Bieber wrote:

> On Sun, 18 Mar 2012 02:14:15 -0700 (PDT), orschiro
>  declaimed the following in
> gmane.comp.python.django.user:
>
> > Is this the case for the ActivePython package?
>
> Since I don't have a non-ActiveState install anywhere to compare
> against...
>
> -=-=-=-=-=-
> Windows PowerShell
> Copyright (C) 2009 Microsoft Corporation. All rights reserved.
>
> PS E:\UserData\Wulfraed\My Documents> ./test.py
> test
>
> PS E:\UserData\Wulfraed\My Documents> python test.py
> test
>
> PS E:\UserData\Wulfraed\My Documents> .\test.py
> test
>
> PS E:\UserData\Wulfraed\My Documents>
>
> PS E:\UserData\Wulfraed\My Documents> get-host
>
>
> Name : ConsoleHost
> Version  : 2.0
> InstanceId   : 253c9466-5541-4737-b974-5b376fd39caa
> UI   :
> System.Management.Automation.Internal.Host.InternalHostUserInterface
> CurrentCulture   : en-US
> CurrentUICulture : en-US
> PrivateData  : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
> IsRunspacePushed : False
> Runspace : System.Management.Automation.Runspaces.LocalRunspace
>
>
>
> PS E:\UserData\Wulfraed\My Documents>
> -=-=-=-=-=-
>
> WinXP (on which I had to download PowerShell as it isn't standard),
> running from a semi-privileged (so-called "power user") account.
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.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.
>
>

-- 
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: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-19 Thread Jani Tiainen
Hi,

Since we use same setup except one part: we use mod_wsgi instead of
mod_fcgi.

(Since wsgi is considered to be defacto protocol). Could you try to use it?


On Mon, Mar 19, 2012 at 7:04 PM, Another Django Newbie <
another.xxx.u...@gmail.com> wrote:

>
>
> On Thursday, March 15, 2012 1:05:53 PM UTC, Another Django Newbie wrote:
>>
>> Hi,
>>
>> I've just started playing with django this week and was following the
>> example in the Django Book.
>>
>> I created an example of my own, based on the models.py in the book and
>> tested it with manage.py runserver. All worked OK, but when I try it
>> in apache one of my admin pages is truncated - a number of fields are
>> left off and there is no Save button. The exact number of fields
>> truncated depends on whether I use Add from the main page or from the
>> Add page of another field (so that the affected page is a pop-up)
>>
>> Apache 2.4.1
>> mod_fcgid 2.3.6
>> django 1.3.1
>> Python 2.7.2
>> cx-Oracle 5.1.1
>>
>> Has anyone seen this behaviour? I've looked in apache and django logs
>> but don't see anything recorded when the page loads. Any ideas greatly
>> appreciated.
>>
>> Thanks.
>
>
> Bump  I've had no luck with this and would still appreciate some
> pointers! I've tried re-arranging the order of statements in my model code
> without any improvement.
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/asZ5sigBBuQJ.
>
> 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.
>

-- 
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: Question about threading a view[REPOSTED]

2012-03-19 Thread Jani Tiainen
Hi,

Basic idea is to send a message to message broker from your view to tell "I
want to run this long running task X".

After that your view can return (with task id). After that your client can
start asking from second view for long running response.

In the background you have to have some means to query message broker for
requested tasks and execute them. For example
using a cron job.

That's where django-celery comes in. It can create tasks and it can run
tasks within Django framework using various message
brokers - rabbitmq being probably most popular.

So first you define task with django-celery. Then in your view you send
message to message broker that "execute that task".
And then you must have some background running process to read messages
from broker and execute them.

What comes to testing usually you mock responses in these kind of tests. Of
course you can still test your long running process but
in unit tests you don't test that communication between broker and running
system.

HTH,

Jani Tiainen

On Mon, Mar 19, 2012 at 11:17 PM, Arruda wrote:

> Some one also gave me that tip.
> I was reading it, but I couldn't see much clear how to use this in this
> case.
> I saw that to execute a task I should run it by using ./manage.py ... and
> how can I do that in a view?
> Another thing is that it seems to me a bit overkill isn't it, and a little
> to complicated to setup.
> To test it in development I need to prepare a huge scenario so that it can
> work out, and also I can't imagine how to use this in tests.
>
> Did I understood it wrong? Ins't it a lot complicated to use?
>
> Thanks
>
> Em segunda-feira, 19 de março de 2012 16h43min03s UTC-3, Kurtis escreveu:
>
>> Did you check out django-celery yet?
>>
>> On Mon, Mar 19, 2012 at 2:18 PM, Arruda 
>> 
>> > wrote:
>>
>>> *(I've created a topic like this a few minutes ago, but was using the
>>> old google groups, and now it's broken. So I created a new one using the
>>> new google groups).*
>>> Hi, I'll try to explain the best I can my problem, and I don't know if
>>> what I'm trying to archive is the best way to get where I want, but
>>> here is it:
>>> I want that a specific view to run in a new thread, ex:
>>> * def foo(request):
>>>do_something_slow()
>>>   return httpResponse*
>>>
>>> But I DON'T want that a new thread is run inside the view, the view it
>>> self should be runned in another thread, ex:
>>> *
>>>  def foo(request):
>>>t = thread(target=do_something_slow())
>>>t.daemon = True
>>>t.start()
>>>
>>>   return httpResponse
>>> *
>>> This way when a user A access any page the site will load, even if a
>>> user B is accessing the 'foo' view.
>>> But the B user when access the view 'foo' will load it just a if if
>>> was a normal view( will be slow and will render the response just
>>> after do_something_slow() finished running).
>>>
>>> I don't know if this is what I want, but I believe that there is
>>> another way around:
>>> when user B calls foo view, it will render to him a page with a JS(I
>>> don't know JS either, so correct me if I'm talking nonsense) that say
>>> its "Loading..."
>>> And after the do_someting_slow() finished running if will change the
>>> content of the page to whatever the result of "do_something_slow" was.
>>>
>>> Thanks for the attention.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit https://groups.google.com/d/**
>>> msg/django-users/-/**jc20eqhcl8oJ<https://groups.google.com/d/msg/django-users/-/jc20eqhcl8oJ>
>>> .
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users+unsubscribe@*
>>> *googlegroups.com .
>>> For more options, visit this group at http://groups.google.com/**
>>> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/9Xk3RQ-y6pgJ.
>
> 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.
>

-- 
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: Question about threading a view[REPOSTED]

2012-03-20 Thread Jani Tiainen

20.3.2012 10:18, Marc Patermann kirjoitti:

Arruda schrieb (19.03.2012 19:18 Uhr):


I don't know if this is what I want, but I believe that there is
another way around:
when user B calls foo view, it will render to him a page with a JS(I
don't know JS either, so correct me if I'm talking nonsense) that say
its "Loading..."
And after the do_someting_slow() finished running if will change the
content of the page to whatever the result of "do_something_slow" was.

I think this is what the "Asynchronous" in AJAX stands for.
http://en.wikipedia.org/wiki/Ajax_%28programming%29
https://code.djangoproject.com/wiki/AJAX

Marc



That is not related to initial problem (long running tasks on server).

Even you can use AJAX calls to perfrom something asyncronously, it still 
requires open connection to server. If you have tasks that runs long, 
let's say 20 minutes your AJAX call will definitely be terminated (timed 
out). So that is not a right solution.


Using AJAX to query long running status makes a lot of sense though.

--

Jani Tiainen

--
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: Question about threading a view[REPOSTED]

2012-03-20 Thread Jani Tiainen

Hi,

Your solution will work perfectly in single process environment (For 
example with manage.py runserver )


But when you put your app behind webserver you usually invoke several 
processes. For example if you're using single round-robin loadbalancing

over 5 different Django instances.

What would happen if Django instances are restarted after n cycles (like 
our wsgi django instances are restarted after 1000 requests). Can you 
guarantee that your thread survives?


If you do "massive" scaling: what happens if you have multiple servers, 
how can you guarantee that consecutive requests from single user goes to 
same server and same process?


That is why there exists things like django-celery and rabbitmq (message 
broker). How they work is already explained to you.


20.3.2012 16:52, Arruda kirjoitti:

Thanks every one, I've manage to work this around.
The solution might not be the best, but it's working:
In the view I call the *do_something_slow()* in a new thread, and in the
end of it(after the role process is done) it change the model of a class
to add the feedback.
While the thread is running it renders the template to the user(with a
*"Loading..."* message).
Then I've made a *ajax_get_feed_back() *view to get this feedback.

In the template, I made a simple JS that every second tries to get the
feedback via ajax.
And if it gets the feedback it stops requesting it.
=)

But I still wanted to know how to use the celery in this case =/
But got very lost in that, does any one have a example(code) of
something similar to do with it?
In the docs I only found examples of process that are kind of tasks...
to run every hour, or things like that.

Em segunda-feira, 19 de março de 2012 15h18min09s UTC-3, Arruda escreveu:

*(I've created a topic like this a few minutes ago, but was using
the old google groups, and now it's broken. So I created a new one
using the new google groups).*
Hi, I'll try to explain the best I can my problem, and I don't know if
what I'm trying to archive is the best way to get where I want, but
here is it:
I want that a specific view to run in a new thread, ex:
*def foo(request):
do_something_slow()
return httpResponse*

But I DON'T want that a new thread is run inside the view, the view it
self should be runned in another thread, ex:
*
def foo(request):
t = thread(target=do_something_slow())
t.daemon = True
t.start()

return httpResponse
*
This way when a user A access any page the site will load, even if a
user B is accessing the 'foo' view.
But the B user when access the view 'foo' will load it just a if if
was a normal view( will be slow and will render the response just
after do_something_slow() finished running).

I don't know if this is what I want, but I believe that there is
another way around:
when user B calls foo view, it will render to him a page with a JS(I
don't know JS either, so correct me if I'm talking nonsense) that say
its "Loading..."
And after the do_someting_slow() finished running if will change the
content of the page to whatever the result of "do_something_slow" was.

Thanks for the attention.

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/ST6KqE0uPqsJ.
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.


--
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: Problem with Django starting up

2012-03-20 Thread Jani Tiainen

21.3.2012 7:50, Samuel Muiruri kirjoitti:

I can't get the first part to work



I assume that you have python installed to c:\python27\

You need to add c:\python27\scripts to your path.

Or alternatively:

c:\python27\scripts\django-admin.py startproject mysite

--

Jani Tiainen

--
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: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Jani Tiainen

20.3.2012 16:45, Another Django Newbie kirjoitti:



On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie wrote:



On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:

On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen 
wrote:
 > Hi,
 >
 > Since we use same setup except one part: we use mod_wsgi
instead of
 > mod_fcgi.
 >
 > (Since wsgi is considered to be defacto protocol). Could you
try to use it?
 >

WSGI is the de-facto for hosting python in web servers. If you
aren't
running just python, it's nice to use the same hosting mechanism for
all your apps, and fastcgi is a supported mechanism.

OP: You mention using mod_fcgid, but you do not give us any idea of
how you are using mod_fcgid. Configuration and error logs
please. FYI,
we run django quite happily under mod_fastcgi.

Cheers

Tom



Hi Tom, Jani,

Currently struggling to compile mod_wsgi, or more specifically a
shared library version of python - something to do with mismatched
32/64 bit libraries I think.

Here's an extract from httpd.conf.

RewriteEngine On
RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]

Options ExecCGI
AddHandler fcgid-script .cgi
# AddHandler cgi-script .cgi
Require all granted


and the relevant django.cgi

#!/usr/local/bin/python
from FcgiWsgiAdapter import list_environment, serve_wsgi

import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'

from django.core.handlers.wsgi import WSGIHandler

# use this to test that fastcgi works and to inspect the environment
# serve_wsgi(list_environment)
# use this to serve django
serve_wsgi(WSGIHandler())

The "FcgiWsgiAdapter" referred to came from djangosnippets.org
<http://djangosnippets.org/snippets/1307/>.

As to error logs, as I mentioned in the original post I don't see
anything added to any logs when this happens and there is only a
warning about the ssl library when apache is restarted.

Regards, ADN



*So I swapped to using WSGI with this apache config *

WSGIScriptAlias / /home/user/python/djcode/cfServer/apache/django.wsgi
WSGIDaemonProcess site-1 threads=30
WSGIProcessGroup site-1


AllowOverride None
Options None
Require all granted


and this django.wsgi

import os, sys
sys.path.append('/home/user/python/djcode')
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

and I get segmentation faults (debug level tracing from apache error log)

[Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid
47401308446624] AH00051: child pid 17490 exit signal Segmentation fault
(11), possible coredump in /tmp/apache2-gdb-dump
[Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid 47401308446624]
mod_wsgi (pid=17490): Process 'site-2' has died, deregister and restart it.
[Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid 47401308446624]
mod_wsgi (pid=17490): Process 'site-2' has been deregistered and will no
longer be monitored.
[Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid 47401308446624]
mod_wsgi (pid=17846): Starting process 'site-2' with uid=48, gid=48 and
threads=25.
[Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid 47401308446624]
mod_wsgi (pid=17846): Initializing Python.

Back trace on core file ...

Core was generated by `/usr/local/apache2/bin/httpd -k start'.
Program terminated with signal 11, Segmentation fault.
#0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
(gdb) bt
#0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
#1 0x2b1c7a05dd79 in apr_poll (aprset=0x7fff13f01e40, num=1,
nsds=0x7fff13f01e94, timeout=0) at poll/unix/poll.c:120
#2 0x2b1c7d5166d3 in wsgi_daemon_main (p=0x1257a138, daemon=0x12696218)
at mod_wsgi.c:11330
#3 0x2b1c7d51851f in wsgi_start_process (p=0x1257a138,
daemon=0x12696218)
at mod_wsgi.c:11969
#4 0x2b1c7d518f50 in wsgi_start_daemons (pconf=0x1257a138,
ptemp=, plog=,
s=) at mod_wsgi.c:12181
#5 wsgi_hook_init (pconf=0x1257a138, ptemp=,
plog=, s=) at mod_wsgi.c:13755
#6 0x00444c2c in ap_run_post_config (pconf=0x1257a138,
plog=0x125df538, ptemp=0x125a5348, s=0x125a3508) at config.c:101
#7 0x00428734 in main (argc=3, argv=0x7fff13f02498) at main.c:765



Using WSGI briefly solved the original problem, in that I could see the
complete admin page that was previously truncated but now nothing works
- I get

  1   2   3   4   5   6   7   8   >