Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-17 Thread DJ-Tom

Hi,

I'm also not sure if the python file is at the correct location.

This is how the directory structure looks:

my_project
\my_project\
 settings.py
\my_app\ # this is where my models are defined
 models.py
 formdesigner.py


Where should my formdesigner.py be located?

my_project ? 
my_project\my_project ?
my_project\my_app ?

What do I put into DJANGO_SETTINGS_MODULE?

'my_project.settings'?


Am Montag, 16. September 2013 18:17:21 UTC+2 schrieb Brad Pitcher:
>
> You need to do something like this before import django stuff:
>
> import os
> import sys
>
> sys.path.append(os.path.abspath(os.path.dirname(__file__)))
> os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
>
>
> -
>
>

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


Image Maps + Django

2013-09-17 Thread +Emmanuel
I am intending to implement something similar to this: 
https://opendata.go.ke/facet/counties
That has been developed in Ruby on Rails. How does Django handle image 
maps? Are there any additional Python/ Django libraries I will require? Is 
there a specific approach (best practices) way of solving this?
Thanks.

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


Re: How to raise exception in model?

2013-09-17 Thread Ladislav Prokopny
Thanks, that solves my problem.


On Mon, Sep 16, 2013 at 4:38 PM, C. Kirby  wrote:

> If you successfully get to render_to_response (or similar) the template
> renderer will silently swallow errors.
> If you want the error to stop rendering and either print an error or a 500
> or something similar, test it in the view before rendering.
>
> Assuming you have an entry (or list of entries I guess) in your view:
>
> for entry in entries: #for a list of entries
>try:
>entry.state
> except:
>return HttpResponse(status = 500)
>
> or something similar
>
>
>
> On Monday, September 16, 2013 5:36:02 AM UTC-5, Ladislav P wrote:
>>
>> I have some custom functions in model classes which processes some data,
>> and add custom attribute to the model. Thing is, I do not know how could I
>> raise an exception if this functions that are accessed when the template is
>> generated (the error seems to be only silent, so it will process the
>> template further but gives NO ERROR )
>>
>> In the template
>> {{ entry.state }}
>>
>> In the model:
>>
>> @property
>> def state(self):
>> somedict = {'a': 111}
>> try:
>>print somedict['b']
>> except Exception as e:
>>FATAL_ERROR
>>
>> What should I put in the place of fatal_error so that the template
>> processing should stop immediatelly, or gives some exception to the render
>> function ?
>> Thanks
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Image Maps + Django

2013-09-17 Thread Nigel Legg
Read the documentation on GeoDjango, it's all there

Cheers, Nigel
07914 740972



On 17 September 2013 09:54, +Emmanuel  wrote:

> I am intending to implement something similar to this:
> https://opendata.go.ke/facet/counties
> That has been developed in Ruby on Rails. How does Django handle image
> maps? Are there any additional Python/ Django libraries I will require? Is
> there a specific approach (best practices) way of solving this?
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Trouble with STATIC_URL in v1.5.2

2013-09-17 Thread Kelvin Wong
Check that your STATIC_URL setting in your template is outputting the same 
string as settings.STATIC_URL. Make sure that any included 
local_settings.py files are not wiping out those settings. You can check it 
using the Django shell:

$ python manage.py shell

>>> from django.conf import settings
>>> settings.STATIC_URL
'/assets/static/'

If not, check that you're using RequestContext to render your views. You 
can do this from the Django shell as well.

>>> from django.http import HttpRequest
>>> r = HttpRequest()
>>> from django.template import Template
>>> t = Template("{{ STATIC_URL }}")
>>> from django.template import RequestContext
>>> c = RequestContext(r, {})
>>> t.render(c)
u'/assets/static/'

Check that you're including 'django.core.context_processors.static'  in 
your settings.TEMPLATE_CONTEXT_PROCESSORS tuple.

>>> settings.TEMPLATE_CONTEXT_PROCESSORS
('django.contrib.auth.context_processors.auth', 
'django.core.context_processors.debug', 
'django.core.context_processors.i18n', 
'django.core.context_processors.media', 
'django.core.context_processors.static', 
'django.core.context_processors.tz', 
'django.contrib.messages.context_processors.messages')

K


On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam wrote:
>
> Maybe this is something well known. 
>
> I'm using STATIC_URL in my templates.  Worked perfectly in Django 1.4.x. 
> Upgraded to v1.5.2.  Now STATIC_URL ONLY works when the DEBUG setting is 
> True.  When set to False (For production), STATIC_URL is an empty string 
> in the template. 
>
> Anybody have any idea why this might be happening or what to look at? 
> Everything that needs to be set for STATIC_URL is set, otherwise it 
> wouldn't have worked in v1.4.x in the first place. 
>
> -- 
> Adam (ad...@csh.rit.edu ) 
>
>
>

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


Help with directory structure of the project

2013-09-17 Thread Ladislav Prokopny
Hi,

I have quite big problems with having the directory structure with correct
hierarchy and I decided to stop the development unless I will have it good.
I have order, customers, users .

So what I have is:

myproj
   |-myproj
   |-web_app
   |---orders (with views.py, ajax.py)
   |templatetags
   |---users
   |---customers
   |---search
   |---static
   |-app
   |---_base
   |-css
   |-images
   |-js
   |---orders
   |-css
   |-images
   |-js
   |---customers
   |-css
   |-images
   |-js
   |---users
   |-css
   |-images
   |-js
   |-bootbox
   |-bootstrap
   |---css
   |---fonts
   |---js
   |-dajax
   |---templates

models.py is in web_app directory, there are models common for all modules.
My questions are:

1) What changes would you do in this structure? (static files for every
module should be where?)
2) I have problem of inserting custom template tag defined in
orders/templatetags/orders_extras.py from users template. How can I make
some common templatetags for every "module" ?

Thank you.

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


Re: Paginattion: How do I pass current page number around views, forms and templates?

2013-09-17 Thread Marcin Szamotulski
You can also pass it around as a GET argument.

Best regards,
Marcin

On 02:10 Mon 16 Sep , DJ-Tom wrote:
> 
> I think I could use the views name as the key to the current page - that 
> way the system "remembers" the page number for each view.
> 
> Am Dienstag, 10. September 2013 18:59:19 UTC+2 schrieb ke1g:
> >
> > The remaining trick will be when to remove it from the session.  You don't 
> > want to go into another list and start at page 5.
> >
> >
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

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


m2m_changed signal not caught

2013-09-17 Thread Roberto López López

Hi,

I need to use the m2m_changed signal to assign permissions over an
object. But somehow, I cannot make it work.

To summarise, my models.py is as follows:

