Re: ModelName.objects.none().update() makes changes to db

2010-09-11 Thread David Somers Harris
Ah! I'm still on Ubuntu's release version. Thanks Bruno!

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



flatpages and views on home page

2010-09-11 Thread Bobby Roberts
hi group.

Got an issue I need some help with asap.  I have flatpages installed
and a url at / for my home page.

I've also got a form on my home page powered by a view.

my urls portion for this view is:

rr'^$','DoNewsLetter'),


my issue is this... the view executes perfectly, but the flatpage
doesn't execute.  Is there anyway to get the flatpage to show AND the
view to execute successfully?


-- 
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: Integrating User Profile with Auth

2010-09-11 Thread darren
I think that my main problem was that I was expecting the save to the model
form to actually create the profile.

Here's what I ended up with in my view.

 86 @login_required
 87 def createProfile(request):
 88 UserProfile.objects.get_or_create(user=request.user)[0]
 89 if request.method == 'POST':
 90 form = UserProfileForm(request.POST,
instance=request.user.get_profile())
 91 if form.is_valid():
 92 form.save()
 93 return HttpResponseRedirect("/")
 94 else:
 95 return render_to_response('fav/createProfile.tpl', { 'form'
: form  }, RequestContext(request) )
 96 else:
 97 form = UserProfileForm(instance=request.user.get_profile())
 98 return render_to_response('fav/createProfile.tpl', { 'form' : form
}, RequestContext(request))
 99


On Sat, Sep 11, 2010 at 12:37 AM, Shawn Milochik  wrote:

> I think you just may be missing a call to get_profile() in this view.
> You can just do that and do a try block with an except block for
> DoesNotExist. That will let you know the situation you're in, whether
> the profile already existed or not.
>
> Also, unless I'm misreading something you're trying to pass a User
> instance as the instance for a user profile, which will not work. If
> anything, you should be doing a .get() on the user profile where user
> = request.user, but that doesn't matter anyway because get_profile()
> does the same thing and is the correct way to do this.
>
> Shawn
>
> --
> 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.



get object qs with generic relation

2010-09-11 Thread Andrew Marder
Dear Django users,

I have a tagging system that uses a GenericForeignKey to assign tags
to generic objects. I would like to write a function that given a
model and a list of tags returns a QuerySet containing all instances
of that model that have been given those tags.

I'm not a huge fan of django-tagging's solution
(get_intersection_by_model):
http://code.google.com/p/django-tagging/source/browse/trunk/tagging/models.py

Any elegant solutions out there?

Thanks for the help, Andrew

-- 
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: home page menu view variables cross every view?

2010-09-11 Thread Goran
Works great! Thank you very much!

Goran


On Sep 8, 3:51 pm, bagheera  wrote:
> Dnia 08-09-2010 o 15:41:13 Goran  napisał(a):
>
>
>
> > Thanks for your help but I think that understand how template works.
> > My menu is drop down menu with menu items which comes from variable
> > {{ for menuitem in myvariable }}
> > {{ menuitem.title }}
> > {{ endfor }}
>
> > and myvariable is in my view:
> > myvariable = Item.objects.all()
>
> > So if I extend base.html menu is there, but menu items are not,
> > because "myvariable" come from the "view". So seems that I need
> > "myvariable = Item.objects.all()" in every view on the site. Which
> > also means that I need to repeat myself about 20 times. I was
> > wondering is there any solution to include myvariable in settings file
> > or something? Also is there any solution to extend flatpage view with
> > myvariable?
>
> > Thanks
>
> http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-c...
>
> You can write ur own context processor, witch variables will be accessible  
> across all templates.
>
> Example code:
> content.py file:
>
>  from nml.newsletter.forms import NewsletterForm
>
> def newsletter_form(request):
>      """
>      Creates unbound newsletter form
>      """
>      nl_form = NewsletterForm()
>      return {'nl_form' : nl_form}
>
> in settings.py:
>
> 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.contrib.messages.context_processors.messages",
>      'static_content.newsletter_form',
> )
>
> I used that once in root template, but it is rendered with any view that  
> extends my root template
> --
> Linux user

