Re: PDF generator in Django

2013-08-06 Thread Jonas Geiregat
On 04/08/2013, navnath gadakh wrote:
> Which is best tool to generate PDF in python django

I sucessfully used django-appypod before. It uses a rather strange
library called appy.pod that uses openoffice odt files as a template.

If you have an openoffice server running you can generate a pdf out of
the generated template.

It's rather verbose and heavy weight but you don't have to fiddle with
pixel placement and such like you have to do with the reportlab pdf
library.

> 
> -- 
> 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: Something similar to a WAMP stack for Django?

2013-06-05 Thread Jonas Geiregat

On 05 Jun 2013, at 18:07, Nafiul Islam wrote:

> Hi!
> 
> Is there something similar to a WAMP stack for django and python development, 
> like there is for PHP? It gives you a better way of emulating how a real 
> server would work.

There is: http://bitnami.com/stack/django 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: linux or windows

2013-05-31 Thread Jonas Geiregat

On 31 May 2013, at 13:26, Kakar Arunachal Service wrote:

> thanks!! So, for the production purpose, one must use linux?
> 

No you can also run django and python applications in general on a window 
system, even in production.

But in is most cases it's easier to deploy a django/python application on a 
*nix based system.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: CBVs and using existing forms for user authentication etc

2013-05-31 Thread Jonas Geiregat

On 31 May 2013, at 12:36, tony gair wrote:

> 
> I'm trying to write my first django app using cbv's and good practice ala 2 
> scoops!
> 
> (thanks for all the help so far in this forum btw!)
> 
> I have constructed the app using django braces and CBV's and have noticed 
> that I can only authenticate into my app through the admin panel.
> 
> I suspect that django already has the logging mechanism for my abstractuser 
> and its just a matter of declaring it in my urls, 
> 
> is this so?
> 

Yes, take a look in django.contrib.auth.views, it has many function based views 
I just reuse and add to my urls.py to quickly get a login system up and running.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: linux or windows

2013-05-31 Thread Jonas Geiregat

On 31 May 2013, at 13:11, Kakar Arunachal Service wrote:

> Hi!
> I know this question is one absurd question, but just out of curiosity, is it 
> important to use linux other than the windows, related to django. Cause i'm 
> in windows, and if it is, then i was thinking to use Ubuntu. Please advise.

The platform is unimportant, if you feel at home in windows then use windows 
else use whatever you like as long as it is supported by django.

On a UNIX based system, you could perfectly run/debug django, without touching 
anything like a shell, inside your IDE of choice . 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: App-structure: how to have a bunch of data in all the pages.

2013-02-05 Thread Jonas Geiregat
On Tue, Feb 05, 2013 at 02:06:28AM -0800, Stefano Tranquillini wrote:
> Now, i can create a base.html template where i render the data. but, how 
> should i do the population of these lists?
> Should i create a middleware that for each request populates the lists?
> or what?
I think that a Context Processor will be a better option.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how to deploy django project to lighttpd server

2013-01-07 Thread Jonas Geiregat
I have several account on djangoeurope.com.

What I mostly do is like you did, create a new project using their admin 
interface.

Next I backup the RUN script and delete that directory completely! The I 
checkout my project code, just make sure the project you are checking out (or 
copying) has the same name as the project you created in the admin interface.

Copy the RUN file back, for you development startup. 

Next thing you'll probably need to do is edit the ~/init/project_name file

If you are using virtualenv the DAEMON line and point it to the python binary 
of the env you which to use.
For example: DAEMON=$HOME/Envs/project/bin/python

You might also want to change the SETTINGS to point to your production settings 
or whatever.

If you want to serve static files you should take a look in 
~/lighthttp/django.conf.
For each project created an entry has been added to this file.
Just make sure the directories are setup correctly.

That should be all and you should now be able to start your project 

~/init/project_name start

Good luck!


> Hi there, 
> 
> i am stumbling over this step: i have django project running at my pc local, 
> i want to deploy it to server to see it online. I have bought the hosting 
> service from djangoeurope.com. they have that one-click django installer, it 
> installs the environment with its lighttpd settings. now i dont know where to 
> upload my django files and where to set and how to get it running,
> 
> in the server i have this files which are installed by one-click django 
> installer: 
> under ~/projectname
> projectname, projectname.pid, projectname.sock, manage.py, RUN
> 
> do i have to upload here? 
> 
> thanks a lot for help in advance
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/U8n69IPW0kgJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: Converting Django app into a Desktop app

2012-12-18 Thread Jonas Geiregat


> Hi
> 
> I am very comfortable with Django, and I was wondering about whether there is 
> some way to convert a Django web app into a Desktop app (may be not 100%), so 
> that I can distribute it to users. May be wrapping it in a light web server 
> "if there is something like this". 
> 
> 
> 

You might try http://www.python-camelot.com/ 

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



Re: Foreignkey Form

2012-12-12 Thread Jonas Geiregat
Thanks for the response Serge,

So basically I was on the right path.

But I don't see what the DetailView has to do with this ? Don't you mean the 
CreateView ?

Jonas.

> 1) you  should create a form for building
> 2) you should create a form for inhabitant and set key to the  correct
> value  before saving
> 
> IMHO   simple way is create a edit form for buiding which has buttons
> add/remove inhabitant .  check  DetailView  in docs please
> 
> thanks, Serge
> skype: skhohlov
> tel: +380636150445
> 
> 
> 2012/12/12 Jonas Geiregat <jo...@geiregat.org>:
>> Hello,
>> 
>> Suppose I have a model with a foreign key.
>> 
>> class Building(models.Model):
>>pass
>> class Inhabitant(models.Model):
>>building = models.ForeignKey(Building)
>> 
>> 
>> I would like to display a form where all fields from the Building model and 
>> Inhabitant model are visible (but only once)
>> 
>> Should I create 2 forms, one for Building and one for Inhabitant ? And upon 
>> submission add the Building to the Inhabitant.
>> 
>> Currently I've worked together a little working something using the 
>> CreateView (Generic views)
>> 
>> 
>> def post(..)
>>self.inhabitant_form = InhabitantForm(data=request.POST)
>>if form.is_valid() and self.inhabitant_form.is_valid():
>>….
>> 
>> def form_valid(self, form):
>># form is an instance of BuildingForm
>>building = form.instance
>>building.save()
>> 
>># I'm also overriding the post method where self.inhabitant_form is being 
>> set
>>inhabitant = self.inhabitant_form.instance
>>self.inhabitant.building = building
>>self.inhabitant.save()
>> 
>> 
>> Am I on the right path or are there are better ways of handling such 
>> situations ?
>> 
>> Regards,
>> 
>> Jonas.
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Foreignkey Form

2012-12-12 Thread Jonas Geiregat
Hello,

Suppose I have a model with a foreign key.

class Building(models.Model):
pass
class Inhabitant(models.Model):
building = models.ForeignKey(Building)


I would like to display a form where all fields from the Building model and 
Inhabitant model are visible (but only once)

Should I create 2 forms, one for Building and one for Inhabitant ? And upon 
submission add the Building to the Inhabitant.

Currently I've worked together a little working something using the CreateView 
(Generic views)


def post(..)
self.inhabitant_form = InhabitantForm(data=request.POST)
if form.is_valid() and self.inhabitant_form.is_valid():
….

def form_valid(self, form):
# form is an instance of BuildingForm
building = form.instance
building.save()

# I'm also overriding the post method where self.inhabitant_form is being 
set
inhabitant = self.inhabitant_form.instance
self.inhabitant.building = building
self.inhabitant.save()


Am I on the right path or are there are better ways of handling such situations 
?

Regards,

Jonas.

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



can't get translation to work

2012-11-16 Thread Jonas Geiregat
I've got an app with the following translation settings:

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'nl-BE'

gettext = lambda s: s
LANGUAGES = ( 
   ('en', gettext('English')),
   ('nl', gettext('Dutch')),
)

MODELTRANSLATION_DEFAULT_LANGUAGE = 'nl'

SITE_ID = 1 

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True


TEMPLATE_CONTEXT_PROCESSORS = ( 
   "django.contrib.auth.context_processors.auth",
   "django.core.context_processors.i18n",
   "django.core.context_processors.debug",
   "django.core.context_processors.media",
   "django.core.context_processors.static",
   "django.core.context_processors.tz",
   "django.contrib.messages.context_processors.messages"
)

MIDDLEWARE_CLASSES = ( 
   'django.contrib.sessions.middleware.SessionMiddleware',
   # i18n
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   # Uncomment the next line for simple clickjacking protection:
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
In my templates I have several {% trans ".." %} tags I run ./manage.py 
makemessages -l en

processing language en

Which runs just fine. The generated file located at 
project/locale/en/LC_MESSAGES/django.po starts with the following:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR , YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-11-16 05:39-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: peltracom/settings.py:37
msgid "English"
msgstr ""

#: peltracom/settings.py:38
msgid "Dutch"
msgstr ""

#: qr_app/templates/product.html:14
msgid "Gemaakt van"
msgstr ""

#: qr_app/templates/product.html:15
msgid "Afkomstig uit"
msgstr ""
After editing the file and adding the correct translations I run:

/manage.py compilemessages -L EN processing file django.po in 
/Volumes/DATA/http/peltracom/locale/en/LC_MESSAGES

My base urls.py contains:

urlpatterns += i18n_patterns('',
url(r'', include('qr_app.urls')),
)
But when I point my browser to /en/some-url everything within trans template 
tags is displayed in Dutch and not in english. I even tried setting the 
accept-language header to en which didn't help at all.

Any clues on what might be going wrong here are welcome!

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



model field not null

2012-09-27 Thread Jonas Geiregat
Hello,

While setting up a new model I'm trying to have a strong data model.

One of the requirements is that a certain field cannot be null.

lastname = models.CharField(
blank=False,
default=None,
..)

I'm accomplishing this by the above code. This ensure that even on a database 
level lastname will not be NULL, by setting default to None.

I'm aware that I can just use blank=False to ensure that on a form level it 
will never be allowed to be empty.  But I want a strong, fully tested, business 
model from the beginning.

As this is a CharField, according to the docs, I cannot use null=True since 
empty string will get stored as empty strings and not as NULL.

Is this an appropriate way of modeling my models, or are there other solutions ?

Regards,

Jonas.


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



Re: content management in django

2012-09-24 Thread Jonas Geiregat
I would advise you to take a look at feincms, it has exactly what you need.


> Hello,
> 
> I'm converting a static website to a Django application and I need a piece of 
> advice from more experienced people what is the right way to store content.
> The website will have some static pages like "about","contacts", etc. and a 
> dynamic content like news and photo galleries that should be updated from the 
> web interface. So my best guess is that static pages should be implemented 
> using templates and news should be stored in a database. I believe this is a 
> common task so is there a better way to solve it? And how is news editing 
> implemented? Does the editor create an html in some html-editor and then 
> paste it into the database, or is a web-based WYSIWYG-editor usually used?
> 
> Thank you!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/_wtR7b_RXKYJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: testing a django package

2012-09-13 Thread Jonas Geiregat
Found the answer:

I need to put from tests import * in the tests/__init__.py file 

> Actually, Django TestCases can override the URLConf, which allows you to have 
> a given URL for a given view in your test:
> 
> from django.test import TestCase
> 
> class MyTestCase(TestCase):
> urls = 'mypackage.tests.urls'
> 
> def test_something():
> # Do stuff...
> 
> 
> From there, you can *totally* just create a tests/views.py file where you add 
> your test view with the actual implementation you're missing, and add it in 
> your tests/urls.py file.
> 
> And everything will be fine : )
> 
> Le mercredi 12 septembre 2012 23:36:03 UTC+2, jonas a écrit :
> 
> 
> 
> > I think you could create an urls.py file for your tests and attach 
> > your views there. Then use the test client to direct requests to those 
> > test URLs and assert that the response is what you expect. 
> 
> I didn't know that could work. 
> I think I'll also need to create views that extend these views that I want to 
> test. 
> Since they need actual implementation, I think, such as template_name and 
> model etc .. 
> 
> How would the test client then now where to look for these views, since there 
> will be some reversing involved I think. 
> 
> self.client.get(reverse("ajax_form_view")) 
> 
> I don't see how the client will find my urls.py file and without the broader, 
> actual django application as context ? 
> 
> 
> > 
> > Now, this is probably not going to be practical to test your jQuery 
> > components, but you might want to ask on a JS-focused list regarding 
> > unittesting JS for this purpose. 
> > 
> > Thomas 
> > 
> > 2012/9/12 Jonas Geiregat <jo...@geiregat.org>: 
> >> 
> >> I can now show you what I really would like to write tests for. 
> >> 
> >> https://github.com/jonasgeiregat/django-ajax-forms 
> >> 
> >> The code I would like to test is in ajax_forms/views.py mainly the 
> >> AjaxFormView and the AjaxModelFormView. 
> >> 
> >> Any help is appreciated! 
> >> 
> >> 
> >> Is it a view mix in? 
> >> 
> >> The package actually already changed from containing a view mix in to 
> >> actual 
> >> views that should be subclassed by the users using the package. 
> >> 
> >> It's a bit difficult to tell you much without more information. 
> >> 
> >> For example, a view derived from FormView. Like I said the user should 
> >> subclass this view again as you would normally do with CBV. 
> >> 
> >> Currently the package is just a package/directory with views.py, 
> >> models.py, 
> >> urls.py and of course __init__.py to make it a module. 
> >> 
> >> It's hard to test views without having an actual django project to test it 
> >> again, I think.  Correct me if I'm wrong here. 
> >> So I created an example django project that is using this package in the 
> >> directory below the package, thus the directory containing the README, 
> >> setup.py etc .. files. 
> >> 
> >> The example app will hold a tests.py file which will contain my tests 
> >> which 
> >> will be testing the actual functionality of my views. 
> >> 
> >> Basically I'm asking do I need an actual django project to test just a 
> >> views.py file or can I just write some tests without a containing django 
> >> project to test a views.py file. 
> >> And if so, I'm kinda lost on how you would start on such a task. 
> >> 
> >> A few you things that you may find useful or not for testing : 
> >> 
> >> .  Test cases can override settings such as the urlconf 
> >> .  There's a test client to test views 
> >> .  Class based views can sometimes be tested without any of the former by 
> >> just testing the methods in them 
> >> .   You can always use mocking library 
> >> .  Tests are basically just python code with a lot of asserts, you can 
> >> always add viewed in them 
> >> .  You can use fixtures for test data if you see fit 
> >> 
> >> Hope this helps! 
> >> 
> >> Thomas 
> >> 
> >> On Sep 10, 2012 5:23 PM, "Jonas Geiregat" <jo...@geiregat.org> wrote: 
> >>> 
> >>> Hello, 
> >>> 
> >>> I've created a simple reusable django package. This package basically 
> >>> consists out of a views.py file, with some helper functions. 
> >>> 
> >>> I want to write some tests fo