from cmsplugin_news.models import News
from django.contrib.auth.models import Group
from django.db import models
from guardian.shortcuts import assign_perm, remove_perm


class Department(models.Model):
news = models.ManyToManyField(
News, blank=True, related_name='departments'
)
write_group = models.ForeignKey(Group, blank=True)


@receiver(m2m_changed, sender=Department.news.through)
def _m2m_changed_news_departments(sender, instance, action, reverse,
model, pk_set, **kwargs):
if action == "pre_add":
for pk in pk_set:
d = Department.objects.get(pk__exact=pk)
assign_perm('cmsplugin_news.change_news', d.write_group,
instance)
assign_perm('cmsplugin_news.delete_news', d.write_group,
instance)
elif action == "pre_remove":
for pk in pk_set:
d = Department.objects.get(pk__exact=pk)
remove_perm('cmsplugin_news.change_news', d.write_group,
instance)
remove_perm('cmsplugin_news.delete_news', d.write_group,
instance)


The point is that the signal is never caught. I am editing the m2m
relation from the admin interface (as an inline in cmsplugin_news). When
I add/delete a department from the formset, the signal is never caught
by my method.

Any help here? Thank you very much.

Roberto


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


Hosting multiple sites on a single application

2013-09-17 Thread James Zildjian

Hi 

I am trying to run around 50 mini sites which share about 90% of their 
code. Each site simply queries and API and returns the results, and will be 
on it's own domain, and have a different style.css and config.py. The 
userbase (and the database generally) will be shared across the board. My 
initial idea was to run them as separate applications with a common 
library, each with their own UWSGI thread. However, I have concerns about 
large memory use. 

I have read about the sites framework which would allow them to run from a 
single instance.

https://docs.djangoproject.com/en/dev/ref/contrib/sites/

My question is, is the site framework the right approach to a problem like 
this, and does it have real benefits over running separate applications. I 
have heard the following:

*Your SITE_ID is set in settings.py, so in order to have multiple sites, 
you need multiple settings.py configurations, which means multiple distinct 
processes/instances. You can of course share the code base between them, 
but each site will need a dedicated worker / WSGIDaemon to serve the site.*

Alternative ideas of systems:

https://github.com/iivvoo/django_layers
https://github.com/shestera/django-multisite 

Any ideas or help would be most appreciated.

James

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


Re: Model inheritance problem

2013-09-17 Thread George Lund


> class MyBaseModel(models.NodeModel):
>name=StringProperty()
>class Meta:
>abstract = True
>
>
In Django you would need CharField or similar. StringProperty is a Google 
App Engine thing? Cf 
http://stackoverflow.com/questions/6132695/django-module-object-has-no-attribute-stringproperty

So your base model has no field called "name".

HTH

George

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


Re: Trouble with STATIC_URL in v1.5.2

2013-09-17 Thread Adam Stein
Turns out that I had to use the new {% static %} template tag.  It seems
that STATIC_URL is only set in the context for template use when in
DEBUG mode (didn't look in the code, but it appears that way).

{% static %} works for both development and production environments.  It
was pretty simple for me to switch.  All STATIC_ variables were already
set correctly.  I just needed to add this to the top of my base template
file:

{% load static %}
{% get_static_prefix as STATIC_URL %}

and everything else remained the same.

On Tue, 2013-09-17 at 02:42 -0700, Kelvin Wong wrote:
> Check that your STATIC_URL setting in your template is outputting the
> same string as settings.STATIC_URL. Make sure that any included
> local_settings.py files are not wiping out those settings. You can
> check it using the Django shell:
> 
> 
> $ python manage.py shell
> 
> 
> >>> from django.conf import settings
> >>> settings.STATIC_URL
> '/assets/static/'
> 
> 
> If not, check that you're using RequestContext to render your views.
> You can do this from the Django shell as well.
> 
> 
> >>> from django.http import HttpRequest
> >>> r = HttpRequest()
> >>> from django.template import Template
> >>> t = Template("{{ STATIC_URL }}")
> >>> from django.template import RequestContext
> >>> c = RequestContext(r, {})
> >>> t.render(c)
> u'/assets/static/'
> 
> 
> Check that you're including 'django.core.context_processors.static'
>  in your settings.TEMPLATE_CONTEXT_PROCESSORS tuple.
> 
> 
> >>> settings.TEMPLATE_CONTEXT_PROCESSORS
> ('django.contrib.auth.context_processors.auth',
> 'django.core.context_processors.debug',
> 'django.core.context_processors.i18n',
> 'django.core.context_processors.media',
> 'django.core.context_processors.static',
> 'django.core.context_processors.tz',
> 'django.contrib.messages.context_processors.messages')
> 
> K
> 
> 
> 
> On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam wrote:
> Maybe this is something well known. 
> 
> I'm using STATIC_URL in my templates.  Worked perfectly in
> Django 1.4.x. 
> Upgraded to v1.5.2.  Now STATIC_URL ONLY works when the DEBUG
> setting is 
> True.  When set to False (For production), STATIC_URL is an
> empty string 
> in the template. 
> 
> Anybody have any idea why this might be happening or what to
> look at? 
> Everything that needs to be set for STATIC_URL is set,
> otherwise it 
> wouldn't have worked in v1.4.x in the first place. 
> 
> -- 
> Adam (ad...@csh.rit.edu) 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
Adam (a...@csh.rit.edu)


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


Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-17 Thread DJ-Tom
I need to use the ORM and more specifcally I want to use the models I 
defined inside my Django application.

I want to avoid using a different ORM like Alchemy because then I would 
have to duplicate the work I already put into my Django models - i hate 
duplicating work...

Apart from that, I don't need much else (maybe the template engine for 
sending emails...)

The formdesigner application should live inside the web application 
structure so I can manage it the same way as I'm doing it with the web 
application and have it included in the same Subversion project.

Thomas

Am Montag, 16. September 2013 18:38:35 UTC+2 schrieb אברהם סרור:
>
> the question is what for? other than the ORM what else is useful for a 
> desktop app?
> if it is only the ORM you want take a look at http://www.sqlalchemy.org/
>
>

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


Re: Recommended dev environment for a Django project deployed to Linode

2013-09-17 Thread Vernon D. Cole

I installed a client for my favourite distributed version control system on 
my Linode instance.  I have a private repository on a public IP.  (github, 
bitbucket, or launchpad will work, depending on your dvcs of choice -- I 
have used all three, and other times I have used a private dvcs host, 
including my Linode server itself.) I "cloned" a "checkout" of my django 
system to the Linode. When I am happy from testing a new version of my 
application:  I push it to the repository,  log in to my Linode using ssh, 
and do a pull.  Easy and error free.  (My django environment is almost 
exactly like yours with PostGIS, etc.)
--