-- 
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: Facebook Comments

2010-09-11 Thread Sævar Öfjörð
Where exactly are you expecting them to be posted?
I think the Facebook Comments plugin is only supposed to provide a
comment feature on individual pages so that you don't have to write
your own, it's not an external comment box for your FB page.

- Sævar

On Sep 10, 5:41 pm, Bobby Roberts  wrote:
> hi i know that this isn't a django related question, but i'm using
> Facebook's comment plugin and am having a strange issue.  I've got it
> installed and you can post comments fine but they never get uploaded
> to facebook.  Is there something you have to do to get them to post
> over to facebook (other than checking the box to do so)?  Has anyone
> else had this issue?

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



python setup.py install errors

2010-09-11 Thread S66
hi there,

i tried to get the current version of django working on my NAS, but
when i run
python setup.py install
i get this error:


byte-compiling /ffp/lib/python2.5/site-packages/django/template/
defaultfilters.py to defaultfilters.pyc
Traceback (most recent call last):
  File "setup.py", line 96, in 
'Topic :: Software Development :: Libraries :: Python Modules',
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/core.py", line 151, in setup
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/dist.py", line 974, in run_commands
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/dist.py", line 994, in run_command
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/command/install.py", line 510, in run
  File "/ffp/lib/python2.5/cmd.py", line 333, in run_command
del help[cmd]
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/dist.py", line 994, in run_command
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/command/install_lib.py", line 99, in run
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/command/install_lib.py", line 135, in byte_compile
  File "/mnt/HD_a2/home/funplug/work/Python-2.5.2/pkg/ffp/lib/
python2.5/distutils/util.py", line 499, in byte_compile
  File "/ffp/lib/python2.5/py_compile.py", line 138, in compile
marshal.dump(codeobject, fc)
ValueError: unmarshallable object


any ida how to solve the problem?

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



windows xp, python 2.6, mod_wsgi, apache 8.4, MySQL 5.1 - CSS not loading.

2010-09-11 Thread Jesse
Hello,
I've successfully implemented mod_wsgi with Apache on Windows XP using
MySQL 5.1.  Everything but the CSS/html for the index page is
working.  Even the admin pages are working with style sheets.  The
following is my code.  I cannot seem to find the error that is not
loading the CSS style sheets for the html pages.

http.conf file
< -- code start
Include "c:/django/apache/apache_django_wsgi.conf"


Order allow,deny
Allow from all


< -- code end

apache_django.wsgi file:

< -- code start
Alias /media/ "C:/Python26/Lib/site-packages/django/contrib/admin/
media/"

Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing



Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing



Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing



WSGIScriptAlias / "C:/django/apache/django.wsgi"

Alias /site_media/ "C:/django/mysite/site_media/"


Allow from all


< -- code end

django.wsgi:

< -- code start
import os, sys
sys.path.append("c:/django")
sys.path.append("c:/django/mysite")
# may be required :)
#sys.path.append('/path/to/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

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

< -- code end


