Re: Newbie django/python with C++ background wants enums

2012-02-02 Thread bruno desthuilliers
On Feb 1, 10:45 pm, NENAD CIKIC  wrote:
> Hello, the subject expresses my discomfort with certain python
> characteristics, given my background, and my lack of python knowledge.
> Specifically lets say that I have a model with a Text field and char field.
> The char field is length 1 and says "use or do not use the text field".

A BooleanField might be better then.

> The
> char field can have Y or N values.
> So using the admin interface I wanted to override the clean method but I
> did not want to write
> if text.__len__==0 and char=='Y':
>   raise exception

"__magic_methods__" are here to support operators (or operator-like)
implementation, and except for a very few corner cases you should not
call them directly. So here you want "len(text)", not
"text.__len__()".

Also note that the parens are the "call operator", so "text.__len__"
will eval to the "__len__" method object itself (remember that in
Python everythin is an object, including classes, functions and
methods), not to the result of calling this method.

And finally, in Python, empty sequences (at least for the builtin
sequence types), empty dicts, empty strings, numeric zero (int, float
etc) and the None object all have a false value in a boolean context
(FWIW, True and False and the bool type are late additions to the
language). So the pythonic way to test for an empty string is just :

if not txt:
print "txt is empty"

> In C/C++ you would use enum for these sort of things. So I ended with
> defining in models.py something as:
> TO_USE= (
>     ('Y', 'Yes'),
>     ('N', 'No'),
>     )
>
> class X(models.Model):
>     txt= models.CharField(db_index=True,null=True, blank=True,max_length=30)
>     use_txt=
> models.CharField(blank=False,max_length=1,default='D',choices=TO_USE)

I'd still use a BooleanField here as far as I'm concerned, but when it
comes to multiple choices, here's how I do:


class X(models.Model):
USE_YES = 'Y'
USE_NO = 'N'
USE_CHOICES = (
(USE_YES, u"Yes"),
(USE_NO, u"No"),
)

   use_txt = models.CharField(
   u"Use text",
   max_length=1,
   choices=USE_CHOICES,
   default=""
   )


then I can test the value using the class pseudo-constants, ie:


x = X.objects.get(pk=1)
if x.use_txt == x.USE_YES:
   pass

> and in admin.py something as
> class XForm(forms.ModelForm):
>     def clean(self):
>         cleaned_data=super(XForm, self).clean()
>         txt= cleaned_data['txt'].strip()
>         use_txt=cleaned_data['use_txt'].strip()
>
>         if txt.__len__()==0 and use_txt==TO_USE.__getitem__(0)[0]:

would be a bit better (or at least a bit less worse ) this way:

if not txt and use_txt == TO_USE[0][0]:

But that's still not something I'd be happy with. My above solution
would make it a bit more readable:

if use_txt == X.USE_YES and not txt:


>             raise forms.ValidationError('This is needed!')
>
>         return cleaned_data
>
> The part .__getitem__(0)[0] is not very readable.

Indeed. And not even consistant - if you insist on using
__magic_methods__ instead of the operators, at least go all the way:

TO_USE.__getitem__(0).__getitem__(0)

?-)

Sorry, just kidding 


-- 
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: template error in html forms

2012-02-02 Thread TANYA
  os.path.join(PROJECT_PATH, 'templates'), solved the error but the old
error with search is still there.

On Wed, Feb 1, 2012 at 3:00 PM, yati sagade  wrote:

> I've never run in to a TemplateError for anything other than what I
> pointed out - maybe in the settings module it is ".../templates" and the
> name of the directory is "template" (note the 's' in the end) or the other
> way round. Anyway, check for any misspelling in the template name itself -
> or whether the template 'search_results.html' is directly under the
> template directory and not under any subdirectory therein.
>
> If you could post the entire debug info (Also the one at the far bottom of
> the error page), it might be helpful for us.
>
>
> On Wed, Feb 1, 2012 at 8:22 PM, TANYA  wrote:
>
>> yes, the path is already there. Maybe the problem is either in views.py
>> or url.py file if changed it gives different error, but i dont know what to
>> look for in those two files.
>>
>>
>> On Wed, Feb 1, 2012 at 2:40 PM, yati sagade wrote:
>>
>>> in settings.py, in the TEMPLATE_DIRS setting, add the absolute path to
>>> your templates directory - something like "/path/to/project/dir/template".
>>> This MUST be an absolute path. And if your modifying this setting for the
>>> first time, be sure to leave a comma (,) in the end of that path (Sorry if
>>> you knew that already :))
>>>
>>>
>>> On Wed, Feb 1, 2012 at 7:59 PM, TANYA  wrote:
>>>
 the installed apps has 'mysite.books', in the path and the html
 files are in a directory under mysite project directory. Is that correct?



 On Wed, Feb 1, 2012 at 12:06 PM, Ankit Rai wrote:

> Please check your template path in settings.py.
>
>
>
>
> On Wed, Feb 1, 2012 at 5:29 PM, TANYA  wrote:
>
>> In views.py, when I add this code gives template error.
>>
>> def search(request):
>> error = False
>> if 'q' in request.GET:
>> q = request.GET['q']
>> if not q:
>> error = True
>> else:
>> books = Book.objects.filter(title__icontains=q)
>> return render_to_response('search_results.html',
>> {'books': books, 'query': q})
>> return render_to_response('search_form.html',
>> {'error': error})
>>
>> I have created search_form.html and search.html and put it in
>> "template" directory but get this error ,
>>
>> TemplateDoesNotExist at /search/
>>
>> search_form.html
>>
>>  Request Method: GET  Request URL: http://127.0.0.1:8000/search/  Django
>> Version: 1.3.1  Exception Type: TemplateDoesNotExist  Exception
>> Value:
>>
>> search_form.html
>>
>>  Exception Location: 
>> /usr/local/lib/python2.6/dist-packages/django/template/loader.py
>> in find_template, line 138  Python Executable: /usr/bin/python
>> --
>> TANYA
>>
>> --
>> 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.
>>
>
>
>
> --
>
> *Ankit Rai*
>
> *
> *
>
> --
> 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.
>



 --
 TANYA

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

>>>
>>>
>>>
>>> --
>>> Yati Sagade 
>>>
>>> (@yati_itay )
>>>
>>>
>>>  --
>>> 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.
>>>
>>
>>
>>
>> --
>> TANYA
>>
>> --
>> 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

Re: template error in html forms

2012-02-02 Thread TANYA
thanks, the template error went away but adding this code to  views.py
still gives  search error.

def search(request):
error = False
if 'q' in request.GET:
q = request.GET['q']
if not q:
error = True
else:
books = Book.objects.filter(title__icontains=q)
return render_to_response('search_results.html',
{'books': books, 'query': q})
return render_to_response('search_form.html',
{'error': error})