On Monday, September 16, 2013 6:33:49 PM UTC+1, Jorge Arevalo wrote:
>
> Hello,
>
> I'm going to start a project based on (Geo)Django + PostgreSQL/PostGIS + 
> OpenLayers/LeafLet + Bootstrap/Foundation. The project will be deployed to 
> a Linode box. That box will be created with something like this: 
> https://manager.linode.com/linodes/deploy/linode393074?StackScriptID=6482
>
> My work box is a MacBook with Mac OS X 10.6.8. There will be 2 people 
> working on the web app (me and another guy). I have almost total freedom to 
> choose, so I want to choose wisely. The whole point is that these 
> constraints should be satisfied:
>
> - I need a reliable way to upload the application to the test/production 
> environments. At least the production environment will be a Linode box. I 
> just don't want to upload files via FTP, or manually copy them with rsync, 
> or any other practice easily subject to errors. How do the professional 
> django developers set up their environment in order to deploy the app?
>
> - I'm not sure about which IDE/editor choose. I don't want to start an 
> editor war, and I've used several options in the past. My main interest is: 
> I want to focus on develop. If Eclipse/Aptana/Eric/PyCharm/any IDE can be 
> easily "linked" to my environment, that's my choice. For example, if I can 
> deploy my app to test/production environment with a couple of clicks or 
> commands, thanks to a plugin or script, that's great. Like deploying to 
> Heroku or EC2, but with Linode. Is there any IDE specially friendly with 
> this kind of development environment?
>
> - The other(s) developer(s) must be up&running ASAP. They can't spend half 
> a day installing and configuring stuff to start being productive. I guess a 
> VirtualBox machine + Vagrant would be a good choice here. But, would it 
> make more difficult the deployment cycle? And using a virtual machine to 
> just open the IDE and develop sounds like a resource waste to me. Is there 
> any other solution?
>
> I think I should use, at least, VirtualEnv, VirtualEnvWrapper and PIP, 
> like I've read in these useful links
>
>
> http://www.slideshare.net/ryan_blunden/virtualenv-and-pip-isolated-python-environments
> http://www.slideshare.net/ajdiaz/isolated-development-in-python
>
> But I'd like to know the opinion of Djanjo experts / hard "pythonistas". 
> Any suggestion is strongly appreciated.
>
> Many thanks in advance, and best regards
>
>

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


Re: Model inheritance problem

2013-09-17 Thread Antonio Mignolli
Thanks, George, but as I said in the beginning, I'm using neo4django, 
which surely has StringProperty, otherwise I would have an 
AttributeError on StringProperty, which I don't have.

I should have written:
from neo4django.db import models

and 
...
name = models.StringProperty(indexed=True)

for completeness.

I think I just discovered another neo4django issue,
in fact it works perfectly only if such attribute 
is not defined with indexed = True.


Il giorno martedì 17 settembre 2013 14:27:34 UTC+2, George Lund ha scritto:
>
>
> class MyBaseModel(models.NodeModel):
>>name=StringProperty()
>>class Meta:
>>abstract = True
>>
>>
> In Django you would need CharField or similar. StringProperty is a Google 
> App Engine thing? Cf 
> http://stackoverflow.com/questions/6132695/django-module-object-has-no-attribute-stringproperty
>
> So your base model has no field called "name".
>
> HTH
>
> George
>

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


Re: Model inheritance problem

2013-09-17 Thread Antonio Mignolli
Hmm, no, it does not work even without indexed=True, 
my mistake.
So the "issue" remains.

Il giorno martedì 17 settembre 2013 16:17:04 UTC+2, Antonio Mignolli ha 
scritto:
>
> Thanks, George, but as I said in the beginning, I'm using neo4django, 
> which surely has StringProperty, otherwise I would have an 
> AttributeError on StringProperty, which I don't have.
>
> I should have written:
> from neo4django.db import models
>
> and 
> ...
> name = models.StringProperty(indexed=True)
>
> for completeness.
>
> I think I just discovered another neo4django issue,
> in fact it works perfectly only if such attribute 
> is not defined with indexed = True.
>
>
> Il giorno martedì 17 settembre 2013 14:27:34 UTC+2, George Lund ha scritto:
>>
>>
>> class MyBaseModel(models.NodeModel):
>>>name=StringProperty()
>>>class Meta:
>>>abstract = True
>>>
>>>
>> In Django you would need CharField or similar. StringProperty is a Google 
>> App Engine thing? Cf 
>> http://stackoverflow.com/questions/6132695/django-module-object-has-no-attribute-stringproperty
>>
>> So your base model has no field called "name".
>>
>> HTH
>>
>> George
>>
>

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


Re: Recommended dev environment for a Django project deployed to Linode

2013-09-17 Thread Vernon D. Cole
Answering the other half of your question:  The choice of IDE is not nearly 
as important as its ease of integration with your dvcs.  If you are already 
familiar with a good one, don't change.

On my present project, my boss and I are both using PyCharm, and my other 
co-worker is using Eclipse, since he is more comfortable (and therefore, 
more productive) with it. Both IDE's have good integration with git (my 
least favourite dvcs, but the boss's choice) and our sharing is done using 
a group private repository on github.  This is on Ubuntu Linux, it all 
works well.   In the evening hours, I use PyCharm on Windows 7 to 
contribute to an open source project hosted on bitbucket using mercurial. 
Both projects end up being tested on the same Linode.

Yes, use virtualenv.  I also made the mistake of thinking of it as a 
virtual computer.  It is not.  It is only a method of separating Python 
library directories so that you can experiment with different 
configurations easily.  It does not slow anything down, and actually makes 
installation of packages easier.  Use virtualenvwrapper to make switching 
environments easy.  PyCharm also supports virtual environments as well as 
django projects. It is commercial, and suffers from a few Java 
idiosyncrasies, but the boss paid for the license ;-) so I don't mind.

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


Re: Model inheritance problem

2013-09-17 Thread George Lund
Ah okay, well I've never used that, I thought you were implying this could 
be a general Django question.

Maybe neo4django doesn't support model inheritance -- I took a look at 
their site briefly and couldn't see anything about it.

Sorry not to be more help...