Re: testing a django package

2012-09-13 Thread Jonas Geiregat
Thanks you for your help. 

I understand now how I should setup testing for a django package. I'm using 
django-registration as an example , which works a similar way.

I have a weird problem at hand.
I'm creating a django package and would like to provide some test cases for it.
The package is named ajax_forms and the full path is part of my PYTHONPATH. 
This directory also contains a tests directory (with the init.py file) a 
tests.py file (containing the tests) and a urls.py file.
Now I want to run the tests.

The ajax_forms parent directory has an example project setup with ajax_forms in 
INSTALLED_APPS.

But I can't seem to let the tests run:

 >> ./manage.py test ajax_forms
Creating test database for alias 'default'...

--
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

No tests are found so I try to be more specific:

 >> ./manage.py test ajax_forms.tests

raise ValueError("Test label '%s' does not refer to a test" % label)
ValueError: Test label 'ajax_forms.tests' does not refer to a test
(ajax-validation)

Even ./manage.py ajax_forms.tests.tests.AjaxFormViewTest will not find the 
tests and gives the same error as above.

But trying to import the test case from the ./manage.py shell works fine

In [2]: from ajax_forms.tests.tests import AjaxFormViewTest

I'm kinda clueless here, on what's going on.


> 
> 
> 
>> I think you could create an urls.py file for your tests and attach
>> your views there. Then use the test client to direct requests to those
>> test URLs and assert that the response is what you expect.
> 
> I didn't know that could work. 
> I think I'll also need to create views that extend these views that I want to 
> test.
> Since they need actual implementation, I think, such as template_name and 
> model etc ..
> 
> How would the test client then now where to look for these views, since there 
> will be some reversing involved I think.
> 
> self.client.get(reverse("ajax_form_view"))
> 
> I don't see how the client will find my urls.py file and without the broader, 
> actual django application as context ?
> 
> 
>> 
>> Now, this is probably not going to be practical to test your jQuery
>> components, but you might want to ask on a JS-focused list regarding
>> unittesting JS for this purpose.
>> 
>> Thomas
>> 
>> 2012/9/12 Jonas Geiregat <jo...@geiregat.org>:
>>> 
>>> I can now show you what I really would like to write tests for.
>>> 
>>> https://github.com/jonasgeiregat/django-ajax-forms
>>> 
>>> The code I would like to test is in ajax_forms/views.py mainly the
>>> AjaxFormView and the AjaxModelFormView.
>>> 
>>> Any help is appreciated!
>>> 
>>> 
>>> Is it a view mix in?
>>> 
>>> The package actually already changed from containing a view mix in to actual
>>> views that should be subclassed by the users using the package.
>>> 
>>> It's a bit difficult to tell you much without more information.
>>> 
>>> For example, a view derived from FormView. Like I said the user should
>>> subclass this view again as you would normally do with CBV.
>>> 
>>> Currently the package is just a package/directory with views.py, models.py,
>>> urls.py and of course __init__.py to make it a module.
>>> 
>>> It's hard to test views without having an actual django project to test it
>>> again, I think.  Correct me if I'm wrong here.
>>> So I created an example django project that is using this package in the
>>> directory below the package, thus the directory containing the README,
>>> setup.py etc .. files.
>>> 
>>> The example app will hold a tests.py file which will contain my tests which
>>> will be testing the actual functionality of my views.
>>> 
>>> Basically I'm asking do I need an actual django project to test just a
>>> views.py file or can I just write some tests without a containing django
>>> project to test a views.py file.
>>> And if so, I'm kinda lost on how you would start on such a task.
>>> 
>>> A few you things that you may find useful or not for testing :
>>> 
>>> .  Test cases can override settings such as the urlconf
>>> .  There's a test client to test views
>>> .  Class based views can sometimes be tested without any of the former by
>>> just testing the methods in them
>>> .   You can always use mocking library
>>> .  Tests are basically just python code with a lot of asserts, you can
>>> always add viewed i

Re: testing a django package

2012-09-12 Thread Jonas Geiregat



> I think you could create an urls.py file for your tests and attach
> your views there. Then use the test client to direct requests to those
> test URLs and assert that the response is what you expect.

I didn't know that could work. 
I think I'll also need to create views that extend these views that I want to 
test.
Since they need actual implementation, I think, such as template_name and model 
etc ..

How would the test client then now where to look for these views, since there 
will be some reversing involved I think.

self.client.get(reverse("ajax_form_view"))

I don't see how the client will find my urls.py file and without the broader, 
actual django application as context ?


> 
> Now, this is probably not going to be practical to test your jQuery
> components, but you might want to ask on a JS-focused list regarding
> unittesting JS for this purpose.
> 
> Thomas
> 
> 2012/9/12 Jonas Geiregat <jo...@geiregat.org>:
>> 
>> I can now show you what I really would like to write tests for.
>> 
>> https://github.com/jonasgeiregat/django-ajax-forms
>> 
>> The code I would like to test is in ajax_forms/views.py mainly the
>> AjaxFormView and the AjaxModelFormView.
>> 
>> Any help is appreciated!
>> 
>> 
>> Is it a view mix in?
>> 
>> The package actually already changed from containing a view mix in to actual
>> views that should be subclassed by the users using the package.
>> 
>> It's a bit difficult to tell you much without more information.
>> 
>> For example, a view derived from FormView. Like I said the user should
>> subclass this view again as you would normally do with CBV.
>> 
>> Currently the package is just a package/directory with views.py, models.py,
>> urls.py and of course __init__.py to make it a module.
>> 
>> It's hard to test views without having an actual django project to test it
>> again, I think.  Correct me if I'm wrong here.
>> So I created an example django project that is using this package in the
>> directory below the package, thus the directory containing the README,
>> setup.py etc .. files.
>> 
>> The example app will hold a tests.py file which will contain my tests which
>> will be testing the actual functionality of my views.
>> 
>> Basically I'm asking do I need an actual django project to test just a
>> views.py file or can I just write some tests without a containing django
>> project to test a views.py file.
>> And if so, I'm kinda lost on how you would start on such a task.
>> 
>> A few you things that you may find useful or not for testing :
>> 
>> .  Test cases can override settings such as the urlconf
>> .  There's a test client to test views
>> .  Class based views can sometimes be tested without any of the former by
>> just testing the methods in them
>> .   You can always use mocking library
>> .  Tests are basically just python code with a lot of asserts, you can
>> always add viewed in them
>> .  You can use fixtures for test data if you see fit
>> 
>> Hope this helps!
>> 
>> Thomas
>> 
>> On Sep 10, 2012 5:23 PM, "Jonas Geiregat" <jo...@geiregat.org> wrote:
>>> 
>>> Hello,
>>> 
>>> I've created a simple reusable django package. This package basically
>>> consists out of a views.py file, with some helper functions.
>>> 
>>> I want to write some tests for what's in this file. This file contains a
>>> mixin , so I probably can't test it directly.
>>> 
>>> What's the best way to test a django package ?
>>> 
>>> Do I need to include some kind of example project that, uses my mixin and
>>> has tests files just as one would test a normal django application ?
>>> 
>>> I've tried googling but, there's little about this. Most of the things
>>> I've found where related to testing actual django applications.
>>> 
>>> Any help is appreciated.
>>> 
>>> Jonas
>>> 
>>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>> 
>> 
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To p

Re: testing a django package

2012-09-12 Thread Jonas Geiregat

I can now show you what I really would like to write tests for.

https://github.com/jonasgeiregat/django-ajax-forms

The code I would like to test is in ajax_forms/views.py mainly the AjaxFormView 
and the AjaxModelFormView.

Any help is appreciated!

> 
>> Is it a view mix in?
>> 
> The package actually already changed from containing a view mix in to actual 
> views that should be subclassed by the users using the package.
>> It's a bit difficult to tell you much without more information.
>> 
> For example, a view derived from FormView. Like I said the user should 
> subclass this view again as you would normally do with CBV.
> 
> Currently the package is just a package/directory with views.py, models.py, 
> urls.py and of course __init__.py to make it a module.
> 
> It's hard to test views without having an actual django project to test it 
> again, I think.  Correct me if I'm wrong here.
> So I created an example django project that is using this package in the 
> directory below the package, thus the directory containing the README, 
> setup.py etc .. files.
> 
> The example app will hold a tests.py file which will contain my tests which 
> will be testing the actual functionality of my views.
> 
> Basically I'm asking do I need an actual django project to test just a 
> views.py file or can I just write some tests without a containing django 
> project to test a views.py file.
> And if so, I'm kinda lost on how you would start on such a task.
> 
>> A few you things that you may find useful or not for testing :
>> 
>> .  Test cases can override settings such as the urlconf 
>> .  There's a test client to test views 
>> .  Class based views can sometimes be tested without any of the former by 
>> just testing the methods in them 
>> .   You can always use mocking library 
>> .  Tests are basically just python code with a lot of asserts, you can 
>> always add viewed in them 
>> .  You can use fixtures for test data if you see fit
>> 
>> Hope this helps!
>> 
>> Thomas
>> 
>> On Sep 10, 2012 5:23 PM, "Jonas Geiregat" <jo...@geiregat.org> wrote:
>> Hello,
>> 
>> I've created a simple reusable django package. This package basically 
>> consists out of a views.py file, with some helper functions.
>> 
>> I want to write some tests for what's in this file. This file contains a 
>> mixin , so I probably can't test it directly.
>> 
>> What's the best way to test a django package ?
>> 
>> Do I need to include some kind of example project that, uses my mixin and 
>> has tests files just as one would test a normal django application ?
>> 
>> I've tried googling but, there's little about this. Most of the things I've 
>> found where related to testing actual django applications.
>> 
>> Any help is appreciated.
>> 
>> Jonas
>> 
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Re: testing a django package

2012-09-11 Thread Jonas Geiregat

> Is it a view mix in?
> 
The package actually already changed from containing a view mix in to actual 
views that should be subclassed by the users using the package.
> It's a bit difficult to tell you much without more information.
> 
For example, a view derived from FormView. Like I said the user should subclass 
this view again as you would normally do with CBV.

Currently the package is just a package/directory with views.py, models.py, 
urls.py and of course __init__.py to make it a module.

It's hard to test views without having an actual django project to test it 
again, I think.  Correct me if I'm wrong here.
So I created an example django project that is using this package in the 
directory below the package, thus the directory containing the README, setup.py 
etc .. files.

The example app will hold a tests.py file which will contain my tests which 
will be testing the actual functionality of my views.

Basically I'm asking do I need an actual django project to test just a views.py 
file or can I just write some tests without a containing django project to test 
a views.py file.
And if so, I'm kinda lost on how you would start on such a task.

> A few you things that you may find useful or not for testing :
> 
> .  Test cases can override settings such as the urlconf 
> .  There's a test client to test views 
> .  Class based views can sometimes be tested without any of the former by 
> just testing the methods in them 
> .   You can always use mocking library 
> .  Tests are basically just python code with a lot of asserts, you can always 
> add viewed in them 
> .  You can use fixtures for test data if you see fit
> 
> Hope this helps!
> 
> Thomas
> 
> On Sep 10, 2012 5:23 PM, "Jonas Geiregat" <jo...@geiregat.org> wrote:
> Hello,
> 
> I've created a simple reusable django package. This package basically 
> consists out of a views.py file, with some helper functions.
> 
> I want to write some tests for what's in this file. This file contains a 
> mixin , so I probably can't test it directly.
> 
> What's the best way to test a django package ?
> 
> Do I need to include some kind of example project that, uses my mixin and has 
> tests files just as one would test a normal django application ?
> 
> I've tried googling but, there's little about this. Most of the things I've 
> found where related to testing actual django applications.
> 
> Any help is appreciated.
> 
> Jonas
> 
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



