Django DateTimeRangeField used with date_hierarchy

2017-10-03 Thread Laurence Sonnenberg
Hi 

It's great that with 1.11 django.contrib.admin and django.contrib.postgres 
have brought the ability to use date_hierarchy with fields from other 
connected tables.

I was wondering if the ability to to create a transform on a given table 
existed so that fields other than DateField or DateTimeField could be used? 
For example DateTimeTZRange. Or perhaps it could be done in the postgresql 
backend?

A transform example might be: 

@admin.register(models.MyModel)
class MyModelAdmin(AdvancedModelAdmin):

date_hierarchy = 'date_range_to_datetime'

def date_range_to_datetime(instance):
"""
Return a datetime from django date range.
"""
return instance.range.lower

Is there anyone who might have some insight into how this could be done?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/420762b0-606a-4ed7-a00b-5c1e5337d07d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to find something in multiple databases... Confused...

2012-06-19 Thread Laurence MacNeill
Right -- different tables in the same database, of course...  Thanks.

L.


On Monday, June 18, 2012, Daniel Roseman wrote:

> On Monday, 18 June 2012 08:40:53 UTC+1, Laurence MacNeill wrote:
>>
>> Ok, I'm a total django noob here, so I am probably doing this wrong...
>> But here goes...
>>
>> When someone comes to my django app's root (index), I need to verify
>> their user-name (which is stored in a Linux environment variable).  Based
>> on where (or if) I find their user-name, I want to send them to one of
>> three different pages -- if I don't find them in any database, I want to
>> add them to a given database, then send them to a page.
>>
>> So here's what I have in my views.py file:
>> def index(request)
>>  current_username = os.environ['REMOTE_USER']
>>
>>
> So Melvyn has answered your question, but a quick note on terminology:
> what you've got there are separate *database tables*, or separate *Django
> models* -- not separate databases. Multiple databases is a whole different
> question, which you really don't want to get into as a newbie (or, indeed,
> at all if possible).
> --
> DR.
>
> --
> 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/-/jSuHg6H4amoJ.
> To post to this group, send email to 
> django-users@googlegroups.com<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> 'django-users%2bunsubscr...@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: Trying to find something in multiple databases... Confused...

2012-06-19 Thread Laurence MacNeill
On Monday, June 18, 2012, Melvyn Sopacua wrote:

> On 18-6-2012 9:52, Laurence MacNeill wrote:
> > well -- I hit the wrong key and posted that before I was finished
> typing...
> >
> > here's what's in my views.py file:
> > def index(request)
> >  current_username = os.environ['REMOTE_USER']
>
> And you're sure this works? Try:
>  return django.shortcuts.render_to_response(current_username)
>
> here to verify it's coming through. Normally, the authenticated username
> would be part of the request dictionary.



Yeah, it's not working...  How do I get the user-name from the request
dictionary?  request.REMOTE_USER or somthing like that?

It's not using Django for the user-validation, though...  When someone logs
into the site, they get redirected to a page that validates them.  This is
controled by the Apache web-server itself -- if they try to access any
document served by Apache, and they don't have a cookie on their computer,
they're redirected to a different page where they enter their user ID and
password, then are sent back to the original page.  The user-id is then
stored in a linux environment variable called REMOTE_USER.  So I figured
the only way to access it was via the os.environ method.



>
> Almost correct:
> if student is not None :
> # the student.html template will now have a variable named student
> # which is the student object you fetched
> return render_to_response('ta/student.html', student=student)
> elif instructor is not None :
> #etc


Ahh, ok -- that makes sense...  Thanks...

L.

-- 
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: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
well -- I hit the wrong key and posted that before I was finished typing... 

here's what's in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

This should provide me with their username (yes I do have 'import os' at 
the top of the file)...