On Tuesday, 17 September 2013 15:28:08 UTC+1, Antonio Mignolli wrote:
>
> Hmm, no, it does not work even without indexed=True, 
> my mistake.
> So the "issue" remains.
>
> Il giorno martedì 17 settembre 2013 16:17:04 UTC+2, Antonio Mignolli ha 
> scritto:
>>
>> Thanks, George, but as I said in the beginning, I'm using neo4django, 
>> which surely has StringProperty, otherwise I would have an 
>> AttributeError on StringProperty, which I don't have.
>>
>> I should have written:
>> from neo4django.db import models
>>
>> and 
>> ...
>> name = models.StringProperty(indexed=True)
>>
>> for completeness.
>>
>> I think I just discovered another neo4django issue,
>> in fact it works perfectly only if such attribute 
>> is not defined with indexed = True.
>>
>>
>> Il giorno martedì 17 settembre 2013 14:27:34 UTC+2, George Lund ha 
>> scritto:
>>>
>>>
>>> class MyBaseModel(models.NodeModel):
name=StringProperty()
class Meta:
abstract = True


>>> In Django you would need CharField or similar. StringProperty is a 
>>> Google App Engine thing? Cf 
>>> http://stackoverflow.com/questions/6132695/django-module-object-has-no-attribute-stringproperty
>>>
>>> So your base model has no field called "name".
>>>
>>> HTH
>>>
>>> George
>>>
>>

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


Re: m2m_changed signal not caught

2013-09-17 Thread John DeRosa
>From memory, I _think_ this catches the signal from the Department model, not 
>the News model. To catch it when you edit the relationship from a *News* model 
>form, you need to hook it up ("sender=News.department.through"). 

On Sep 17, 2013, at 3:59 AM, Roberto López López  wrote:

> 
> Hi,
> 
> I need to use the m2m_changed signal to assign permissions over an object. 
> But somehow, I cannot make it work.
> 
> To summarise, my models.py is as follows:
> 
> from cmsplugin_news.models import News
> from django.contrib.auth.models import Group
> from django.db import models
> from guardian.shortcuts import assign_perm, remove_perm
> 
> 
> class Department(models.Model):
> news = models.ManyToManyField(
> News, blank=True, related_name='departments'
> )
> write_group = models.ForeignKey(Group, blank=True)
> 
> 
> @receiver(m2m_changed, sender=Department.news.through)
> def _m2m_changed_news_departments(sender, instance, action, reverse, model, 
> pk_set, **kwargs):
> if action == "pre_add":
> for pk in pk_set:
> d = Department.objects.get(pk__exact=pk)
> assign_perm('cmsplugin_news.change_news', d.write_group, instance)
> assign_perm('cmsplugin_news.delete_news', d.write_group, instance)
> elif action == "pre_remove":
> for pk in pk_set:
> d = Department.objects.get(pk__exact=pk)
> remove_perm('cmsplugin_news.change_news', d.write_group, instance)
> remove_perm('cmsplugin_news.delete_news', d.write_group, instance)
> 
> The point is that the signal is never caught. I am editing the m2m relation 
> from the admin interface (as an inline in cmsplugin_news). When I 
> add/delete a department from the formset, the signal is never caught by my 
> method.
> 
> Any help here? Thank you very much.
> 
> Roberto
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

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


Re: Trouble with STATIC_URL in v1.5.2

2013-09-17 Thread Kelvin Wong
If your software works then I guess it works, but I just ran this in the 
shell on Django 1.5.4.

$ python manage.py shell
Python 2.7.3 (default, May  4 2012, 11:07:18) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> settings.STATIC_URL
'/static/'
>>> settings.DEBUG
False
>>> from django.http import HttpRequest
>>> r = HttpRequest()
>>> from django.template import Template
>>> t = Template("{{ STATIC_URL }}")
>>> from django.template import RequestContext
>>> c = RequestContext(r, {})
>>> t.render(c)
u'/static/'
>>> import django
>>> django.get_version()
'1.5.4'

If you look at django.core.context_processors you can see that the 
STATIC_URL is placed in the RequestContext unconditionally on line 65:

https://github.com/django/django/blob/stable/1.5.x/django/core/context_processors.py

K



On Tuesday, September 17, 2013 6:09:54 AM UTC-7, Adam wrote:
>
> Turns out that I had to use the new {% static %} template tag.  It seems 
> that STATIC_URL is only set in the context for template use when in 
> DEBUG mode (didn't look in the code, but it appears that way). 
>
> {% static %} works for both development and production environments.  It 
> was pretty simple for me to switch.  All STATIC_ variables were already 
> set correctly.  I just needed to add this to the top of my base template 
> file: 
>
> {% load static %} 
> {% get_static_prefix as STATIC_URL %} 
>
> and everything else remained the same. 
>
> On Tue, 2013-09-17 at 02:42 -0700, Kelvin Wong wrote: 
> > Check that your STATIC_URL setting in your template is outputting the 
> > same string as settings.STATIC_URL. Make sure that any included 
> > local_settings.py files are not wiping out those settings. You can 
> > check it using the Django shell: 
> > 
> > 
> > $ python manage.py shell 
> > 
> > 
> > >>> from django.conf import settings 
> > >>> settings.STATIC_URL 
> > '/assets/static/' 
> > 
> > 
> > If not, check that you're using RequestContext to render your views. 
> > You can do this from the Django shell as well. 
> > 
> > 
> > >>> from django.http import HttpRequest 
> > >>> r = HttpRequest() 
> > >>> from django.template import Template 
> > >>> t = Template("{{ STATIC_URL }}") 
> > >>> from django.template import RequestContext 
> > >>> c = RequestContext(r, {}) 
> > >>> t.render(c) 
> > u'/assets/static/' 
> > 
> > 
> > Check that you're including 'django.core.context_processors.static' 
> >  in your settings.TEMPLATE_CONTEXT_PROCESSORS tuple. 
> > 
> > 
> > >>> settings.TEMPLATE_CONTEXT_PROCESSORS 
> > ('django.contrib.auth.context_processors.auth', 
> > 'django.core.context_processors.debug', 
> > 'django.core.context_processors.i18n', 
> > 'django.core.context_processors.media', 
> > 'django.core.context_processors.static', 
> > 'django.core.context_processors.tz', 
> > 'django.contrib.messages.context_processors.messages') 
> > 
> > K 
> > 
> > 
> > 
> > On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam wrote: 
> > Maybe this is something well known. 
> > 
> > I'm using STATIC_URL in my templates.  Worked perfectly in 
> > Django 1.4.x. 
> > Upgraded to v1.5.2.  Now STATIC_URL ONLY works when the DEBUG 
> > setting is 
> > True.  When set to False (For production), STATIC_URL is an 
> > empty string 
> > in the template. 
> > 
> > Anybody have any idea why this might be happening or what to 
> > look at? 
> > Everything that needs to be set for STATIC_URL is set, 
> > otherwise it 
> > wouldn't have worked in v1.4.x in the first place. 
> > 
> > -- 
> > Adam (ad...@csh.rit.edu) 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to django-users...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>
> -- 
> Adam (ad...@csh.rit.edu ) 
>
>
>

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


Re: m2m_changed signal not caught

2013-09-17 Thread Roberto López López

Thanks for your advice, but that dint't solve the issue :-/

@receiver(m2m_changed, sender=News.department.through)



On 09/17/2013 05:02 PM, John DeRosa wrote:
> From memory, I _think_ this catches the signal from the Department
> model, not the News model. To catch it when you edit the relationship
> from a *News* model form, you need to hook it up
> ("sender=News.department.through"). 
>
> On Sep 17, 2013, at 3:59 AM, Roberto López López  > wrote:
>
>>
>> Hi,
>>
>> I need to use the m2m_changed signal to assign permissions over an
>> object. But somehow, I cannot make it work.
>>
>> To summarise, my models.py is as follows:
>>
>> from cmsplugin_news.models import News
>> from django.contrib.auth.models import Group
>> from django.db import models
>> from guardian.shortcuts import assign_perm, remove_perm
>>
>>
>> class Department(models.Model):
>> news = models.ManyToManyField(
>> News, blank=True, related_name='departments'
>> )
>> write_group = models.ForeignKey(Group, blank=True)
>>
>>
>> @receiver(m2m_changed, sender=Department.news.through)
>> def _m2m_changed_news_departments(sender, instance, action,
>> reverse, model, pk_set, **kwargs):
>> if action == "pre_add":
>> for pk in pk_set:
>> d = Department.objects.get(pk__exact=pk)
>> assign_perm('cmsplugin_news.change_news',
>> d.write_group, instance)
>> assign_perm('cmsplugin_news.delete_news',
>> d.write_group, instance)
>> elif action == "pre_remove":
>> for pk in pk_set:
>> d = Department.objects.get(pk__exact=pk)
>> remove_perm('cmsplugin_news.change_news',
>> d.write_group, instance)
>> remove_perm('cmsplugin_news.delete_news',
>> d.write_group, instance)
>>
>>
>> The point is that the signal is never caught. I am editing the m2m
>> relation from the admin interface (as an inline in cmsplugin_news).
>> When I add/delete a department from the formset, the signal is never
>> caught by my method.
>>
>> Any help here? Thank you very much.
>>
>> Roberto
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to django-users@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

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


Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-17 Thread Brad Pitcher
To make my code work, you could set DJANGO_SETTINGS_MODULE to
'my_project.settings', and just put formdesigner.py directly under
my_project.

If you wanted to keep formdesigner.py where it is, you would want to change
the sys.path.append line to this:

sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),
'..'))