testing a django package

2012-09-10 Thread Jonas Geiregat
Hello,

I've created a simple reusable django package. This package basically consists 
out of a views.py file, with some helper functions.

I want to write some tests for what's in this file. This file contains a mixin 
, so I probably can't test it directly. 

What's the best way to test a django package ? 

Do I need to include some kind of example project that, uses my mixin and has 
tests files just as one would test a normal django application ?

I've tried googling but, there's little about this. Most of the things I've 
found where related to testing actual django applications.

Any help is appreciated.

Jonas


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



[ANN] django-ajax-form-mixin v.0.0.1

2012-09-03 Thread Jonas Geiregat
Hello everyone,

I made a small application last weekend that is ready to be released.

It's takes on django-ajax-validation by replacing the view with a mixin and 
improving the jQuery callback possibilities.

Source: https://github.com/jonasgeiregat/django-ajax-form-mixin

Documentation: http://django-ajax-form-mixin.readthedocs.org/en/latest/

Hope you enjoy it!

Regards,

Jonas Geiregat.

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



Re: 'CSRF verification failed." from django.contrib.comments. can you help solve it? django 1.3

2012-06-28 Thread Jonas Geiregat
On do, jun 28, 2012 at 09:14:36 -0700, brycenesbitt wrote:
> http://127.0.0.1:8000/comments/post/>" method="post">
>/>
>id="id_timestamp" />
>value="6e85e1c846861c80575ce435b21a855706725b00" id="id_security_hash" 
> />

After the starting form tag add {% csrf_token %}

More information about it: 
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

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



Translated urls and accept-language header

2012-06-27 Thread Jonas Geiregat
Hello,

I've setup translated urls for some languages. The default language 
for django has been set to en-US.

If you request a page /registration/ with nl-NL as Accept-Language
header, I get a 404. 
I wasn't expecting such behaviour. Rather I was hoping I would be 
redirected to /registratie/ ,the tranlated url that corresponds my
Accept-Language header.
Ofcourse /registratie/ with the nl-Nl Accept-Language header, works
fine and gives me the expected 200.

I'm guessing this is just as normal as it can get ?

Isn't there a chance a user might get link from some website and
the link is build for the English language, but the user in question
has a different supported language setting, Accept-Language header ?
In such a case he would be presented with a 404.
He should be presented with or the English (default) content or
or be redirected to the correct url for his language if supported.

Also what happens if a user has a not supported language setting ?
Will the django default LANGUAGE_CODE be used, en-US in my case ?

Is there a way to work around this or handle it in a different better way ?

an extract from my urls.py file, shows how I've setup translated urls:

url(_(r'^step1/$'), AccountTypeSelectionView.as_view(), 
name="registration_step1"),

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



Re: Testing Google Charts within Django Unit Tests

2012-04-26 Thread Jonas Geiregat


> I'm looking for a way to test the data that a google chart displays on
> a web site with a unit test. Is this at all possible, and if so, where
> should I look to accomplish this? I've tried accessing the Google
> visualization datatable that is used to create the chart, but it
> doesn't seem to be a part of the context of the HTTP responses that I
> am getting.

Take a look at selenium or windmill, they might be able to solve your 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: mocking out a Model

2012-04-15 Thread Jonas Geiregat


>> @patch('apps.market.models.House')
> 
> Is create house in apps.market.models, or is it somewhere else? If
> it's somewhere else, mock it relative to that file eg:
> @patch('apps.some_file.House')

def create_house can be found in apps/deps/house_factory.py
Inside house_factory I ' from apps.market.models import House '


I tried running the test like you said by patching it like:
@patch('apps.deps.house_factory.House')

But for some reason I'm getting a MemoryError by nose.

I tried patching it with patch.object next,
@patch.object('apps.deps.house_factory', 'House')

Then I'm receiving a:
AttributeError: apps.deps.house_factory does not have the attribute 'House'

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



mocking out a Model

2012-04-14 Thread Jonas Geiregat
Hello,

I'm trying to test a function that imports and acts upon a django model, named 
House.

from apps.market.models import House

def create_house(location, date, price):
house = House(id=None, date, price)
house.save()

# calculate some stuff and further expand the house instance
# for example house.tag.add("some-tag")

# save after calculations
house.save()

I like to mock out the House model.
This is what I've tried so far, this is a method of a TestCase class:

@patch('apps.market.models.House')
   def create_house_test(self, MockedHouse):

   """ Constants """
   DAYS_FROM_TODAY = 55
   DATE = datetime.date.today() + datetime.timedelta(days=DAYS_FROM_TODAY)
PRICE = 25

# A location is also a django module , I'm using factory_boy here for 
building a 'mocked' location
   location = LocationFactory.build()


   create_house(DATE, PRICE)
   MockedHouse.assert_called_with(None, DATE, PRICE)   
MockedHouse.save.assert_called_with()


I keep getting an assertionError, the Class is never called.

I'm also wondering if it's possible to inspect MockedHouse to see if it has for 
example some tags added to it.

Any help is appreciated,

Jonas.

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



Re: RequestContext(request)

2012-01-09 Thread Jonas Geiregat
I'm no expert but the problem should most likely lay with how STATIC_URL is 
populated.

When the line:  str(request.POST.get('question')) , email = "" +
> str(request.POST.get('email')))
>p.save()
> 
>else:
>form = newform() # An unbound form
> 
>return render_to_response('index.html', {
>'form': form,
>},context_instance=RequestContext(request))
> 
> 
> 
> but everytime i add the context_instance=RequestContext(request)  all
> the images in me website goes away !! why
> 
> 
> 
> my html page  index.html :
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  width="800" height="200" id="movie_name" align="middle">
>> 
>
>
>
>
>http://www.adobe.com/go/getflash;>
>http://www.adobe.com/images/shared/
> download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>
>
>
>
>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Welcome
> Lorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula. Etiam erat diam,
> elementum in dapibus bibendum, ultrices eget enim. Nulla et nibh nec
> elit venenatis commodo sit amet pretium eros. Duis vel velit at augue
> tristique vehicula. Nulla in lectus quis nisi egestas egestas at ac
> lacus. Donec rutrum volutpat rhoncus. Proin condimentum, odio eu
> commodo laoreet, turpis leo tincidunt nisi, nec mollis quam justo
> vitae velit.
> 
> 
> 
> 
> textarea{
> background-color:#CC;
> border-color:#1B4D90;
> width:250px;
> height:150px;
> margin-left:20px;
> }
> 
> input[type=text]{
> background-color:#CC;
> border-color:#1B4D90;
> width:250px;
> margin-left:20px;
> 
> }
> input[type=submit]{
> background-color:#1B4D90;
> color:#ff;
> width:100px;
> margin-left:170px;
> 
> }
> 
> {% csrf_token %}
> Quick
> Question 
> {{ form.question }}
> E-
> Mail
> {{ form.email }}
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Global (c) 2011 | Privet policy
>  Powerd by http://www.gardeniatelco.com;>Gardeniatelco a>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> and my settings.py is :
> 
> # Django settings for global project.
> 
> import os
> PROJECT_ROOT =
> os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
> 
> 
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
> 
> ADMINS = (
># ('Your Name', 'your_em...@example.com'),
> )
> 
> MANAGERS = ADMINS
> 
> DATABASES = {
>'default': {
>'ENGINE': 'django.db.backends.sqlite3', # Add
> 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
>'NAME': 'sqlite.db',  # Or path to
> database file if using sqlite3.
>'USER': '',  # Not used with sqlite3.
>'PASSWORD': '',  # Not used with sqlite3.
>'HOST': '',  # Set to empty string for
> localhost. Not used with sqlite3.
>'PORT': '',  # Set to empty string for
> default. Not used with sqlite3.
>}
> }
> 
> # Local time zone for this installation. Choices can be found here:
> # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
> # although not all choices may be available on all operating systems.
> # On Unix systems, a value of None will cause Django to use the same
> # timezone as the operating system.
> # If running in a Windows environment this must be set to the same as
> your
> # system time zone.
> TIME_ZONE = 'America/Chicago'
> 
> # Language code for this installation. All choices can be found here:
> # http://www.i18nguy.com/unicode/language-identifiers.html
> LANGUAGE_CODE = 'en-us'
> 
> SITE_ID = 1
> 
> # If you set this to False, Django will make some optimizations so as
> not
> # to load the internationalization machinery.
> USE_I18N = True
> 
> # If you set this to False, Django will not format dates, numbers and
> # calendars according to the current locale
> USE_L10N = True
> 
> # Absolute filesystem path to the directory that will hold user-
> uploaded files.
> # Example: "/home/media/media.lawrence.com/media/"
> MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")
> 
> # 

Re: RequestContext(request)

2012-01-09 Thread Jonas Geiregat
I'm no expert but the problem should most likely lay with how STATIC_URL is 
populated.

When the line:  str(request.POST.get('question')) , email = "" +
> str(request.POST.get('email')))
>p.save()
> 
>else:
>form = newform() # An unbound form
> 
>return render_to_response('index.html', {
>'form': form,
>},context_instance=RequestContext(request))
> 
> 
> 
> but everytime i add the context_instance=RequestContext(request)  all
> the images in me website goes away !! why
> 
> 
> 
> my html page  index.html :
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  width="800" height="200" id="movie_name" align="middle">
>> 
>
>
>
>
>http://www.adobe.com/go/getflash;>
>http://www.adobe.com/images/shared/
> download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>
>
>
>
>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> About Us
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut dictum
> enim. Quisque posuere justo sem, posuere lobortis ligulaLorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Welcome
> Lorem ipsum
> dolor sit amet, consectetur adipiscing elit. In ut dictum enim.
> Quisque posuere justo sem, posuere lobortis ligula. Etiam erat diam,
> elementum in dapibus bibendum, ultrices eget enim. Nulla et nibh nec
> elit venenatis commodo sit amet pretium eros. Duis vel velit at augue
> tristique vehicula. Nulla in lectus quis nisi egestas egestas at ac
> lacus. Donec rutrum volutpat rhoncus. Proin condimentum, odio eu
> commodo laoreet, turpis leo tincidunt nisi, nec mollis quam justo
> vitae velit.
> 
> 
> 
> 
> textarea{
> background-color:#CC;
> border-color:#1B4D90;
> width:250px;
> height:150px;
> margin-left:20px;
> }
> 
> input[type=text]{
> background-color:#CC;
> border-color:#1B4D90;
> width:250px;
> margin-left:20px;
> 
> }
> input[type=submit]{
> background-color:#1B4D90;
> color:#ff;
> width:100px;
> margin-left:170px;
> 
> }
> 
> {% csrf_token %}
> Quick
> Question 
> {{ form.question }}
> E-
> Mail
> {{ form.email }}
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Global (c) 2011 | Privet policy
>  Powerd by http://www.gardeniatelco.com;>Gardeniatelco a>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> and my settings.py is :
> 
> # Django settings for global project.
> 
> import os
> PROJECT_ROOT =
> os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
> 
> 
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
> 
> ADMINS = (
># ('Your Name', 'your_em...@example.com'),
> )
> 
> MANAGERS = ADMINS
> 
> DATABASES = {
>'default': {
>'ENGINE': 'django.db.backends.sqlite3', # Add
> 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
>'NAME': 'sqlite.db',  # Or path to
> database file if using sqlite3.
>'USER': '',  # Not used with sqlite3.
>'PASSWORD': '',  # Not used with sqlite3.
>'HOST': '',  # Set to empty string for
> localhost. Not used with sqlite3.
>'PORT': '',  # Set to empty string for
> default. Not used with sqlite3.
>}
> }
> 
> # Local time zone for this installation. Choices can be found here:
> # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
> # although not all choices may be available on all operating systems.
> # On Unix systems, a value of None will cause Django to use the same
> # timezone as the operating system.
> # If running in a Windows environment this must be set to the same as
> your
> # system time zone.
> TIME_ZONE = 'America/Chicago'
> 
> # Language code for this installation. All choices can be found here:
> # http://www.i18nguy.com/unicode/language-identifiers.html
> LANGUAGE_CODE = 'en-us'
> 
> SITE_ID = 1
> 
> # If you set this to False, Django will make some optimizations so as
> not
> # to load the internationalization machinery.
> USE_I18N = True
> 
> # If you set this to False, Django will not format dates, numbers and
> # calendars according to the current locale
> USE_L10N = True
> 
> # Absolute filesystem path to the directory that will hold user-
> uploaded files.
> # Example: "/home/media/media.lawrence.com/media/"
> MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")
> 
> # 

Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> Thanks Jonas, the statements you had provided would give me a list of users 
> who belong that group, but how can I retrieve the photos of those users? 
> Actually I was looking for a single statement which would join all these 
> tables and returns the data based on the Group ID.