Which views.py should i add that code to? -- mysite/views.py OR
mysite/books/views.py ??
Should every folder in mysite have the path set? I mean to ask if I should
have "os.path.join(PROJECT_PATH, 'models')," for databse folder and
"os.path.join(PROJECT_PATH, 'picture')," for my jpg images and "
os.path.join(PROJECT_PATH, 'test'), for the test files and
os.path.join(PROJECT_PATH, 'documentation'), for documentation. Maybe this
is a silly question but its not very clear what to do for the path. thanks.





On Wed, Feb 1, 2012 at 5:51 PM, Joel Goldstick wrote:

>
>
> On Wed, Feb 1, 2012 at 10:00 AM, yati sagade wrote:
>
>> I've never run in to a TemplateError for anything other than what I
>> pointed out - maybe in the settings module it is ".../templates" and the
>> name of the directory is "template" (note the 's' in the end) or the other
>> way round. Anyway, check for any misspelling in the template name itself -
>> or whether the template 'search_results.html' is directly under the
>> template directory and not under any subdirectory therein.
>>
>> If you could post the entire debug info (Also the one at the far bottom
>> of the error page), it might be helpful for us.
>>
>>
>> On Wed, Feb 1, 2012 at 8:22 PM, TANYA  wrote:
>>
>>> yes, the path is already there. Maybe the problem is either in views.py
>>> or url.py file if changed it gives different error, but i dont know what to
>>> look for in those two files.
>>>
>>>
>>> On Wed, Feb 1, 2012 at 2:40 PM, yati sagade wrote:
>>>
 in settings.py, in the TEMPLATE_DIRS setting, add the absolute path to
 your templates directory - something like "/path/to/project/dir/template".
 This MUST be an absolute path. And if your modifying this setting for the
 first time, be sure to leave a comma (,) in the end of that path (Sorry if
 you knew that already :))


 On Wed, Feb 1, 2012 at 7:59 PM, TANYA  wrote:

> the installed apps has 'mysite.books', in the path and the html
> files are in a directory under mysite project directory. Is that correct?
>
>
>
> On Wed, Feb 1, 2012 at 12:06 PM, Ankit Rai wrote:
>
>> Please check your template path in settings.py.
>>
>>
>>
>>
>> On Wed, Feb 1, 2012 at 5:29 PM, TANYA  wrote:
>>
>>> In views.py, when I add this code gives template error.
>>>
>>> def search(request):
>>> error = False
>>> if 'q' in request.GET:
>>> q = request.GET['q']
>>> if not q:
>>> error = True
>>> else:
>>> books = Book.objects.filter(title__icontains=q)
>>> return render_to_response('search_results.html',
>>> {'books': books, 'query': q})
>>> return render_to_response('search_form.html',
>>> {'error': error})
>>>
>>> I have created search_form.html and search.html and put it in
>>> "template" directory but get this error ,
>>>
>>> TemplateDoesNotExist at /search/
>>>
>>> search_form.html
>>>
>>>  Request Method: GET  Request URL: http://127.0.0.1:8000/search/  Django
>>> Version: 1.3.1  Exception Type: TemplateDoesNotExist  Exception
>>> Value:
>>>
>>> search_form.html
>>>
>>>  Exception Location: 
>>> /usr/local/lib/python2.6/dist-packages/django/template/loader.py
>>> in find_template, line 138  Python Executable: /usr/bin/python
>>> --
>>> TANYA
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>>
>> *Ankit Rai*
>>
>> *
>> *
>>
>> --
>> 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.
>>
>
>
>
> --
> TANYA
>
> --
> You received this message because you 

Re: Help Me With omab/django-socialauth

2012-02-02 Thread coded kid
I'm getting a redirect loop error. Whats the probs?

On Feb 1, 1:22 pm, Thorsten Sanders  wrote:
> Some sort of error traceback/description would be helpful, from a quick
> look it seems all right.
>
> On 01.02.2012 13:23, coded kid wrote:
>
>
>
> > Hey guys, I'm facing a huge  problem with omab/django/socialauth.
>
> > After setting all the necessary settings, I clicked on the Enter
> > using Twitter link on my homepage, it couldn t redirect me to where I
> > will enter my twitter username and password. Below are my settings.
> > In settings.py
>
> > INSTALLED_APPS = (
> > 'social_auth',
> > }
>
> > TEMPLATE_CONTEXT_PROCESSORS = (
> >     "django.core.context_processors.auth",
> >     "django.core.context_processors.debug",
> >     "django.core.context_processors.i18n",
> >     "django.core.context_processors.media",
> >     "django.core.context_processors.static",
> >    "django.contrib.messages.context_processors.messages",
> >    "django.core.context_processors.request",
> >     social_auth.context_processors.social_auth_by_type_backends ,
>
> > )
> > AUTHENTICATION_BACKENDS = (
> >     'social_auth.backends.twitter.TwitterBackend',
> >    'django.contrib.auth.backends.ModelBackend',
> > )
>
> > SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter')
>
> > TWITTER_CONSUMER_KEY         = '0hdgdhsnmzHDGDK'
> > TWITTER_CONSUMER_SECRET      = 'YyNngsgw[1jw lcllcleleedfejewjuw'
>
> > LOGIN_URL = '/accounts/login/' #login form for users to log in with
> > their username and password!
> > SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/homi/'  #page after user get
> > authenticated
> > SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/homi/'   '  #page after
> > user get authenticated
> > SOCIAL_AUTH_ERROR_KEY='social_errors'
>
> > SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete'
> > SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
>
> > from django.template.defaultfilters import slugify
> > SOCIAL_AUTH_USERNAME_FIXER = lambda u: slugify(u)
> > SOCIAL_AUTH_UUID_LENGTH = 16
> > SOCIAL_AUTH_EXTRA_DATA = False
>
> > In urls.py
> > url(r'', include('social_auth.urls')),
>
> > In my template:
> > 
> >   Enter using Twitter > a>
> >   
> > 
> > What do you think I m doing wrong? Hope to hear from you soon. Thanks
> > so much!
> > N:B : I m coding on windows machine. And in the development
> > environment using localhost:8000.

-- 
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: Newbie django/python with C++ background wants enums

2012-02-02 Thread Pavlo Kapyshin
https://github.com/daevaorn/turbion/blob/master/turbion/bits/utils/enum.py

-- 
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: ANN: Releasing Django Media Tree, a media file management application for the Django admin

2012-02-02 Thread Gabriel - Iulian Dumbrava
Hi Samuel,
thanks for the update.