-
Brad Pitcher


On Tue, Sep 17, 2013 at 12:25 AM, DJ-Tom  wrote:

>
> Hi,
>
> I'm also not sure if the python file is at the correct location.
>
> This is how the directory structure looks:
>
> my_project
> \my_project\
>  settings.py
> \my_app\ # this is where my models are defined
>  models.py
>  formdesigner.py
>
>
> Where should my formdesigner.py be located?
>
> my_project ?
> my_project\my_project ?
> my_project\my_app ?
>
> What do I put into DJANGO_SETTINGS_MODULE?
>
> 'my_project.settings'?
>
>
> Am Montag, 16. September 2013 18:17:21 UTC+2 schrieb Brad Pitcher:
>
>> You need to do something like this before import django stuff:
>>
>> import os
>> import sys
>>
>> sys.path.append(os.path.**abspath(os.path.dirname(__**file__)))
>> os.environ['DJANGO_SETTINGS_**MODULE'] = 'web.settings'
>>
>>
>> -
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Trouble with STATIC_URL in v1.5.2

2013-09-17 Thread Adam Stein
I'm not using RequestContext().  The behavior must have changed between
v1.4 and v1.5 regarding this.

On Tue, 2013-09-17 at 08:27 -0700, Kelvin Wong wrote:
> If your software works then I guess it works, but I just ran this in
> the shell on Django 1.5.4.
> 
> 
> $ python manage.py shell
> Python 2.7.3 (default, May  4 2012, 11:07:18) 
> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>> from django.conf import settings
> >>> settings.STATIC_URL
> '/static/'
> >>> settings.DEBUG
> False
> >>> from django.http import HttpRequest
> >>> r = HttpRequest()
> >>> from django.template import Template
> >>> t = Template("{{ STATIC_URL }}")
> >>> from django.template import RequestContext
> >>> c = RequestContext(r, {})
> >>> t.render(c)
> u'/static/'
> >>> import django
> >>> django.get_version()
> '1.5.4'
> 
> 
> If you look at django.core.context_processors you can see that the
> STATIC_URL is placed in the RequestContext unconditionally on line 65:
> 
> 
> https://github.com/django/django/blob/stable/1.5.x/django/core/context_processors.py
> 
> 
> 
> K
> 
> 
> 
> 
> 
> On Tuesday, September 17, 2013 6:09:54 AM UTC-7, Adam wrote:
> Turns out that I had to use the new {% static %} template
> tag.  It seems 
> that STATIC_URL is only set in the context for template use
> when in 
> DEBUG mode (didn't look in the code, but it appears that
> way). 
> 
> {% static %} works for both development and production
> environments.  It 
> was pretty simple for me to switch.  All STATIC_ variables
> were already 
> set correctly.  I just needed to add this to the top of my
> base template 
> file: 
> 
> {% load static %} 
> {% get_static_prefix as STATIC_URL %} 
> 
> and everything else remained the same. 
> 
> On Tue, 2013-09-17 at 02:42 -0700, Kelvin Wong wrote: 
> > Check that your STATIC_URL setting in your template is
> outputting the 
> > same string as settings.STATIC_URL. Make sure that any
> included 
> > local_settings.py files are not wiping out those settings.
> You can 
> > check it using the Django shell: 
> > 
> > 
> > $ python manage.py shell 
> > 
> > 
> > >>> from django.conf import settings 
> > >>> settings.STATIC_URL 
> > '/assets/static/' 
> > 
> > 
> > If not, check that you're using RequestContext to render
> your views. 
> > You can do this from the Django shell as well. 
> > 
> > 
> > >>> from django.http import HttpRequest 
> > >>> r = HttpRequest() 
> > >>> from django.template import Template 
> > >>> t = Template("{{ STATIC_URL }}") 
> > >>> from django.template import RequestContext 
> > >>> c = RequestContext(r, {}) 
> > >>> t.render(c) 
> > u'/assets/static/' 
> > 
> > 
> > Check that you're including
> 'django.core.context_processors.static' 
> >  in your settings.TEMPLATE_CONTEXT_PROCESSORS tuple. 
> > 
> > 
> > >>> settings.TEMPLATE_CONTEXT_PROCESSORS 
> > ('django.contrib.auth.context_processors.auth', 
> > 'django.core.context_processors.debug', 
> > 'django.core.context_processors.i18n', 
> > 'django.core.context_processors.media', 
> > 'django.core.context_processors.static', 
> > 'django.core.context_processors.tz', 
> > 'django.contrib.messages.context_processors.messages') 
> > 
> > K 
> > 
> > 
> > 
> > On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam
> wrote: 
> > Maybe this is something well known. 
> > 
> > I'm using STATIC_URL in my templates.  Worked
> perfectly in 
> > Django 1.4.x. 
> > Upgraded to v1.5.2.  Now STATIC_URL ONLY works when
> the DEBUG 
> > setting is 
> > True.  When set to False (For production),
> STATIC_URL is an 
> > empty string 
> > in the template. 
> > 
> > Anybody have any idea why this might be happening or
> what to 
> > look at? 
> > Everything that needs to be set for STATIC_URL is
> set, 
> > otherwise it 
> > wouldn't have worked in v1.4.x in the first place. 
> > 
> > -- 
> > Adam (ad...@csh.rit.edu) 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the
>