I would recommend reading through 
https://docs.djangoproject.com/en/dev/topics/db/queries/

Getting a row by ID:

Group.objects.get(pk=group_id)

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



Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> The user field is a foreign key to django auth User model. Each user is 
> assigned to a group (django Auth Group model). I want to retrieve all the 
> photos which belongs to users of a specific group. How can it be done?
> 

from django.contrib.auth.models import Group

group = Group.objects.get(name='your_group')
users = group.user_set.all()

Haven't tested it, but I think that's what you want/need.


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



Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> The user field is a foreign key to django auth User model. Each user is 
> assigned to a group (django Auth Group model). I want to retrieve all the 
> photos which belongs to users of a specific group. How can it be done?
> 

from django.contrib.auth.models import Group

group = Group.objects.get(name='your_group')
users = group.user_set.all()

Haven't tested it, but I think that's what you want/need.


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



Re: Creating clean URLS

2012-01-01 Thread Jonas Geiregat


> I want my url to be free from parameters being passed.
> 
> I have handled the request in "twitter_after_auth" function of view
> and
> 
> I am redirecting user to the new url "http://localhost/create_cr/;
> 
> but instead the url shows some additional parameters that I have
> already handled.

> something like below:-
> 
> "http://localhost/create_cr/?
> oauth_token=SOME_VALUE_verifier=SOME_VALUE"
> 
> I just want my url to be of something like below:-
> 
> "http://localhost/create_cr/;
> 

It would be interesting to see some part of the view code for further 
inspection of 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Keep getting TemplateDoesNotExist when unit testing

2011-12-24 Thread Jonas Geiregat
Hello,

I'm fairly new to Unit Testing.

As I'm trying to setup a simple unit test in one of my Projects,
it keeps returning a TemplateDoesNotExist Exception.

It looks like for some reason the unit test framework can't locate my template 
directory I've correctly defined in settings.py

Here's the traceback:

==
ERROR: test_url (gig.tests.GigURLTest)
--
Traceback (most recent call last):
  File "/home/jonasg/dev/wiespeeltwaar/gig/tests.py", line 14, in test_url
response = c.get('/')
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
 line 445, in get
response = super(Client, self).get(path, data=data, **extra)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
 line 229, in get
return self.request(**r)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/core/handlers/base.py",
 line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/home/jonasg/dev/wiespeeltwaar/../wiespeeltwaar/gig/views.py", line 74, 
in index
http_res = render_to_response('gig/index.html', c , 
context_instance=RequestContext(request))
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/shortcuts/__init__.py",
 line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), 
**httpresponse_kwargs)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 181, in render_to_string
t = get_template(template_name)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 157, in get_template
template, origin = find_template(template_name)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: gig/index.html


The unit test itself is simple:

from django.test import TestCase
from django.test.client import Client

class GigURLTest(TestCase):
def test_url(self):
c = Client()
response = c.get('/')
self.assertEqual(response.status_code, 200) 

   

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



Keep getting TemplateDoesNotExist when unit testing

2011-12-24 Thread Jonas Geiregat
Hello,

I'm fairly new to Unit Testing.

As I'm trying to setup a simple unit test in one of my Projects,
it keeps returning a TemplateDoesNotExist Exception.

It looks like for some reason the unit test framework can't locate my template 
directory I've correctly defined in settings.py

Here's the traceback:

==
ERROR: test_url (gig.tests.GigURLTest)
--
Traceback (most recent call last):
  File "/home/jonasg/dev/wiespeeltwaar/gig/tests.py", line 14, in test_url
response = c.get('/')
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
 line 445, in get
response = super(Client, self).get(path, data=data, **extra)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/test/client.py",
 line 229, in get
return self.request(**r)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/core/handlers/base.py",
 line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
  File "/home/jonasg/dev/wiespeeltwaar/../wiespeeltwaar/gig/views.py", line 74, 
in index
http_res = render_to_response('gig/index.html', c , 
context_instance=RequestContext(request))
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/shortcuts/__init__.py",
 line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), 
**httpresponse_kwargs)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 181, in render_to_string
t = get_template(template_name)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 157, in get_template
template, origin = find_template(template_name)
  File 
"/home/jonasg/.virtualenvs/wiespeeltwaar/lib/python2.6/site-packages/django/template/loader.py",
 line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: gig/index.html


The unit test itself is simple:

from django.test import TestCase
from django.test.client import Client

class GigURLTest(TestCase):
def test_url(self):
c = Client()
response = c.get('/')
self.assertEqual(response.status_code, 200) 

   

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



Re: Does ModelForm follow ForeignKey relations ?

2011-09-20 Thread Jonas Geiregat



> So you want to edit the User object through the ModelForm of the other model, 
> or you just want to display it?
> 

I want to edit the User object through the ModelForm.

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



Re: Does ModelForm follow ForeignKey relations ?

2011-09-20 Thread Jonas Geiregat

> Hi,
> 
> ModelForm should automatically create a dropdown list for your foreign key.
> If there is nor such drop-down created probably you are doing something wrong.
> 

I don't want the dropdown list I want the values of the foreinkey to be 
expaneded into fields

For example I have user as ForeignKey to the contrib.auth.models.User model. 
This model has username as field.

I want to display the username field of the user foreinkey.

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



Does ModelForm follow ForeignKey relations ?

2011-09-20 Thread Jonas Geiregat
Hello,

I have a UserProfile model:

class UserProfile(FacebookProfileModel):
user = models.ForeignKey(User, unique=True) 

 
lastfm_user = models.CharField(max_length=20, blank=True)

This should be turned into a real HTML form , I which to use the ModelForm 
class for this.

class UserProfileForm(ModelForm):
class Meta:
model = UserProfile
# I can select lastfm_user or any other properties I have 
defined in the UserProfile model 
# But what if I wanted to only show the user__username field in 
the form ?

# This doesn't work
fields = ('user__username',)

I've searched the docs , read the page about creating froms from models but 
didn't found any clues. 
Is this even possible at all ?

Now I'm implementing the form by hand , which is a lot of work , being able to 
use the ModelForm would speed up this process.

Regards,


Jonas Geiregat
jo...@geiregat.org





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



limit foreignkey of queryset

2011-07-22 Thread Jonas Geiregat
Hello,

How would I limit the results of a foreign key of a queryset ?
Ie. I have the models Person and Task. I want to get all Person's but only get 
their 2 latest tasks.

Person__task points to Task__name 
It's a ManyToMany Relationship.


Jonas Geiregat
jo...@geiregat.org





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



Re: django.contrib.auth.view.login reuse

2011-07-21 Thread Jonas Geiregat


> Hello,
> 
> I would like to add login fields to each page. But I want to keep it as DRY 
> as possible.
> I'm pretty satisfied until now about using django.contrib.auth.views.login 
> ,but that's just one specific view in my case host.com/login. With a urls.py 
> line as: 
> (r'^/login/$', 'django.contrib.auth.views.login', {'template_name': 
> 'myapp/login.html'}),
> 
> All this django builtin view does is add stuff to the context of the request 
> and render one single template.
> 
> My problem now is, can I reuse that view in other views or use it so I can as 
> a template context processor, so it's always available ? 
> I'm having trouble figuring out which would be the best route to take.

I've figured some stuff out already. Being able to read the django source code 
is such a bless!
I can use the form stored at django.contrib.auth.forms.AuthenticationForm.

Knowing I can easily access the login from I could create my own context 
processor and add it side-wide from there. 

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



Re: import django models without runing the server

2011-07-21 Thread Jonas Geiregat

> Alexander,
> 
> Try use this
> 
> #test.py
> import os, sys
> sys.path.append('../')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
> 
> myproject/test.py
> 


This is a good read on the subject , it presents an elegant solution.

http://superjared.com/entry/django-and-crontab-best-friends/

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



django.contrib.auth.view.login reuse

2011-07-21 Thread Jonas Geiregat
Hello,

I would like to add login fields to each page. But I want to keep it as DRY as 
possible.
 I'm pretty satisfied until now about using django.contrib.auth.views.login 
,but that's just one specific view in my case host.com/login. With a urls.py 
line as: 
(r'^/login/$', 'django.contrib.auth.views.login', {'template_name': 
'myapp/login.html'}),

All this django builtin view does is add stuff to the context of the request 
and render one single template.

My problem now is, can I reuse that view in other views or use it so I can as a 
template context processor, so it's always available ? 
I'm having trouble figuring out which would be the best route to take.

Any advise is welcome,

Regards,

Jonas.

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



Re: session and caching

2011-07-13 Thread Jonas Geiregat


> I have site with with a lay-out depending on a session, set in my
> view. I first tried site-wide caching, and this obviously didn't work.
> The caching is not session aware, and the lay-out changes almost
> randomly.

Are you sure because in the docs I find the opposite.

https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cached-sessions



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



Re: Inspecting objects

2011-07-13 Thread Jonas Geiregat

Op 13-jul-2011, om 08:25 heeft Jirka Vejrazka het volgende geschreven:

>> Thank you all for your help!!!
> 
> I know I'm a bit late to the party (blame timezones :), but thought
> I'd put my 2 cents worth in :)
> 
> For inspecting models from command lines (usually when working with
> models from legacy databases) I often use model_to_dict which is
> "hidden" in django.forms.models.



This is new for me. I've noticed before that django's API docs doesn't all 
function available. There's probably a good reason for it.

What's the advantage of using model_to_dict against dict(some_queryset) ?

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



Re: Inspecting objects

2011-07-13 Thread Jonas Geiregat
I like to add:

import pdb; pdb.set_trace();

To my code.

Reload the page.

Go to the development server instance. You'll see that the page hangs forever 
,since we started the python debugger. 
Now you can easily inspect all variables, classes and functions from PDB. 
Of course you're not limited to using set_trace().

Good luck !


>> Thank you all for your help!!!
> 
> I know I'm a bit late to the party (blame timezones :), but thought
> I'd put my 2 cents worth in :)
> 
> For inspecting models from command lines (usually when working with
> models from legacy databases) I often use model_to_dict which is
> "hidden" in django.forms.models.
> 
>>>> from django.forms.models import model_to_dict
>>>> print model_to_dict(some_model)
> 
>  HTH
> 
> Jirka
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org





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



Re: get all objects that are related to current, reverse look up

2011-07-13 Thread Jonas Geiregat

Op 12-jul-2011, om 09:18 heeft bruno desthuilliers het volgende geschreven:

> On Jul 12, 4:32 am, garagefan  wrote:
>> simply put, here's my code
>> 
>> class ContentBlock(Orderable, Displayable):
>>   location = models.ManyToManyField(ContentBlockLocation, blank=True,
>> null=True, help_text="list of locations to display content block")
>>   page = models.ManyToManyField(Page, blank=True, null=True,
>> help_text="list of pages to display content block")
>>   height = models.IntegerField(blank=True, null=True)
>>   width = models.IntegerField(blank=True, null=True)
>> 
>>   def __unicode__(self):
>> return self.title
>> 
>> class StaticContent(Displayable, RichText):
>>  content_block =  models.ForeignKey(ContentBlock, blank=True,
>> null=True)
>> 
>> class StaticContent2(Displayable, RichText):
>>  content_block =  models.ForeignKey(ContentBlock, blank=True,
>> null=True)
>> 
>> putting together a template tag that will return all the items
>> associated with a given ContentBlock, but i would like to do so
>> without knowing upfront all of the classes that have a foreign key to
>> ContentBlock as i'll want to be able to add more content types at any
>> time
> 
> 
> Are you sure your data model is right ?
> 

Displayable and RichText are probably classes that inherit from 
django.db.models.Model.




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



Re: block bots and spiders

2011-07-12 Thread Jonas Geiregat


> Hi all,
> 
> has someone an effective way to block away bots and spiders?
> There are so many ignoring robots.txt - besides facebook and tons of
> Java/xyz clients there are many more illegal spiders around.
> 
> So does anyone have a performance effective way to block them out?
> Or do you think - if performance matters, leave them crawling...
> 
> regards
> 
> Henrik

The only thing I can think of is checking the request.META dictionary. It 
contains the HTTP_HOST and HTTP_USER_AGENT settings by the client. You could 
check if those are valid but of course a spider could fake those values. But 
I'm guessing not all spiders fake them.
You could at least filter out those that don't set these values.

It would probably require lot's of heavy regular expression code (since there 
are so many valid client headers) which would be best implemented as a 
decorator on each view method.  Or you could probably put the code in a 
middleware.
Eventually taking out those spiders would slow down your request.

Again I have no experience on this field, it's just an idea that might be 
possible.

Regards,

Jonas.

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



Re: request.method GET or POST

2011-07-12 Thread Jonas Geiregat

Op 12-jul-2011, om 07:04 heeft Venkatraman S het volgende geschreven:

> We have to check for request.method to suitably route the request to the 
> logic.
> 
> Would it be nice if we have something like doGet or doPost(similar to java 
> servlets) that we have in our views,
> so that the request gets automatically routed , and the code is structured 
> nicely?
> 
> So a view would look like:
> def funcname(request,itemid,..):
>   def doPOST():
> #.do things when the request is POST
>   def doGET():
> #.do things when the request is GET..
> 

How would that be different from doing something like

@require_http_methods(["GET", "POST"])
def funcname(request, itemid):
if request.method == 'POST':
# do something

 #We can savely assume it's a GET request since it's not a POST request and 
those are the only two allowed
# do something 


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



Django API

2011-07-12 Thread Jonas Geiregat
Hello,

I really love django's documentation. It covers a lot of ground and is really 
well written. 
I do have one problem with it. It might be best explained with an example.

I want to see all methods and properties of the request parameter in the view. 
Search the docs for "request" doesn't help me much. In fact searching the docs 
for a particular method often doesn't point me to the correct page.

What I sometimes need is a tree view of all django's modules, classes, methods 
and properties. It also might help me better understand the structure of how 
django was written.

Is there something like that out there ?

Regards,

Jonas Geiregat
jo...@geiregat.org





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



Re: need help with calling following complex query

2011-07-11 Thread Jonas Geiregat
> 
> results.extra(select={
> 'distance': 
> '(acos(sin(latitude)*sin(%(latitude)f)+cos(latitude)*cos(%(latitude)f)*cos(%(longitude)f-longitude)))'
>   % {
>  'latitude': latitude,
>  'longitude': longitude
> }
> }).order_by('distance')  
> 

This is an interesting solution to the issue. I never really looked into the 
extra method. 
So I read the docs and I'm wondering if it wouldn't be better to use the 
select_params parameter ?


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



Re: need help with calling following complex query

2011-07-10 Thread Jonas Geiregat
> 
> 
> In order to find the places in near by area I want to make following
> mysql query. but I am not sure how should I translate it using django
> models and managers.

You could execute the raw sql query string, see: 
https://docs.djangoproject.com/en/dev/topics/db/sql/
for more information on the subject. Seeing the complexity of the query and 
knowing it's a good working version why should you even bother translating it 
to django's ORM framework ?

> 
> orig.lat = x
> orig.lon = y
> 
> "SELECT  destination.*,
> 3956 * 2 * ASIN(SQRT(  POWER(SIN((orig.lat - dest.lat) * pi()/180 /
> 2), 2) +
> COS(orig.lat * pi()/180) *  COS(dest.lat * pi()/180) *
> POWER(SIN((orig.lon -dest.lon) * pi()/180 / 2), 2)  )) as
> distance
> FROM place as dest
> WHERE  dest.longitude
> BETWEEN lon1 and lon2
> AND dest.latitude
> BETWEEN lat1 and lat2
> "
> 
> the model which talks to database is called Place in my case.
> 
> Thank you all for the help,
> sanket
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org





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



Re: Extending User model with Inheritance - Attribute Error

2011-07-10 Thread Jonas Geiregat

Op 10-jul-2011, om 12:37 heeft Venkatraman S het volgende geschreven:

> 
> This is not good design. If you want to store some extra fields for a User - 
> i would define just another model called ProfileDetails, FK it to User and 
> use it as such.

That's also how I would do it, some example code to make it even more clear:

from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
url = models.URLField("Website", blank=True)
company = models.CharField(max_length=50, blank=True)

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



Re: login form

2011-07-09 Thread Jonas Geiregat

> @ All
> i have created a login form in django.
> but after filling the username and password when click on submit, it
> shows the following error :
> 
> Forbidden (403)
> 
> CSRF verification failed. Request aborted.


This has been asked many times before on this list.  
I advise you to read the extra guidelines that come with the error message , as 
they explain what you should do in order to get the page working.



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



Re: cropping of an image

2011-07-07 Thread Jonas Geiregat


> 
> I want the code for including an image with crop feature.

Django doesn't come with any image handling libraries.
I've done this before and have used PIL (Python Image Library) for it.

It might be advised to use this in combination with celery if you're handling 
large files. 
That way it wouldn't slow down the request.

Regards,

Jonas

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



Re: django/python performance vs play/java

2011-07-05 Thread Jonas Geiregat
equest)
> 
> 
> so play is outperforming django! obviously django is not in debug mode
> ecc..., is there something wrong in my test setup (I already tried to
> adjust the uwsgi launch line I tryed more process or 1 process with
> threads ecc with no relevant improvement) or django/python is simply
> much slower than java? I tried to run play behind nginx proxy too: the
> results are pratically identical. Note the response time too: the
> slowest play response is 47 ms, the fastest django one is 110 ms,
> 
> any suggestion to improve performance is appreciated,
> 
> thanks in advance,
> drakkan
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org





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



complex query

2011-07-03 Thread Jonas Geiregat
Hello,

I have the following models

class Book(models.Model):
author = models.ManyToManyField(Author)
pub_date = models.DateTimeField()
...

class Author(models.Model):
tag = models.ManyToManyField(Tag)

class Tag(models.Model):
name = models.CharField(max_length=20)

What I want to query for is:

The most used Tags (and their count) for all books who's pub_date is greater 
then today.

I can solve the last part 
Book.objects.filter(pub_date__gt=datetime.date.today())

But how do I count all the tags for all these books ?

Jonas Geiregat
jo...@geiregat.org





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



Re: Stuck on "ViewDoesNotExist" last step of tutorial part 4

2011-06-18 Thread Jonas Geiregat
The view function may have been deleted but the urls.py file (in the root of 
your project) is still (probably) referring to those functions. So look at your 
urls.py file and you'll figure it out!

Good luck!

> I am using Django 1.3 with SQlite. I got through the entire tutorial
> except the last step of part 4.
> 
> It says "You can now delete the index(), detail() and results() views
> from polls/views.py. We don't need them anymore -- they have been
> replaced by generic views."
> 
> However when I do this I get the following error:
> 
> Environment:
> 
> 
> Request Method: POST
> Request URL: http://localhost:8000/polls/1/vote/
> 
> Django Version: 1.3
> Python Version: 2.7.2
> Installed Applications:
> ['django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'polls',
> 'django.contrib.admin']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware')
> 
> 
> Traceback:
> File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in
> get_response
>  111. response = callback(request,
> *callback_args, **callback_kwargs)
> File "C:\Documents and Settings\ask\Desktop\Stream Coding Project
> \Django First Tutorial\mysite\polls\views.py" in vote
>  24. return HttpResponseRedirect(reverse('poll_results',
> args=(p.id,)))
> File "c:\Python27\lib\site-packages\django\core\urlresolvers.py" in
> reverse
>  391. *args, **kwargs)))
> File "c:\Python27\lib\site-packages\django\core\urlresolvers.py" in
> reverse
>  312. possibilities = self.reverse_dict.getlist(lookup_view)
> File "c:\Python27\lib\site-packages\django\core\urlresolvers.py" in
> _get_reverse_dict
>  229. self._populate()
> File "c:\Python27\lib\site-packages\django\core\urlresolvers.py" in
> _populate
>  220. lookups.appendlist(pattern.callback, (bits,
> p_pattern))
> File "c:\Python27\lib\site-packages\django\core\urlresolvers.py" in
> _get_callback
>  170. raise ViewDoesNotExist("Tried %s in module %s.
> Error was: %s" % (func_name, mod_name, str(e)))
> 
> Exception Type: ViewDoesNotExist at /polls/1/vote/
> Exception Value: Tried results in module polls.views. Error was:
> 'module' object has no attribute 'results'
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org





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



Re: django database

2011-05-26 Thread Jonas Geiregat


> do i have to install mysql to create a database in my website?

As mentioned before you can use sqlite but consider the disadvantages:

* Speed (sqlite for me ,even when developing a serious application, is a no go) 
When deleting large rows sqlite is remarkably slower then mysql.
* I've seen some issues where sqlite locks tables when there are multiple 
requests or queries.

I don't see any advantages for mysql over postgresql. But then again I'm no 
expert in this area.




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



Re: How do you organize your deployment enviroment

2011-05-25 Thread Jonas Geiregat
I'm just wondering how you could handle database changes.

Let's say you have a existing working project and the client asks for some 
changes.

These changes force you to create an extra table and modify some tables 
(models). 
On the development server I could modify the changes to the database and the 
models files myself.
But deploying these changes to the production server seems a bit harder to 
overcome without the fear of loosing your data.

I don't think the newly created models and database tables would form a 
problem. Simply running ./manage.py syncdb would create the table(s) for us 
without any problems. 
But what about tables (models) that are modified ?

How would you best handle such cases of deployment ?


Op 23-mei-2011, om 09:00 heeft DK het volgende geschreven:

> Hi,
> 
> I am having a django project that  is being frequently deployed on clean 
> linux installation. After a few deployments I have noticed that this process 
> is very time consuming for me (every time I am preparing run scripts for 
> everything, configuring cronjobs, paths to log files, etc) but this could be 
> easily automated.
> 
> What are a ready solutions to manage such deployments?
> 
> My typical workflow is:
> 1) install packages on debian/ubuntu via aptitude (like database, etc)
> 2) creating new virtualenv + getting pip
> 3) pip install -r requirements (to setup enviroment)
> 4) fetch django project from code repository
> 5) setup runtime dir (I keep there: run - for pid files, logs, conf - for 
> some config variables or scritps, scripts - some starting srcipts)
> 6) setup crontab jobs 
> 7) setup webserver + django wsgi to be started 
> 
> 
> Sure - I can write some custom made installer for that, but wondering if 
> there is some generic tool for such things.
> 
> PS. I have heard about fabric, but didn't investigate this tool yet. 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.


Jonas Geiregat
jo...@geiregat.org





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



Re: Authenticating from a mysql database

2011-05-23 Thread Jonas Geiregat

> Hello Jonas,
> 
> thanks again for your reply. I think migrating the database over to
> django may be a good idea, however it's still being used as a legacy
> authentication database for other projects.
> 
> In case I'd decide to migrate the existing users over to the new
> database, how could I make sure the passwords end up in django
> correctly? All I have is the old_password()-crypted user passwords,
> can I simply insert those as values into the auth_user db field?

That might be one of the bigger things to overcome.

In order to succeed you must find out how django stores passwords and how your 
current passwords are stored.
That way you can start converting , probably by writing some python conversion 
script.
You can find out more on how django stores it's passwords here 
http://docs.djangoproject.com/en/dev/topics/auth/#passwords

For the Zope part you're on you're own, I've never looked at it in my life. 


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


Jonas Geiregat
jo...@geiregat.org





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



Re: Authenticating from a mysql database

2011-05-23 Thread Jonas Geiregat
Defining your specific user profile as described in my previous post would 
work. It might need some work arounds and
additional methods to get it working.

If possible I think migrating the database table (the login , name and password 
fields only) you presented to the database your django project database is 
using, seems more elegant.
There would be no need for writing extra code to get this working. 
The only code extra would be , again, a user profile. For storing the role 
column.

For more information about user profiling and django , take a look at:

open http://docs.djangoproject.com/en/dev/topics/auth/#auth-profiles

> Thanks much for your reply Jonas, I'll give it a try later.
> 
> SimpleUserFolder is a Zope "Product" that allows for authentication
> via other mechanisms than Zope's built-in user management. I'm sure
> there is a way to bend Django around the database tables in some way,
> but as i've never tried that before I thought it a good idea to ask
> the experts first.
> 
> The database table is called "users" and has, among others, the
> following columns:
> 
> mysql> desc users;
> +-++--+-
> +---++
> | Field   | Type   | Null | Key |
> Default   | Extra  |
> +-++--+-
> +---++
> | user_id | int(11)| NO   | PRI |
> NULL  | auto_increment |
> | login   | varchar(16)| NO   | UNI
> |   ||
> | name| varchar(80)| NO   | MUL
> |   ||
> | password| varchar(16)| YES  | |
> NULL  ||
> | role| set('Manager','User','Driver') | YES  | MUL |
> Driver||
> 
> The password is encrypted using mysql's password() function, but I
> guess that would not pose too much of a problem, right?
> 
> All the best, Uwe
> 
> 
> On 23 Mai, 00:16, Jonas Geiregat <jo...@geiregat.org> wrote:
>> Hello,
>> 
>> I've never worked with Zope so SompleUserFolder doesn't ring a bell.
>> I'm assuming it's a database table name.
>> 
>> You can always extend the default user's profile.
>> 
>> This is done by creating a class , most people use UserProfile
>> 
>> class UserProfile(models.Model):
>> user = models.ForeignKey(User, unique=True, related_name='profile')
>> #your fields that point to your SimpleUserFolder
>> 
>> Then add the following to your settings.py file to let django use your class
>> 
>> AUTH_PROFILE_MODULE = 'accounts.UserProfile' # assuming you have created a 
>> accounts application
>> 
>> Op 22-mei-2011, om 17:31 heeft Uwe Schuerkamp het volgende geschreven:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Hi folks,
>> 
>>> I'm in the process of migrating (or re-designing for that matter) a
>>> Zope-based user database /ranking system over to Django with roughly
>>> 30,000 accounts in it. The Zope instance uses SimpleUserFolder for
>>> authentication, so I was wondering if there is a way to authenticate
>>> django users from within the existing mysql database.
>> 
>>> Would it be possible to extract roles information from the user table
>>> as well?
>> 
>>> Thanks in advance for any ideas,
>> 
>>> Uwe
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=en.
>> 
>> Jonas Geiregat
>> jo...@geiregat.org
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org





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