Is there an easy way to use it within TinyMCE? I have used filebrowser
in the past, but I would like to use yours instead.

Thanks!
Gabriel

On 28 ian., 07:03, Samuel Luescher  wrote:
> Hi,
>
> I just pushed a massive update todjango-media-treethat may interest you.
>
> It now contains generic view classes, and the CMS plugins are actually
> based on those. So creating FeinCMS plugins should now be quite easy.
>
> It's all documented, these pages are relevant:
>
> http://readthedocs.org/docs/django-media-tree/en/latest/custom_plugin...http://readthedocs.org/docs/django-media-tree/en/latest/bundled_plugi...http://readthedocs.org/docs/django-media-tree/en/latest/views.html
>
> Sam
>
> On 20 January 2012 15:34, Samuel Luescher  wrote:
>
>
>
>
>
>
>
> > I'm not planning to create Fein CMS plugins myself, but I'm very much hoping
> > the community will take a stab at this.
> > Actually, now that I think of it, the actual output generated by the CMS
> > plugins should be abstracted from the CMS and moved to the
> > media_tree.contrib.widgets package so that people can easily build on them.
>
> > --
> > 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/-/FMW6EnGQe4IJ.
>
> > 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.



Startup seeks Python dev for large scale scraping / data mining

2012-02-02 Thread Cal Leeming [Simplicity Media Ltd]
Hi all,

If anyone is interested in the below spec, please feel free to contact me
on cal.leem...@insurancezebra.com

Cheers

Cal



InsuranceZebra, an Innovation Works, Inc. AlphaLab company seeks a Python
developer to join its exciting entrepreneurial team - on a remote working
basis with immediate start and flexible hourly rate depending on exp.

You'll be working directly with the CTO and our existing team of two
developers.

The role will primarily be scraping / data mining via a non standardized
format (no API currently exists), and our scraping model (using css
selectors and regex/string matches) must be used to extract information
from a HTML.

You will need to have an broad understanding in this area (proficiency in
firebug, burpproxy, tcpdump, wireshark, curl etc) and be able to work to
tight deadlines without much hand holding.

Our code base has already been started, much of the groundwork has already
been done, and the code and architecture itself has been put together
beautifully.

Looking to start interviews today, with same day decision (we don't mess
around!) :-)

Any questions, please feel free to contact me directly on
cal.leem...@insurancezebra.com .

MUST MEET THE FOLLOWING REQUIREMENTS:

* Work on either EST or GMT time zone.
* Proficient in both written/spoken English.
* Be able to commit AT LEAST 37.5 hours/week.
* Be available for AT LEAST 6 weeks.
* Start by 6th Feburary 2012 at the /very/ latest.


HERE IS THE HIRING PROCESS:

* First stage 15 minute phone interview with CTO (with same hour decision)
* Second stage 15 minute phone interview with CEO (with same hour decision)
* Sign NDAs
* 2 hour introduction to show you existing code
* If both sides are happy, work contract will be signed same day.


HERE ARE THE TECHNOLOGIES WE USE:

NGINX - Web server
uWSGI- Web application server
Supervisord - Process management
Django 1.3  - Frontend web framework
Celery- Job scheduling framework
RabbitMQ   - Messaging system used for Celery
PYQuery - HTML inspect/extraction framework (JQuery for
Python)
Debian   - OS used for our unmanaged servers
Redhat   - OS used for our managed servers
Eventlet  - Concurrency framework for Python
Requests- HTTP requests
Git / Github - Code repository
JQuery   - JS Framework
MySQL   - Database
JIRA  - Project management
New Relic  - Web application and server monitoring

If you'd like to know more about the company, you can check out the
following links:

http://uk.linkedin.com/pub/cal-leeming/5/391/380
http://www.linkedin.com/pub/adam-lyons/11/904/85a
http://www.linkedin.com/company/2456950
https://www.facebook.com/insurancezebra
http://www.alphalab.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.



ImportError at /accounts/login/

2012-02-02 Thread Miten
Hi,

I am trying simple generic view + auth and get exception as below.
The dpaste shows traceback.  Please guide what am I missing.  From
manage shell I am able to import login view fine but when I runserver
and try to go to url it gives the error.  Let me know if need more
info.

http://dpaste.com/696518/


ImportError at /accounts/login/

No module named login

Request Method: GET
Request URL:http://127.0.0.1:8000/accounts/login/?next=/event/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:

No module named login

Exception Location: i:\learn\python\Django-1.3.1\django\utils
\importlib.py in import_module, line 35
Python Executable:  \\ms\dist\python\PROJ\core\2.5.4\bin\python.EXE
Python Version: 2.5.4
Python Path:

['I:\\learn\\python\\event',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5\\lib-
dynload',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib',
 'i:\\learn\\python\\Django-1.3.1',
 'I:\\learn\\python\\event',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin\\python25.zip',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\DLLs',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\plat-win',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\lib-tk',
 'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5',
 'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-tk',
 'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\site-
packages',
 'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-
dynload',
 'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin',
 'ms\\dist\\python\\PROJ\\core\\2.5.4',
 '//ms/dist/python/PROJ/msversion/1.0/lib',
 '//ms/dist/python/PROJ/ms.version/prod-2.5/lib']

Server time:Thu, 2 Feb 2012 15:58:44 +0530


Regards,

Miten.

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



create users from /etc/passwd?

2012-02-02 Thread Tim
I'm running Django 1.3.1 on FreeBSD + Apache2.2 inside an intranet. 

I do not grok authentication, so here is my problem and a question about 
how I can solve it (maybe).
What I need is the name of the user who hits the application. I don't care 
about the password, I just need to know who they are. I've been unable to 
get the REMOTE_USER from Apache, mainly because I think Apache doesn't know 
it either (no authentication is used on the httpd.conf).