Re: django template string and int comparison behavior

2013-09-17 Thread Rafael Durán Castañeda
Hi,

I don´t think using requests objects into templates is a good idea, use request 
object in the view so you source the template context with whatever you need.

HTH

El 17/09/2013, a las 20:50, J Y  escribió:

> I am building a search form that provides a drop down list, and then on the 
> search results, I am redisplaying the search form, but with the search 
> parameters already pre-selected, so this is what I attempted to do:
> 
> 
> {% for item in object_list %}
>  selected="selected" {% endif %}>
> {{ item.name }}
> 
> {% endfor %}
> 
> 
> Unfortunately, this did not work.  When I did some testing, I realized that 
> item.id is giving back an int, while request.GET.system is giving back a 
> string.  If I used the view to change the GET value to an int in the context, 
> then the comparison works.
> 
> What I am wondering is, is this expected behavior?  Does the request object 
> always return a string, and that I am better off writing my own custom tag to 
> convert request objects into int for comparison?  What is the best practice 
> to employ here?  I am fairly new to django and could use some pointers.
> 
> Thanks,
> 
> Jack
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

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


Re: Any API for dojo/jquery in django template language ?? For dojo i need urgently , thanks

2013-09-17 Thread Nikolas Stevenson-Molnar
I'm not sure I understand your question. You can use jQuery and/or Dojo
in your Django template the same as you would anywhere else. If you want
nice integration between Django forms and Dojo dijits, you might be
interested in Dojango: https://github.com/klipstein/dojango/

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

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


django template string and int comparison behavior

2013-09-17 Thread J Y
I am building a search form that provides a drop down list, and then on the 
search results, I am redisplaying the search form, but with the search 
parameters already pre-selected, so this is what I attempted to do:


{% for item in object_list %}

{{ item.name }}

{% endfor %}


Unfortunately, this did not work.  When I did some testing, I realized that 
item.id is giving back an int, while request.GET.system is giving back a 
string.  If I used the view to change the GET value to an int in the 
context, then the comparison works.

What I am wondering is, is this expected behavior?  Does the request object 
always return a string, and that I am better off writing my own custom tag 
to convert request objects into int for comparison?  What is the best 
practice to employ here?  I am fairly new to django and could use some 
pointers.

Thanks,

Jack

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


iterating over a queryset?

2013-09-17 Thread Johan Bergkvist
Hi 
I'm quite new to both django and python, and OOP for that matter. I do have 
some embedded programming experience though.
I have a question regarding querysets and dictionaries, I think.

I was trying to build a model that provides an overview for subscribed 
customers over their services and subscription status, etc.

I have a model like this:
class Customer (models.Model):
user_id = models.AutoField( primary_key=True )
auth_user = models.OneToOneField( User)
subscription_type = models.ForeignKey( SubscType, related_name='type', 
null = 'true', blank = 'true' )
first_name = models.CharField( max_length = 64, verbose_name = 
'Fornavn' )
last_name = models.CharField( max_length = 64, verbose_name = 
'Efternavn' )
email_address = models.EmailField( max_length = 75, verbose_name = 
'eMail adresse' )
join_date = models.DateField(auto_now_add = 'True', verbose_name = 
'Oprettet dato')
delivery_address = models.ForeignKey( Address, related_name='delivery', 
null = 'true', blank = 'true', verbose_name = 'Leveringsadresse')
address = models.ForeignKey( Address, related_name='home', verbose_name 
= 'Hjemmeadresse' )
phone_number = models.IntegerField(max_length = 10, verbose_name = 
'Telefon nummer')
mobile_number = models.IntegerField(max_length = 10, blank = 'true', 
null = 'true', verbose_name = 'Mobilnummer')
image = models.ImageField(upload_to = 'Customer_img', blank = 'true', 
verbose_name = 'Billede')

class customerHistory (models.Model):
customer_id = models.ForeignKey( Customer, related_name ='customer' )
used_service = models.ManyToManyField(Services, related_name='services' 
)
action_date = models.DateField(auto_now_add = 'True')
notes = models.TextField(verbose_name = 'Noter til handling')

views like so:
class CustomerInfo(TemplateView):
#info page, displays base info about customer such as address, phone 
number and  subscription entries
template_name = "subscribtions/info.html"
   

def get_context_data(self, **kwargs):
context = super(CustomerInfo, self).get_context_data(**kwargs)

context = Customer.objects.filter( auth_user = self.request.user 
).values(
'first_name', 
'last_name', 
'address', 
'delivery_address',
'phone_number',
'mobile_number',
'email_address', 
'join_date',
'subscription_type',
'image'
).get()
return { 'info' : context }

First of all, when I ommit the .get() method I cannot iterate over the 
above query, I just get an empty queryset when doing this:
{% for key, value in info.items %}
{{ key }}: {{ value }} 
{% empty %} 
 no data 
{% endfor %}

I guess this has something to do with it not being a dictionary without the 
.get() method. But in the documentation it seems that it should return a 
iterable, I might be using it wrong, any suggestions?

Second question is:
When I try to to a "backwards relation" in the template, like so:
{% for services in info.customerhistory_set.all %}
{{ services }}
{% endfor %}
It also winds up empty.
It might be that I'm interpreting the documentation wrong but I've been 
googling on this subject and tried several different combinations. Any help?

Thanks 
Johan

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


Re: django template string and int comparison behavior