Re: How do you organize your deployment enviroment

2011-05-23 Thread Jonas Geiregat
I'm using Fabric for my deployment it's python based although it still leans on 
some shell scripting.

Op 23-mei-2011, om 09:00 heeft DK het volgende geschreven:

> Hi,
> 
> I am having a django project that  is being frequently deployed on clean 
> linux installation. After a few deployments I have noticed that this process 
> is very time consuming for me (every time I am preparing run scripts for 
> everything, configuring cronjobs, paths to log files, etc) but this could be 
> easily automated.
> 
> What are a ready solutions to manage such deployments?
> 
> My typical workflow is:
> 1) install packages on debian/ubuntu via aptitude (like database, etc)
> 2) creating new virtualenv + getting pip
> 3) pip install -r requirements (to setup enviroment)
> 4) fetch django project from code repository
> 5) setup runtime dir (I keep there: run - for pid files, logs, conf - for 
> some config variables or scritps, scripts - some starting srcipts)
> 6) setup crontab jobs 
> 7) setup webserver + django wsgi to be started 
> 
> 
> Sure - I can write some custom made installer for that, but wondering if 
> there is some generic tool for such things.
> 
> PS. I have heard about fabric, but didn't investigate this tool yet. 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.


Jonas Geiregat
jo...@geiregat.org





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



Re: Authenticating from a mysql database

2011-05-22 Thread Jonas Geiregat
Hello,

I've never worked with Zope so SompleUserFolder doesn't ring a bell.
I'm assuming it's a database table name.

You can always extend the default user's profile.

This is done by creating a class , most people use UserProfile

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True, related_name='profile')
#your fields that point to your SimpleUserFolder


Then add the following to your settings.py file to let django use your class

AUTH_PROFILE_MODULE = 'accounts.UserProfile' # assuming you have created a 
accounts application


Op 22-mei-2011, om 17:31 heeft Uwe Schuerkamp het volgende geschreven:

> Hi folks,
> 
> I'm in the process of migrating (or re-designing for that matter) a
> Zope-based user database /ranking system over to Django with roughly
> 30,000 accounts in it. The Zope instance uses SimpleUserFolder for
> authentication, so I was wondering if there is a way to authenticate
> django users from within the existing mysql database.
> 
> Would it be possible to extract roles information from the user table
> as well?
> 
> Thanks in advance for any ideas,
> 
> Uwe
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 


Jonas Geiregat
jo...@geiregat.org




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



Re: Json serialization for use in JS

2011-05-20 Thread Jonas Geiregat
> 
> class Serializer(PythonSerializer):
> def end_object(self, obj):
> self.objects.append({
> "fields" : self._current
> })  
> self._current = None
> 
> 

I've made a small mistake I was importing PythonSerializer while It should've 
been JsonSerializer

Corrected code bellow:

from django.core.serializers.json import Serializer as JsonSerializer

class Serializer(JsonSerializer):
def end_object(self, obj):
self.objects.append({
"fields" : self._current
})
self._current = None



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



Re: Json serialization for use in JS

2011-05-20 Thread Jonas Geiregat

> 
> Your idea of overriding the Serializer class sounds like a better idea to me. 
> It should be possible (and will be interesting) ,I'll think I'll look into 
> that tonight.

Overwriting django's default serializers is possible.
This is how I've done it:

In the root of my django project:

mkdir serializers
touch serializers/__init__.py

create serializers/json.py and add the following (I've just removed the pk and 
model fields which I don't like , but can of course be modified to your liking)

from django.core.serializers.python import Serializer as PythonSerializer

class Serializer(PythonSerializer):
def end_object(self, obj):
self.objects.append({
"fields" : self._current
})  
self._current = None


I've only tested this interactively but it seems to work

In [15]: from serializers.json import Serializer as JsonSerializer

In [16]: json_serializer = JsonSerializer()

In [17]: json_serializer.serialize(Item.objects.all())
Out[17]: [{'fields': {'name': u'foobar'}}]




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



Re: Json serialization for use in JS

2011-05-19 Thread Jonas Geiregat
Hello,

I'm also finding the built in serialization a bit overhead. It puts to much 
information in your JSON string that can be modified such as the PK field.

I often import json ( http://docs.python.org/library/json.html ) and serialize 
the data myself before passing it to the render method.
This isn't the best solution but it works and I get a beautiful JSON string 
such as I wanted it to.

Your idea of overriding the Serializer class sounds like a better idea to me. 
It should be possible (and will be interesting) ,I'll think I'll look into that 
tonight.

Op 19-mei-2011, om 07:55 heeft redfive het volgende geschreven:

> I'm trying to return some JSON from one of my views. My objects are
> simple and I can get the built-in json serializer working, but wanted
> a cleaner object when I deserialize in my webpage, i.e. I don't want
> the pk or model entries. What is the best way to go about that? I
> played around a little with overriding the end_object method in an
> extension of the shipped JSONSerializer and was able to translate the
> pk into the _current object (to reflect the pk as a member of the
> object) but the resultant object still had pk/model and the fields
> object that I had to traverse into.
> 
> my models.py (snippet):
> 
> Class Bug (models.Model):
>id = models.IntegerField ( primary_key=True)
>summary = models.CharField (max_length=256)
>status = models.ForeignKey( Status, default=1 )
> 
> Class Status (models.Model):
>objects = NaturalKeyManager()
>value = models.TextField(unique=True, blank=True)
>def natural_key(self):
>return (self.value)
> 
> my serializers.py:
> 
> from django.core.serializers.json import Serializer as JSONSerializer
> 
> Class Serializer:
>def end_object(self, obj):
> 
># to allow bug.fields.bugId in the javascript
>self._current['bugId'] = obj.id
> 
># append the object to the array of objects to be serialized
>self.objects.append( self._current )
> 
># clear the bug currently being processed so we don't mix up
> data
>self._current = None
> 
> In JSON I'm looking for:
> 
> { "buglist" : [ { "id" : 2, "summary" : "my summary", "status" :
> "open" } ] }
> 
> versus
> 
> { "buglist" : [ { "pk" : 2, "model" : "my.models.Bug", "fields" :
> [ "summary" : "my summary", "status" : "open"] } ] }
> 
> 
> thanks for any guidance you can give. Perhaps there is a better way
> entirely to handle JSON in django I haven't run across yet.
> 
> -- redfive
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




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



django random template tag

2011-03-10 Thread Jonas Geiregat
Hello,

I've ran into a situation where I might need a random generator in my templates.
I'm aware that the default template tag set doesn't support any random 
generator.
Previous attempts in adding one to the default set where ignored because off 
out of scope issues with the standard set.

Anyway here's my case.

I've got some queryset which I want to display. Each item has 3 possible visual 
presentation modes or way's it's might be displayed.
I could simply append some random data in my views.py file to the result set. 

gigs = Gig.objects.filter(date__gt = date.today()).order_by('date')[:17]

for gig in gigs:
#append the random item to each result
   # This doesn't seem like a sensible solution and it I'm not even sure if 
it's even possible appending some data to a querset


Next I would check the random data in my template and act upon it.





My other idea is a random generator in my template tags.

something like

{% random %}
{{gig.data}}
{% or %}
{{gig.data}}
etc ...
{% endrandom %}

This behavior is mimicked after: 
http://code.djangoproject.com/attachment/ticket/919/random_tag.patch

Is this a sensible solution ? 

Or are there other better way's of solving random issues in the template layer ?

Regards,

Jonas.

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



Using markdown within admin interface

2011-02-23 Thread Jonas Geiregat
Hello,

I love markdown for writing content on websites. I use it almost all the time 
when I'm working with django.

The only issue I hate is that the default django admin interface gives you a 
standard textfield. 
There's nothing wrong with that but when you're pasting some code on let's say 
a blog you need to prepend each line of code with 4 spaces (or a tab).
You can imagine that if you have several lines of code this is frustrating. 

So my question is, how do you come around this issue or are there any decent 
editors that work well with markup ?

Regards,

Jonas.

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



Re: Accessing the HttpRequest object from a model

2011-02-15 Thread Jonas Geiregat
>> 
> 
> Two ways:
> 
> 1) Pass the form which is creating/modifying this object the current
> request. It can then use the request object in the save() method to
> populate the field. Eg:
> 
> class FooForm(forms.ModelForm):
>  def __init__(self, *args, **kwargs):
>self.request = kwargs.pop('request')
>super(FooForm, self).__init__(*args, **kwargs)
>  def save(commit=False):
>foo = super(FooForm, self).save(commit=False)
>if not foo.user:
>  foo.user = request.user
>if commit:
>  foo.save()
>return foo
> 
> Even better would be to not pass around an opaque object which has
> magic data in it - if you need the current user to correctly create
> objects, then pass the user to the form which creates the objects.
> 
> 2) At the start of each request, store the current request in thread
> local storage[1], so that it is globally available everywhere.
> 
> You may have noticed I can knock out the implementation to 1) from
> rote, this is because this is the correct way of doing it. It's
> harder, more work, and doesn't 'just work', but it means you haven't
> tied your models to only working within the context of a web request.
> For instance, if you went the thread local route, and you wanted to
> run a management command to import data, you would have to prep thread
> local storage with a dummy 'request' object, providing the 'current
> user' to your scripts.
> 


Thanks for your reply. But I found out about save_model().
>From there I have access to the HttpRequest object that contains my 
>contrib.auth.models.User model.

But that seemed to be half the story. 

class Post(models.Model):
def save_model(self, req, obj, form, change):
if self.author is None:
self.author = req.User

Doesn't seem to do the trick. I'm getting error reports telling me author_id 
can't be null.
And indeed if  I look in my mysql database I see a author_id column and no 
author column. Makes sence since author is of the type models.ForeignKey().

Anyway how do I get around this ?

Regards,

Jonas.



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



Accessing the HttpRequest object from a model

2011-02-15 Thread Jonas Geiregat
I have a model

from django.contrib.auth.models import User

class Post(models.Model):
with_some_properties = model.CharField(max_length=1)
author  = models.ForeignKey(User)

def clean(self):
if self.author is None:
self.author = 


When a post is saved I would like to bind the current logged in user the the 
self.author field in the clean method.
How could I accomplish this ?

Regards,

Jonas.

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



Re: Redirect with current data

2011-01-31 Thread Jonas Geiregat
Maybe this will help you: 
http://docs.djangoproject.com/en/dev/topics/http/shortcuts/


Op 31-jan-2011, om 06:36 heeft Antônio Ribeiro het volgende geschreven:

> Hello guys!
> 
> I've been wondering about this all night and i've already made a search on 
> google and everything, but I didn't get a straight answer.
> 
> Is there a way to make a redirect and send data from my current request to 
> the other page.
> 
> I mean, I could use the render_to_response to call another template and 
> render the content I want.
> But I just want to know if it's possible to redirect to other view with the 
> data coming from the current request.
> 
> I know it's odd, but this would send a 302 HTTP code to the User-Agent, I 
> think that would be the right way.
> 
> Sorry for my horrible english.
> It's been years since I wrote something that long in English.
> 
> Thanks in advance!
> 
> -- 
> Antonio Ribeiro
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




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



Re: example do not work, TypeError

2011-01-30 Thread Jonas Geiregat



> ... print form.as_table()   # ERROR  'WordFormFormSet' object is
> not iterable


Sounds like pretty obvious error to me.
You can't iterate over the WordFormFormSet object.

just write formsetw.as_table().




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



Re: Adding an App to the Admin

2011-01-28 Thread Jonas Geiregat
>> 
>> Are you logged in as a user with permission to change models in that app? It 
>> won't appear if not.