Now, after I get their username I want to do something like this (but I'm 
not sure how to write in django -- so I've put ## around the pseudo-code)
 try:
 student = Student.objects.get(student_name=current_username)
 except (#can't find it in Student database, but I don't know what code 
to put here#)
 try:
 instructor = 
Instructor.objects.get(instructor_name=current_username)
 except (#can't find it in Instructor database, but I don't know 
what code to put here#)
   try:
administrator = 
Administrator.objects.get(administrator_name=current_username)
   except (#fail condition - can't find current_username in 
Administrator database, but I don't know what code to put here#)
#because we failed to find it in any database, we 
assume it's a student and add it
student = Student(student_name=current_username)
student.save
 #here's where I'm not sure how to continue -- I want to do something 
like this#
 #if student is defined#
  return render_to_response('ta/student.html', student)
 #else if instructor is defined#
  return render_to_response('ta/instructor.html', instructor)
 #else if administrator is defined#
  return render_to_response('ta/administrator.html', administrator)
#end of my code#

So -- can someone please help me fill in the missing code above?  I've been 
searching for hours, but I just can't seem to hit on the correct 
search-terms to get done what I want here...

Thanks,
Laurence MacNeill
Mableton, Georgia, USA


On Monday, June 18, 2012 3:40:53 AM UTC-4, Laurence MacNeill wrote:
>
> Ok, I'm a total django noob here, so I am probably doing this wrong...  
> But here goes...
>
> When someone comes to my django app's root (index), I need to verify their 
> user-name (which is stored in a Linux environment variable).  Based on 
> where (or if) I find their user-name, I want to send them to one of three 
> different pages -- if I don't find them in any database, I want to add them 
> to a given database, then send them to a page.
>
> So here's what I have in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']
>
>

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



Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
Ok, I'm a total django noob here, so I am probably doing this wrong...  But 
here goes...

When someone comes to my django app's root (index), I need to verify their 
user-name (which is stored in a Linux environment variable).  Based on 
where (or if) I find their user-name, I want to send them to one of three 
different pages -- if I don't find them in any database, I want to add them 
to a given database, then send them to a page.

So here's what I have in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

-- 
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/-/89ghQfC_J0IJ.
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 Tutorial part 2... Admin Site won't work...

2012-06-18 Thread Laurence MacNeill
I'm using 1.4

I finally figured out that if I just create the site manually, everything 
works fine...  I don't know why it wasn't being created when syncdb was 
run...

L.


On Sunday, June 17, 2012 2:17:35 AM UTC-4, Xavier Ordoquy wrote:
>
> Hi,
>
> The site entry is usually created when the syncdb is run.
> What Django version are you using ? If you're using the development 
> version, please remove it and install a stable version.
>
> Regards,
> Xavier Ordoquy,
> Linovia.
>
> Le 16 juin 2012 à 23:16, Laurence MacNeill a écrit :
>
> I'm going through the django tutorial and I'm having difficulties at the 
> beginning of the second part...
>
> It tells me to create the admin site, and browse to 127.0.0.1:8000/adminto 
> log in to the admin site I just created...  But when I do that, I get 
> the python server telling me that the site is not found -- it's not the 
> usual apache web-server 404 error, it's definitely coming from the python 
> server, so I know that's running properly.
>
> Searching through some of the other posts, I came across one responder who 
> asked someone with this same problem to find their site ID in their 
> settings.py file.  Mine says the site ID is 1.  So, armed with that 
> information, I go to the python shell, and type the following:
> >>> from django.contrib.sites.models import Site
> >>> Site.objects.get(id=1)
>
> And I get the following in response:
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", 
> line 131, in get
> return self.get_query_set().get(*args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 
> 366, in get
> % self.model._meta.object_name)
> DoesNotExist: Site matching query does not exist.
>
> So, it seems that the entire site doesn't exist?  I've followed every step 
> in the tutorial exactly, with no problems so far...  Can anyone help me 
> with this?
>
> Thanks,
> Laurence MacNeill
> Mableton, Georgia, USA
>
>
> -- 
> 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/-/Aq18U3mxM1MJ.
> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/FA-ss7hNR50J.
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.



Where are my posts?

2012-06-16 Thread Laurence MacNeill
How do I get privileges to post in this group?  I've posted two questions, 
and have not seen them pop up yet...  Who do I need to contact to get 
posting privileges?  I really was hoping to get these questions answered 
soon.

Thanks,
Laurence MacNeill
Mableton, Georgia, USA

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



How do I get django working without having to manually run the server?

2012-06-16 Thread Laurence MacNeill
Ok...  I'm still learning this stuff here, and I'm confused about one 
thing...  Well, many things, actually, but only one thing that I'll ask 
about here.

During the tutorial I have to type "python manage.py runserver" in order to 
see my django pages in a web-browser.  Obviously, I don't want to do this 
for anything but the tutorial...  In fact, I don't even want to do this for 
the tutorial -- I have apache and mod_wsgi already running on this machine, 
so why won't those things just automatically serve up these django pages 
I'm creating?  What more do I need to do to get apache and mod_wsgi to 
server my django pages?

Thanks,
Laurence MacNeill
Mableton, Georgia, USA

-- 
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/-/XyTCXN8L3FIJ.
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 Tutorial part 2... Admin Site won't work...

2012-06-16 Thread Laurence MacNeill
I'm going through the django tutorial and I'm having difficulties at the 
beginning of the second part...

It tells me to create the admin site, and browse to 127.0.0.1:8000/admin to 
log in to the admin site I just created...  But when I do that, I get the 
python server telling me that the site is not found -- it's not the usual 
apache web-server 404 error, it's definitely coming from the python server, 
so I know that's running properly.

Searching through some of the other posts, I came across one responder who 
asked someone with this same problem to find their site ID in their 
settings.py file.  Mine says the site ID is 1.  So, armed with that 
information, I go to the python shell, and type the following:
>>> from django.contrib.sites.models import Site
>>> Site.objects.get(id=1)

And I get the following in response:
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 
131, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 
366, in get
% self.model._meta.object_name)
DoesNotExist: Site matching query does not exist.

So, it seems that the entire site doesn't exist?  I've followed every step 
in the tutorial exactly, with no problems so far...  Can anyone help me 
with this?

Thanks,
Laurence MacNeill
Mableton, Georgia, USA

-- 
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/-/Aq18U3mxM1MJ.
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: AttributeError at /admin/coltrane/entry/add/ 'Entry' object has no attribute 'pubdate'

2012-04-07 Thread laurence Turpin
Thank you  akaariai for replying to my post.
When I looked at the problem the next day I had a different problem.
I have since learnt that when you create a django project in eclipse you 
should not select the option for an src folder as it confuse django. I have
therefore decided to restart from scratch.

On Wednesday, 4 April 2012 08:43:09 UTC+1, akaariai wrote:
>
> Do you get a stacktrace from the error? You should get one, and it 
> should point out the code-path to the erroneous pubdate usage. If you 
> do not get one for one reason or another, search your project for the 
> string "pubdate" and go through all locations containing that string. 
>
> The code snippets you have below seem clean to me. 
>
>  - Anssi 
>
> On Apr 3, 10:59 pm, laurence Turpin <laurencejosephtur...@gmail.com> 
> wrote: 
> > Hello, 
> > 
> > I'm trying to learn Django from the book "Practical Django Projects 2nd 
> > Edition" 
> >  I'm using Django 1.3.1 and Python 2.7.2 on Windows 7 
> > Also I'm using Eclipse Indigo with pydev 
> > 
> > The current project I'm working on is to create a Weblog called 
> coltrane. 
> > coltrane is an application that exists in a project called 
> > "cmswithpythonanddjango" 
> > 
> > Inside the models.py is a class called Entry which holds the fields used 
> to 
> > Enter a weblog entry. 
> > When I go to localhost:8000/admin/I get the option to add and Entry. 
> > I can select this option fill out sample data, but when I try to save 
> it. 
> > I get the following error. 
> > 
> > AttributeError at /admin/coltrane/entry/add/ 
> > 
> > 'Entry' object has no attribute 'pubdate' 
> > 
> > There is a field called pub_date in Entry 
> > 
> > It's as if I have made a typing error somewhere and typed pubdate 
> instead of pub_date. 
> > 
> > Below is the models.py, views.py , url.py , and admin.py files 
> > 
> > 
> //
>  
>
> > 
> > Here is my models.py 
> > 
> > 
> /
>  
>
> > 
> > from django.db import models 
> > import datetime 
> > from tagging.fields import TagField 
> > from django.contrib.auth.models import User 
> > from markdown import markdown 
> > 
> > class Category(models.Model): 
> > title = models.CharField(max_length=250, help_text="Maximum 250 
> > characters.") 
> > slug = models.SlugField(help_text="Suggested value automatically 
> > generated from title. Must be unique.") 
> > description = models.TextField() 
> > 
> > class Meta: 
> > ordering = ['title'] 
> > verbose_name_plural = "Categories" 
> > 
> > def __unicode__(self): 
> > return self.title 
> > 
> > def get_absolute_url(self): 
> > return "/categories/%s/" % self.slug 
> > 
> > class Entry(models.Model): 
> > LIVE_STATUS = 1 
> > DRAFT_STATUS = 2 
> > HIDDEN_STATUS = 3 
> > STATUS_CHOICES = ( 
> > (LIVE_STATUS, 'Live'), 
> > (DRAFT_STATUS, 'Draft'), 
> > (HIDDEN_STATUS, 'Hidden') 
> > ) 
> > 
> > # Core fields 
> > title = models.CharField(max_length=250, help_text = "Maximum 250 
> > characters. ") 
> > excerpt = models.TextField(blank=True, help_text = "A short summary 
> of 
> > the entry. Optional.") 
> > body = models.TextField() 
> > pub_date = models.DateTimeField(default = datetime.datetime.now) 
> > 
> > # Fields to store generated HTML 
> > excerpt_html = models.TextField(editable=False, blank=True) 
> > body_html = models.TextField(editable=False, blank=True) 
> > 
> > # Metadata 
> > author = models.ForeignKey(User) 
> > enable_comments = models.BooleanField(default=True) 
> > featured = models.BooleanField(default=False) 
> > slug = models.SlugField(unique_for_date = 'pub_date', help_text = 
> > "Suggested value automatically generated from title. Must be unique.") 
> > status = models.IntegerField(choices=STATUS_CHOICES, 
> > default=LIVE_STATUS, help_text = "Only entries with 

AttributeError at /admin/coltrane/entry/add/ 'Entry' object has no attribute 'pubdate'

2012-04-03 Thread laurence Turpin
Hello,

I'm trying to learn Django from the book "Practical Django Projects 2nd 
Edition"
 I'm using Django 1.3.1 and Python 2.7.2 on Windows 7
Also I'm using Eclipse Indigo with pydev 

The current project I'm working on is to create a Weblog called coltrane.
coltrane is an application that exists in a project called 
"cmswithpythonanddjango"

Inside the models.py is a class called Entry which holds the fields used to 
Enter a weblog entry.
When I go to localhost:8000/admin/I get the option to add and Entry.
I can select this option fill out sample data, but when I try to save it.
I get the following error.

AttributeError at /admin/coltrane/entry/add/

'Entry' object has no attribute 'pubdate'


There is a field called pub_date in Entry

It's as if I have made a typing error somewhere and typed pubdate instead of 
pub_date.

Below is the models.py, views.py , url.py , and admin.py files


//

Here is my models.py

/

from django.db import models
import datetime
from tagging.fields import TagField
from django.contrib.auth.models import User
from markdown import markdown



class Category(models.Model):
title = models.CharField(max_length=250, help_text="Maximum 250 
characters.")
slug = models.SlugField(help_text="Suggested value automatically 
generated from title. Must be unique.")
description = models.TextField()

class Meta:
ordering = ['title']
verbose_name_plural = "Categories"

def __unicode__(self):
return self.title

def get_absolute_url(self):
return "/categories/%s/" % self.slug

class Entry(models.Model):
LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
(LIVE_STATUS, 'Live'),
(DRAFT_STATUS, 'Draft'),
(HIDDEN_STATUS, 'Hidden')
)

# Core fields
title = models.CharField(max_length=250, help_text = "Maximum 250 
characters. ")
excerpt = models.TextField(blank=True, help_text = "A short summary of 
the entry. Optional.")
body = models.TextField()
pub_date = models.DateTimeField(default = datetime.datetime.now)

# Fields to store generated HTML
excerpt_html = models.TextField(editable=False, blank=True)
body_html = models.TextField(editable=False, blank=True)

# Metadata
author = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
featured = models.BooleanField(default=False)
slug = models.SlugField(unique_for_date = 'pub_date', help_text = 
"Suggested value automatically generated from title. Must be unique.")
status = models.IntegerField(choices=STATUS_CHOICES, 
default=LIVE_STATUS, help_text = "Only entries with live status will be 
publicly displayed.")

# Categorization.
categories = models.ManyToManyField(Category)
tags = TagField(help_text = "Separate tags with spaces.")
   
class Meta:
verbose_name_plural = "Entries"
ordering = ['-pub_date']

def __unicode__(self):
return self.title

def save(self, force_insert=False, force_update=False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save(force_insert, force_update)

def get_absolute_url(self):
return "/weblog/%s/%s/" % 
(self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)

///

Here is the views.py

//

from django.shortcuts import render_to_response

from cmswithpythonanddjango.coltrane.models import Entry

def entries_index(request):
return render_to_response('coltrane/entry_index.html', { 'entry_list': 
Entry.objects.all() })

///

Here is the url.py


Re: IntegrityError at /register/ auth_user.username may not be NULL

2012-03-28 Thread laurence Turpin


On Mar 28, 9:38 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Wednesday, 28 March 2012 20:31:09 UTC+1, laurence Turpin wrote:
>
> > I'm getting the following error with my registration  section of my
> > program.
>
> > IntegrityError at /register/
> > auth_user.username may not be NULL
>
> > I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the
> > database.
> > I am a newbie and I'm learning Djanogo from the book "Learning website
> > development with Django"
>
> > The registration form is displayed ok  and I'm able to fill it out and
> > it is when I click register that the problem occurs.
>
> > /// 
> > /// 
> > /
>
> > My views.py  looks like the following and register_page is the
> > relevant function here:
>
> > 
>
> >     def clean_username(self):
> >         username = self.cleaned_data['username']
> >         if not re.search(r'^\w+$', username):
> >             raise forms.ValidationError('Username can only contain
> > alphanumeric characters and underscores')
> >             try:
> >                 User.objects.get(username=username)
> >             except ObjectDoesNotExist:
> >                 return username
> >             raise forms.ValidationError('Username already taken. ')
>
> Looks like you have an indentation problem in clean_username - the lines
> under the first "raise forms.ValidationError" should be one level to the
> left, otherwise they will never be reached and the method will never return
> the cleaned value for username.
> --
> DR.

Thank you Danial you are absolutely right. I tried what you said and
it works fine now.

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



IntegrityError at /register/ auth_user.username may not be NULL

2012-03-28 Thread laurence Turpin
I'm getting the following error with my registration  section of my
program.

IntegrityError at /register/
auth_user.username may not be NULL

I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the
database.
I am a newbie and I'm learning Djanogo from the book "Learning website
development with Django"

The registration form is displayed ok  and I'm able to fill it out and
it is when I click register that the problem occurs.

///

My views.py  looks like the following and register_page is the
relevant function here:

///

from django.http import Http404
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib.auth import logout
from django.template import RequestContext
from bookmarks.bookmarksapp.forms import RegistrationForm


def main_page(request):
return render_to_response(
'main_page.html', RequestContext(request)
)

def user_page(request, username):
try:
user = User.objects.get(username=username)
except:
raise Http404('Requested user not found')

bookmarks = user.bookmark_set.all()
variables = RequestContext(request, {
'username': username,
'bookmarks': bookmarks
})
return render_to_response('user_page.html', variables)

def logout_page(request):
logout(request)
return HttpResponseRedirect('/')

def register_page(request):
if request.method =='POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.user = User.objects.create_user(
username = form.cleaned_data['username'],
password = form.cleaned_data['password1'],
email = form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
else:
form = RegistrationForm()
variables = RequestContext(request, {
   'form': form
})
return render_to_response(
   'registration/register.html',
   variables
)

///

My forms.py  is the following:

///

from django import forms
import re
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

class RegistrationForm(forms.Form):
username = forms.CharField(label="Username", max_length=30)
email = forms.EmailField(label='Email')
password1 = forms.CharField(
label='Password',
widget=forms.PasswordInput()
)
password2 = forms.CharField(
label='Password',
widget=forms.PasswordInput()
)

def clean_password2(self):
if 'password1' in self.cleaned_data:
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
raise forms.ValidationError('Passwords do not match.')

def clean_username(self):
username = self.cleaned_data['username']
if not re.search(r'^\w+$', username):
raise forms.ValidationError('Username can only contain
alphanumeric characters and underscores')
try:
User.objects.get(username=username)
except ObjectDoesNotExist:
return username
raise forms.ValidationError('Username already taken. ')

///

my register.html looks like the following:

///

{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}
{% csrf_token %}
{{ form.as_p }}


{% endblock %}

///

I hope somebody has an idea of what the problem is all I know is it's
something to do with the database.

The exception location is:

Groups Model Randomly Disappears In the Admin View

2011-08-30 Thread Laurence
I have a very strange problem that I am having difficultly in
debugging. In my application I have registered two models, each of
which contains two classes. When I go to the admin view, the groups
class from the auth model sometimes disappears. If I keep refreshing,
it will appear then disappear almost randomly. Does anyone know what
the cause might be or how I can debug this. I am using Django v1.2.5.

Thanks,

Laurence

-- 
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 on Debian Sarge?

2006-07-03 Thread Dustin Laurence
On Mon, Jul 03, 2006 at 07:54:44AM -0700, Rudolph wrote:

> I've got Django running on Sarge and de default mod_python package. No
> problem at all.

Perfect, that's what I was hoping someone would say.  What about putting
a note at

http://www.djangoproject.com/documentation/install/

that the previous note about Sarge's mod_python not being sufficient is
wrong?  Presumably it should come from someone who knows first-hand.

Dustin


pgp4q3VN7qY9L.pgp
Description: PGP signature


Re: Django on Debian Sarge?

2006-07-02 Thread Dustin Laurence
On Sun, Jul 02, 2006 at 09:09:59PM -0700, Iain Duncan wrote:
> 
> I haven't installed on Sarge, but on Gentoo it's no problem because
> installing the newest stable packages is the default ( sarge's are
> tested much longer with much longer release cycle ).

I normally would assume so, but here is what bothered me.  From the
install page comments:

> pol April 21, 2006 at 4:23 p.m.
>
> Though is says states that only "mod_python 3.x" is required, this is
> wrong. You must ahve version 3.2.7 at least. Debian (sarge) stable only
> includes 3.1.3, so you will have to get and install the newest version
> of mod_python manually.

but

lindy laurence # emerge mod_python -p

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-python/mod_python-3.1.4-r1
lindy laurence #

which would indicate that Gentoo's stable mod_python still isn't new
enough, odd as that sounds.  It's only one patchlevel higher than
Sarge's version.

> ...My home dev box is
> gentoo, all I had to do was emerge mod_python and the mysqldb e-build (
> can't remember name ), checkout django from svn, and follow the
> instructions on the tutorial.

OK, well, that's reassuring, and maybe indicates that that comment is
wrong and Sarge is likely to work too.

Dustin



pgpexRcom6bJ0.pgp
Description: PGP signature


Django on Debian Sarge?

2006-07-02 Thread Dustin Laurence
Hi, I was looking at trying Django for a project and noticed that in the
comments to the installation directions it was claimed that Debian
Sarge's mod_python isn't recent enough to run Django.  That would be a
big complication.  Is anyone running Django on Sarge, and can anyone
confirm that it does/does not need something besides the bog-standard
apache2/mod_python/postgres/etc already in the stable package pool?

Though it's much less important, I wouldn't mind knowing the same answer
for Gentoo (with just x86 keywords) since it might be handy to do some
development on a Gentoo laptop.

Dustin



pgpZNjkLIvwIb.pgp
Description: PGP signature