2013-09-17 Thread Bill Freeman
Yes, this is the expected behavior.  The GET parameter is a string, being
something that is just parsed out of the query parameter portion of the URL
(which is, itself, a string).  There is nothing to inform the code that
parses the query parameters which of the things that might look like
numbers should be converted to int, float, or left alone.  Since converting
to a numeric type and back is not a null operation ('001' -> 1 -> '1',
'1.00' -> 1.0 -> '1.0'), leaving it as the string it is already is the
correct choice.  Knowing how a parameter is to be interpreted is an
application specific task.

Probably the correct approach for you is to have view code capture the
system argument and convert it to an int (perhaps there is a form field
instance handy which has already done that and put it in the form's
cleaned_data?), and pass that into the template context.  Then compare
item.id to that, rather than something you dug out of request.GET.

Bill


On Tue, Sep 17, 2013 at 2:50 PM, J Y  wrote:

> I am building a search form that provides a drop down list, and then on
> the search results, I am redisplaying the search form, but with the search
> parameters already pre-selected, so this is what I attempted to do:
>
> 
> {% for item in object_list %}
>  %} selected="selected" {% endif %}>
> {{ item.name }}
> 
> {% endfor %}
> 
>
> Unfortunately, this did not work.  When I did some testing, I realized
> that item.id is giving back an int, while request.GET.system is giving
> back a string.  If I used the view to change the GET value to an int in the
> context, then the comparison works.
>
> What I am wondering is, is this expected behavior?  Does the request
> object always return a string, and that I am better off writing my own
> custom tag to convert request objects into int for comparison?  What is the
> best practice to employ here?  I am fairly new to django and could use some
> pointers.
>
> Thanks,
>
> Jack
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


iterating over a queryset?

2013-09-17 Thread Daniel Roseman
Without the get(), you get a queryset, which is an iterable of all elements 
that match the query - in effect, a list of dicts. Even though only one record 
matches, you still get a queryset containing a single dict. So in order to use 
that in your template, you'd have to add an outer loop iterating through each 
item in the queryset, while the inner loop iterates over the elements in each 
dict.

Reverse relations work with a model instance. But you don't have one of those - 
you've got a dict, because you used .values(). If you dropped that call, you'd 
have an instance which you could use the backwards relation on, but you 
wouldn't be able to iterate over the fields with .items(). Note that most of 
the time you don't need to do that, so mostly you would use the instance rather 
than calling .values().

-- 
DR.

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


Exception Value: 'Decimal' object is not callable dont no where this is coming from, Any help will be kindly appreciated

2013-09-17 Thread MAurice
class Loan(models.Model):
id = models.AutoField(primary_key=True,default=1)
loan_type   =models.CharField(max_length=20, 
choices=LTYPE,default=1)
def number():
no =Account.objects.count()
if no == None:
return 10
else:
return no + 11



loan_statement_no=models.IntegerField(('loan_statement_no'),max_length=10, 
unique =True, default=number)
branch_cod  =models.IntegerField(blank=True, null=True)
comp_per_ya =models.IntegerField(default=1, help_text="Number 
of compoundings in a year")
time_years  =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=1)
loan_number =models.SlugField(unique=True)
#branch =models.ManyToManyField(Branche)
start_date  =models.DateField(blank=True, 
null=True,default=datetime.datetime.now())
end_date=models.DateField(blank=True, null=True)
no_days =models.IntegerField(default=1)
account_name=models.ForeignKey(Account)
loan_amount =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2)
interest_rate   =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
compound_period =models.IntegerField(max_length=64, 
choices=compound_period, default=Yearly)
loan_fee=models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
ammount_repaid= models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
sd_amount   =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
dd_amount   =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
#interest (base) rate
ib_rate =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
#interest (penal) rate
ip_rate =models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, null=True, blank=True)
#interest repayment frequency
ir_frequency
=models.IntegerField(max_length=64,choices=IRFREQUENCY,default=WEEKLY)
pr_frequency
=models.IntegerField(max_length=64,choices=PRFREQUENCY,default=DAILY,help_text="Suggested
 
value automatically generated from title. Must be unique.")


last_edit_time  = models.TimeField(auto_now=True)
last_edit_date  = models.DateField(auto_now=True)
   no_of_instalments = models.DecimalField(default=1.0, 
max_digits=10, decimal_places=2, null=True, blank=True)
no_of_instalments_interest =models.DecimalField(default=1.0, 
max_digits=10, decimal_places=2, null=True, blank=True)
interest_charged = models.DecimalField(default=1.0, max_digits=10, 
decimal_places=2, editable=False)
   

def save(self, *args, **kwargs):
i
self.no_days =(self.end_date - self.start_date).days
self.required_payment =self.loan_amount 
((1+(((self.interest_rate)/(self.compound_period))/100))**((self.compound_period)
 
* (self.time_years)))
self.no_of_instalments = (self.no_days) / (self.pr_frequency)
self.no_of_instalments_interest = (self.no_days) / 
(self.ir_frequency)
 def name(self):
return self.account_name.name
 


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


Re: How do I create a standalone python application that uses the django environment (e.g. the ORM etc...)?

2013-09-17 Thread Russell Keith-Magee
Hi,

Django's own documentation contains a description of how to do this:

https://docs.djangoproject.com/en/1.5/topics/settings/#using-settings-without-setting-django-settings-module

James Bennett has also written a blog post that gives a good rundown on
approaches you can take:

http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/

Unfortunately, the links in that blog post are a little stale; however, he
provides code samples, which should be enough to get you going.

Yours,
Russ Magee %-)

On Tue, Sep 17, 2013 at 3:25 PM, DJ-Tom  wrote:

>
> Hi,
>
> I'm also not sure if the python file is at the correct location.
>
> This is how the directory structure looks:
>
> my_project
> \my_project\
>  settings.py
> \my_app\ # this is where my models are defined
>  models.py
>  formdesigner.py
>
>
> Where should my formdesigner.py be located?
>
> my_project ?
> my_project\my_project ?
> my_project\my_app ?
>
> What do I put into DJANGO_SETTINGS_MODULE?
>
> 'my_project.settings'?
>
>
> Am Montag, 16. September 2013 18:17:21 UTC+2 schrieb Brad Pitcher:
>
>> You need to do something like this before import django stuff:
>>
>> import os
>> import sys
>>
>> sys.path.append(os.path.**abspath(os.path.dirname(__**file__)))
>> os.environ['DJANGO_SETTINGS_**MODULE'] = 'web.settings'
>>
>>
>> -
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Django unittest failure

2013-09-17 Thread Ryan Boggs
I reported it.  #21118.

Thanks for taking a look at this.

Thanks,
Ryan