I thought (here's my maybe solution) I might create a bunch of users in 
Django by parsing the /etc/passwd database. Then at least each user would 
have the same username/password they use to login to the network.

Is that possible? Is there a better way to get the username?
thanks,
--Tim

-- 
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/-/qO-mxTOE0joJ.
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: ImportError at /accounts/login/

2012-02-02 Thread akaariai
I don't think we are able to help you without more detail. The browser
window should contain the lines which caused the error (when run with
settings.DEBUG=True). Include those lines, and it is more likely that
you get an answer. Including full stack trace of the ImportError is
even better.

 - Anssi

On Feb 2, 12:41 pm, Miten  wrote:
> Hi,
>
> I am trying simple generic view + auth and get exception as below.
> The dpaste shows traceback.  Please guide what am I missing.  From
> manage shell I am able to import login view fine but when I runserver
> and try to go to url it gives the error.  Let me know if need more
> info.
>
> http://dpaste.com/696518/
>
> ImportError at /accounts/login/
>
> No module named login
>
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/accounts/login/?next=/event/
> Django Version:         1.3.1
> Exception Type:         ImportError
> Exception Value:
>
> No module named login
>
> Exception Location:     i:\learn\python\Django-1.3.1\django\utils
> \importlib.py in import_module, line 35
> Python Executable:      \\ms\dist\python\PROJ\core\2.5.4\bin\python.EXE
> Python Version:         2.5.4
> Python Path:
>
> ['I:\\learn\\python\\event',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5\\lib-
> dynload',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib',
>  'i:\\learn\\python\\Django-1.3.1',
>  'I:\\learn\\python\\event',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin\\python25.zip',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\DLLs',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\plat-win',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\lib-tk',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-tk',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\site-
> packages',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-
> dynload',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin',
>  'ms\\dist\\python\\PROJ\\core\\2.5.4',
>  '//ms/dist/python/PROJ/msversion/1.0/lib',
>  '//ms/dist/python/PROJ/ms.version/prod-2.5/lib']
>
> Server time:    Thu, 2 Feb 2012 15:58:44 +0530
>
> Regards,
>
> Miten.

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



south create_table doesn't work

2012-02-02 Thread Alessandro Candini
I'm trying to use django-south-0.7.3 API's to create a table, following 
this: http://south.aeracode.org/docs/databaseapi.html#accessing-the-api


This is my code:
from south.db import dbs
dbs['lc'].create_table('test', [
('id', models.AutoField(primary_key=True)),
('name', models.CharField(max_length=255)),
])

The problem is that I do not get any error, but in the lc database, no 
table appears.

Where is the issue?

Thanks in advance

--
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: create users from /etc/passwd?

2012-02-02 Thread Furbee
Hi Tim,

I'm not totally sure, but I don't think this will work. You could parse the
passwd file to get the usernames, but the passwords are encrypted. Since
you don't have the system's decryption key, you would not be able to
determine the password. If you just used what is in /etc/shadow it would
not match the password that the users enter when they try to authenticate
in Django.

I would suggest using Django's built-in authentication system. Then when a
user goes to your site, and enters their credentials, you will be able to
access the user information in the view with request.user (assuming
"request" is your view's first parameter name).

Django's documentation is a lifesaver, here's setting up User
Authentication:
https://docs.djangoproject.com/en/1.3/topics/auth/

Here's accessing session information when a user is logged in.
https://docs.djangoproject.com/en/1.3/topics/http/sessions/

Finally, you can use the decorator @login_required for views that require
authentication. However, I found it easier for many applications that use
site-wide authentication (usually the case with intranet development) to
use middleware to require login for every page. I implemented something
similar to this and it works perfectly.:
http://onecreativeblog.com/post/59051248/django-login-required-middleware

You're want to study up on how middleware works, here:
https://docs.djangoproject.com/en/1.3/topics/http/middleware/


Good Luck,

Furbee

On Thu, Feb 2, 2012 at 7:47 AM, Tim  wrote:

> I'm running Django 1.3.1 on FreeBSD + Apache2.2 inside an intranet.
>
> I do not grok authentication, so here is my problem and a question about
> how I can solve it (maybe).
> What I need is the name of the user who hits the application. I don't care
> about the password, I just need to know who they are. I've been unable to
> get the REMOTE_USER from Apache, mainly because I think Apache doesn't know
> it either (no authentication is used on the httpd.conf).
>
> I thought (here's my maybe solution) I might create a bunch of users in
> Django by parsing the /etc/passwd database. Then at least each user would
> have the same username/password they use to login to the network.
>
> Is that possible? Is there a better way to get the username?
> thanks,
> --Tim
>
>  --
> 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/-/qO-mxTOE0joJ.
> 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: create users from /etc/passwd?

2012-02-02 Thread Thorsten Sanders

https://bitbucket.org/maze/django-pam/

maybe that helps?

On 02.02.2012 16:47, Tim wrote:

I'm running Django 1.3.1 on FreeBSD + Apache2.2 inside an intranet.

I do not grok authentication, so here is my problem and a question 
about how I can solve it (maybe).
What I need is the name of the user who hits the application. I don't 
care about the password, I just need to know who they are. I've been 
unable to get the REMOTE_USER from Apache, mainly because I think 
Apache doesn't know it either (no authentication is used on the 
httpd.conf).


I thought (here's my maybe solution) I might create a bunch of users 
in Django by parsing the /etc/passwd database. Then at least each user 
would have the same username/password they use to login to the network.


Is that possible? Is there a better way to get the username?
thanks,
--Tim

--
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/-/qO-mxTOE0joJ.

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: ImportError at /accounts/login/

2012-02-02 Thread Miten
Hi,

Thanks for reply.  I sought help from irc django channel and they
asked for the same.  Actually in urls.py in url call we cannot include
views.  I corrected it to plain url string and it worked.

Regards,

Miten.

On Feb 2, 8:49 pm, akaariai  wrote:
> I don't think we are able to help you without more detail. The browser
> window should contain the lines which caused the error (when run with
> settings.DEBUG=True). Include those lines, and it is more likely that
> you get an answer. Including full stack trace of the ImportError is
> even better.
>
>  - Anssi
>
> On Feb 2, 12:41 pm, Miten  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I am trying simple generic view + auth and get exception as below.
> > The dpaste shows traceback.  Please guide what am I missing.  From
> > manage shell I am able to import login view fine but when I runserver
> > and try to go to url it gives the error.  Let me know if need more
> > info.
>
> >http://dpaste.com/696518/
>
> > ImportError at /accounts/login/
>
> > No module named login
>
> > Request Method:         GET
> > Request URL:    http://127.0.0.1:8000/accounts/login/?next=/event/
> > Django Version:         1.3.1
> > Exception Type:         ImportError
> > Exception Value:
>
> > No module named login
>
> > Exception Location:     i:\learn\python\Django-1.3.1\django\utils
> > \importlib.py in import_module, line 35
> > Python Executable:      \\ms\dist\python\PROJ\core\2.5.4\bin\python.EXE
> > Python Version:         2.5.4
> > Python Path:
>
> > ['I:\\learn\\python\\event',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5\\lib-
> > dynload',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\python2.5',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib',
> >  'i:\\learn\\python\\Django-1.3.1',
> >  'I:\\learn\\python\\event',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin\\python25.zip',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\DLLs',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\plat-win',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\lib\\lib-tk',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-tk',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\site-
> > packages',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4-0\\lib\\python2.5\\lib-
> > dynload',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4\\bin',
> >  'ms\\dist\\python\\PROJ\\core\\2.5.4',
> >  '//ms/dist/python/PROJ/msversion/1.0/lib',
> >  '//ms/dist/python/PROJ/ms.version/prod-2.5/lib']
>
> > Server time:    Thu, 2 Feb 2012 15:58:44 +0530
>
> > Regards,
>
> > Miten.

-- 
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: Help Me With omab/django-socialauth

2012-02-02 Thread Thorsten Sanders
I took your config and its working fine, maybe your twitter api key is 
wrong?


On 02.02.2012 11:22, coded kid wrote:

I'm getting a redirect loop error. Whats the probs?

On Feb 1, 1:22 pm, Thorsten Sanders  wrote:

Some sort of error traceback/description would be helpful, from a quick
look it seems all right.

On 01.02.2012 13:23, coded kid wrote:




Hey guys, I'm facing a huge  problem with omab/django/socialauth.
After setting all the necessary settings, I clicked on the Enter
using Twitter link on my homepage, it couldn t redirect me to where I
will enter my twitter username and password. Below are my settings.
In settings.py
INSTALLED_APPS = (
'social_auth',
}
TEMPLATE_CONTEXT_PROCESSORS = (
 "django.core.context_processors.auth",
 "django.core.context_processors.debug",
 "django.core.context_processors.i18n",
 "django.core.context_processors.media",
 "django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
 social_auth.context_processors.social_auth_by_type_backends ,
)
AUTHENTICATION_BACKENDS = (
 'social_auth.backends.twitter.TwitterBackend',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter')
TWITTER_CONSUMER_KEY = '0hdgdhsnmzHDGDK'
TWITTER_CONSUMER_SECRET  = 'YyNngsgw[1jw lcllcleleedfejewjuw'
LOGIN_URL = '/accounts/login/' #login form for users to log in with
their username and password!
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/homi/'  #page after user get
authenticated
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/homi/'   '  #page after
user get authenticated
SOCIAL_AUTH_ERROR_KEY='social_errors'
SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
from django.template.defaultfilters import slugify
SOCIAL_AUTH_USERNAME_FIXER = lambda u: slugify(u)
SOCIAL_AUTH_UUID_LENGTH = 16
SOCIAL_AUTH_EXTRA_DATA = False
In urls.py
url(r'', include('social_auth.urls')),
In my template:

   Enter using Twitter
   

What do you think I m doing wrong? Hope to hear from you soon. Thanks
so much!
N:B : I m coding on windows machine. And in the development
environment using localhost:8000.


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



base.css 404ing on Django 1.4a1

2012-02-02 Thread Alec Taylor
Trunk version cannot load Admin CSS.

First I tried setting the ADMIN_MEDIA_PREFIX to MEDIA_PREFIX, when
that didn't work I tried manual replacing. Yes, I know it has been
depreciated and that the css are stored in
django\django\contrib\admin\static\admin\css, however it did not work
when omitted so I placed that \static\admin\ folder as a subdirectory
of my regular static directory.

ADMIN_MEDIA_PREFIX is now set to: '/static/admin/' in settings.py.

This partially worked, the top of my admin pages now look like this:



So dashboard.css is loading fine now, it's just base.css which isn't.

How should I go about getting that base.css link to not 404, or
*actually* changing that ADMIN_MEDIA_PREFIX?

Thanks for all suggestions,

Alec Taylor

-- 
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: Newbie django/python with C++ background wants enums

2012-02-02 Thread NENAD CIKIC
thanks, to all.
I have now some code to study and understand.
Nenad

-- 
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/-/WZCA-XCSg_IJ.
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.



Need help regarding url patterns

2012-02-02 Thread ankitrocks
Please take a look at the following files:

http://pastebin.com/F86G9XJn

http://pastebin.com/p6gArpuG

http://pastebin.com/zxNHVHbV

http://pastebin.com/Rf9Kg9jf

Now my problem is that, I want all the logout links in the templates
point to polls/login and this change should also be reflected in the
url on my address bar. Same holds for home link which should point to
polls/welcome .


Please help me out.

-- 
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: Newbie django/python with C++ background wants enums

2012-02-02 Thread ajohnston
I would probably do it Bruno's way, since it is more explicit, but
just so you know, there are some enumeration tools in Python. Just not
an 'enum' type:

>>> base_choices = ['No', 'Yes'] <-- transform this any way you want:

>>> choices = list(enumerate(base_choices))
>>> choices
[(0, 'No'), (1, 'Yes')] <-- can be used for 'choices' parameter in
BooleanField

>>> use_txt_choices = {v:k for k,v in enumerate(base_choices)}
>>> use_txt_choices
{'Yes': 1, 'No': 0} <-- can be used in 'clean' method:

if len(txt) == 0 and use_txt==use_txt_choices['Yes']:
pass

If the values have to be boolean instead of ints, you can:
>>> txt_choices = [(True if i else False, j) for i,j in enumerate(base_choices)]
>>> txt_choices
[(False, 'No'), (True, 'Yes')]

>>> lookup_choices = {v:True if k else False for k,v in enumerate(base_choices)}
>>> lookup_choices
{'Yes': True, 'No': False}

-- 
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: create users from /etc/passwd?

2012-02-02 Thread David Fischer
Depending on your intranet, you may already have an LDAP directory. If you 
do, I would use a combination of Apache, 
mod_ldapand Django's 
RemoteUserMiddleware
.

-- 
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/-/TzmTnfKg1nQJ.
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 regarding url patterns

2012-02-02 Thread akaariai
On Feb 2, 4:57 pm, ankitrocks  wrote:
> Please take a look at the following files:
>
> http://pastebin.com/F86G9XJn
>
> http://pastebin.com/p6gArpuG
>
> http://pastebin.com/zxNHVHbV
>
> http://pastebin.com/Rf9Kg9jf
>
> Now my problem is that, I want all the logout links in the templates
> point to polls/login and this change should also be reflected in the
> url on my address bar. Same holds for home link which should point to
> polls/welcome .

Two quick pointers:
  - You probably want to use the reverse method and the url template
tag. Django documentation will tell you more about these.
  - Why does the login/logout views take optional poll_id argument
which is then not used. You should have the login and logout views
only once defined in your urls.py, that is, not also under /id/login.

 - Anssi

-- 
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-taggit] Recording additional tagging metadata with the admin

2012-02-02 Thread Lorenzo Franceschini

Hi, I have a question about ``django-taggit`` and the admin site.

I have written a custom intermediate model [1] for storing additional 
tagging metadata, i.e. the user doing the tagging and when the tagging 
happen:


class TaggedItem(GenericTaggedItemBase, TaggedItemBase):
tagger = models.ForeignKey(User, null=True, blank=True, editable=False)
tagging_time = models.DateTimeField(null=True, auto_now_add=True)

Then, I made a model taggable:

class Foo(models.Model):
# field defs

   tags = TaggableManager(through=TaggedItem, blank=True)

Now when a ``Foo`` model instance is created/changed, I would like those 
additional tagging metadata to be filled with ``request.user`` and the 
current time.


My question is: how can I achieve this behaviour ? I suppose I have to 
hook someway in the admin, but I don't know way.


Thanks in advance for any answers.


[1] http://readthedocs.org/docs/django-taggit/en/latest/custom_tagging.html

--
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-mptt compared w/ django-treebeard

2012-02-02 Thread creecode
Hello Aljosa,

I wouldn't assume that just because something hasn't been updated for 
awhile that it isn't good.  It simply could be that the app does what it 
needs to and there hasn't been a reason to change it.  You might want to 
contact the app authors and ask if their projects are actively maintained.

Toodle-looo.
creecode

-- 
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/-/3wQ_QTSjmwEJ.
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: Newbie django/python with C++ background wants enums

2012-02-02 Thread ajohnston
I'm straying a bit off-topic here, but I forgot to mention that other
way I've seen people do 'enum' in Python is:

>>> class Colors(object):
... RED, GREEN, BLUE = range(3)
...
>>> c = Colors()
>>> c.RED
0
>>> c.BLUE
2
>>> c.GREEN
1

Not sure this helps much in this particular case though.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: create users from /etc/passwd?

2012-02-02 Thread Tim
Thanks for all this great information. Thorsten, I do have hope that 'pam' 
will solve the problem, but if I get nowhere with that, Furbee's links and 
info will help me go further; I just didn't want the user to have to sign 
on twice when I don't really care about authentication, just user 
identification.  In any case, I'm reading those docs now, and the blog 
article.

David, I wish I could do this via the LDAP set up but as far as I can tell 
there isn't one.

thanks again!
--Tim

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



Rooting my application at the base (/) of the URL

2012-02-02 Thread Johan
Hi

  I have deployed my application on Apache using WSGI, using
WSGIScriptAlias / /var/www/site/django.wsgi. Everything looks very
good. My actual application lives at http:///application. So
with the setup above when I browse to http://http://groups.google.com/group/django-users?hl=en.



advice needed using a form in one app in another

2012-02-02 Thread richard
I have two apps one called mysite and one called register which is a
nested app to mysite that handles registration. In mysite app views i
have a view that imports the register form from register app and
renders to home.html and home.html includes another template called
register.html. So the register form is included on the home page but i
want to keep all registration specific handling seperate thats why i
have put it in its own app. So on the homepage the included
register.html page that has a form with a url to post to say /
register/ where it will head off to the register app and register the
user and redirect elsewhere or return back to home.html with the form
errors. So my question is that when it posts off to /register/ my
views in the register app would need to render_to_response home.html
to get back to where it was sent from in order to get the form errors
which has now got a new url in the url bar so instead of /home/ it
says /register/ but still displaying the home page which i think is
silly. Does anyone have any input on this or would it be better to use
an ajax request in this situation so the url doesnt have to change and
i dont have 2 views rendering the same page.?

thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Entering Text into a Database

2012-02-02 Thread ds39
Hello Everyone,

I've just started web programming and using Django, and I'm still not
sure how to enter text into a database via a page. From everything
I've read, the suggestion seems to be that a ModelForm should be used.
I've tried to implement this on a simple example model, but I'm sure
I'm doing most of this wrong. Is there any page, outside of the
official documentation, that gives an example from beginning to end
regarding how to save ModelForms in your database using views.py
rather than the shell (including sample URLs) ? Also, how would I
access the entered text via the shell to determine if it was saved ?

Thank you

-- 
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: admin list_filter: limit choices to model values?

2012-02-02 Thread Micky Hulse
On Wed, Feb 1, 2012 at 1:59 PM, Micky Hulse  wrote:
> Anywho... Anyone know when Django 1.4 is scheduled to be released?



[quote]

The Django 1.4 roadmap

Before the final Django 1.4 release, several other preview/development
releases will be made available. The current schedule consists of at
least the following:

* Week of January 30, 2012: First Django 1.4 beta release; final
feature freeze for Django 1.4.

* Week of February 27, 2012: First Django 1.4 release candidate;
string freeze for translations.

* Week of March 5, 2012: Django 1.4 final release.

If necessary, additional alpha, beta or release-candidate packages
will be issued prior to the final 1.4 release. Django 1.4 will be
released approximately one week after the final release candidate.

[/quote]

--

-- 
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: Routing to database based on user

2012-02-02 Thread Tom Eastman
On 31/01/12 11:45, akaariai wrote:
> On Jan 31, 12:01 am, Tom Eastman  wrote:
>> Hey guys,
>>
>> I'm writing a django project that will require me to route queries to
>> certain large databases based on who the logged in user is.
>>
>> So all the tables for django.contrib.auth and session and stuff will be
>> in the 'central' database, as well as a table that maps users to which
>> database they need to use for the main app.
>>
>> Can you help me come up with a way of routing database queries this way
>> using a Django database router?
>>
>> At the start of the view could I take the logged in user from
>> request.user or wherever it is, and some how provide that variable to my
>> database router for the rest of the request?
>>
>> All suggestions welcome.

> 
> I think the best solution forward is to use threading.local to store
> the request.user. So, something like this should work:
>   - have a middleware that stores the request.user in threading.local
>   - database routers just fetch the request.user from the
> threading.local storage.


Thanks Anssi!

Here is my solution, I wonder if you could just tell me if you think
there's a major problem with it.

In simplistic terms, the goal is "whenever a model from wxdatabase is
accessed, route the query to the database specified in the user's
organization's field".

It consists of a piece of django middleware and a db_router.

I guess my main question is: am I using threading.local() correctly?

Cheers!

Tom


##
##
import threading

_local = threading.local()

class WXDatabaseMiddleware(object):
def process_request(self, request):
_local.wx_database_label = None

try:
profile = request.user.get_profile()
_local.wx_database_label = profile.organization.database.label
except:
## This exception needs to be logged!
pass


class WxRouter(object):
def _get_database_label(self):
return _local.wx_database_label

def read_and_write(self, model, **hints):
if model._meta.app_label == "wxdatabase":
return self._get_database_label()
else:
return None

db_for_read  = read_and_write
db_for_write = read_and_write

###
###



signature.asc
Description: OpenPGP digital signature


Re: create users from /etc/passwd?

2012-02-02 Thread Mike Dewhirst

On 3/02/2012 7:00am, Tim wrote:

Thanks for all this great information. Thorsten, I do have hope that
'pam' will solve the problem, but if I get nowhere with that, Furbee's
links and info will help me go further; I just didn't want the user to
have to sign on twice when I don't really care about authentication,
just user identification. In any case, I'm reading those docs now, and
the blog article.

David, I wish I could do this via the LDAP set up but as far as I can
tell there isn't one.


You can.

If you accept that users will have to authenticate in your Django app 
then if you use ldap you won't have to worry about passwords at all. 
They will enter the same username and password they usually do when they 
power up their workstations.


I have used Peter Herndon's django-ldap-groups very successfully to do 
just that. It will create a new user including any ldap groups you set 
up for Django based entirely on successful ldap authentication. It will 
bring whatever ldap info across to Django that you require.


Mike



thanks again!
--Tim

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



problem installing PIL

2012-02-02 Thread NENAD CIKIC
I came across this problem (the problem is that i can not install PIL on my 
windows 7 64 bit machine) when I have tried to use ImageField. I have first 
tried to use C++ Express but I came across 
http://bugs.python.org/issue7511. Then I have tried to use mingw and cygwin 
but the gcc complied about some parameters the setup was passing.
I know I can use just the Filefield, and i will do it; I am now just 
curious how can i install this PIL on windows machine?
I have also tried the pillow, but it blocks with the same issue. Is there 
an alternative, since I have noticed the last release is from 2 years ago, 
but then again from django docs it says I should have it if i want to use 
ImageField?

Thanks

-- 
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/-/0gETXuOV40oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: problem installing PIL

2012-02-02 Thread Mike Dewhirst

This might help ...

http://stackoverflow.com/questions/2088304/installing-pil-python-imaging-library-in-win7-64-bits-python-2-6-4


On 3/02/2012 10:40am, NENAD CIKIC wrote:

I came across this problem (the problem is that i can not install PIL on
my windows 7 64 bit machine) when I have tried to use ImageField. I have
first tried to use C++ Express but I came across
http://bugs.python.org/issue7511. Then I have tried to use mingw and
cygwin but the gcc complied about some parameters the setup was passing.
I know I can use just the Filefield, and i will do it; I am now just
curious how can i install this PIL on windows machine?
I have also tried the pillow, but it blocks with the same issue. Is
there an alternative, since I have noticed the last release is from 2
years ago, but then again from django docs it says I should have it if i
want to use ImageField?

Thanks

--
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/-/0gETXuOV40oJ.
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: Routing to database based on user

2012-02-02 Thread akaariai


On Feb 3, 1:30 am, Tom Eastman  wrote:
> Here is my solution, I wonder if you could just tell me if you think
> there's a major problem with it.
>
> In simplistic terms, the goal is "whenever a model from wxdatabase is
> accessed, route the query to the database specified in the user's
> organization's field".
>
> It consists of a piece of django middleware and a db_router.

I must warn you that I don't know too much about db routers.

> I guess my main question is: am I using threading.local() correctly?

To me it seems correct.

> class WXDatabaseMiddleware(object):
>     def process_request(self, request):
>         _local.wx_database_label = None
>
>         try:
>             profile = request.user.get_profile()
>             _local.wx_database_label = profile.organization.database.label
>         except:
>             ## This exception needs to be logged!
>             pass

I think here you should make sure you always also clear the
wx_database_label variable, so that it won't be left pointing to a
user's DB in any case. That is, you would need a finally block, and a
process_response method.

Also, I think you are going to generate some more queries than needed
by the user.profile.organization.database.label. If I guess correctly,
that is going to be 5 DB calls for each request. .select_related()
could be handy here...

>
> class WxRouter(object):
>     def _get_database_label(self):
>         return _local.wx_database_label
>
>     def read_and_write(self, model, **hints):
>         if model._meta.app_label == "wxdatabase":
>             return self._get_database_label()
>         else:
>             return None
>
>     db_for_read  = read_and_write
>     db_for_write = read_and_write

Can't comment about this.

 - Anssi

-- 
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 Snippet imports?

2012-02-02 Thread Jesramz
What would I have to import to use the following snippet (source:
http://djangosnippets.org/snippets/847/)?

@register.filter
def in_group(user, groups):
"""Returns a boolean if the user is in the given group, or comma-
separated
list of groups.

Usage::

{% if user|in_group:"Friends" %}
...
{% endif %}

or::

{% if user|in_group:"Friends,Enemies" %}
...
{% endif %}

"""
group_list = force_unicode(groups).split(',')
return
bool(user.groups.filter(name__in=group_list).values('name'))

-- 
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: Entering Text into a Database

2012-02-02 Thread ajohnston
On Feb 2, 2:30 pm, ds39  wrote:
Is there any page, outside of the
> official documentation, that gives an example from beginning to end
> regarding how to save ModelForms in your database using views.py
> rather than the shell (including sample URLs) ? Also, how would I
> access the entered text via the shell to determine if it was saved ?

Did you do the tutorial[1]?. Be sure to do all four parts. After that
the examples in the ModelForms documentation[2] should make sense. If
not, ask specific questions about what is not working the way you
think it should. Good luck.

{1] https://docs.djangoproject.com/en/dev/intro/tutorial01/
[2] https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/

-- 
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: Entering Text into a Database

2012-02-02 Thread Python_Junkie
Not sure if this will help, but I have diverted from the standard
method of database updates taught in the tutorial.

I take a more traditional sql methodology

for example in any view that I am using.

I collect the data elements via a request
and then build a sql statement

for example

(The exact syntax may be a little off.)

var_1=request.post(name)

var_2=...etc

insert into table 1(col_1,col_2) values ('var_1,var_2)

commit


Let me know if this helps and I can update the syntax to be more
precise.

On Feb 2, 9:51 pm, ajohnston  wrote:
> On Feb 2, 2:30 pm, ds39  wrote:
> Is there any page, outside of the
>
> > official documentation, that gives an example from beginning to end
> > regarding how to save ModelForms in your database using views.py
> > rather than the shell (including sample URLs) ? Also, how would I
> > access the entered text via the shell to determine if it was saved ?
>
> Did you do the tutorial[1]?. Be sure to do all four parts. After that
> the examples in the ModelForms documentation[2] should make sense. If
> not, ask specific questions about what is not working the way you
> think it should. Good luck.
>
> {1]https://docs.djangoproject.com/en/dev/intro/tutorial01/
> [2]https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/

-- 
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: about QuerySet

2012-02-02 Thread newme
so it means when i call user[1] after user[0], it is possible that i
will get same record if someone else insert a new record into database
between 2 calls.

On Feb 1, 5:34 pm, akaariai  wrote:
> On Feb 1, 9:36 am, newme  wrote:
>
> > do you mean that queryset will query database every time i call
> > user[0]?
>
> Yes. That is exactly what happens:
> In [7]: qs[0]
> Out[7]: 
> In [9]: print connection.queries
> [{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
> 1'}]
>
> In [10]: qs[0]
> Out[10]: 
> In [11]: print connection.queries
> [{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
> 1'},
>  {'time': '0.001', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
> 1'}]
>
> If you do not want this to happen, you can evaluate your queryset into
> a list first by:
> objlist = list(qs[0:wanted_limit])
> and now objlist is just a regular Python list.
>
> The lazy evaluation of querysets can be a little surprising sometimes.
> Using django-debug-toolbar or just settings.DEBUG = True, and then
> print connection.queries is recommended :)
>
>  - Anssi

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



auth groups puzzle

2012-02-02 Thread Mike Dewhirst
I want to use the built-in auth_groups permissions system in a 
many-to-many sense but can't quite figure it out for my use case. Any 
help will be appreciated.


The use case is: users have different types of access (r/o, r/w or 
admin) to different companies. Any single user can have r/o access to 
company-1, r/w access to company-2 and admin access to company-3 and so 
on. Any company can have relationships with many users each of whom will 
have one of the r/o, r/w or admin group permissions.


So there has to be a many-to-many relationship between user and company 
and the group needs to be specified in that relationship table rather 
than in the auth_user_groups table - where it currently sits.


How do I invoke a different set of permissions depending on the name of 
the group established in the user-company relationship table when a user 
is accessing that company's data?


A side question is how do I remove the displayed Groups in the Django 
Admin auth/user display?


Thanks

Mike

--
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: Entering Text into a Database

2012-02-02 Thread Mario Gudelj
Hey dude,

Let's say you have some model with fields defined. It's called Business.
Looks something like this:

class Business(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField("Business Name", max_length=NAME, blank=False)

You create a ModelForm like this:

class BusinessDetailsForm(forms.ModelForm):
class Meta:
model = Business

In your view you have a method that captures the POST and saves it inside
the model:

def save_business_details(request):
if request.POST:
form = BusinessDetailsForm(request.POST)
if form.is_valid():
form.save()
return
HttpResponseRedirect(reverse("your_app.views.some_view_when_submission_is_successful",
args=[]))
else:
here you pass back the form or whatever
return render_to_response(and render that whatever)

So, form.save() will save the details.

I hope that helps!

-m

On 3 February 2012 14:40, Python_Junkie wrote:

> Not sure if this will help, but I have diverted from the standard
> method of database updates taught in the tutorial.
>
> I take a more traditional sql methodology
>
> for example in any view that I am using.
>
> I collect the data elements via a request
> and then build a sql statement
>
> for example
>
> (The exact syntax may be a little off.)
>
> var_1=request.post(name)
>
> var_2=...etc
>
> insert into table 1(col_1,col_2) values ('var_1,var_2)
>
> commit
>
>
> Let me know if this helps and I can update the syntax to be more
> precise.
>
> On Feb 2, 9:51 pm, ajohnston  wrote:
> > On Feb 2, 2:30 pm, ds39  wrote:
> > Is there any page, outside of the
> >
> > > official documentation, that gives an example from beginning to end
> > > regarding how to save ModelForms in your database using views.py
> > > rather than the shell (including sample URLs) ? Also, how would I
> > > access the entered text via the shell to determine if it was saved ?
> >
> > Did you do the tutorial[1]?. Be sure to do all four parts. After that
> > the examples in the ModelForms documentation[2] should make sense. If
> > not, ask specific questions about what is not working the way you
> > think it should. Good luck.
> >
> > {1]https://docs.djangoproject.com/en/dev/intro/tutorial01/
> > [2]https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/
>
> --
> 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: auth groups puzzle

2012-02-02 Thread Mike Dewhirst
I'm going to simplify the use case and live with users being in the same 
group for all companies. This is only a prototype. If a demand arises in 
production I'll worry about it then.


Sorry to bother you

Mike

On 3/02/2012 4:58pm, Mike Dewhirst wrote:

I want to use the built-in auth_groups permissions system in a
many-to-many sense but can't quite figure it out for my use case. Any
help will be appreciated.

The use case is: users have different types of access (r/o, r/w or
admin) to different companies. Any single user can have r/o access to
company-1, r/w access to company-2 and admin access to company-3 and so
on. Any company can have relationships with many users each of whom will
have one of the r/o, r/w or admin group permissions.

So there has to be a many-to-many relationship between user and company
and the group needs to be specified in that relationship table rather
than in the auth_user_groups table - where it currently sits.

How do I invoke a different set of permissions depending on the name of
the group established in the user-company relationship table when a user
is accessing that company's data?

A side question is how do I remove the displayed Groups in the Django
Admin auth/user display?

Thanks

Mike



--
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: Getting started with Django: New Udemy Class, free for a limited time

2012-02-02 Thread Shabda Raaj
I was hoping to get about 100 people in a month, but we already have
289 people signed up in a week. :). I wasn't expecting this. (You can
verify this at Udemy.)

Because I am still adding the content, I am keeping the price to $9
for the whole of February, and would raise once I am done with adding
the tutorials.

You can join here:
http://www.udemy.com/getting-started-with-django2/

Whats added already.

1. 4 part screencast for the four part Django tutorial.
2. Screencasts on using pip, pep8.py, pyflakes, ipython.
3. PDF versions of Django design patterns and Djen of Django book.
4. Various other tutorials.
5. Code samples of all code written in the screencasts and the
tutorials.

On Jan 28, 11:13 pm, Shabda Raaj  wrote:
> Here is the link:http://www.udemy.com/getting-started-with-django2/
>
> More info:
> I am starting aUdemyclass called  "Getting started with Django".
> This is supposed to be a fast paced introduction to Django, and is
> going to be useful to people from beginner to intermediate Django
> skills.
>
> Please join:http://www.udemy.com/getting-started-with-django2/or
> forward to people who may be interested. I am keeping the course free
> for the first 100 people, and I am going to set the price to 149$
> once
> we have the 100 people signed up.

-- 
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: south create_table doesn't work

2012-02-02 Thread Alessandro Candini
Nobody who has experience with south?

On Feb 2, 5:14 pm, Alessandro Candini  wrote:
> I'm trying to use django-south-0.7.3 API's to create a table, following
> this:http://south.aeracode.org/docs/databaseapi.html#accessing-the-api
>
> This is my code:
> from south.db import dbs
> dbs['lc'].create_table('test', [
>              ('id', models.AutoField(primary_key=True)),
>              ('name', models.CharField(max_length=255)),
>          ])
>
> The problem is that I do not get any error, but in the lc database, no
> table appears.
> Where is the issue?
>
> Thanks in advance

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