I once changed my admin.py file and after reloading nothing had changed.
What did solve this issue was restarting the server or hard refreshing the page 
(Shift + F5  or something like that, depending on the browser you're using)
But I'm guessing you've already done that.

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



Re: Adding an App to the Admin

2011-01-28 Thread Jonas Geiregat

Op 28-jan-2011, om 04:09 heeft Corey Richardson het volgende geschreven:

> I'm following the tutorial at [1]. I'm trying to add the app to the
> admin site. I've run manage.py syncdb, and I've restarted the dev
> server. Any hints? The appropriate files that I was instructed to modify
> can be seen at [2]. Request more information and I can provide it.
> 
> Thank you!
> ~Corey
> 
> [1] - http://docs.djangoproject.com/en/1.2/intro/tutorial02/
> [2] - http://bpaste.net/show/13260/
> 

Did you create a admin.py file in the application directory ?
Because the only thing I see is your settings.py file.


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



Re: Confusion about the new staticfiles contrib app

2011-01-26 Thread Jonas Geiregat
>> 
> 
> I don't understand this. One is a URL, the other is a file path. Why
> would I set STATIC_URL = MEDIA_ROOT? Or did you make a typo and mean
> MEDIA_URL? That might make more sense to me.



MEDIA_ROOT is the path to the directory where your files will live.


MEDIA_URL is the URL the get to those files.

So if MEDIA_ROOT='/home/you/media'
and MEDIA_URL='site-media/' 

Attention never use MEDIA_URL='media/' because that url is already used by the 
admin interface.

Then if you want to view a file located at /home/you/media/thisFile.jpg you 
enter http://yoursite.com/site-media/thisFile.jpg.

The same counts for STATIC_ROOT and STATIC_URL.

I hope everything is clear now. I'm aware the docs are pretty much useless on 
these subjects. But then again that's about the only thing you can say bad 
about django's documentation.

Sorry if I wasn't that obvious this morning but I didn't sleep well and I had 
little time. But I could feel your frustration since I had the same problem 
going on some day's ago.

Good luck!

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



Re: looking cheap Python/Django/mySQL hosting

2011-01-26 Thread Jonas Geiregat



> for small project.
> 

I use djangoeurope.com. They have server in Paris and Zurich.



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



Re: Confusion about the new staticfiles contrib app

2011-01-25 Thread Jonas Geiregat

Op 26-jan-2011, om 06:46 heeft Brian Neal het volgende geschreven:

> Hi -
> I'm trying to cut over my project to use the new staticfiles
> application. I'm using the dev server with DEBUG = True on a recent
> SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is
> 'http://localhost:8000/media/' in this environment.

STATIC_URL and MEDIA_URL are two different things.

if you want to serve static files that are related to your 
webdesign/development you should use STATIC.
User related files such as uploaded files such be placed inside the MEDIA path.

so change STATIC_URL into MEDIA_ROOT='static/'. I always use a fullpath when 
defining a MEDIA_ROOT or STATIC_ROOT.

> 
> My first confusion point:
> Maybe it was just me, but I got confused about serving my media
> (MEDIA_ROOT/MEDIA_URL) files with the dev server. After cutting over
> to staticfiles, my MEDIA_URL files started getting 404s. Eventually I
> came to the conclusion that I had do this:
> 
> urls.py:
> if settings.DEBUG:
>   urlpatterns += patterns('django.contrib.staticfiles.views',
>  (r'^media/(?P.*)$', 'serve', {'document_root':
> settings.MEDIA_ROOT}),
>   )

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



Re: Forbidden (403) CSRF verification failed. Request aborted.

2011-01-25 Thread Jonas Geiregat
Hey,

I've also struggled with CSRF for a while.
Maybe I can give you some guidance.

> you need to ensure:
> 
> •The view function uses RequestContext for the template, instead of
> Context.
> •In the template, there is a {% csrf_token %} template tag inside each
> POST form that targets an internal URL.
> •If you are not using CsrfViewMiddleware, then you must use
> csrf_protect on any views that use the csrf_token template tag, as
> well as those that accept the POST data.
> You're seeing the help section of this page because you have DEBUG =
> True in your Django settings file. Change that to False, and only the
> initial error message will be displayed.
> 

Have you checked each item mentioned by the error report ?
> 
> 

Add {% crsf_token %} directly after the opening form tag.

> 
>return render_to_response('polls/uploadfile.html', {'form':
> form})
> 

You must always a ContextRequest like this:

from django.template import RequestContext

return render_to_response('polls/uploadfile.html', {'form':form}, 
context_instance=RequestContext(your_request_var))

If you are still stuck I can advise you to read the following article: 
http://andrew.io/weblog/2010/01/django-piston-and-handling-csrf-tokens

Good luck!

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



Re: Django form(s) for intermediary models

2011-01-25 Thread Jonas Geiregat

> In that form, I'd
> like to see a checkbox for each Person (member) and a text field for
> 'date_joined'. Anyway to do this?

You can create forms from models. See this page for more information: 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

You can always override the default widgets.

In your case it would become something like:

class Membership(ModelForm):
class Meta:
model = Membership
fields = ('person', 'date_joined') 
widgets = {
'person' : CheckBox(),
'date_joined': TextInput(),
}



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



Re: copying sqlite database file between projects

2011-01-25 Thread Jonas Geiregat



> 've copied the database file, and the models.py file to the
> appropriate locations in the new project. 

Have you adjusted the settings.py database settings to the correct values ?
If so, maybe try the full path to your database file.

Regards,

Jonas.






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



Re: 'unique' field upon inserting

2011-01-25 Thread Jonas Geiregat
The id field (which is added by django by default has this) other then that the 
field doesn't have unique=True

I was also thinking of a better solution.

I have a Gig model which contains gigs with a ForeignKey to Artist.
I have a Artist model which contains artists.

One Gig can have multiple artists.

So instead of creating a field that is unique for each Gig (which might occur 
more then once since each gig might have more the  one artist) I was thinking 
of the following.

Create a model GigArtist (and leave the Artist Foreign key out of the Gig 
model).

This model contains two fields one who references to a specific gig and one 
that references to a (or more then one) specific artist.





Op 25-jan-2011, om 16:20 heeft Shawn Milochik het volgende geschreven:

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

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




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



'unique' field upon inserting

2011-01-25 Thread Jonas Geiregat
Hello, 

I have a model that has a field of the type BigIntegerField(). When inserting 
something into that field the value must not have been used before but upon 
inserting it's possible to insert the same value twice.
 Is there a way to do this using django ?

I could generate a random number check if it's already present etc .. but that 
seems like overhead.

Regards,

Jonas.

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



ModelForm changing default field for ForeingKey

2011-01-21 Thread Jonas Geiregat
Hello,

I'm creating a subset of a ModelForm.

class FavArtistForm(ModelForm):
class Meta:
model = FavArtist
fields = ('artist',)
widgets = { 
'artist': CharField(),
}   



The field artist is of the type ForeignKey which is by default represented by 
django as a select tag.
I'd rather have the user enter their own value, so I tried to change it to the 
CharField field. 
This doesn't work. 

I'm receiving the following error: AttributeError: 'CharField' object has no 
attribute 'is_hidden'


Is changing the default representation of a ForeignKey field not allowed in 
django or am I missing something ?


Regards,

Jonas.

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



Parse content

2010-12-24 Thread Jonas Geiregat
Hello,

I have some content that is stored as models.TextField().
Content is mainly text but there should be option to add additional parsing.
Such as a code block [code] which should be formatting in some way.

But where would you best place this code ? 
Inside the model view or are there options for implementing such behavior using 
the built-in template language ?

Regards,


Jonas Geiregat
jo...@geiregat.org




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



css templates

2010-12-06 Thread Jonas Geiregat
Hello,

I'm developing a application that has the ability to be viewed with two 
stylesheets.
There are some differences between the stylesheets. It's not only a different 
CSS file that is loaded but some pages also have different HTML output.
How could something like this be implemented within the django framework ?


Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Not main content on site - how to?

2010-11-21 Thread Jonas Geiregat
Inside your views.py file you define functions where you render the template 
and do your queries.

For example:


def last_post(req):
# Get some results out of your database
post = Post.objects.order_by('-pub_date')[0]
# render the results
return render_to_response('blog/last_post.html', {"post", post})

Now you need to edit your urls.py file and add something like:

(r'^blog/last_post/$', 'yoursite.blog.last_post.'),

Now if you visit http://yourhost.com/blog/last_post it should render the latest 
post. Of course you still need to define a template file (last_post.html) to 
make this work.

yoursite is the name of the django project and blog is a django application.

Good luck!


Op 21-nov-2010, om 12:54 heeft robos85 het volgende geschreven:

> I'm wondering how to make a sidebars on my site. Main content is not a
> problem - I use views to do that. What about the rest of site content?
> I want for example to have last comments, last posts, the most popular
> posts and the most rated. How to plan that. Which Django structures
> should I use?
> Additionally I want to have different sets of that content of
> different sub-sites.
> 
> Thanks for clue.
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




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



Generic relation overflows the maximum recursion depth

2010-11-19 Thread Jonas Geiregat
I'm trying to save a model and then insert it into a generic relation.
Having this models.py file:

from django.db import models
from datetime import datetime
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db.models.signals import post_save


STATUSCHOICE = (
('d', 'Working draft'),
('p', 'Publish!')
)


# Create your models here.

class Tag(models.Model):
name = models.CharField(max_length=20, unique=True)

def __unicode__(self):
return self.name


class PostBase(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
pub_date = models.DateTimeField()
tags = models.ManyToManyField(Tag, null=True)
status = models.CharField(max_length=1, choices=STATUSCHOICE)

def clean(self):
self.pub_date = datetime.now()

class Meta:
abstract = True

def __unicode__(self):
return self.title

class Post(PostBase):
pass

class Review(PostBase):
image = models.ImageField(upload_to="blog/upload")

class BlogContent(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')


class Comment(models.Model):
content = models.CharField(max_length=300)
pub_date = models.DateTimeField()
email = models.EmailField()
name = models.CharField(max_length=30)
post = models.ForeignKey(Post)

# Signals
def post_save_callback(sender, instance, **kwargs):
bc = BlogContent(content_object=instance)
bc.save()
post_save.connect(post_save_callback)



The problem occurs when creating a Post model and saving it:

p = Post(title="foobar", )
p.save()

I get the following error message: 
RuntimeError: maximum recursion depth exceeded

The problem should be located in the post_save_callback function.


Kind regards,


Jonas Geiregat
jo...@geiregat.org




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



Re: how to hide a field on

2010-11-18 Thread Jonas Geiregat
I've never seen Marcos's way of solving this. But I do it this way:

First hide the field:

class PostAdmin(admin.ModelAdmin):
exclude=('registered_date')
   

admin.register(Post, PostAdmin)

And let a default value be filled in, in your models.py file:

class Post(models.Model):
title = models.CharField(max_legth=100)
desc = models.TextField()
registered_date = models.DateTimeField()

def clean(self):
self.registered_date = datetime.datetime.now()


Op 18-nov-2010, om 21:11 heeft Anderson Goulart het volgende geschreven:

> Hi,
> 
> Imagine that I have a simple model like this:
> 
> import datetime
> 
> class Post(models.Model):
>   title = models.CharField(max_legth=100)
>   desc = models.TextField()
>   registered_date = models.DateTimeField(default=datetime.datetime.now)
> 
> Now I  want to use admin interface to fill those fields with an exception: 
> registered_date should be a hidden field filled with the default value. How 
> to set this option?
> 
> 
> thanks, global
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Using foreignkey data as a primary key

2010-11-18 Thread Jonas Geiregat
I myself am far from a django expert.
But I think you should be using a ForeignKey Field. Because one Tag can be 
bound to more then one CurrentTag object, not ?


Op 18-nov-2010, om 15:04 heeft JE het volgende geschreven:

> class CurrentTag(models.Model):
>tag = models.OneToOneField(Tag)
> 
>def __unicode__(self):
>return self.tag
> 
> 
> Should I be using OneToOne field or ForeignKey or neither and some
> other mechanism?

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Generic relations

2010-11-18 Thread Jonas Geiregat
That was it!
After running:
./manage.py sqlclear foo | ./manage.py dbshell && ./manage.py syncdb

it works!

So something in my db was inconsistent!

Thanks!

Op 18-nov-2010, om 09:57 heeft Marc Aymerich het volgende geschreven:

> On Thu, Nov 18, 2010 at 12:00 AM, Jonas Geiregat <jo...@geiregat.org> wrote:
>> 
>> Op 17-nov-2010, om 23:46 heeft Marc Aymerich het volgende geschreven:
>> 
>>>>>> GenericPost.objects.get(pk=1).content_object.content
>> 
>> 
>> That's the strange thing. It just doesn't work:
>> 
>> Some code:
>> 
>> 
>> In [3]: GenericPost.objects.get(pk=1).content_object
>> 
>> In [4]: GenericPost.objects.get(pk=1).content_object.content
>> ---
>> AttributeErrorTraceback (most recent call last)
>> 
>> /Users/Jonas/Webdesign/genericv/ in ()
>> 
>> AttributeError: 'NoneType' object has no attribute 'content'
>> 
> 
> 
> Yep, that is very strange!. I promise that I've try exactly the same
> code that you post here and it works well with my django installation.
> I use the devel version with python 2.6.6 and mysql backend.
> 
> Try to drop your database and create a new one. Maybe you have some
> kind of inconsistency there.
> 
> -- 
> Marc
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Generic relations

2010-11-17 Thread Jonas Geiregat

Op 17-nov-2010, om 23:46 heeft Marc Aymerich het volgende geschreven:

>>>> GenericPost.objects.get(pk=1).content_object.content


That's the strange thing. It just doesn't work:

Some code:


In [3]: GenericPost.objects.get(pk=1).content_object

In [4]: GenericPost.objects.get(pk=1).content_object.content
---
AttributeErrorTraceback (most recent call last)

/Users/Jonas/Webdesign/genericv/ in ()

AttributeError: 'NoneType' object has no attribute 'content'





Jonas Geiregat
jo...@geiregat.org




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



Generic relations

2010-11-17 Thread Jonas Geiregat
Hello,

 Can I use django's generic relations to create a model (GenericPost) that can 
point to other model (APost) or model (ReviewPost) ?
 And then use this GenericPost model to get a list of all latest APost's and 
ReviewPost's ?

I've been trying this all day long but I couldn't get around the API.

Here's what I've done:

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic


# Create your models here.

class Post(models.Model):
title = models.CharField(max_length=100)

class Meta:
abstract = True

class APost(Post):
content = models.CharField(max_length=100)

class Review(Post):
rcontent = models.CharField(max_length=100)

class GenericPost(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')


Some shell code trying to build up some data:

In [1]: from genericv.foo.models import APost, GenericPost, Review

In [2]: a = APost(content="something")

In [3]: a.save()

In [4]: g = GenericPost(content_object=a)

In [5]: g.save()

In [6]: GenericPost.objects.all()
Out[6]: [, , 
, ]



Why is it that I have 4 objects already when I only have created one ? And how 
do I access that particular object by using the GenericPost model ?



Regards,

Jonas Geiregat
jo...@geiregat.org




-- 
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-1.2.1 on ubuntu

2010-10-03 Thread Jonas Geiregat
Hello

I've been currently developing a django application on my Mac which runs 1.2.1.
Now I've setup a  ubuntu server which I like to move my project to.
Ubuntu installs django-1.1 by default. 
My current setup on ubuntu uses apache and mod_wsgi with django version 1.1.
I wish to move to version 1.2.1 on the ubuntu box.


Can I manually install version 1.2.1 without updating apache2 or mod_wsgi ?
Or are there any ubuntu .deb packages available ?

Kind regards,

Jonas Geiregata
jo...@geiregat.org




-- 
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: {% csrf_token %} template tag not outputting the hidden field

2010-09-01 Thread Jonas Geiregat
I had the same problem some day's ago.
Did you add the context_instance parameter in the render_to_reponse function 
call. It's needed for CSRF to work.

For example: return render_to_response('blog/index.html', {'posts': posts}, 
context_instance=RequestContext(req))

Regards,

Jonas.
Op 30-aug-2010, om 20:46 heeft Erik het volgende geschreven:

> Hi Django Users-
> I'm having trouble with the {% csrf_token %} tag.
> On my site I have a regular login view / page / url, which uses
> the django contrib registration app.  I include the CSRF token in my
> login template and it works fine.
> I'd also like a little login box in the corner of every page,
> which will either show a login form or a "you're logged in!" message
> depending on whether the user is logged in.  So, I wrote a little form
> into my base.html template that other templates inherit from; and I
> stuck the {% csrf_token %} tag in there as well.
> The part I don't understand is, if I load the login url in the
> browser ( mysite.com/login/ ) both forms work, I can login with them,
> and when I view the source the CSRF token tag has put a hidden field
> into my form.
> However, when I'm on any other page - for example the front page
> - the token tag just leaves a blank space and doesn't output anything,
> but it doesn't give me an error message on loading the page - as it
> would when I try to use a token tag that doesn't exist - such as {%
> faketokentag  %}.  Of course, because the csrf token tag doesn't
> create any output (in the HTML source generated) when the form is
> submitted the CSRF error occurs.
> I'm rendering all such pages with the generic view
> direct_to_template , which, because it's a generic view, the
> documentation suggests should just work with CSRF.
> Does anyone have any suggestions?
> 
> Thank you,
> Erik
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Query overhead or not ?

2010-09-01 Thread Jonas Geiregat
Tag.objects.values('name').annotate(times_used=Count('post__tags'))

That's the solution!

Op 1-sep-2010, om 15:00 heeft Jonas Geiregat het volgende geschreven:

> I look at aggregation and annotation but I don't think It's possible to solve 
> this by using any of those two systems. 
> Or am I overlooking something ?
> 
> 
> Op 31-aug-2010, om 13:09 heeft Jonas Geiregat het volgende geschreven:
> 
>> Thanks for your advise. I'm short of time right now so I briefly looked at 
>> django's aggregation possibilities.
>> I'll look into them more deeply tonight.
>> 
>> But I stumbled upon a problem.
>> 
>> Post.objects.values('tags')
>> 
>> Gives me:
>> 
>> FieldError: Invalid field name: 'tags'
>> 
>> In [56]: Post.tags
>> Post.tags  
>> 
>> In [56]: Post.tags
>> Out[56]: 
>> > at 0x78f9f0>
>> 
>> Post.tags does exist. Maybe it's because it's a ManyToManyField ? So I tried 
>> Post.objects.values('tags__name'). Still got an error ?
>> 
>> I'm wondering why ?
>> 
>> Op 31-aug-2010, om 09:28 heeft Jirka Vejrazka het volgende geschreven:
>> 
>>>> tags = Tag.objects.all()
>>>> 
>>>> for t in tags:
>>>>  indexed_tags[t] = Post.objects.filter(tags__name=t).count()
>>>> 
>>>> Next I would sort indexed_tags and I have a dictionary of which tags are 
>>>> used the most.
>>>> 
>>>> I'm wondering if this is a good idea ? Since if I have 1000 tags this 
>>>> would require 1000 queries just for one simple tag cloud.
>>>> Is there a better way of solving this without adding an extra count field 
>>>> to the Tag model.
>>> 
>>> Hi Jonas,
>>> 
>>> your gut feeling was correct - it's not a very good idea, although
>>> it might work for a small site. You might want to take a look at
>>> database aggregation in Django:
>>> http://docs.djangoproject.com/en/1.2/topics/db/aggregation/
>>> 
>>> Cheers
>>> 
>>>   Jirka
>>> 
>>> -- 
>>> 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.
>>> 
>> 
>> Met vriendelijke groeten,
>> 
>> Jonas Geiregat
>> jo...@geiregat.org
>> 
>> 
>> 
>> 
>> -- 
>> 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.
>> 
> 
> Met vriendelijke groeten,
> 
> Jonas Geiregat
> jo...@geiregat.org
> 
> 
> 
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: fetching values from model

2010-09-01 Thread Jonas Geiregat
I suggest you read the djangobook or some of the django documentation because 
this is very well documented.

Good luck with that!

Op 1-sep-2010, om 15:13 heeft Pradnya het volgende geschreven:

> ok. Is there any way I can load the model inside HTML template? What
> is {% load  %} tag all about?
> 
> On Sep 1, 6:02 pm, Jonas Geiregat <jo...@geiregat.org> wrote:
>> You don't write Python code inside your template file. That's one of the 
>> basic django template rules.
>> You can pass values from your views to your template and show them there.
>> Or generate the HTML in your view and show it from there, which isn't 
>> something I could advise if you're creating a larger application.
>> 
>> Op 1-sep-2010, om 14:53 heeft Pradnya het volgende geschreven:
>> 
>> 
>> 
>>> Hello,
>> 
>>> Is it possible to fetch a particular record from model using
>>> school.object.get(id = 1) inside html template.
>> 
>>> Please suggest.
>> 
>>> Thanks
>>> Pradnya
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=en.
>> 
>> Met vriendelijke groeten,
>> 
>> Jonas Geiregat
>> jo...@geiregat.org
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: fetching values from model

2010-09-01 Thread Jonas Geiregat

You don't write Python code inside your template file. That's one of the basic 
django template rules.
You can pass values from your views to your template and show them there.
Or generate the HTML in your view and show it from there, which isn't something 
I could advise if you're creating a larger application.



Op 1-sep-2010, om 14:53 heeft Pradnya het volgende geschreven:

> Hello,
> 
> Is it possible to fetch a particular record from model using
> school.object.get(id = 1) inside html template.
> 
> Please suggest.
> 
> Thanks
> Pradnya
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Query overhead or not ?

2010-09-01 Thread Jonas Geiregat
I look at aggregation and annotation but I don't think It's possible to solve 
this by using any of those two systems. 
Or am I overlooking something ?


Op 31-aug-2010, om 13:09 heeft Jonas Geiregat het volgende geschreven:

> Thanks for your advise. I'm short of time right now so I briefly looked at 
> django's aggregation possibilities.
> I'll look into them more deeply tonight.
> 
> But I stumbled upon a problem.
> 
> Post.objects.values('tags')
> 
> Gives me:
> 
> FieldError: Invalid field name: 'tags'
> 
> In [56]: Post.tags
> Post.tags  
> 
> In [56]: Post.tags
> Out[56]:  object at 0x78f9f0>
> 
> Post.tags does exist. Maybe it's because it's a ManyToManyField ? So I tried 
> Post.objects.values('tags__name'). Still got an error ?
> 
> I'm wondering why ?
> 
> Op 31-aug-2010, om 09:28 heeft Jirka Vejrazka het volgende geschreven:
> 
>>> tags = Tag.objects.all()
>>> 
>>> for t in tags:
>>>   indexed_tags[t] = Post.objects.filter(tags__name=t).count()
>>> 
>>> Next I would sort indexed_tags and I have a dictionary of which tags are 
>>> used the most.
>>> 
>>> I'm wondering if this is a good idea ? Since if I have 1000 tags this would 
>>> require 1000 queries just for one simple tag cloud.
>>> Is there a better way of solving this without adding an extra count field 
>>> to the Tag model.
>> 
>> Hi Jonas,
>> 
>> your gut feeling was correct - it's not a very good idea, although
>> it might work for a small site. You might want to take a look at
>> database aggregation in Django:
>> http://docs.djangoproject.com/en/1.2/topics/db/aggregation/
>> 
>>  Cheers
>> 
>>Jirka
>> 
>> -- 
>> 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.
>> 
> 
> Met vriendelijke groeten,
> 
> Jonas Geiregat
> jo...@geiregat.org
> 
> 
> 
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




-- 
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: Query overhead or not ?

2010-08-31 Thread Jonas Geiregat
Thanks for your advise. I'm short of time right now so I briefly looked at 
django's aggregation possibilities.
I'll look into them more deeply tonight.

But I stumbled upon a problem.

Post.objects.values('tags')

Gives me:

FieldError: Invalid field name: 'tags'

In [56]: Post.tags
Post.tags  

In [56]: Post.tags
Out[56]: 

Post.tags does exist. Maybe it's because it's a ManyToManyField ? So I tried 
Post.objects.values('tags__name'). Still got an error ?

I'm wondering why ?

Op 31-aug-2010, om 09:28 heeft Jirka Vejrazka het volgende geschreven:

>> tags = Tag.objects.all()
>> 
>> for t in tags:
>>indexed_tags[t] = Post.objects.filter(tags__name=t).count()
>> 
>> Next I would sort indexed_tags and I have a dictionary of which tags are 
>> used the most.
>> 
>> I'm wondering if this is a good idea ? Since if I have 1000 tags this would 
>> require 1000 queries just for one simple tag cloud.
>> Is there a better way of solving this without adding an extra count field to 
>> the Tag model.
> 
>  Hi Jonas,
> 
>  your gut feeling was correct - it's not a very good idea, although
> it might work for a small site. You might want to take a look at
> database aggregation in Django:
> http://docs.djangoproject.com/en/1.2/topics/db/aggregation/
> 
>   Cheers
> 
> Jirka
> 
> -- 
> 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.
> 

Met vriendelijke groeten,

Jonas Geiregat
jo...@geiregat.org




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



Query overhead or not ?

2010-08-31 Thread Jonas Geiregat
First of all I know of the django-taggit application. But I'm new to django and 
I thought this would be a good way of getting to know this great framework a 
little bit better.
That lined out, I have a Post and a Tag model. Each Tag.name property of the 
tag model is unique.

I'm trying to figure out which Tags are used most.

I do this by the following code:

from homepage.models.blog import Post, Tag

indexed_tags = {}

tags = Tag.objects.all()

for t in tags:
indexed_tags[t] = Post.objects.filter(tags__name=t).count()

Next I would sort indexed_tags and I have a dictionary of which tags are used 
the most.

I'm wondering if this is a good idea ? Since if I have 1000 tags this would 
require 1000 queries just for one simple tag cloud.
Is there a better way of solving this without adding an extra count field to 
the Tag model.




Regards,

Jonas Geiregat
jo...@geiregat.org




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



CSRF token is missing

2010-08-25 Thread Jonas Geiregat
I'm using django-1.2.1 on Mac OS X.

I'm trying out the comments framework that comes with django by default.

I'm able to   {% load comments %} and   {% render_comment_list for post %}  and 
   {% render_comment_form for post %} .
But when I try to post a message I get a 403 error:

""" 
CSRF verification failed. Request aborted.

Help

Reason given for failure:

CSRF token missing or incorrect.

"""

I know that after the form tag there should be a csrf token template tag. Or at 
least it should be generated and visible inside the HTML code. Which is not 
there.
So I looked where django lived by running: import django; django.__file__. 
Looked in the contrib/comments/templates/comments/form.html file. 
Inside that file the I'm seeing "  {% csrf_token %}"

So my question is; Why isn't the csrf_token generated ?

Kind regards,

Jonas Geiregat
jo...@geiregat.org




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