On Monday, September 16, 2013 7:16:25 PM UTC-7, WongoBongo wrote:
>
> You should probably open a bug on this issue. The test suite fails for me 
> on MacOS/Python 2.7 on the stable/1.5.x branch. This is the command that 
> fails reliably on my machine:
>
> $ PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite 
> utils formtools
>
> It might be related to this addition
>
> https://github.com/django/django/commit/cb9aaac
>
> The user created by this line (l.129):
>
> user = User.objects.create_user('johndoe', 'jo...@example.com', 
> 'pass')
>
> ... persists into subsequent WizardFormKwargsOverrideTests tests on 
> the stable/1.5.x branch
>
> Running the individual test for 'formtools' passes without issue.
>
> K
>
>
> On Sunday, September 15, 2013 12:30:54 PM UTC-7, Ryan Boggs wrote:
>>
>> FYI,
>>
>> Just tried with 1.5.4 and the same test is still failing.
>>
>> Thanks,
>> Ryan
>>
>

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


Need help figuring out why my { key:value } doesn't seem to be passed to my view by my javascript file.

2013-09-17 Thread 7equivalents
I have a javascript file that successfully request a Django view. However 
it seems as if it is not passing the key:value pairs. I have created an if 
else statement that test for the key, and it never see's it. Not sure how 
to proceed. Here is my django View and Javascript click function, in the 
view the else statement always executes

def pi_page(request):
  
  if request.method == "GET":
get = request.GET.copy()
if get.has_key('pathID'):
path_ID = get['pathID']
path = Path.objects.get(pathID=1)
   #path.pathFill = '#fff'   
path.save()
variables = RequestContext(request, {'path': path})
return render_to_response('main_page.html', RequestContext(request))
else:
path = Path.objects.get(pathID=2)
path.pathFill = '#eee'   
path.save()
variables = RequestContext(request, {'path': path})
return render_to_response('main_page.html', RequestContext(request))


.click(function(){
var outputColor = document.getElementById("output");
var outputColorFill =  outputColor.value;
var pathID = paths[arr[this.id]].pathID;
var data = { pathID:pathID };
$.ajax({
url:"/pi/",
cache: "false",
data:data  
});

})



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


Re: Exception Value: 'Decimal' object is not callable dont no where this is coming from, Any help will be kindly appreciated

2013-09-17 Thread Leonardo Giordani
Hi Maurice,

where do you get this exception? Do you have a Django debug page as output?
Are you calling a view? Can you paste its code?

Leo

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub
page- My Coderwall
profile 


2013/9/18 MAurice 

> class Loan(models.Model):
> id = models.AutoField(primary_key=True,default=1)
> loan_type   =models.CharField(max_length=20,
> choices=LTYPE,default=1)
> def number():
> no =Account.objects.count()
> if no == None:
> return 10
> else:
> return no + 11
>
>
>
> loan_statement_no=models.IntegerField(('loan_statement_no'),max_length=10,
> unique =True, default=number)
> branch_cod  =models.IntegerField(blank=True, null=True)
> comp_per_ya =models.IntegerField(default=1, help_text="Number
> of compoundings in a year")
> time_years  =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=1)
> loan_number =models.SlugField(unique=True)
> #branch =models.ManyToManyField(Branche)
> start_date  =models.DateField(blank=True,
> null=True,default=datetime.datetime.now())
> end_date=models.DateField(blank=True, null=True)
> no_days =models.IntegerField(default=1)
> account_name=models.ForeignKey(Account)
> loan_amount =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2)
> interest_rate   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> compound_period =models.IntegerField(max_length=64,
> choices=compound_period, default=Yearly)
> loan_fee=models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> ammount_repaid= models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> sd_amount   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> dd_amount   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest (base) rate
> ib_rate =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest (penal) rate
> ip_rate =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest repayment frequency
> ir_frequency
> =models.IntegerField(max_length=64,choices=IRFREQUENCY,default=WEEKLY)
> pr_frequency
> =models.IntegerField(max_length=64,choices=PRFREQUENCY,default=DAILY,help_text="Suggested
> value automatically generated from title. Must be unique.")
>
>
> last_edit_time  = models.TimeField(auto_now=True)
> last_edit_date  = models.DateField(auto_now=True)
>no_of_instalments = models.DecimalField(default=1.0,
> max_digits=10, decimal_places=2, null=True, blank=True)
> no_of_instalments_interest =models.DecimalField(default=1.0,
> max_digits=10, decimal_places=2, null=True, blank=True)
> interest_charged = models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, editable=False)
>
>
> def save(self, *args, **kwargs):
> i
> self.no_days =(self.end_date - self.start_date).days
> self.required_payment =self.loan_amount
> ((1+(((self.interest_rate)/(self.compound_period))/100))**((self.compound_period)
> * (self.time_years)))
> self.no_of_instalments = (self.no_days) / (self.pr_frequency)
> self.no_of_instalments_interest = (self.no_days) /
> (self.ir_frequency)
>  def name(self):
> return self.account_name.name
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Need help figuring out why my { key:value } doesn't seem to be passed to my view by my javascript file.

2013-09-17 Thread Leonardo Giordani
If I correctly understand you are using jQuery.ajax(). Documentation says
"Data to be sent to the server. It is converted to a query string, if not
already a string. It's appended to the url for GET-requests." So I think
that the ajax() function is calling the URL "/pi/?pathID=somevalue". May
you perhaps check the devel server output?

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub
page- My Coderwall
profile 


2013/9/18 <7equivale...@gmail.com>

> I have a javascript file that successfully request a Django view. However
> it seems as if it is not passing the key:value pairs. I have created an if
> else statement that test for the key, and it never see's it. Not sure how
> to proceed. Here is my django View and Javascript click function, in the
> view the else statement always executes
>
> def pi_page(request):
>
>   if request.method == "GET":
> get = request.GET.copy()
> if get.has_key('pathID'):
> path_ID = get['pathID']
> path = Path.objects.get(pathID=1)
>#path.pathFill = '#fff'
> path.save()
> variables = RequestContext(request, {'path': path})
> return render_to_response('main_page.html',
> RequestContext(request))
> else:
> path = Path.objects.get(pathID=2)
> path.pathFill = '#eee'
> path.save()
> variables = RequestContext(request, {'path': path})
> return render_to_response('main_page.html',
> RequestContext(request))
>
>
> .click(function(){
> var outputColor =
> document.getElementById("output");
> var outputColorFill =  outputColor.value;
> var pathID = paths[arr[this.id]].pathID;
> var data = { pathID:pathID };
> $.ajax({
> url:"/pi/",
> cache: "false",
> data:data
> });
>
> })
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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