settings file
< -- code start
MEDIA_ROOT = 'c:/django/mysite/site_media'
MEDIA_URL = 'http://www.myproject.org/mysite/site_media/'
ADMIN_MEDIA_PREFIX = 'http://www.myproject.org/media/'
TEMPLATE_DIRS = (
'C:/django/mysite/templates',
< -- code end

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

2010-09-11 Thread nick.l...@gmail.com
Not sure if this will help ya...but the guys at Eldarion have brabeion for
doing badges (awards). http://github.com/eldarion/brabeion

That's all I got right now!

n

On Sat, Sep 11, 2010 at 12:26 PM, Joel Klabo  wrote:

> Does anyone know of an example of someone using django signals to do
> achievements for a website? similar to foursquare or something like
> that? I am going to attempt it and i don't really know where to start.
> I would love some example or a nudge in the right direction.
>
> --
> 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.
>
>


-- 
Guadajuko! Vamos a correr!
 -"Cool! we are going to run!"

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



django achievements

2010-09-11 Thread Joel Klabo
Does anyone know of an example of someone using django signals to do
achievements for a website? similar to foursquare or something like
that? I am going to attempt it and i don't really know where to start.
I would love some example or a nudge in the right direction.

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



Please add tag for Django 1.2.3 release

2010-09-11 Thread creecode
I too find the tagged releases useful.  Thanks for all your hard work
people!

Toodle-lo.
creecode

On Sep 11, 9:03 am, shacker  wrote:

> It looks like there is no svn tag for 1.2.3:
>
> http://code.djangoproject.com/svn/django/tags/releases/
>
> which affects those of us who use pip requirements files for version

-- 
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: Staticstic app, ask for idea.

2010-09-11 Thread Lucian Romi
Thanks for your help. It's very clear.
I used measure_list method but it thrown and exception.
Here's how I did,
In my app's ModelAdmin I override changelist_view method.
I was able to get the queryset, then instantied cube with this queryset.
If I didn't call measure_list, everything works fine. But if I call
it, there is exception, but django didn't give much useful infomation
in stdout, and I'm going to debug it later.
If you aware of anything I'm doing wrong, please let me know. Or is
there any sample I can quickly run just to verify there is nothing
wrong with my enviroment.
Thanks.

On Sat, Sep 11, 2010 at 7:40 AM, sebastien piquemal  wrote:
>    class MyModelCube(Cube):
>        my_dimension = Dimension(field='my_float_field__range',
> sample_space=[(0, 1.5), (1.5, 6.2)])
>
>       �...@static
>        def aggregation(queryset):
>            return queryset.count()/MyModel.objects.count() * 100
>
> Basically when you declare a dimension, you can use any field-lookup
> from Django, so when I write 'my_float_field__range' it means :
> -> You said in your question "There is a float field in my
> model(table)", as you didn't tell the name of your "float field", I
> wrote : 'my_float_field'
> -> You said that you want the percentage in each range... so I used
> the field look-up '__range' from Django.
>
> If your "float field" is called "gnagna", then you would declare your
> dimension like this : Dimension(field="gnagna__range", ...
>
>
> Ok ... when you have declared this, you have a Cube class. After, you
> need to instantiate an object from this class, in order to use its
> methods ! To do this, you call the Cube constructor, with a queryset
> as argument :
 instantiated_cube = MyModelCube(a_queryset)
>
> Then, and only then, you can use the methods (all the calculations
> will be based on "a_queryset"). For exemple, if you want a list of
> measures :
 my_measures = instantiated_cube.measure_list("my_dimension")
>
> Considering the sample space I used to declare the dimension, this
> should give something like this :
 my_measures
> [65, 29]
> Where 65 means "65% of the floats are in the range [0, 1.5]", 29 means
> "29% of the floats are in the range [1.5, 6.2]"
>
> Is it clearer like this ?
>
> On Sep 11, 4:04 am, Lucian Romi  wrote:
>> Also, need I define "my_float_field__range"? Thanks
>>
>> On Fri, Sep 10, 2010 at 6:52 PM, Lucian Romi  wrote:
>> > Hi, Sebastien
>>
>> > Follow your instruction, I was able to create a Cube object and define
>> > sample_space.
>> > However, I don't know how to retrieve the measure result. Can you tell
>> > me how to do that?
>> > What do you mean by "instantiate a cube with a base queryset, and use
>> > one of the methods
>> > provided to calculate the statistics"
>>
>> > Thanks.
>>
>> > On Tue, Aug 31, 2010 at 1:33 AM, sebastien piquemal  
>> > wrote:
>> >> To integrate a calculated value with search features from admin app, I
>> >> don't know any other way than create and save a calculated field on
>> >> your model ...
>> >> This calculated field, you can calculate it with cube ... but if you
>> >> don't use the Cube for any other statistic than that, it is too much
>> >> overhead.
>>
>> >> On Aug 31, 5:30 am, Lucian Romi  wrote:
>> >>> Thanks Sebastien.
>>
>> >>> Can I integrate Cube with filter and search features from the admin app?
>> >>> Also, to make things simple, I'm going to use GChart, but I need
>> >>> statistic data.
>> >>> Let me download Cube and spend some time on it. Thanks.
>>
>> >>> On Mon, Aug 30, 2010 at 4:16 PM, sebastien piquemal  
>> >>> wrote:
>> >>> > I created an app to easily generate the stats part :
>> >>> >http://code.google.com/p/django-cube/;however you still have to
>> >>> > create the chart, for example with matplotlib :
>> >>> >http://www.scipy.org/Cookbook/Matplotlib/Django.
>>
>> >>> > To create your stats with django-cube, you can use this code :
>>
>> >>> >    from cube.models import Cube, Dimension
>>
>> >>> >    class MyModelCube(Cube):
>> >>> >        my_dimension = Dimension(field='my_float_field__range',
>> >>> > sample_space=[(0, 1.5), (1.5, 6.2)])
>>
>> >>> >       �...@static
>> >>> >        def aggregation(queryset):
>> >>> >            return queryset.count()/MyModel.objects.count() * 100
>>
>> >>> > - You specify one dimension for the cube, this dimension refers to the
>> >>> > field lookup 'my_float_field__range' (where 'my_float_field' is of
>> >>> > course the name of your field)
>> >>> > - then you specify a sample space for this dimension, which in fact
>> >>> > means that you specify for which ranges the stats will be calculated
>> >>> > (here, on the ranges (0, 1.5) and (1.5, 6.2))
>> >>> > - then you write your aggregation function, which is in your case a
>> >>> > percentage calculation ('queryset' is the queryset filtered according
>> >>> > to the dimensions you will use 

Django-Cms Installation Error with stable Version

2010-09-11 Thread Jagdeep Singh Malhi
I am use  Install the Django-Cms using this link
http://www.django-cms.org/en/documentation/2.0/installation/

I face this error. I am able understand this error
I am using Django Version is 1.1.2 and Django -cms is 2.0.2
Version is matching with Documentation of Django-Cms
ERROR is : -
{
ImproperlyConfigured at /

'PageAdmin.exclude' refers to field 'created_by' that is missing from
the form.

Request Method: GET
Request URL:http://localhost/djangocms/
Exception Type: ImproperlyConfigured
Exception Value:

'PageAdmin.exclude' refers to field 'created_by' that is missing from
the form.

Exception Location: /usr/local/lib/python2.6/dist-packages/django/
contrib/admin/validation.py in check_formfield, line 310
Python Executable:  /usr/bin/python
Python Version: 2.6.5

}

-- 
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: Integrating User Profile with Auth

2010-09-11 Thread darren
Thanks.

That helped me figure it out.  I'll post my solution back later
today/tonight.


On Sat, Sep 11, 2010 at 12:37 AM, Shawn Milochik  wrote:

> I think you just may be missing a call to get_profile() in this view.
> You can just do that and do a try block with an except block for
> DoesNotExist. That will let you know the situation you're in, whether
> the profile already existed or not.
>
> Also, unless I'm misreading something you're trying to pass a User
> instance as the instance for a user profile, which will not work. If
> anything, you should be doing a .get() on the user profile where user
> = request.user, but that doesn't matter anyway because get_profile()
> does the same thing and is the correct way to do this.
>
> Shawn
>
> --
> 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: Wiki in Django?

2010-09-11 Thread Sean W
After a bit of googling I found:

https://code.google.com/p/sct-project/

On Sep 11, 12:47 pm, Shamail Tayyab  wrote:
> Hi,
>
>   I need a very minimal wiki, best if it runs on flat files. moinmoin is too
> heavy for what I am looking. Is there some Django thing available or written
> by someone here?
>
> Thanks
>
> --
> Shamail Tayyab
> Blog:http://shamail.in/blog

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



Wiki in Django?

2010-09-11 Thread Shamail Tayyab
Hi,

  I need a very minimal wiki, best if it runs on flat files. moinmoin is too
heavy for what I am looking. Is there some Django thing available or written
by someone here?

Thanks

-- 
Shamail Tayyab
Blog: http://shamail.in/blog

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



Sorting related model

2010-09-11 Thread Brad Buran
Given the following two models forming the base of a wiki-style app:

class Page(models.Model):
current_revision = models.IntegerField()

class PageContent(models.Model):
page = models.ForeignKey(Page)
revision = models.IntegerField()
created = models.DateTimeField()

Here, we have a canonical Page object with a current_revision that always
points to the most current revision, stored in PageContent.  How can I
construct a Page queryset, ordered by the Pages that have the most
recently-created PageContent?

Currently, what I am doing is:

qs =
PageContent.objects.filter(revision=F('page__current_revision')).order_by('created').select_related()
pages = [content.page for content in qs]

This works fine, but is there a more straightforward way to do this?

Thanks,
Brad

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



can i get model field type from a model queryset in django?

2010-09-11 Thread victor
can i get model field type from a model queryset in django?
for example:
a is b model's queryset
b model has following field:

 - f:charfield
 - g:foreignkey
 - h:manytomany

is there any way to get field g's type from queryset a?
thx.

-- 
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 1.2.3 released

2010-09-11 Thread shacker
On Sep 11, 12:00 am, James Bennett  wrote:
> To correct several issues in the 1.2.2 package earlier this week,
> tonight the Django team has issued Django 1.2.3. Details are available
> on the Django weblog:
>

It looks like there is no svn tag for 1.2.3:

http://code.djangoproject.com/svn/django/tags/releases/

which affects those of us who use pip requirements files for version
maintenance.

Thanks,
Scot

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



Overriding individual models in an app without forking

2010-09-11 Thread Eric Man
Oops my previous post got hard-wrapped by safari's textarea. :( Here  
it is again. (I'm assuming moderator is going to prevent me from  
double posting).


---

I was reading about how django's apps' models can't be easily  
overridden. - e.g http://www.scribd.com/doc/37113340/Why-Django-Sucks-and-How-we-Can-Fix-it


So I was looking at this new app I was making, a CMS for online shops,  
and thought of a way for users of my app to override individual models  
in my app without forking.


I want to ask, how does it look? Would it be "bad practice"? How else  
could I enable user to override individual models?


It uses django-nonrel version of django so the code might be a bit  
weird to some. I think it works the same for normal django, though.


abstract.py - "Normal Model Code"
http://pastebin.com/C9FFJJK8

This file has a bunch of the models I would have had anyway if I  
didn't enable model overriding. i.e 'Setting', 'Country', 'Product',
'UserProfile', 'Category', 'Promotion', 'Cart', 'PaymentMethod',  
'Order' and 'Item'


models.py - "The 'Magic' Code"
http://pastebin.com/ezhPA6uJ
This file contains an "override_models" method. Use it like  
"override_models(Country=MyCountry)" whereever... e.g in your  
models.py, where MyCountry is has a strict is-a relationship with the  
Country model in abstract.py, meaning they must have at least all the  
fields and all the relationships of the original model, though more  
can be added.


It also contains some lazy many to many links. I used appengine so I  
couldn't use django's many_to_many.


management.py - "Example Usage Code"
http://pastebin.com/jK3vzMt7
(I was just using management.py to do random testing... )

Note my new custom model have new fields... "parent" and "test".

I don't really know any advantages of overriding individual models in  
a module this way besides being able to make the models have  
additional fields so you don't have to do something like define a  
UserProfile model to add extra features to User, though.


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



Django document said the QueryDict is only immutable, but why I can edit it sometimes

2010-09-11 Thread ouds...@gmail.com
Django document said the QueryDict is only immutable, but why I can
edit it sometimes

The codes is almost the same, for example following,

The first kind of condition, the item I want to edit is not a field of
form.

I add a Captcha when user register or login, the querydict is mutable
when registering

if request.method == 'POST':
data = request.POST
data['captcha_text'] = Captcha(request).get()

But the same code when do login, the querydict is immutable, it is
must be create a copy

if request.method == "POST":
data = request.POST.copy()
data['captcha_text'] = Captcha(request).get()

The second kind of condition, the item I want to edit is a field of
form, but in fact I think it has no relation with form.

user = request.user
if request.method == "POST":
data = request.POST
data['title'] = data['title'].strip()
now = datetime.datetime.now()
topic = Topic(id = _md5_key(now, user.username), profile =
user.get_profile(), \

It is ok, but when I do this in other view, then django tell me the
querydict is immutable.

if request.method == 'POST':
data = request.POST
print data, '\n\n'
data['name'] = data['name'].strip()
print data, '\n\n'

What's difference ?

Thanks

-- 
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: Staticstic app, ask for idea.

2010-09-11 Thread sebastien piquemal
class MyModelCube(Cube):
my_dimension = Dimension(field='my_float_field__range',
sample_space=[(0, 1.5), (1.5, 6.2)])

@static
def aggregation(queryset):
return queryset.count()/MyModel.objects.count() * 100

Basically when you declare a dimension, you can use any field-lookup
from Django, so when I write 'my_float_field__range' it means :
-> You said in your question "There is a float field in my
model(table)", as you didn't tell the name of your "float field", I
wrote : 'my_float_field'
-> You said that you want the percentage in each range... so I used
the field look-up '__range' from Django.

If your "float field" is called "gnagna", then you would declare your
dimension like this : Dimension(field="gnagna__range", ...


Ok ... when you have declared this, you have a Cube class. After, you
need to instantiate an object from this class, in order to use its
methods ! To do this, you call the Cube constructor, with a queryset
as argument :
>>> instantiated_cube = MyModelCube(a_queryset)

Then, and only then, you can use the methods (all the calculations
will be based on "a_queryset"). For exemple, if you want a list of
measures :
>>> my_measures = instantiated_cube.measure_list("my_dimension")

Considering the sample space I used to declare the dimension, this
should give something like this :
>>> my_measures
[65, 29]
Where 65 means "65% of the floats are in the range [0, 1.5]", 29 means
"29% of the floats are in the range [1.5, 6.2]"

Is it clearer like this ?

On Sep 11, 4:04 am, Lucian Romi  wrote:
> Also, need I define "my_float_field__range"? Thanks
>
> On Fri, Sep 10, 2010 at 6:52 PM, Lucian Romi  wrote:
> > Hi, Sebastien
>
> > Follow your instruction, I was able to create a Cube object and define
> > sample_space.
> > However, I don't know how to retrieve the measure result. Can you tell
> > me how to do that?
> > What do you mean by "instantiate a cube with a base queryset, and use
> > one of the methods
> > provided to calculate the statistics"
>
> > Thanks.
>
> > On Tue, Aug 31, 2010 at 1:33 AM, sebastien piquemal  
> > wrote:
> >> To integrate a calculated value with search features from admin app, I
> >> don't know any other way than create and save a calculated field on
> >> your model ...
> >> This calculated field, you can calculate it with cube ... but if you
> >> don't use the Cube for any other statistic than that, it is too much
> >> overhead.
>
> >> On Aug 31, 5:30 am, Lucian Romi  wrote:
> >>> Thanks Sebastien.
>
> >>> Can I integrate Cube with filter and search features from the admin app?
> >>> Also, to make things simple, I'm going to use GChart, but I need
> >>> statistic data.
> >>> Let me download Cube and spend some time on it. Thanks.
>
> >>> On Mon, Aug 30, 2010 at 4:16 PM, sebastien piquemal  
> >>> wrote:
> >>> > I created an app to easily generate the stats part :
> >>> >http://code.google.com/p/django-cube/;however you still have to
> >>> > create the chart, for example with matplotlib :
> >>> >http://www.scipy.org/Cookbook/Matplotlib/Django.
>
> >>> > To create your stats with django-cube, you can use this code :
>
> >>> >    from cube.models import Cube, Dimension
>
> >>> >    class MyModelCube(Cube):
> >>> >        my_dimension = Dimension(field='my_float_field__range',
> >>> > sample_space=[(0, 1.5), (1.5, 6.2)])
>
> >>> >       �...@static
> >>> >        def aggregation(queryset):
> >>> >            return queryset.count()/MyModel.objects.count() * 100
>
> >>> > - You specify one dimension for the cube, this dimension refers to the
> >>> > field lookup 'my_float_field__range' (where 'my_float_field' is of
> >>> > course the name of your field)
> >>> > - then you specify a sample space for this dimension, which in fact
> >>> > means that you specify for which ranges the stats will be calculated
> >>> > (here, on the ranges (0, 1.5) and (1.5, 6.2))
> >>> > - then you write your aggregation function, which is in your case a
> >>> > percentage calculation ('queryset' is the queryset filtered according
> >>> > to the dimensions you will use while querying the cube, divided by the
> >>> > total, multiplied by 100)
> >>> > - finally, you instantiate a cube with a base queryset, and use one of
> >>> > the methods provided to calculate the statistics
>
> >>> > Ok, the doc is kind of bad for now, but I can help you if you want to
> >>> > use it but you don't manage to do so.
>
> >>> > On Aug 30, 8:24 pm, hollando  wrote:
> >>> >> I want to make a statistic app.
> >>> >> There is a float field in my model(table).I want to use a chart to
> >>> >> show what's the percentage in each range.
> >>> >> Any suggestion to make such and app that can fit into django model.
> >>> >> Thanks.
>
> >>> > --
> >>> > You received this message because you are subscribed to the Google 
> >>> > Groups "Django users" group.
> >>> > 

paypal ipn change

2010-09-11 Thread Tim Arnold
Hi,
I started having trouble with paypal IPN on Sept. 4 (a week ago), but
didn't know it until they notified me yesterday that my endpoint url
was failing. Well, I had just upgraded to Django 1.2.1 and figured it
had to be that or some code refactoring I had done.

However, as far as I can tell, the problems were due to a change in
paypal's mechanism. What I did was change my endpoint to accept data
from either a POST or a GET. Previously it only accepted POST data.
When I made that change the IPN started coming through again.  Just
for completeness, here's my endpoint code. Note that yes, I'm not
doing anything special with the data now, just writing it to a file so
I can see the last transaction's data:

@csrf_exempt
def endpoint(request):
def verify(data):
newparams={}
for key in data.keys():
newparams[key]=data[key]

newparams["cmd"]="_notify-validate"
params=urllib.urlencode(newparams)
req = urllib2.Request(verify_url)
req.add_header("Content-type", "application/x-www-form-
urlencoded")
fo = urllib2.urlopen(verify_url, params)
return fo.read()

def process(data):
f = open('/home/myuser/mydata.txt','wb')
f.write('%r valid' % data)
f.close()
return HttpResponse('Ok')

def process_invalid(data):
f = open('/home/myuser/myerrors.txt','wb')
f.write('%r error' % data)
f.close()
return HttpResponse('NOT Ok')

default_response_text = 'Nothing to see here'
verify_url = "https://www.paypal.com/cgi-bin/webscr;
if request.method == 'POST':
data = request.POST
elif request.method == 'GET':
data = request.GET
if verify(data):
process(data)
else:
process_invalid(data)
return HttpResponse(default_response_text)

-- 
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: Filter for non-True NullBooleanField

2010-09-11 Thread Preston Holmes


On Sep 10, 2:43 pm, Christos Jonathan Hayward
 wrote:
> P.S. Setting:
>
> .filter(is_invisible__in = [False, None])

how about:

.exclude(is_invisible__exact = True)

>
> is not working as intended; I seem to be getting no matches when I should be
> getting matches.
>
> On Fri, Sep 10, 2010 at 4:19 PM, Christos Jonathan Hayward <
>
>
>
>
>
> christos.jonathan.hayw...@gmail.com> wrote:
> > How can I filter for instances having a NullBooleanField that is not True
> > (i.e. is either False or a null)?
>
> > --
> > [image: Christos Jonathan Hayward] 
> > Christos Jonathan Hayward, an Orthodox Christian author.
>
> > Author Bio  • 
> > Books
> >  • *Email * • 
> > Facebook
> >  • LinkedIn  • 
> > Twitter
> >  • *Web * • What's 
> > New?
> > I invite you to visit my "theology, literature, and other creative works"
> > site.
>
> --
> [image: Christos Jonathan Hayward] 
> Christos Jonathan Hayward, an Orthodox Christian author.
>
> Author Bio  • 
> Books
>  • *Email * •
> Facebook
>  • LinkedIn  •
> Twitter
>  • *Web * • What's
> New?
> I invite you to visit my "theology, literature, and other creative works"
> site.

-- 
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: ModelName.objects.none().update() makes changes to db

2010-09-11 Thread bruno desthuilliers
On 10 sep, 21:57, David Somers Harris  wrote:
> I haven't set a custom manager as far as I'm aware. Here is what happens to
> me:

(snip)

http://code.djangoproject.com/ticket/12142

Looks like you have to update your Django install !-)

-- 
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 does django convert string to modules

2010-09-11 Thread bruno desthuilliers
On 11 sep, 02:37, Bachir  wrote:
> What if was gibing a string like this: 'math.ceil', and i had to import the
> function(not the module) dynamically(from the string), how can i do that?
> import_module is for importing... modules, not functions.

Why don't you just read the code snippet I posted ?

For the record:

* modules are objects
* functions, classes and anything else defined in a module are
attributes of the module
* "getattr(obj, "attrib")" is the exact equivalent of "obj.attrib"

also and FWIW, you never import functions (or anything else) directly.
The

  from module import name

syntax is syntactic sugar for:

  import module
  name  = module.name
  del module





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



Django document said the QueryDict is only immutable, but why I can edit it sometimes

2010-09-11 Thread DingDongQuan.com
Django document said the QueryDict is only immutable, but why I can
edit it sometimes

The codes is almost the same, for example following,

The first kind of condition, the item I want to edit is not a field of
form.

I add a Captcha when user register or login, the querydict is mutable
when registering

if request.method == 'POST':
data = request.POST
data['captcha_text'] = Captcha(request).get()

But the same code when do login, the querydict is immutable, it is
must be create a copy

if request.method == "POST":
data = request.POST.copy()
data['captcha_text'] = Captcha(request).get()

The second kind of condition, the item I want to edit is a field of
form, but in fact I think it has no relation with form.

user = request.user
if request.method == "POST":
data = request.POST
data['title'] = data['title'].strip()
now = datetime.datetime.now()
topic = Topic(id = _md5_key(now, user.username), profile =
user.get_profile(), \

It is ok, but when I do this in other view, then django tell me the
querydict is immutable.

if request.method == 'POST':
data = request.POST
print data, '\n\n'
data['name'] = data['name'].strip()
print data, '\n\n'

What's difference ?

Thanks

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



[ANN] Django 1.2.3 released

2010-09-11 Thread James Bennett
To correct several issues in the 1.2.2 package earlier this week,
tonight the Django team has issued Django 1.2.3. Details are available
on the Django weblog:

http://www.djangoproject.com/weblog/2010/sep/10/123/

All users are encouraged to upgrade as soon as possible.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



AW: PayPAL-IPN-request doesn't call the view

2010-09-11 Thread daqube
Thank you, guys.
I found out what the problem was, now.
It was a stupid error in my middleware, which couldn’t handle
the empty referstring from paypal...
now everything is working fine again

-Ursprüngliche Nachricht-
Von: django-users@googlegroups.com [mailto:django-us...@googlegroups.com] Im
Auftrag von Brian Neal
Gesendet: Samstag, 11. September 2010 02:05
An: Django users
Betreff: Re: PayPAL-IPN-request doesn't call the view

On Sep 10, 12:01 pm, Bill Freeman  wrote:
>
> My advice is to protect everything with try or by using get,
> log your progress (we had a logging model, but you can
> also append to a file, wrapping everything in a try-finally
> that closes the filehandle to be sure things get flushed
> out), and when you get something you haven't provided
> for, log the contents of request.POST.  It will be something
> simple, such as there's some field they no longer provide
> or don't always provide.

I have to echo Bill's advice here. Use the Python logger generously in
your IPN view handling code. Paypal has a habit of subtly changing
their API or their POST parameters periodically. Anyway, unless you
are getting hundreds of IPN's a day, I'd log all kinds of stuff to a
file and study it to see where it is going wrong. Good luck,

BN

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