Override queryset for admin Inline

2010-08-06 Thread Nick
I have an admin set up with three inlines.  I would like to filter the
inline's editable options by a variable that is defined in a settings
file.  I can over ride the actual admin pieces for each of the inlines
(they all have full admin screens of their own). But I can't seem to
get the standard def queryset(self, request): etc. over ride to work
for inlines. I have seen a little talk about how inlines require you
to create a new manager to filter the list of options.

Here is my inline admin code:

class CandidateInline(admin.TabularInline):
 model = Candidate

fields = ['%s_vote' % (race_type)]

extra = 0

 ordering = ('party', 'last_name')

## here is where the trouble is starting, I'd like to get rid of
everything that isn't status 1 ###

 def queryset(self, request):
 qs = super(CandidateInline, self).queryset(request)
return qs.filter(status="1").exclude(party="Independent")


and here is the primary admin model that this inline is attached to:

class RaceAdmin(admin.ModelAdmin):


 inlines = [
CandidateInline,
PrecinctInline,
]


form = RaceForm

 fieldsets = (
 ('General Race Information', {

'fields': ('name', 'office_name', 'type', 'county',
'general_winner')
 }),
   ('Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
   'fields': ('runoff_winner_d', 'runoff_winner_r',
'primary_advance_d', 'primary_advance_r'),
}),
('Non Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
'fields': ('runoff_winner_np',)
}),
 )
   list_display = ('name', 'type', 'county', )
list_filter = ('type', 'office_name', 'county')
ordering = ['name']


 # redefine the queryset to get rid of finals
def queryset(self, request):
qs = super(RaceAdmin, self).queryset(request)
return qs.filter(type="2")

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



Re: Django IDE

2010-08-03 Thread Nick Arnett
On Sun, Jul 18, 2010 at 10:19 AM, Biju Varghese <bijukava...@gmail.com>wrote:

> Eclipse is the best IDE for python and django.
>
>
I don't know if it is actually the best, but I'm happy with it.

Nick

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



Re: Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
On Mon, Aug 2, 2010 at 9:39 AM, Antoni Aloy <antoni.a...@gmail.com> wrote:

> My first thought would be to backup the database, then put the project
> under South control. Then create a one-to-one relation between models
> and the possible create a upgrade script.
> Then, if necessary, you could create properties in the original model
> to map the names you have in your application.


Interesting idea... anybody here ever tried anything like that?

Nick

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



Re: Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
On Mon, Aug 2, 2010 at 2:34 PM, Steve Holden <holden...@gmail.com> wrote:

>
> Another alternative would be to create a view of the joined tables using
> SQL CREATE VIEW, then treat the view as a table in Django. You do have
> to be careful that the view should be updatable, though.


Ah... I didn't think of views.  Haven't used them in a while, but that's
worth a shot, I think, since that way, I might not have to touch the Django
code at all.

Nick

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



Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
I'm thinking that I could get a pretty good performance improvement on a
couple of tables by moving their LONGTEXT columns into their own tables.
Just wondering if there's anybody here who has done something like that - is
there a way to do this transparently to Django, so I don't have to re-write
every piece of code that uses those tables.

In other words, I'm looking at vertical partitioning, but only across
tables, not databases, as transparently as possible to the code that I've
already written.

Thanks in advance for any pointers.

Nick

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



updating admin values with other fields

2010-07-27 Thread Nick
I have a save override in my admin file that catches a value from one
field and applies it to another. The values it grabs from a manytomany
field.

I can get it to work, but only when I save twice. It looks like it
needs the manytomany to update with the new values and then it needs
to second save to assigne the values to the other field.

Here is the method override:

 def save_model(self, request, obj, form, change):
obj.primary_winner_r = obj.primary_advance_r.values_list('id',
flat=True)
obj.primary_winner_d = obj.primary_advance_d.values_list('id',
flat=True)
obj.primary_winner_np =
obj.primary_advance_np.values_list('id', flat=True)
obj.save()

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



Re: save a values_list to a charfield

2010-07-27 Thread Nick
It is a bit of a last minute deal and will be changed after today, but
we had a handful of "improvements" handed down to us from management
and this was the fastest thing we could come up with using some old
mysql query logic and several already built templates for output.

I appreciate the help.

On Jul 27, 2:49 pm, ringemup <ringe...@gmail.com> wrote:
> ', '.join(primary_ids)
>
> The fact that you're doing this with foreign keys, though, suggests to
> me that you may have a database normalization problem.
>
> On Jul 27, 3:26 pm, Nick <nickt...@gmail.com> wrote:
>
> > I am getting this to save but I can't get it to output properly
>
> > it's outputting as [16L, 451L, 521L] for a list of id's, which it
> > should according to documentation.  However, how can I output it like
> > this 16, 451, 521
>
> > On Jul 27, 12:11 pm, Nick <nickt...@gmail.com> wrote:
>
> > > I am needing to do some duct taping for a project that is going on
> > > right now. In it I need to take a values_list of id's from a
> > > ManyToMany field and save those values to a varchar field so a mysql
> > > query can access the values. I am working with two different sets of
> > > developers and this is the best we can come up with in such a short
> > > period of time
>
> > > Here is the model:
>
> > > Candidate
> > >     filing_id = models.IntegerField()
> > >     name = models.CharField()
>
> > > Race:
> > >     name = models.CharField()
> > >     primary_advance = models.ManyToManyField('Candidate')
> > >     primary_advnace_list = models.CahrField()
>
> > >     def(save, *args, **kwargs):
> > >         primary_ids = self.primary_advace.values_list('id', flat=True)
> > >         if primary_ids.count() > 0:
> > >             primary_advance_list = primary_ids
> > >         else:
> > >             primary_advance_list = []
> > >         super(Race, self).save(*args, **kwargs)
>
> > > I've tried this but I'm coming back with empty values for the list
> > > fields.

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



Re: save a values_list to a charfield

2010-07-27 Thread Nick
I am getting this to save but I can't get it to output properly

it's outputting as [16L, 451L, 521L] for a list of id's, which it
should according to documentation.  However, how can I output it like
this 16, 451, 521

On Jul 27, 12:11 pm, Nick <nickt...@gmail.com> wrote:
> I am needing to do some duct taping for a project that is going on
> right now. In it I need to take a values_list of id's from a
> ManyToMany field and save those values to a varchar field so a mysql
> query can access the values. I am working with two different sets of
> developers and this is the best we can come up with in such a short
> period of time
>
> Here is the model:
>
> Candidate
>     filing_id = models.IntegerField()
>     name = models.CharField()
>
> Race:
>     name = models.CharField()
>     primary_advance = models.ManyToManyField('Candidate')
>     primary_advnace_list = models.CahrField()
>
>     def(save, *args, **kwargs):
>         primary_ids = self.primary_advace.values_list('id', flat=True)
>         if primary_ids.count() > 0:
>             primary_advance_list = primary_ids
>         else:
>             primary_advance_list = []
>         super(Race, self).save(*args, **kwargs)
>
> I've tried this but I'm coming back with empty values for the list
> fields.

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



save a values_list to a charfield

2010-07-27 Thread Nick
I am needing to do some duct taping for a project that is going on
right now. In it I need to take a values_list of id's from a
ManyToMany field and save those values to a varchar field so a mysql
query can access the values. I am working with two different sets of
developers and this is the best we can come up with in such a short
period of time


Here is the model:

Candidate
filing_id = models.IntegerField()
name = models.CharField()

Race:
name = models.CharField()
primary_advance = models.ManyToManyField('Candidate')
primary_advnace_list = models.CahrField()

def(save, *args, **kwargs):
primary_ids = self.primary_advace.values_list('id', flat=True)
if primary_ids.count() > 0:
primary_advance_list = primary_ids
else:
primary_advance_list = []
super(Race, self).save(*args, **kwargs)

I've tried this but I'm coming back with empty values for the list
fields.

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



Re: Custom admin input app

2010-07-26 Thread Nick
Completely missed that section. You are always very helpful, Daniel.
Thank you.

On Jul 26, 10:08 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 26, 3:56 pm, Nick <nickt...@gmail.com> wrote:
>
> > Has anyone heard of, see, or used an app that would transform the
> > table view of the admin into a data entry point, basically jumping the
> > need to click through to individual entries in order to edit them?
>
> This is built-in, to an extent - 
> seehttp://docs.djangoproject.com/en/1.2/ref/contrib/admin/#admin-list-ed...
> --
> DR.

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



Custom admin input app

2010-07-26 Thread Nick
Has anyone heard of, see, or used an app that would transform the
table view of the admin into a data entry point, basically jumping the
need to click through to individual entries in order to edit them?

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



modelformset vs. inlineformset vs. DIY

2010-07-23 Thread Nick
I have inherited a project with a tight deadline and I am lost for how
to proceed.

There are two tables: Canididates and Race.

The race table holds 145 different races with information about
precincts, winners of different stages of the race (primary, runoff,
gneral)

The Candidates table has 1100+ candidates, each one is assigned to a
specific race via a FK and a list of three race vote totals (general,
runoff, primary)

I am supposed to create a way to display each race based on a search
and then return the candidates associated with that race so that the
race vote totals can be updated. I will also need to be able to update
values in the Race table.

It would be highly preferable for this to be seemless for the data
input people. I am looking at producing something like this:

Race 1
precincts reporting input - precincts total (static value)
Candidate 1 primary vote input - Candidate 1 status (active,
eliminated)
Candidate 2 primary vote input - Candidate 2 status (active,
eliminated)

winner of primary (list of candidates)

I have most of the form fields and widgets ready to go, but being able
to edit multiple entries in two different tables seemless has me
stuck.  Is this something that I should handle in inlineformsets since
I am spanning an FK? Would I need modelformsets to display all of the
candidates?

I can easily truncate the Race table and change it so that it has a
many to many relationship to all of the candidates instead of the
Candidates having an FK relationship to the race? Would that give me
more flexibility?

Thanks for the help in figuring this out, this has been an incredibly
stressful project.

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



Re: values() returning more than values

2010-07-22 Thread Nick
This is still an issue I'm seeing. I don't know how it can return the
proper count but then when i request the actual values it spits out 9
times as many

On Jul 21, 11:08 pm, Nick <nickt...@gmail.com> wrote:
> It looks like its returning every organization instance in the table,
>
> There are about 190 organizations and 900 totals entries, each of
> which are assigned an organization.
>
> The count on the query is correct, but when I output the actualvalues
> it returns every entry in the table, so I'm seeing multiple duplicate
> organizations.
>
> On Jul 21, 10:47 pm, Kenneth Gonsalves <law...@au-kbc.org> wrote:
>
> > On Thursday, July 22, 2010 09:10:31 am Nick wrote:
>
> > > Readers = Readers.objects.values_list('organization').distinct()
>
> > > The count returns 189 results but when I send it to output to a csv it
> > > returns all of thevalues, with duplicates which is something like 900
> > > entries.
>
> > by duplicates do you mean the whole row is duplicate or it is duplicate with
> > the exception of the id of the row?
> > --
> > Regards
> > Kenneth Gonsalves
> > Senior Associate
> > NRC-FOSS at AU-KBC

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



Re: using the update() method

2010-07-22 Thread Nick
That was only returning the F('library') piece of the code for sorter

I rewrote the update like this:

for reader in readers:
reader.sorter = "%s%s" % (reader.library, reader.book)
reader.save()

On Jul 21, 6:08 pm, Santiago Perez <san...@santip.com.ar> wrote:
> I think that what you want can be accomplished by:
>
> from django.db.models import F
>
> readers = Readers.objects.filter(status=active)
> readers.update(sorter=(F('library') + F('book'))
>
>
>
> On Wed, Jul 21, 2010 at 19:40, Nick <nickt...@gmail.com> wrote:
>
> > I am trying to loop through a queryset and assign values to a field
> > based on other values in that entry.
>
> > So something like this
>
> > readers = Readers.objects.filter(status=active)
>
> > for reader in readers:
> >    library = reader.library
> >    book = reader.book
>
> > readers.update(sorter="%s%s" % (lirbary, book))
>
> > however, when I run the update it assigns the same value to all of the
> > readers.  I would like this to assign the value to sorter based on
> > what their individual library and book choices are.
>
> > reader.update return and error "reader has no attribute 'update'"
>
> > --
> > You received this message because you are subscribed to the Google Groups
>
> "Django users" group.> To post to this group, send email to 
> django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
>
> django-users+unsubscr...@googlegroups.com<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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: values() returning more than values

2010-07-21 Thread Nick
It looks like its returning every organization instance in the table,

There are about 190 organizations and 900 totals entries, each of
which are assigned an organization.

The count on the query is correct, but when I output the actual values
it returns every entry in the table, so I'm seeing multiple duplicate
organizations.

On Jul 21, 10:47 pm, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> On Thursday, July 22, 2010 09:10:31 am Nick wrote:
>
> > Readers = Readers.objects.values_list('organization').distinct()
>
> > The count returns 189 results but when I send it to output to a csv it
> > returns all of the values, with duplicates which is something like 900
> > entries.
>
> by duplicates do you mean the whole row is duplicate or it is duplicate with
> the exception of the id of the row?
> --
> Regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC

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



values() returning more than values

2010-07-21 Thread Nick
I may be misunderstanding the values method but it is returning
duplicate results when I use the distinct method. I have a query that
pulls the values of a column:

Readers = Readers.objects.values_list('organization').distinct()

The count returns 189 results but when I send it to output to a csv it
returns all of the values, with duplicates which is something like 900
entries.

Any help is appreciated.

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



using the update() method

2010-07-21 Thread Nick
I am trying to loop through a queryset and assign values to a field
based on other values in that entry.

So something like this

readers = Readers.objects.filter(status=active)

for reader in readers:
library = reader.library
book = reader.book

readers.update(sorter="%s%s" % (lirbary, book))

however, when I run the update it assigns the same value to all of the
readers.  I would like this to assign the value to sorter based on
what their individual library and book choices are.

reader.update return and error "reader has no attribute 'update'"

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



Re: formatting values list

2010-07-21 Thread Nick
Perfect, thanks

On Jul 21, 4:50 pm, n3ph <n...@terminal21.de> wrote:
>  Definitely the better way..
>
> On 07/21/10 23:42, Franklin Einspruch wrote:
>
> > Nick,
>
> > I think you're looking for this:
>
> >http://docs.djangoproject.com/en/dev/howto/outputting-csv/
>
> > Franklin
>
> > On Wed, Jul 21, 2010 at 5:38 PM, Nick <nickt...@gmail.com> wrote:
> >> I would like to format the output of a values_list into something a
> >> little more usable for a CSV.
>
> >> My view is really simple
>
> >> def values_view(request)
> >>    list = MyModel.objects.values_list('id', 'name', 'type')
> >>    template = loader.get_template('mytemp.html')
> >>    c = Context({'list': list})
> >>    html = t.render(c)
> >>    HttpResponse(html)
>
> >> my template looks like this
>
> >> {% for item in list %}
> >> {{item}}
> >> {% endfor %}
>
> >> it spits out a list of things like this:
>
> >> (u'id', u'name', u'type), (u'id2', u'name2', u'type2)
>
> >> etc. etc.
>
> >> How can I format a values_list so I could return something like a
> >> table or csv?
>
> >> so:
>
> >> id, name, type
> >> id2, name, type
>
> >> etc. etc.
>
> >> Thanks for the help
> >> Nick
>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to 
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/django-users?hl=en.
>
>
>
>  signature.asc
> < 1KViewDownload

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



formatting values list

2010-07-21 Thread Nick
I would like to format the output of a values_list into something a
little more usable for a CSV.

My view is really simple

def values_view(request)
list = MyModel.objects.values_list('id', 'name', 'type')
template = loader.get_template('mytemp.html')
c = Context({'list': list})
html = t.render(c)
HttpResponse(html)

my template looks like this

{% for item in list %}
{{item}}
{% endfor %}

it spits out a list of things like this:

(u'id', u'name', u'type), (u'id2', u'name2', u'type2)

etc. etc.

How can I format a values_list so I could return something like a
table or csv?

so:

id, name, type
id2, name, type

etc. etc.

Thanks for the help
Nick

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



Re: Django memory requirements

2010-07-19 Thread Nick Arnett
On Mon, Jul 19, 2010 at 10:01 AM, Tereno <ter...@gmail.com> wrote:

> Web Faction does look like an interesting option. However, looking at
> the memory specs, how would I be able to tell if it's sufficient for
> at least 2 Django applications? For example, if I got with Shared 1, I
> get 80MB (180MB VPS) - I'm assuming that's not going to be enough
> right? Of course it does depend on the application itself but in
> general, do you reckon it can support 2 Django apps?


The only honest answer is "it depends."  But the good news about Webfaction,
which I've been using for about six months, is that you can start with the
cheapest option and then upgrade at any time.  And downgrade.  They make it
easy.

You'll get warnings from them immediately if you exceed the allocated
memory.

I was able to run a database-intensive app under Shared 1 for a long time.
It was only when I started doing some heavier analysis that I had to bump up
to Shared 2.

Nick

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



Re: www.djangoproject.com

2010-07-15 Thread Nick Raptis

On 07/15/2010 02:20 PM, Russell Keith-Magee wrote:


You, mean, like... oh, I don't know... one of the core developers of
Django? Like the one that's been asking for details on how to
reproduce the problem? :-)

Yours,
Russ Magee %-)

   

Ahaha! Exactly! Nice to make your acquittance Russ.
Knowing who is who is a bit of magic art on lists, unless of course you 
google every email :)


To my mind, the devs and the site maintainers don't have to be the same 
people, but I threw it on the list so someone (turns out to be you) 
could get the word through.

Mischief managed :)

your obliged new-guy,
Nick

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



Re: www.djangoproject.com

2010-07-15 Thread Nick Raptis

On 07/15/2010 05:55 AM, Danny Adair wrote:

Hi,

I had the exact same problem, and I had _not_ installed Weave.
The offending config entry in my case was:
"chrome://global/locale/intl.properties"
and it was at the bottom of the accepted languages list. This is on
Firefox 3.6.6

I can reproduce the problem anytime by visiting about:config and
changing "intl.accept_languages" to
en-nz,en,de,chrome://global/locale/intl.properties

*.djangoproject.com will stop responding, (all?) other websites seem fine.

Cheers,
Danny


Yep, that's the one!
I tried to open chrome://global/locale/intl.properties as a link in 
Firefox, and (oh, the surprise :P ) it's a settings file.
Either the file doesn't get resolved unto something useful in my 
platform (I'm using ubuntu-based) or it's something depreciated and it's 
a migration issue.
Also checked the Firefox bugzilla and there are indeed a couple of bug 
reports for it.


My feelings still stand. Other than making sure that django itself 
handles such erroneous values gracefully,  the list shouldn't be too 
concerned about it.


Now, I wonder if there's a way we can give a heads-up to the 
djangoproject.com and djangobook.com maintainers a heads-up on this is 
issue, so they can cater for it.


Nick

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



Re: www.djangoproject.com

2010-07-14 Thread Nick Raptis

On 07/14/2010 02:28 PM, Russell Keith-Magee wrote:


I'm glad we've worked out that Weave is the culprit, but nobody has
answered the question of whether this is an indicator of a problem
with Django itself. What is weave passing as a header (and under what
conditions) that is causing a problem? Is there a need to improve
Django's error handling to protect against this case?

Yours,
Russ Magee %-)

   

Hi Russ.
I hate to admit that I didn't saved that offending value so someone can 
reproduce this.


My reasoning back then for not raising a bug on django was this:
1. It was an obvious invalid value. As I said, Weave probably introduced 
it at some point (I guess while still in beta) but other than that, it 
could also be a number of things. Fixing that locale value solves it for 
good. So I rinsed, wiped, forgot.
2. I tried to access some other django-powered sites with l10n, and they 
loaded just fine. Only djangoproject.com and djangobook.com had the 
problem. So my guess was that it was caused by something else on that 
sites' stack and not django itself.

3. Improving the error-handling of django just didn't cross my mind.

I hope someone else with the same problem here could provide you with 
the offending value.


Nick

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



Re: Trouble writing a view for a model

2010-07-12 Thread Nick
I think a choice field is probably best, then you can customize the
presentation in a forms file.

class Question(models.Model):
q_cjoices = (
('choice1', 'choice1'),
('choice2', 'choice2'),
('choice3', 'choice3'),
('choice4', 'choice4'),
('choice5', 'choice5'),
)

title = modelsForeignKey(Title)
choices = models.CharField(choices=q_choices, max_length=100)

In the form declaration you can use this

from models.Questions import q_choices
from django.forms.extras.widgets import RadioSelect

choices = forms.CharField(choices=q_choices, widget=RadioSelect)

That would work unless you want someone to be able add choices based
on individual questions in which case you'll need to use a many to
many field, something like this:

Question(models.Model)
title = models.ForeignKey(Title)
Choice = models.ManyToManyField(Choice)

class Choice(models.CharField)
choice_1 = models.CharField( etc. etc. etc.



On Jul 12, 4:21 pm, rupert  wrote:
> Thanks for replying.
>
> I'm ultimately trying to create a feedback form where there is a list
> of say 10 questions with 5 choices for response to each question. It
> also needs to be editable in the admin (and I can't get forms to be
> editable in the admin).
>
> On Jul 12, 5:11 pm, Rodion Raskolnikiv  wrote:
>
> > Rupert,
> > Without knowing what you are aiming to accomplish, my advice might not
> > be pertinent. However, it looks like your models could be rearranged
> > like this:
>
> > class Question(models.Model):
> >     question = models.CharField(max_length=200)
> >     pub_date = models.DateTimeField('date published')
>
> > class Choice(models.Model):
> >     poll = models.ForeignKey(Question)
> >     choice = models.CharField(max_length=200)
> >     votes = models.IntegerField()
>
> > (Slightly modified from:http://docs.djangoproject.com/en/dev/intro/
> > tutorial01/)
>
> > On Jul 12, 1:49 pm, rupert  wrote:
>
> > > For this code:
>
> > > class Title(models.Model):
> > >         title = models.CharField(max_length=200)
> > >         pub_date = models.DateTimeField('date published')
>
> > >         def __unicode__(self):
> > >                 return self.title
>
> > >         def was_published_today(self):
> > >                 return self.pub_date.date() == datetime.date.today()
>
> > > class Question(models.Model):
> > >         title = models.ForeignKey(Title)
> > >         question = models.CharField(max_length=200)
> > >         choice1 = models.CharField(max_length=200)
> > >         choice2 = models.CharField(max_length=200)
> > >         choice3 = models.CharField(max_length=200)
> > >         choice4 = models.CharField(max_length=200)
> > >         choice5 = models.CharField(max_length=200)
>
> > >         def __unicode__(self):
> > >                 return self.question
>
> > > I'm trying to write a view where it outputs like this
>
> > > Question
>
> > > Choice 1-choice 5 in a radio button

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



__init__ custom form validation

2010-07-12 Thread Nick
I am working on a validation that will require a field be filled in if
it is another field enters on of three values:

For example:

I have a form

class myform(forms.Modelform):
field1 = forms.CharField
field2 = forms.Charfield
field3_type = forms.CharField(choices=choices)
field3 = forms.DateTimeField(required=True)

def __init__(self, field3_type, *args, **kwargs):
super(myform, self_.__init__(*args, **kwargs)
if field3_type in ('option 1', 'option 2', 'option 3'):
self.field['field3'] = forms.DateTiemField(required=False)

The view:
if request.method == 'POST':
form = myform(request.POST)
field3_type = form.cleaned_data['field3_type']
if form.is_valid():
# some form processing
else:
   form = myform()

When i try to use the form I get an error at the myform() line stating
that __init__ takes exactyl 2 arguments and only 1 is given.

Any thoughts?

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



Re: www.djangoproject.com

2010-07-12 Thread Nick Raptis


I too have upgraded my Ubuntu systems over several versions in the 
past, and also have Weave (now Firefox Sync) installed since a few 
weeks, which leaves me wondering how the nonstandard setting got into 
the profile in the first place.



Yea, for some reason, my thoughts went to Weave too. Maybe it has 
something to do with it, maybe it doesn't. Haven't got any more trouble 
since I fixed it though.

Glad I could help :)

Nick

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



Re: www.djangoproject.com

2010-07-08 Thread Nick Raptis
Sorry for the rant but I can finally express my delayed frustration on 
this bug..


I first I spent some 2-3 hours trying to find out if this problem came 
from a broken ipv6 configuration.
Then, I actually had to delete all my profile files (delete half, find 
out if it solves it, restore, delete half again) until I knew that 
prefs.js (the about:config file) was responsible.
I then checked the more than a 6000 lines of that file in the same 
manner (deleting half the lines each time) to find the offending option.

At that time I thought half my hair had gone grey!

The only two sites affected by this was djangoproject.com and 
djangobook.com Could be a django configuration issue on those, as other 
django powered sites behaved normally.


I'm SO glad that my frustrating time hunting this down actually helped 
another soul! :D


I don't know why my profile had the locale option as such. I've migrated 
this profile from windows, then ubuntu karmic to ubuntu lucid, and I'm 
also using weave sync so I can't tell for sure. Hopefully, once you know 
it's there you can easily fix it :)


I'm also sorry for double-posting the last mail. I have both mail 
accounts configured for the  list and thought only one would go through 
as the first answer I sent lagged significantly. I hope this gets sent 
properly.


Glad i could be of help, Nick

On 07/08/2010 06:32 PM, Andi wrote:

On Jul 8, 5:12 pm, Nick Raptis<airsc...@gmail.com>  wrote:
   

If there is a non-standard value there (perhaps "/etc/locale/prefs.conf"
or something) instead of a locale like en-US,
some django pages won't ever display.
 

That's it.  You have to *remove* this non-standard value, it's not
sufficient to add another locale to the first position.

Thank you very much, I would never have found this.
--
Bye, Andi

   


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



Re: www.djangoproject.com

2010-07-08 Thread Nick Raptis
Hey, haven't read the whole thread but I spend a whole day last month 
troubleshooting something like this.


In firefox, check your preffered language settings, in the content tab.

If there is a non-standard value there (perhaps "/etc/locale/prefs.conf" 
or something) instead of a locale like en-US,

some django pages won't ever display.

Nick

On 07/08/2010 04:11 PM, eon wrote:

Same for me. The problem is in the firefox profile (maybe due to the
switch from 3.5 to 3.6 ?)

Start-up with a new profile (backport plugins, bookmarks argh...)
resolves the issue

On 5 juil, 20:52, Andi<apoi...@gmail.com>  wrote:


On Jul 2, 10:44 pm, Bill Freeman<ke1g...@gmail.com>  wrote:



What might be of help is adding the IP address to /etc/hosts, if you are
on linux.


I have the same problem regarding djangoproject.com (Firefox 3.6.6 on
Ubuntu).  Everything works but Firefox using my default profile: host
and nslookup succeed in resolving the domain name.  Adding the IP to /
etc/hosts or accessing the IP address directly in firefox doesn't
help.  Opera, chromium, arora, w3m, elinks, lynx and konqueror are not
affected.  Firefoxes on other hosts within the same LAN can connect to
djangoproject.com without a problem.  Disabling all add-ons living in
my Firefox doesn't have an effect -- but starting with a fresh profile
does: djangoproject.com loads successfully.

It's a very strange problem, because there is no problem with the
other thousands of websites I've visited during the last days.  It's
the combination djangoproject.com + my main Firefox profile which
produces the problem exclusively.

--
Andi





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



Re: www.djangoproject.com

2010-07-08 Thread Nick Raptis
Hey, haven't read the whole thread but I spend a whole day last month 
troubleshooting something like this.


In firefox, check your preffered language settings, in the content tab.

If there is a non-standard value there (perhaps "/etc/locale/prefs.conf" 
or something) instead of a locale like en-US,

some django pages won't ever display.

Nick

On 07/08/2010 04:11 PM, eon wrote:

Same for me. The problem is in the firefox profile (maybe due to the
switch from 3.5 to 3.6 ?)

Start-up with a new profile (backport plugins, bookmarks argh...)
resolves the issue

On 5 juil, 20:52, Andi<apoi...@gmail.com>  wrote:
   

On Jul 2, 10:44 pm, Bill Freeman<ke1g...@gmail.com>  wrote:

 

What might be of help is adding the IP address to /etc/hosts, if you are
on linux.
   

I have the same problem regarding djangoproject.com (Firefox 3.6.6 on
Ubuntu).  Everything works but Firefox using my default profile: host
and nslookup succeed in resolving the domain name.  Adding the IP to /
etc/hosts or accessing the IP address directly in firefox doesn't
help.  Opera, chromium, arora, w3m, elinks, lynx and konqueror are not
affected.  Firefoxes on other hosts within the same LAN can connect to
djangoproject.com without a problem.  Disabling all add-ons living in
my Firefox doesn't have an effect -- but starting with a fresh profile
does: djangoproject.com loads successfully.

It's a very strange problem, because there is no problem with the
other thousands of websites I've visited during the last days.  It's
the combination djangoproject.com + my main Firefox profile which
produces the problem exclusively.

--
Andi
 
   


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



Re: Query raises a DoesNotExist error

2010-07-07 Thread Nick
A lot of this is me trying to find out why it's failing. The problem
I'm getting is that there is a FullProfile associated with the email
address. When i go through the steps in the shell it works perfectly.
When I run it through the form it throws an error. If you look at the
custom ValidationError I am checking to see if I can get an error to
spit out any information for that profile that is being submitted in
the form.

Each time I get the error to return the test information without fail.
If I do try to submit an address that isn't in the FullProfile table
then I get a different DoesNotExist error, it jumps right over the
custom validation error.

So the custom ValidationError triggers when there is a profile in the
DB and the default debug page DoesNotExist triggers when there isn't a
FulLProfile associated with the email address.

On Jul 7, 12:42 pm, Nuno Maltez  wrote:
> At a glance:
>
> >        try:
> >            FullProfile.objects.get(email=email)
> >        except FullProfile.DoesNotExist:
>
> >         test =
> > FullProfile.objects.get(email=self.cleaned_data['email'])
> >         raise forms.ValidationError("%s" % (test))
>
> Shouldn't the second FullProfile.objects.get just raise a
> FullProfile.DoesNotExist eception again? It seems you're just catching
> an exception in order to throw it again in the except block...
>
> hth,
> Nuno

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



Query raises a DoesNotExist error

2010-07-07 Thread Nick
I am working on a form to resend an account activation email for newly
registered users who did not receive their first email.

The form is currently raising a DoesNotExist error and I can't figure
out why:

Here is the activation code:

class resend_activation(forms.Form):
email = forms.EmailField(label="E-Email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
FullProfile.objects.get(email=email)
except FullProfile.DoesNotExist:

 test =
FullProfile.objects.get(email=self.cleaned_data['email'])
 raise forms.ValidationError("%s" % (test))

def send(self):
email = self.cleaned_data['email']
user = FullProfile.objects.get(email=email)
thread = Thread(target=send_activation, args=[user])
thread.setDaemon(True)
thread.start()

Here is the view:

def resend(request):
if request.method == 'POST':
form = resend_activation(request.POST)
if form.is_valid():
resend = form.send()


return HttpResponseRedirect("../activate_message")
else:
form = resend_activation()

return render_to_response("registration/resend.html", {'form':
form })

Everytime I try to use the form I get a "FullProfile matching query
does not exist." error. But in the above code I added a little test to
see if the query was returning any values and it is. I have no clue
why this portion of process is holding up everything else.

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



URL configuration

2010-07-06 Thread Nick
I currently have several django projects on one server. I am working
with subdomains for some of these projects and I'd like the base URL
to be a little different than the default behavior. I am working with
modwsgi and apache.

I have a project called MyProject.

I have a subdomain set up at myproject.mysite.com

the project's base url is myproejct.mysite.com/myproject
the admin is myproject.mysite.com/myprojects/admin

what I would like is myrpojects.mysite.com/admin

How would I accomplish this

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



Price fixing (was Re: How much would you charge for this? £5k? £15k? £50k?)

2010-06-21 Thread Nick Arnett
On Mon, Jun 21, 2010 at 2:12 AM, ALJ <astley.lejas...@gmail.com> wrote:

> I'm just starting out with Django so using an hourly rate isn't really
> applicable because I'm going to be much slower that a 'real'
> developer. So far I've spent about 6 months part time.
>
> What kind of ballpark amounts would people suggest this is worth?


I don't know about the law elsewhere, but in the United States, having a
discussion with other vendors on what to charge clients opens you up to
prosecution for price fixing.  It almost certainly should be a banned topic
here.

For a fairly good description of the issue, look at the HTML Writer's Guild
guidelines:

http://www.hwg.org/resources/faqs/priceFAQ.html

Nick

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



Re: Django Sphinx or haystack Xapian

2010-06-19 Thread Nick Arnett
On Sat, Jun 19, 2010 at 9:21 AM, zweb <traderash...@gmail.com> wrote:

>
> (Mysql text search will not work as I use INNODB. Solr is powerful but
> I heard it is very memory hungry and it is in Java. Whoosh is not yet
> as mature as others. So that leaves choice between Django Sphinx and
> Haystack Xapian.)


I meant to mention that although I'm using InnoDB, I'm storing a copy of the
searchable text in a MyISAM table and using the MySQL search on it.  That's
okay for now, but I'm looking for clustering, faceted search and other fancy
stuff.

I've worked in search-related technology for a long time and I should know
that search performance always demands lots of memory...  So I may bite the
bullet and use Solr, after all.  I just wish there were a way to trade off
the memory for speed until I'm ready to deploy a real working version.

Nick

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



Re: Django Sphinx or haystack Xapian

2010-06-19 Thread Nick Arnett
On Sat, Jun 19, 2010 at 9:21 AM, zweb <traderash...@gmail.com> wrote:

> I need to implement search solution over models in mysql.
>
> Anyone has experience with both or has gone through same decision
> making?
>
> What should I consider before choosing one or other?


I'm making a similar decision... as far as I can see, neither one does
search result clustering, which I'd like.  But the memory required to host
Solr means a big increase in hosting costs.  I'm using Webfaction, so to go
from their basic service to the one that offers 300 MB of memory is an
increase of about $25/month, which I'd rather not have to pay yet.

Nick

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



Re: How to implement this model

2010-06-16 Thread Nick
The question is how do I relate this to the business_types in the
FulLProfile model? Since a business can have multiple "Premises"

On Jun 16, 4:44 pm, Peter Bengtsson <pete...@gmail.com> wrote:
> Without caring or even attempting to understand your business I sounds
> like you just need to stop using a BooleanField() and instead use a
> ForeignKey(null=True) and then judge if it's "on_premise" by a method
> rather than a field something like this:
>
> class MyModel(Model):
>     related_premise = ForeignKey(Premise, null=True)
>     def on_premise(self):
>         return self.related_premise is not None
>     def get_related_premise(self):
>         assert self.on_premise()
>         return self.related_premise
>
> On Jun 16, 3:39 pm, Nick <nickt...@gmail.com> wrote:
>
> > OK, here's the deal. I'm working up an obituary site. There are 3
> > models/tables and at one point I need to connect two in a way that is
> > different than I have done up to this point. Here is the situation,
> > any recommendations on how to accomplish this would be great:
>
> > I have an obituary table. In that table there is a field that checks
> > if a funeral service is on the premises (column name "on_premises" of
> > the Funeral Home that is entering the information.
>
> > If this BooleanField is checked then it returns the location
> > information of the funeral home which is stored in a business_profile
> > table. Not difficult, just check if the boolean returns a value and
> > then populate the template
>
> > That works out nicely except I have been given an extra criteria for
> > this project. Some business have both a funeral home and a
> > crematorium. Many of these situations require that we list the address
> > of one or the other. Since the "on premises" is a BooleanField there
> > is no way for someone to state what part of their business is
> > responsible for the service.
>
> > What I would like to do is make this option a drop down in the
> > obituary form that basically gives the business the option of choosing
> > which one of their locations is the one we want attached to this obit.
> > Once this is chosen then I will pull the value into the templates.
>
> > How do I relate these models? My first thought is to create two
> > "business type" columns in the business profile table and then relate
> > the "service_location" column to these columns in a drop down? Is that
> > even possible?
>
> > How do I retrieve the values from two different fields and then select
> > from them in another model?

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



Re: How to implement this model

2010-06-16 Thread Nick
I am going to try to add better information for this issue, here we
go:

The model for the obituary looks like this:


class obit_entry(models.Model):
first_name = models.CharField('First Name', max_length=100,
blank=False)
middle_name = models.CharField('Middle Name', max_length=100,
blank=False)
last_name = models.CharField('Last Name', max_length=100,
blank=False)
nick_name = models.CharField('Nickname', max_length=100,
blank=True)
city = models.CharField('City', max_length=100, blank=False)
state = USStateField(blank=False)
occupation = models.CharField('Occupation', blank=True,
max_length=100)
date_of_birth = models.DateField(blank=False)
date_of_death = models.DateField(blank=False)
date_of_service = models.DateTimeField(blank=False)
type_of_service = models.CharField('Type of service',
max_length=100, choices=Service_Type, blank=False)
on_premises = models.BooleanField(blank=True)
service_location = models.CharField('Location of service',
max_length=100, blank=True)
service_address = models.CharField('Service Address',
max_length=100, blank=True)
service_city = models.CharField('City of service', max_length=100,
blank=True)
service_state = USStateField('State of service', blank=True)
additional_info = models.TextField('Additional Information',
blank=True)
organ_donor = models.BooleanField(blank=True)
natural_causes = models.CharField('Died of Natural causes',
max_length=100, choices=Causes_Choices, blank=False)
date_to_run = models.DateField('Date obit should run', blank=True,
null=True)
date_created = models.DateTimeField(auto_now_add=True)
date_update = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(FullProfile,
related_name="createdBY", null=True, blank=True)

the model for the business profile (FullProfile) looks like this:


class FullProfile(User):
bus_name = models.CharField('Full Business Name',
help_text='excluding type (e.g. Funeral Home, Crematorium)',
max_length=200, blank=True)
bus_type = models.CharField('Business Type', help_text='(e.g.
Funeral Home, Crematorium, etc.)', max_length=200, blank=True)
address_street = models.CharField('Street Number', max_length=200,
blank=True)
address_city = models.CharField('City', max_length=200,
blank=True)
address_zip = models.CharField('Zip Code', max_length=10,
blank=True)
phone = PhoneNumberField('Phone Number', blank=True)
contact = models.CharField('Contact Name', max_length=100,
blank=True)
bus_type_2 = models.CharField('Business Type 2', help_text='(e.g.
Funeral Home, Crematorium, etc.)', max_length=200, blank=True)
address_street_2 = models.CharField('Street Number',
max_length=200, blank=True)
address_city_2 = models.CharField('City', max_length=200,
blank=True)
address_zip_2 = models.CharField('Zip Code', max_length=10,
blank=True)
completed = models.BooleanField()
objects = UserManager()

There is an obituary form that is a model form of the obit model:

I would like to change the on_premises field to lookup of the two
business type fields in the FullProfile model so that the user can
select which business type they want to attach to the individual
obituary.

So if a business has bus_type = Funeral Home and bus_type_2 =
Crematorium, in the obituary form the user will have a drop down of
either "Funeral Home" or "Crematorium" to choose from.


On Jun 16, 2:39 pm, Nick <nickt...@gmail.com> wrote:
> OK, here's the deal. I'm working up an obituary site. There are 3
> models/tables and at one point I need to connect two in a way that is
> different than I have done up to this point. Here is the situation,
> any recommendations on how to accomplish this would be great:
>
> I have an obituary table. In that table there is a field that checks
> if a funeral service is on the premises (column name "on_premises" of
> the Funeral Home that is entering the information.
>
> If this BooleanField is checked then it returns the location
> information of the funeral home which is stored in a business_profile
> table. Not difficult, just check if the boolean returns a value and
> then populate the template
>
> That works out nicely except I have been given an extra criteria for
> this project. Some business have both a funeral home and a
> crematorium. Many of these situations require that we list the address
> of one or the other. Since the "on premises" is a BooleanField there
> is no way for someone to state what part of their business is
> responsible for the service.
>
> What I would like to do is make this option a drop down in the
> obituary form that basically gives the business the option of choosing
> which one of their locations is the one we want attached to this obit.
> Once this is chosen then I will pull the value into the templates.
>
>

Re: How to create the model in a different database from within the same database server.

2010-06-16 Thread Nick
Which version of django are you working with?

On Jun 16, 2:28 pm, thusjanthan  wrote:
> Hi,
>
> when I mean database I mean the separate databases from within one
> mysql database server. So ex:
>
> DB server: server.example.com
> Databases that are contained in the one instance of mysql:
> People
> Books
>
> I have made the connection in the settings.py at the project level but
> in the individual applications suppose People I would like to create
> the models that write the tables in that database space and the
> application Books to write its models in the Books database. This
> should be possible to do but not sure why its not working.
>
> Any thoughts?

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



How to implement this model

2010-06-16 Thread Nick
OK, here's the deal. I'm working up an obituary site. There are 3
models/tables and at one point I need to connect two in a way that is
different than I have done up to this point. Here is the situation,
any recommendations on how to accomplish this would be great:

I have an obituary table. In that table there is a field that checks
if a funeral service is on the premises (column name "on_premises" of
the Funeral Home that is entering the information.

If this BooleanField is checked then it returns the location
information of the funeral home which is stored in a business_profile
table. Not difficult, just check if the boolean returns a value and
then populate the template

That works out nicely except I have been given an extra criteria for
this project. Some business have both a funeral home and a
crematorium. Many of these situations require that we list the address
of one or the other. Since the "on premises" is a BooleanField there
is no way for someone to state what part of their business is
responsible for the service.

What I would like to do is make this option a drop down in the
obituary form that basically gives the business the option of choosing
which one of their locations is the one we want attached to this obit.
Once this is chosen then I will pull the value into the templates.

How do I relate these models? My first thought is to create two
"business type" columns in the business profile table and then relate
the "service_location" column to these columns in a drop down? Is that
even possible?

How do I retrieve the values from two different fields and then select
from them in another model?

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



Re: Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?

2010-06-14 Thread Nick
Many thanks for your helpful posts - in the end I just changed a bit
of my code to work with 2.4, but this will come in handy for when I
finally make the upgrade.

Thanks again,
Nick

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



Re: assigning data based on a comparison between two tables

2010-06-09 Thread Nick
Just to let you know, this code worked out nicely.

I made a few changes to the bottom save function:

if len(candidates) > 1:
raise Exception
candidates.update(incumbent=True)


On Jun 8, 6:11 pm, Nick <nickt...@gmail.com> wrote:
> Thanks Dan, I'll give it a shot
>
> On Jun 8, 6:00 pm, Dan Harris <dih0...@gmail.com> wrote:
>
> > Perhaps not the greatest way of doing things, but simple to code/read:
>
> > class Candidate(models.Model):
> >    first_name = models.CharField(max_length=30)
> >    last_name = models.CharField(max_length=30)
> >    incumbent = models.BooleanField()
>
> > class HoldsOffice(models.Model):
> >    first_name = models.CharField(max_length=30)
> >    last_name = models.CharField(max_length=30)
>
> > for officer in HoldsOffice.objects.all():
> >    candidates =
> > Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name)
>
> >    if len(candidates)>0:
> >       raise Exception("More than 1 match found")
> >    candidates[0].incumbent = True
> >    candidates[0].save()
>
> > Something like that might work for you assuming that the models and
> > stuff are similar. Also, this code is just off the top of my head, so
> > who knows if it will actually work :)
>
> > Cheers,
>
> > Dan Harris
> > dih0...@gmail.com
>
> > On Jun 8, 6:30 pm, Nick <nickt...@gmail.com> wrote:
>
> > > I have two models. One is a list of candidates that have filed to run
> > > for office. The second is a list of people who currently hold
> > > office.
>
> > > I'd like to compare the two tables and whenever a match is found
> > > between the two (an entry in the candidate table shares the same
> > > last_name and first_name with an office holder from the holds office
> > > table) I'd like to check off a box in the Candidate table called
> > > 'incumbent'.
>
> > > how would I begin to do this. They both have columns called last_name
> > > and first_name that I can use to compare but I don't know the syntax.

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



Re: ordering integers with regroup

2010-06-09 Thread Nick
You are right, I wasn't even thinking about it like that. This is bad
news as the information is coming across as "District 45" from another
source and so I don't have just a district number to go off of. State
government data is always terrible to work with.

On Jun 9, 10:04 am, Scott Gould <zinck...@gmail.com> wrote:
> If you're ordering on "District 1", "District 2", etc. then the number
> is part of a string and will be sorted alphabetically. I image your
> only recourse will be to use the numeric field directly, and deal with
> prepending "District " to it in some other fashion.
>
> On Jun 9, 10:38 am, Nick <nickt...@gmail.com> wrote:
>
> > Has anyone come across an ordering issue with the regroup tag whereby
> > if the field that is being ordered is an integer you get the following
> > problem:
>
> > say you have the grouped field "District" and the following groupings
>
> > District 1
> > District 2
> > District 3
> > District 10
> > District 14
> > District 20
> > District 29
> > District 30
>
> > Their ordering will come out:
>
> > District 1
> > District 10
> > District 14
> > District 2
> > District 20
> > District 29
> > District 3
> > District 30
>
> > I can see why this is happening, but how do I tell the regroup tag to
> > sort as though 1 were 01, etc. Adding a 0 to the front isn't really an
> > option as their are thousands of records that reach from 1 - 250
>
> > 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ordering integers with regroup

2010-06-09 Thread Nick
Has anyone come across an ordering issue with the regroup tag whereby
if the field that is being ordered is an integer you get the following
problem:

say you have the grouped field "District" and the following groupings

District 1
District 2
District 3
District 10
District 14
District 20
District 29
District 30

Their ordering will come out:

District 1
District 10
District 14
District 2
District 20
District 29
District 3
District 30

I can see why this is happening, but how do I tell the regroup tag to
sort as though 1 were 01, etc. Adding a 0 to the front isn't really an
option as their are thousands of records that reach from 1 - 250

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



Re: assigning data based on a comparison between two tables

2010-06-08 Thread Nick
Thanks Dan, I'll give it a shot

On Jun 8, 6:00 pm, Dan Harris <dih0...@gmail.com> wrote:
> Perhaps not the greatest way of doing things, but simple to code/read:
>
> class Candidate(models.Model):
>    first_name = models.CharField(max_length=30)
>    last_name = models.CharField(max_length=30)
>    incumbent = models.BooleanField()
>
> class HoldsOffice(models.Model):
>    first_name = models.CharField(max_length=30)
>    last_name = models.CharField(max_length=30)
>
> for officer in HoldsOffice.objects.all():
>    candidates =
> Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name)
>
>    if len(candidates)>0:
>       raise Exception("More than 1 match found")
>    candidates[0].incumbent = True
>    candidates[0].save()
>
> Something like that might work for you assuming that the models and
> stuff are similar. Also, this code is just off the top of my head, so
> who knows if it will actually work :)
>
> Cheers,
>
> Dan Harris
> dih0...@gmail.com
>
> On Jun 8, 6:30 pm, Nick <nickt...@gmail.com> wrote:
>
> > I have two models. One is a list of candidates that have filed to run
> > for office. The second is a list of people who currently hold
> > office.
>
> > I'd like to compare the two tables and whenever a match is found
> > between the two (an entry in the candidate table shares the same
> > last_name and first_name with an office holder from the holds office
> > table) I'd like to check off a box in the Candidate table called
> > 'incumbent'.
>
> > how would I begin to do this. They both have columns called last_name
> > and first_name that I can use to compare but I don't know the syntax.

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



assigning data based on a comparison between two tables

2010-06-08 Thread Nick
I have two models. One is a list of candidates that have filed to run
for office. The second is a list of people who currently hold
office.

I'd like to compare the two tables and whenever a match is found
between the two (an entry in the candidate table shares the same
last_name and first_name with an office holder from the holds office
table) I'd like to check off a box in the Candidate table called
'incumbent'.

how would I begin to do this. They both have columns called last_name
and first_name that I can use to compare but I don't know the syntax.

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



Re: styling with django templates

2010-06-08 Thread Nick
Boy, that just flew right past me. Ridiculous. Thanks everyone.

On Jun 8, 1:06 pm, Dejan Noveski <dr.m...@gmail.com> wrote:
> http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for
>
> scroll a bit down to see the forloop object and its properties.
>
>
>
> On Tue, Jun 8, 2010 at 8:05 PM, Dejan Noveski <dr.m...@gmail.com> wrote:
> > change {% if is_first_item %} with {% if forloop.first %} and you are set.
>
> > On Tue, Jun 8, 2010 at 7:59 PM, Nick <nickt...@gmail.com> wrote:
>
> >> I am looking for a way to identify the first item returned in a loop
> >> and display it differently than the others:
>
> >> basically it would go like:
>
> >> {% for item in items %}
> >>    {% if is_first_item %}
> >>     This is what will show
> >>    {% else %}
> >>    this is what will show
> >> {% endfor %}
>
> >> Am I overlooking something in the docs?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
> > --
> > --
> > Dejan Noveski
> > Web Developer
> > dr.m...@gmail.com
> > Twitter:http://twitter.com/dekomote| LinkedIn:
> >http://mk.linkedin.com/in/dejannoveski
>
> --
> --
> Dejan Noveski
> Web Developer
> dr.m...@gmail.com
> Twitter:http://twitter.com/dekomote| 
> LinkedIn:http://mk.linkedin.com/in/dejannoveski

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



styling with django templates

2010-06-08 Thread Nick
I am looking for a way to identify the first item returned in a loop
and display it differently than the others:

basically it would go like:

{% for item in items %}
{% if is_first_item %}
 This is what will show
{% else %}
this is what will show
{% endfor %}

Am I overlooking something in the docs?

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



Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?

2010-06-08 Thread Nick
Hi,

I'm currently running Django on CentOS using the supplied Python 2.4.
I now need to use Python 2.6.  I have installed Python 2.6 from the
EPEL repositories, which sits alongside 2.4 (which is required for
CentOS things such as "yum").

Django (and other Python modules) are all located in Python 2.4's site-
packages folder.  When I upgrade to 2.6, is it just a case of copying
these over into 2.6's site-packages folder, or do I need to install
the modules afresh?

Thanks,
Nick

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



Re: If is first time logging in

2010-05-19 Thread Nick
 I am, but I'm not opposed to custmizing one. This part of the project
will undoubtedly get bundled as a reusable registratioon and login app
for other projects so it doing what I'd like it to do is more
important than convenience.

On May 19, 5:23 pm, Dejan Noveski <dr.m...@gmail.com> wrote:
> Do you use the generic login view?
>
>
>
>
>
> On Thu, May 20, 2010 at 12:16 AM, Nick <nickt...@gmail.com> wrote:
> > I have an expanded user form right now. Here is the sign up process.
>
> > user registers using username, email, password
>
> > It sends and activation link to that email.
>
> > User clicks on the link and they are activated
>
> > User logs in
>
> > Here is where I would like the extended profile to pop up the first
> > time. When they pass through the login screen to their home page (each
> > user has a home page with a selection of different actions).
>
> > I can kind of see where you are going with what you have, I'm adding a
> > field to check to make sure the forms are finished?
>
> > I'm not too worried about users not filling out the profile, this is a
> > site built for submitted obituaries and the users will be funeral
> > homes so filling out the form is a necessary part of their job. I just
> > want to know how to make it really obvious to them the first time they
> > login.
>
> > On May 19, 4:36 pm, Dejan Noveski <dr.m...@gmail.com> wrote:
> > > Best will be if you make Useraccount model that will inherit from User,
> > add
> > > field formsets_passed = BooleanField(initial = False)
>
> > > The reason why i think this is better idea is, user might leave the page
> > > before finishing the aditional forms. That way, next time it will be
> > second
> > > login and you will be able to show them again.
>
> > > On Wed, May 19, 2010 at 11:05 PM, Nick <nickt...@gmail.com> wrote:
> > > > I'm trying to figure out a way to see if it is a users first time
> > > > logging in after registering on the site. If it is then I will pass
> > > > them through some formsets, otherwise I let them go to their profile
> > > > page.
>
> > > > I tried using date_joined == last_login but that doesn't work, as the
> > > > last login date changes the second you log in.
>
> > > > Anyone ever done anything like this?
>
> > > > Any thoughts?
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google
> > > >  groups.com>
> > <django-users%2bunsubscr...@google groups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > --
> > > Dejan Noveski
> > > Web Developer
> > > dr.m...@gmail.com
> > > Twitter:http://twitter.com/dekomote|LinkedIn:
> >http://mk.linkedin.com/in/dejannoveski
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google 
> > groups.com>
> > .
> > > For more options, visit this group athttp://
> > groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google 
> > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> --
> Dejan Noveski
> Web Developer
> dr.m...@gmail.com
> Twitter:http://twitter.com/dekomote| 
> LinkedIn:http://mk.linkedin.com/in/dejannoveski
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: If is first time logging in

2010-05-19 Thread Nick
I have an expanded user form right now. Here is the sign up process.

user registers using username, email, password

It sends and activation link to that email.

User clicks on the link and they are activated

User logs in

Here is where I would like the extended profile to pop up the first
time. When they pass through the login screen to their home page (each
user has a home page with a selection of different actions).

I can kind of see where you are going with what you have, I'm adding a
field to check to make sure the forms are finished?

I'm not too worried about users not filling out the profile, this is a
site built for submitted obituaries and the users will be funeral
homes so filling out the form is a necessary part of their job. I just
want to know how to make it really obvious to them the first time they
login.



On May 19, 4:36 pm, Dejan Noveski <dr.m...@gmail.com> wrote:
> Best will be if you make Useraccount model that will inherit from User, add
> field formsets_passed = BooleanField(initial = False)
>
> The reason why i think this is better idea is, user might leave the page
> before finishing the aditional forms. That way, next time it will be second
> login and you will be able to show them again.
>
>
>
>
>
> On Wed, May 19, 2010 at 11:05 PM, Nick <nickt...@gmail.com> wrote:
> > I'm trying to figure out a way to see if it is a users first time
> > logging in after registering on the site. If it is then I will pass
> > them through some formsets, otherwise I let them go to their profile
> > page.
>
> > I tried using date_joined == last_login but that doesn't work, as the
> > last login date changes the second you log in.
>
> > Anyone ever done anything like this?
>
> > Any thoughts?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google 
> > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> --
> Dejan Noveski
> Web Developer
> dr.m...@gmail.com
> Twitter:http://twitter.com/dekomote| 
> LinkedIn:http://mk.linkedin.com/in/dejannoveski
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



If is first time logging in

2010-05-19 Thread Nick
I'm trying to figure out a way to see if it is a users first time
logging in after registering on the site. If it is then I will pass
them through some formsets, otherwise I let them go to their profile
page.

I tried using date_joined == last_login but that doesn't work, as the
last login date changes the second you log in.

Anyone ever done anything like this?

Any thoughts?

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



Re: send_mail not firing

2010-05-19 Thread Nick
Welp, indentation error:

def save(self):

needed to unindent so it was called when the form was process, instead
it was waiting for an error to trigger it, which it wouldn't do
because the error halts the form from processing.  There goes 13 hours
of my life I'm never getting back.

On May 19, 10:07 am, Nick <nickt...@gmail.com> wrote:
> It looks like the problem isn't with send_mail, its the save override
> on the form, the is_active = False isn't setting that option in the DB
> either, so it is skipping over the save options. Here they are again:
>
> forms.py:
> class RegisterForm(UserCreationForm):
>     email = forms.EmailField(label="E-Email")
>
>     class Meta:
>         model = User
>         fields = ("username", "email")
>
>     def clean_email(self):
>         email = self.cleaned_data["email"]
>
>         try:
>             User.objects.get(email=email)
>         except User.DoesNotExist:
>             return email
>
>         raise forms.ValidationError("A user with that email address
> already exists.")
>
>         def save(self):
>             user = super(RegisterForm, self).save(commit=False)
>             send_activation(user)
>             user.is_active = False
>             user.save()
>
> and the view:
>
> def register(request):
>     if request.method == 'POST':
>         form = RegisterForm(request.POST)
>         if form.is_valid():
>             new_user = form.save()
>
>             return HttpResponseRedirect("/obits/")
>     else:
>         form = RegisterForm()
>
>     return render_to_response("obits/register.html", {'form': form })
>
> So, the username and all of that are saving by the user.is_active and
> send_mail are getting skipped
>
> On May 19, 4:37 am, Nuno Maltez <nuno.li...@gmail.com> wrote:
>
>
>
> > Anything it the mail server's logs? Any trace of your app trying tosendthe 
> > message? Any errors?
>
> > Nuno
>
> > On Tue, May 18, 2010 at 11:42 PM, Nick <nickt...@gmail.com> wrote:
> > > Actually, I've fixed the problem with send_activation. If i go via the
> > > form it still doesn't trigger the email.
>
> > > On May 18, 5:19 pm, Nick <nickt...@gmail.com> wrote:
> > >> I get the same results.
>
> > >> I dropped into the shell and tried it out
>
> > >> >>> user = User(username="nick", email="t...@test.com")
> > >> >>> send_activation(user)
>
> > >> 1
>
> > >> I think the 1 means that it passed but I don't get any emails sent
>
> > >> On May 18, 5:08 pm, "ge...@aquarianhouse.com"
>
> > >> <ge...@aquarianhouse.com> wrote:
> > >> > what happens if you set fail_silently to True?
>
> > >> > On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
> > >> > > I am having an issue with an authentication app I am writing. The app
> > >> > > saves the form appropriately but doesn'tsendthe confirmation email.
> > >> > > I am using the same email_host settings as with other application 
> > >> > > that
> > >> > >sendemail messages but with no results. Here is the process.
>
> > >> > > First a form processes the information:
>
> > >> > > from django.contrib.auth.forms import UserCreationForm
> > >> > > from django import forms
> > >> > > from django.contrib.auth.models import User
> > >> > > from activate import send_activation
>
> > >> > > class RegisterForm(UserCreationForm):
> > >> > >     email = forms.EmailField(label="E-Email")
>
> > >> > >     class Meta:
> > >> > >         model = User
> > >> > >         fields = ("username", "email")
>
> > >> > >     def clean_email(self):
> > >> > >         email = self.cleaned_data["email"]
>
> > >> > >         try:
> > >> > >             User.objects.get(email=email)
> > >> > >         except User.DoesNotExist:
> > >> > >             return email
>
> > >> > >         raise forms.ValidationError("A user with that email address
> > >> > > already exists.")
>
> > >> > >         def save(self):
> > >> > >             user = super(RegisterForm, self).save(commit=False)
> > >> > >             s

Re: send_mail not firing

2010-05-19 Thread Nick
It looks like the problem isn't with send_mail, its the save override
on the form, the is_active = False isn't setting that option in the DB
either, so it is skipping over the save options. Here they are again:

forms.py:
class RegisterForm(UserCreationForm):
email = forms.EmailField(label="E-Email")

class Meta:
model = User
fields = ("username", "email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
User.objects.get(email=email)
except User.DoesNotExist:
return email

raise forms.ValidationError("A user with that email address
already exists.")

def save(self):
user = super(RegisterForm, self).save(commit=False)
send_activation(user)
user.is_active = False
user.save()

and the view:

def register(request):
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
new_user = form.save()

return HttpResponseRedirect("/obits/")
else:
form = RegisterForm()

return render_to_response("obits/register.html", {'form': form })

So, the username and all of that are saving by the user.is_active and
send_mail are getting skipped


On May 19, 4:37 am, Nuno Maltez <nuno.li...@gmail.com> wrote:
> Anything it the mail server's logs? Any trace of your app trying tosendthe 
> message? Any errors?
>
> Nuno
>
>
>
> On Tue, May 18, 2010 at 11:42 PM, Nick <nickt...@gmail.com> wrote:
> > Actually, I've fixed the problem with send_activation. If i go via the
> > form it still doesn't trigger the email.
>
> > On May 18, 5:19 pm, Nick <nickt...@gmail.com> wrote:
> >> I get the same results.
>
> >> I dropped into the shell and tried it out
>
> >> >>> user = User(username="nick", email="t...@test.com")
> >> >>> send_activation(user)
>
> >> 1
>
> >> I think the 1 means that it passed but I don't get any emails sent
>
> >> On May 18, 5:08 pm, "ge...@aquarianhouse.com"
>
> >> <ge...@aquarianhouse.com> wrote:
> >> > what happens if you set fail_silently to True?
>
> >> > On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
> >> > > I am having an issue with an authentication app I am writing. The app
> >> > > saves the form appropriately but doesn'tsendthe confirmation email.
> >> > > I am using the same email_host settings as with other application that
> >> > >sendemail messages but with no results. Here is the process.
>
> >> > > First a form processes the information:
>
> >> > > from django.contrib.auth.forms import UserCreationForm
> >> > > from django import forms
> >> > > from django.contrib.auth.models import User
> >> > > from activate import send_activation
>
> >> > > class RegisterForm(UserCreationForm):
> >> > >     email = forms.EmailField(label="E-Email")
>
> >> > >     class Meta:
> >> > >         model = User
> >> > >         fields = ("username", "email")
>
> >> > >     def clean_email(self):
> >> > >         email = self.cleaned_data["email"]
>
> >> > >         try:
> >> > >             User.objects.get(email=email)
> >> > >         except User.DoesNotExist:
> >> > >             return email
>
> >> > >         raise forms.ValidationError("A user with that email address
> >> > > already exists.")
>
> >> > >         def save(self):
> >> > >             user = super(RegisterForm, self).save(commit=False)
> >> > >             send_activation(user)
> >> > >             user.is_active = False
> >> > >             user.save()
>
> >> > > the activate.py file:
>
> >> > > from django.core.mail import send_mail
> >> > > from hashlib import md5
> >> > > from django.template import loader, Context
> >> > > from Obits.settings import BASE_URL as base_url
>
> >> > > def send_activation(user):
> >> > >     code = md5(user.username).hexdigest()
> >> > >     url = "%sactivate/?user=%s=%s" % (base_url, user.username,
> >> > > code)
> >> > >     template = loader.get_template('obits/eactivate.html')
> >> > >     context = ({
> &g

Re: send_mail not firing

2010-05-18 Thread Nick
Actually, I've fixed the problem with send_activation. If i go via the
form it still doesn't trigger the email.

On May 18, 5:19 pm, Nick <nickt...@gmail.com> wrote:
> I get the same results.
>
> I dropped into the shell and tried it out
>
> >>> user = User(username="nick", email="t...@test.com")
> >>> send_activation(user)
>
> 1
>
> I think the 1 means that it passed but I don't get any emails sent
>
> On May 18, 5:08 pm, "ge...@aquarianhouse.com"
>
>
>
> <ge...@aquarianhouse.com> wrote:
> > what happens if you set fail_silently to True?
>
> > On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
> > > I am having an issue with an authentication app I am writing. The app
> > > saves the form appropriately but doesn't send the confirmation email.
> > > I am using the same email_host settings as with other application that
> > > send email messages but with no results. Here is the process.
>
> > > First a form processes the information:
>
> > > from django.contrib.auth.forms import UserCreationForm
> > > from django import forms
> > > from django.contrib.auth.models import User
> > > from activate import send_activation
>
> > > class RegisterForm(UserCreationForm):
> > >     email = forms.EmailField(label="E-Email")
>
> > >     class Meta:
> > >         model = User
> > >         fields = ("username", "email")
>
> > >     def clean_email(self):
> > >         email = self.cleaned_data["email"]
>
> > >         try:
> > >             User.objects.get(email=email)
> > >         except User.DoesNotExist:
> > >             return email
>
> > >         raise forms.ValidationError("A user with that email address
> > > already exists.")
>
> > >         def save(self):
> > >             user = super(RegisterForm, self).save(commit=False)
> > >             send_activation(user)
> > >             user.is_active = False
> > >             user.save()
>
> > > the activate.py file:
>
> > > from django.core.mail import send_mail
> > > from hashlib import md5
> > > from django.template import loader, Context
> > > from Obits.settings import BASE_URL as base_url
>
> > > def send_activation(user):
> > >     code = md5(user.username).hexdigest()
> > >     url = "%sactivate/?user=%s=%s" % (base_url, user.username,
> > > code)
> > >     template = loader.get_template('obits/eactivate.html')
> > >     context = ({
> > >          'username': user.username,
> > >          'url': url,
> > >      })
> > >     send_mail('Activate account at super site', 'this is a test',
> > > 'myem...@mydomain.com, [user.email], fail_silently=False)
>
> > > The form saves to the DB, it hits all of the conditions but fails to
> > > send an email. I can't get any error messages so I'm really at a loss.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: send_mail not firing

2010-05-18 Thread Nick
OK, it's all fixed. I updated the template rendering to actually use
Context, if you look at activate.py I just put "context = ({". That's
not helping anything out. I also added a default_host_email to the
settings file. I don't know if that was the problem, but I'm leaving
it in.

On May 18, 5:19 pm, Nick <nickt...@gmail.com> wrote:
> I get the same results.
>
> I dropped into the shell and tried it out
>
> >>> user = User(username="nick", email="t...@test.com")
> >>> send_activation(user)
>
> 1
>
> I think the 1 means that it passed but I don't get any emails sent
>
> On May 18, 5:08 pm, "ge...@aquarianhouse.com"
>
>
>
> <ge...@aquarianhouse.com> wrote:
> > what happens if you set fail_silently to True?
>
> > On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
> > > I am having an issue with an authentication app I am writing. The app
> > > saves the form appropriately but doesn't send the confirmation email.
> > > I am using the same email_host settings as with other application that
> > > send email messages but with no results. Here is the process.
>
> > > First a form processes the information:
>
> > > from django.contrib.auth.forms import UserCreationForm
> > > from django import forms
> > > from django.contrib.auth.models import User
> > > from activate import send_activation
>
> > > class RegisterForm(UserCreationForm):
> > >     email = forms.EmailField(label="E-Email")
>
> > >     class Meta:
> > >         model = User
> > >         fields = ("username", "email")
>
> > >     def clean_email(self):
> > >         email = self.cleaned_data["email"]
>
> > >         try:
> > >             User.objects.get(email=email)
> > >         except User.DoesNotExist:
> > >             return email
>
> > >         raise forms.ValidationError("A user with that email address
> > > already exists.")
>
> > >         def save(self):
> > >             user = super(RegisterForm, self).save(commit=False)
> > >             send_activation(user)
> > >             user.is_active = False
> > >             user.save()
>
> > > the activate.py file:
>
> > > from django.core.mail import send_mail
> > > from hashlib import md5
> > > from django.template import loader, Context
> > > from Obits.settings import BASE_URL as base_url
>
> > > def send_activation(user):
> > >     code = md5(user.username).hexdigest()
> > >     url = "%sactivate/?user=%s=%s" % (base_url, user.username,
> > > code)
> > >     template = loader.get_template('obits/eactivate.html')
> > >     context = ({
> > >          'username': user.username,
> > >          'url': url,
> > >      })
> > >     send_mail('Activate account at super site', 'this is a test',
> > > 'myem...@mydomain.com, [user.email], fail_silently=False)
>
> > > The form saves to the DB, it hits all of the conditions but fails to
> > > send an email. I can't get any error messages so I'm really at a loss.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: send_mail not firing

2010-05-18 Thread Nick
I get the same results.

I dropped into the shell and tried it out

>>> user = User(username="nick", email="t...@test.com")
>>> send_activation(user)
1

I think the 1 means that it passed but I don't get any emails sent

On May 18, 5:08 pm, "ge...@aquarianhouse.com"
<ge...@aquarianhouse.com> wrote:
> what happens if you set fail_silently to True?
>
> On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
>
>
> > I am having an issue with an authentication app I am writing. The app
> > saves the form appropriately but doesn't send the confirmation email.
> > I am using the same email_host settings as with other application that
> > send email messages but with no results. Here is the process.
>
> > First a form processes the information:
>
> > from django.contrib.auth.forms import UserCreationForm
> > from django import forms
> > from django.contrib.auth.models import User
> > from activate import send_activation
>
> > class RegisterForm(UserCreationForm):
> >     email = forms.EmailField(label="E-Email")
>
> >     class Meta:
> >         model = User
> >         fields = ("username", "email")
>
> >     def clean_email(self):
> >         email = self.cleaned_data["email"]
>
> >         try:
> >             User.objects.get(email=email)
> >         except User.DoesNotExist:
> >             return email
>
> >         raise forms.ValidationError("A user with that email address
> > already exists.")
>
> >         def save(self):
> >             user = super(RegisterForm, self).save(commit=False)
> >             send_activation(user)
> >             user.is_active = False
> >             user.save()
>
> > the activate.py file:
>
> > from django.core.mail import send_mail
> > from hashlib import md5
> > from django.template import loader, Context
> > from Obits.settings import BASE_URL as base_url
>
> > def send_activation(user):
> >     code = md5(user.username).hexdigest()
> >     url = "%sactivate/?user=%s=%s" % (base_url, user.username,
> > code)
> >     template = loader.get_template('obits/eactivate.html')
> >     context = ({
> >          'username': user.username,
> >          'url': url,
> >      })
> >     send_mail('Activate account at super site', 'this is a test',
> > 'myem...@mydomain.com, [user.email], fail_silently=False)
>
> > The form saves to the DB, it hits all of the conditions but fails to
> > send an email. I can't get any error messages so I'm really at a loss.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: send_mail not firing

2010-05-18 Thread Nick
I get the same result.

I dropped into the shell and ran this

>>> user = User(username="test", email="t...@test.com")
>>>send_activation(user)
1

I don't really know what that 1 means, though.

On May 18, 5:08 pm, "ge...@aquarianhouse.com"
<ge...@aquarianhouse.com> wrote:
> what happens if you set fail_silently to True?
>
> On May 19, 12:05 am, Nick <nickt...@gmail.com> wrote:
>
>
>
> > I am having an issue with an authentication app I am writing. The app
> > saves the form appropriately but doesn't send the confirmation email.
> > I am using the same email_host settings as with other application that
> > send email messages but with no results. Here is the process.
>
> > First a form processes the information:
>
> > from django.contrib.auth.forms import UserCreationForm
> > from django import forms
> > from django.contrib.auth.models import User
> > from activate import send_activation
>
> > class RegisterForm(UserCreationForm):
> >     email = forms.EmailField(label="E-Email")
>
> >     class Meta:
> >         model = User
> >         fields = ("username", "email")
>
> >     def clean_email(self):
> >         email = self.cleaned_data["email"]
>
> >         try:
> >             User.objects.get(email=email)
> >         except User.DoesNotExist:
> >             return email
>
> >         raise forms.ValidationError("A user with that email address
> > already exists.")
>
> >         def save(self):
> >             user = super(RegisterForm, self).save(commit=False)
> >             send_activation(user)
> >             user.is_active = False
> >             user.save()
>
> > the activate.py file:
>
> > from django.core.mail import send_mail
> > from hashlib import md5
> > from django.template import loader, Context
> > from Obits.settings import BASE_URL as base_url
>
> > def send_activation(user):
> >     code = md5(user.username).hexdigest()
> >     url = "%sactivate/?user=%s=%s" % (base_url, user.username,
> > code)
> >     template = loader.get_template('obits/eactivate.html')
> >     context = ({
> >          'username': user.username,
> >          'url': url,
> >      })
> >     send_mail('Activate account at super site', 'this is a test',
> > 'myem...@mydomain.com, [user.email], fail_silently=False)
>
> > The form saves to the DB, it hits all of the conditions but fails to
> > send an email. I can't get any error messages so I'm really at a loss.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



send_mail not firing

2010-05-18 Thread Nick
I am having an issue with an authentication app I am writing. The app
saves the form appropriately but doesn't send the confirmation email.
I am using the same email_host settings as with other application that
send email messages but with no results. Here is the process.

First a form processes the information:

from django.contrib.auth.forms import UserCreationForm
from django import forms
from django.contrib.auth.models import User
from activate import send_activation

class RegisterForm(UserCreationForm):
email = forms.EmailField(label="E-Email")

class Meta:
model = User
fields = ("username", "email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
User.objects.get(email=email)
except User.DoesNotExist:
return email

raise forms.ValidationError("A user with that email address
already exists.")

def save(self):
user = super(RegisterForm, self).save(commit=False)
send_activation(user)
user.is_active = False
user.save()

the activate.py file:

from django.core.mail import send_mail
from hashlib import md5
from django.template import loader, Context
from Obits.settings import BASE_URL as base_url

def send_activation(user):
code = md5(user.username).hexdigest()
url = "%sactivate/?user=%s=%s" % (base_url, user.username,
code)
template = loader.get_template('obits/eactivate.html')
context = ({
 'username': user.username,
 'url': url,
 })
send_mail('Activate account at super site', 'this is a test',
'myem...@mydomain.com, [user.email], fail_silently=False)


The form saves to the DB, it hits all of the conditions but fails to
send an email. I can't get any error messages so I'm really at a loss.


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



Re: Pluggable Q app?

2010-05-14 Thread Nick
I actually just got done writing a QandA app. It's very basic. I don't
have it open yet but I would turn over the source to you if you
wanted.

Here are the features:

Question
Answer
Answerer
Answerer's credentials
site specific QandA (using django.contrib sites)
tagging (using django-tagging)
creation date
update date

It outputs a json api based on several filters

site (required)
general search (optional)
id, id list (optional)
pub_date (optional)
tags (optional)


On May 14, 9:20 am, "bax...@gretschpages.com" 
wrote:
> Can anyone give me any suggestions for a relatively simple, pluggable
> Q app? I'm looking for something sorta Stack-Overflow-ish, but I'm
> OK with handling voting, authentication, search, etc. separately.
>
> What I've found so far (OSQA, Askbot, soclone) are far from pluggable.
> I don't want a whole other site, just an app.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Taking on a NoneType error

2010-05-12 Thread Nick
Well, I am embarrassed to admin that this issue was 100% user error.

I recently set up a dev and production server and copied everything
from the old production server to the two new servers.

I was testing the search results page on dev, that's the page that
generates the links to the pages that I'm having issue with (they
appear in a pop up, BTW). While the search results page was on dev the
actual page that was having the age issue was on production. So as I
edited the templates for the age pages on dev it was not updating
production so that's why i couldn't get the simple "if" statements to
work. I had full absolute URLS to the age pages, they've been changed
to relative URLS to prevent this from happening.

There is, however, a bright side to my ignorance.  The suggestions to
update the template tag filter were right on. I use this filter a lot
so it makes more since to have a built in fail safe rather than
checking in the templates each time.

Thanks a bunch,

Dummy

On May 12, 12:46 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Wed, May 12, 2010 at 1:06 PM, Nick <nickt...@gmail.com> wrote:
> > I am using a custom template tag called calculate age to produce an
> > age in numbers based on a filter for a template tag.
>
> > Here is the tag:
>
> > def age(bday, d=None):
> >    if d is None:
> >        d = datetime.datetime.now()
> >    return (d.year - bday.year) - int((d.month, d.day) < (bday.month,
> > bday.day))
>
> > register.filter('age', age)
>
> > here is how it is used in a template:
>
> > {{ entry.DOB|age }} # that produces an age
>
> > Here is the problem, not all of the entries in my DB have a date of
> > birth (henceforth known as DOB).
>
> > This raises and error.
>
> [snip remainder]
>
> Why not just handle it in the age filter itself:
>
> def age(bday, d=None):
>    if not bday:
>       return 'N/A'
>    if d is None:
>        d = datetime.datetime.now()
> ... remainder of filter ...
>
> ?
>
> Karen
> --http://tracey.org/kmt/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Taking on a NoneType error

2010-05-12 Thread Nick
I am using a custom template tag called calculate age to produce an
age in numbers based on a filter for a template tag.

Here is the tag:

def age(bday, d=None):
if d is None:
d = datetime.datetime.now()
return (d.year - bday.year) - int((d.month, d.day) < (bday.month,
bday.day))

register.filter('age', age)

here is how it is used in a template:

{{ entry.DOB|age }} # that produces an age


Here is the problem, not all of the entries in my DB have a date of
birth (henceforth known as DOB).

This raises and error.

I have tried to get around this many different ways. Here are few:

{% ifequal entry.DOB None %} N/A {% else %}  {{ entry.DOB|age }} {%
endif %}

{% ifequal entry.DOB "None" %} N/A {% else %}  {{ entry.DOB|age }} {%
endif %}

{% if entry.DOB == None #I have custom operators set up and this logic
works in the shell but not in the template %} N/A {% else %}
{{ entry.DOB|age }} {% endif %}

{% if entry.DOB == 'None' %} N/A {% else %}  {{ entry.DOB|age }} {%
endif %}

I've even tried it in my view:


def detail(request, last_name, first_name):
r = get_object_or_404(Rep, Last_Name=last_name,
First_Name=first_name)
if r.DOB == None:
r.DOB = NULLage
return render_to_response('Government/repsSingle.html', {'entry':
r, 'NULLage': NULLage})

The in the template:

{% if NULLage %}

This is a good grief sort of error and is making my brain blood boil.


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



Re: Saving objects that have foreign key fields using the pk instead of an instance of the foreignkeyed object

2010-05-12 Thread Nick Serra
Exactly what I was looking for, thanks!

On May 12, 11:50 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On May 12, 4:34 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > Thanks for the response. I actually will already have the PK, and am
> > trying to avoid grabbing an instance of the actual item object.
>
> Yes, that's what I meant. You can assign the foreign key directly when
> instantiating an object, without having to get the item object by
> using the FOO_id field.
>
>   manager = Manager(item_id=mypkvalue)
>
> (sorry, previous example was missing the "_id" suffix.)
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Saving objects that have foreign key fields using the pk instead of an instance of the foreignkeyed object

2010-05-12 Thread Nick Serra
Thanks for the response. I actually will already have the PK, and am
trying to avoid grabbing an instance of the actual item object.

On May 12, 11:26 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On May 12, 4:04 pm, Nick Serra <nickse...@gmail.com> wrote:
>
>
>
>
>
> > Sorry for the confusing title. Here is a simple example to illustrate
> > my question:
>
> > class Item(models.Model):
> >     name = models.CharField()
>
> > class Manager(models.Model):
> >     item = models.ForeignKey(Item)
>
> > On a POST I have the PK of the Item I want to link to a new instance
> > of the Manager object. I am saving a new Manager object that will be
> > linked to the Item with the PK i have. So I can do:
>
> > item_pk = request.POST.get('item')
> > item = Item.objects.get(pk=item_pk)
> > new_manager = Manager(item=item)
> > new_manager.save()
>
> > ...but I don't like the idea of grabbing the item object first. Is
> > there any way to just save the new Manager object with just the PK of
> > the Item, thus avoiding the database call to grab the Item object?
>
> > Thanks!
>
> You should just be able to do
>     manager = Manager(item=item_pk)
> but in general, you can always refer to item_id, as the underlying
> database field representing the foreign key value.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Saving objects that have foreign key fields using the pk instead of an instance of the foreignkeyed object

2010-05-12 Thread Nick Serra
Sorry for the confusing title. Here is a simple example to illustrate
my question:

class Item(models.Model):
name = models.CharField()

class Manager(models.Model):
item = models.ForeignKey(Item)


On a POST I have the PK of the Item I want to link to a new instance
of the Manager object. I am saving a new Manager object that will be
linked to the Item with the PK i have. So I can do:

item_pk = request.POST.get('item')
item = Item.objects.get(pk=item_pk)
new_manager = Manager(item=item)
new_manager.save()

...but I don't like the idea of grabbing the item object first. Is
there any way to just save the new Manager object with just the PK of
the Item, thus avoiding the database call to grab the Item object?

Thanks!

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



Re: Paginating search results

2010-05-11 Thread Nick
It's all firing well, thanks for the heads up and the help.

On May 11, 9:26 am, Nuno Maltez <nuno.li...@gmail.com> wrote:
> Great, Just make sure you don't end up with multiple "page" arguments
> on your query string when navigating through the results (click next;
> click next again...).
>
> Nuno
>
>
>
> On Tue, May 11, 2010 at 2:41 PM, Nick <nickt...@gmail.com> wrote:
> > The POST thing was the result of late night meltdowns and desperation.
> > I tend to just try stupid things when i'm working through an issue
> > like this, just seeing what the application is capable of doing. I've
> > switched it all back to GET.
>
> > I found the answer around 1 this morning.  You are exactly right, I
> > needed to capture the query string and place it in the "next" and
> > "previous" page links. Here's how I went about doing that, just in
> > case someone else runs into this issue:
>
> >  query_string = request.GET.copy()
>
> > and then in the dict:
>
> > 'query_string': query_string.urlencode()
>
> > On May 11, 4:46 am, Nuno Maltez <nuno.li...@gmail.com> wrote:
> >> You need to pass the current search paramters in your query string
> >> (?party=D== ) when you create the links to all the
> >> pages, and you need to be able to retrieve them from request.GET in
> >> order to recreate the object list (reps) when rendering a specific
> >> page (any particular reason why are you using POST in the search
> >> form?).
>
> >> hth,
> >> Nuno
>
> >> On Tue, May 11, 2010 at 1:58 AM, Nick <nickt...@gmail.com> wrote:
> >> > I'm trying to paginate results from a search with multiple options.
> >> > The only problem is, once I hit the next button it clears the query
> >> > and I'm left paginating all the objects in the DB.
>
> >> > Here is my view:
>
> >> > def filter_search(request):
> >> >    if request.POST:
> >> >        reps = Rep.objects.all()
> >> >    else:
> >> >        reps = []
> >> >    query = request.POST
> >> >    if 'q' in request.POST:
> >> >        q = request.POST.get('q', '')
> >> >        qset = (
> >> >        Q(Last_Name__icontains=q) | Q(First_Name__icontains=1)
> >> >               )
> >> >        reps = reps.filter(qset)
> >> >    else:
> >> >        q = []
> >> >    if len(q):
> >> >        qlist = q
> >> >    else:
> >> >        qlist = []
> >> >    if 'party' in request.POST:
> >> >        party = request.POST.getlist('party')
> >> >        reps = reps.filter(Party__in=party)
> >> >    else:
> >> >        party = []
> >> >    if len(party):
> >> >        plist = party
> >> >    else:
> >> >        plist = []
> >> >    paginator = Paginator(reps, 15)
> >> >    results = paginator.count
> >> >    try:
> >> >        page = int(request.POST.get('page', '1'))
> >> >    except:
> >> >        page = 1
> >> >    try:
> >> >        repList = paginator.page(page)
> >> >    except (EmptyPage, InvalidPage):
> >> >        repList = paginator.page(paginator.num_pages)
> >> >    finalq = request.POST
> >> >    return render_to_response("Government/search.html", {
> >> >            'reps': repList,
> >> >            'query': query,
> >> >            'plist': plist,
> >> >            'qlist': qlist,
> >> >            'results': results,
> >> >            'finalq': finalq
> >> > })
>
> >> > Here is my tpl:
>
> >> >        
> >> >        
> >> >        Democrat  
> >> >        Republican 
> >> >        
> >> >        
>
> >> > {% if query %}
> >> > Your search for {% if qlist %} {{ qlist}} {% endif %}
> >> > {% if plist %} {% for p in plist %} {% if forloop.first %} Party
> >> > ({{ p }}) {% else %} &  Party ({{p}}) {% endif %}
> >> > {% endfor %}{% endif %} returned {{ reps.paginator.count }} >> > span> result(s)
> >> > 
> >> > {% for object in reps.object_list %}
> >> > {{ object.Position }} {{ object.First_Name }}
> >> > {{ object.Last_Name }} http://django.newsok.com/government/
> >> > reps/{{ object.Last_Name }}_{{ object.First_Nam

Re: Paginating search results

2010-05-11 Thread Nick
The POST thing was the result of late night meltdowns and desperation.
I tend to just try stupid things when i'm working through an issue
like this, just seeing what the application is capable of doing. I've
switched it all back to GET.

I found the answer around 1 this morning.  You are exactly right, I
needed to capture the query string and place it in the "next" and
"previous" page links. Here's how I went about doing that, just in
case someone else runs into this issue:

 query_string = request.GET.copy()

and then in the dict:

'query_string': query_string.urlencode()





On May 11, 4:46 am, Nuno Maltez <nuno.li...@gmail.com> wrote:
> You need to pass the current search paramters in your query string
> (?party=D== ) when you create the links to all the
> pages, and you need to be able to retrieve them from request.GET in
> order to recreate the object list (reps) when rendering a specific
> page (any particular reason why are you using POST in the search
> form?).
>
> hth,
> Nuno
>
>
>
> On Tue, May 11, 2010 at 1:58 AM, Nick <nickt...@gmail.com> wrote:
> > I'm trying to paginate results from a search with multiple options.
> > The only problem is, once I hit the next button it clears the query
> > and I'm left paginating all the objects in the DB.
>
> > Here is my view:
>
> > def filter_search(request):
> >    if request.POST:
> >        reps = Rep.objects.all()
> >    else:
> >        reps = []
> >    query = request.POST
> >    if 'q' in request.POST:
> >        q = request.POST.get('q', '')
> >        qset = (
> >        Q(Last_Name__icontains=q) | Q(First_Name__icontains=1)
> >               )
> >        reps = reps.filter(qset)
> >    else:
> >        q = []
> >    if len(q):
> >        qlist = q
> >    else:
> >        qlist = []
> >    if 'party' in request.POST:
> >        party = request.POST.getlist('party')
> >        reps = reps.filter(Party__in=party)
> >    else:
> >        party = []
> >    if len(party):
> >        plist = party
> >    else:
> >        plist = []
> >    paginator = Paginator(reps, 15)
> >    results = paginator.count
> >    try:
> >        page = int(request.POST.get('page', '1'))
> >    except:
> >        page = 1
> >    try:
> >        repList = paginator.page(page)
> >    except (EmptyPage, InvalidPage):
> >        repList = paginator.page(paginator.num_pages)
> >    finalq = request.POST
> >    return render_to_response("Government/search.html", {
> >            'reps': repList,
> >            'query': query,
> >            'plist': plist,
> >            'qlist': qlist,
> >            'results': results,
> >            'finalq': finalq
> > })
>
> > Here is my tpl:
>
> >        
> >        
> >        Democrat  
> >        Republican 
> >        
> >        
>
> > {% if query %}
> > Your search for {% if qlist %} {{ qlist}} {% endif %}
> > {% if plist %} {% for p in plist %} {% if forloop.first %} Party
> > ({{ p }}) {% else %} &  Party ({{p}}) {% endif %}
> > {% endfor %}{% endif %} returned {{ reps.paginator.count }} > span> result(s)
> > 
> > {% for object in reps.object_list %}
> > {{ object.Position }} {{ object.First_Name }}
> > {{ object.Last_Name }} http://django.newsok.com/government/
> > reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more
> > {% endfor %}
> > 
>
> > 
> > {% if reps.has_previous %}
> >  > href="={{ reps.previous_page_number }}">Previous
> > {% else %}
> > Previous
> > {% endif %}
>
> > {% if reps.has_next %}
> > Next > a>
> > {% else %}
> > Next
> > {% endif %}
> > 
>
> > That href is the cause of the problem, how do I pass a page to the url
> > without resetting the query?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: How to define different user types?

2010-05-10 Thread Nick
Yeah, this is built in to django.

You are on the right track with user.contrib.auth. If you are doing
this all from the admin then it's as simple as creating a few groups,
giving them the permisions you want and then assigning users to those
groups.

If you are doing it on a front facing site, then there are many
template tags and view for checking permissions.

I hate to just point you at the documentation but it's pretty thorough
in this topic and without specific examples it would be difficult to
work through any examples.

http://docs.djangoproject.com/en/1.1/topics/auth/



On May 10, 6:18 am, signallock  wrote:
> Hi all, I'm a Python n00b but find Django very useful for me. However,
> there is a problem in my recent project which needs several user
> roles. For example, the 'user' role can browse some information and
> submit some register forms, the 'admin' role can view and verify these
> forms and/or modify them, the 'manager' role can add or delete 'admin'
> users. All users need to login in order to specify their roles. I've
> read some documentations about django.contrib.auth and django-
> authorization all day but still confused...  Is there any way to
> implement this? Or, can django.contrib.auth do this? I really want to
> use decorations in views.py to authenticate different types of users
> or verify different permissions of users if it is possible.
> I'm sorry to post this low-level thread but I've really read the
> documentation first. Maybe there aren't many examples, or maybe I feel
> a little bit hard to understand English :-[
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Paginating search results

2010-05-10 Thread Nick
I'm trying to paginate results from a search with multiple options.
The only problem is, once I hit the next button it clears the query
and I'm left paginating all the objects in the DB.

Here is my view:

def filter_search(request):
if request.POST:
reps = Rep.objects.all()
else:
reps = []
query = request.POST
if 'q' in request.POST:
q = request.POST.get('q', '')
qset = (
Q(Last_Name__icontains=q) | Q(First_Name__icontains=1)
   )
reps = reps.filter(qset)
else:
q = []
if len(q):
qlist = q
else:
qlist = []
if 'party' in request.POST:
party = request.POST.getlist('party')
reps = reps.filter(Party__in=party)
else:
party = []
if len(party):
plist = party
else:
plist = []
paginator = Paginator(reps, 15)
results = paginator.count
try:
page = int(request.POST.get('page', '1'))
except:
page = 1
try:
repList = paginator.page(page)
except (EmptyPage, InvalidPage):
repList = paginator.page(paginator.num_pages)
finalq = request.POST
return render_to_response("Government/search.html", {
'reps': repList,
'query': query,
'plist': plist,
'qlist': qlist,
'results': results,
'finalq': finalq
})

Here is my tpl:




Democrat  
Republican 



{% if query %}
Your search for {% if qlist %} {{ qlist}} {% endif %}
{% if plist %} {% for p in plist %} {% if forloop.first %} Party
({{ p }}) {% else %} &  Party ({{p}}) {% endif %}
{% endfor %}{% endif %} returned {{ reps.paginator.count }} result(s)

{% for object in reps.object_list %}
{{ object.Position }} {{ object.First_Name }}
{{ object.Last_Name }} http://django.newsok.com/government/
reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more
{% endfor %}




{% if reps.has_previous %}
Previous
{% else %}
Previous
{% endif %}


{% if reps.has_next %}
Next
{% else %}
Next
{% endif %}



That href is the cause of the problem, how do I pass a page to the url
without resetting the query?

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



Custom Model Fields

2010-05-09 Thread Nick Taylor
Hi all,

I want to create my own "field" type for a model, this essentially
will be a relationship to another model via a generic link model
(using GenericForeignKey etc).

As en example I basically want to do the following in models.py:

class Pizza(models.Model):
   toppings = IngredientsField()

Which can then be reused in another app sandwiches/models.py as:

class Sandwich(models.Model)
   filling = IngredientsField()

Where I use a IngredientsField() field type which then controls the
links as a separate set of models Ingredients and IngredientItems.

Now I have created in fields.py:

class IngredientsField(CharField):
def __init__(self, *args, **kwargs):
..

However I get an "Unknown column 'pizza_pizza.toppings' in 'field
list'" error - BUT I don't want to add it as a column in toppings as I
want it to be linked via the link table/model IngredientItems.
Eventually what I want to achieve is while using the admin system for
certain models that you manage there will be a text box where you can
enter ingredients into a TextField in the admin comma delimited
"Cheese, Ham" and then the model take care of the rest.

Hopefully I'm pretty close, any ideas anyone?

Thanks in advance,

Nick

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



Additional Text Form Field within a Models Admin Screen

2010-05-08 Thread Nick Taylor
Hi all,

I'm pretty new to Django so bare with me if this is a simple question.

Basically, I have an Article model which is simply title, body, status
etc. Now, I want to add an additional TextBox to the admin for the
model, but I don't want to add it as part of the Article model, as I
don't want to store it directly into the database as a string.

The TextBox will take an input, lets say "1, 2, 3, 4" I then want to
programmatically split this by the comma and add each item (1, 2, 3,
4) as a separate record which is a pre-existing model.

Any advice here would be greatly appreciated!

Thanks a lot,

Nick

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



Re: Working out some custom API stuff

2010-05-06 Thread Nick
Never mind this, I got it figured out.

Thanks again

On May 6, 12:51 pm, Nick <nickt...@gmail.com> wrote:
> Thanks for the help on that portion, it is working wonderfully.
>
> I've been able to power through most of the requests for this project
> but there is one outstanding element in regards to pagination.
>
> Here is my view:
>
> def QandAAPI(request, site):
>     quest = entry.objects.filter(site__name__icontains=site)
>     if 'id' in request.GET:
>         ids = request.GET.getlist('id')
>         quest = quest.filter(id__in=ids)
>     if 'sect' in request.GET:
>         sect = request.GET.getlist('sect')
>         quest = TaggedItem.objects.get_by_model(quest, sect)
>     if 's' in request.GET:
>         s = request.GET['s']
>         search_query = (
>         Q(question__icontains=s) | Q(answer__icontains=s) |
> Q(answerer__icontains=s)
>         )
>         quest = quest.filter(search_query)
>     if 'count' in request.GET and not 'page' in request.GET:
>         count = request.GET['count']
>         quest = quest[:count]
>     if 'count' in request.GET and 'page' in request.GET:
>         page = int(request.GET['page'])
>         count = request.GET['count']
>         paginator = Paginator(quest, count)
>         try:
>             page = paginator.page(page)
>         except ValueError:
>             page = 1
>     json = serializers.serialize("json", quest)
>     return HttpResponse(json)
>
> I am getting the following error when I try to plug a page=1 into the
> URL
>
> coercing to Unicode: need string or buffer, int found
>
> I'm not entirely sure how to fix this error, I've tried many times.
>
> The final view should do the following:
>
> Check to see if 'page' and 'coutn' are part of the url. If they are,
> then pull up the results of that page with the count declared in the
> URL.
>
> There will be another component that will skip the 'count' if it isn't
> declared but I haven't got there yet.
>
> On May 5, 4:11 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
>
>
> > On May 5, 4:46 am, Nick <nickt...@gmail.com> wrote:
>
> > > Here's the deal. I'm working on a customAPIfor moving information
> > > about. I am stuck at a point in creating my view.
> > > It might be best just to get into the details.
>
> > > Here is the model:
>
> > > class entry(models.Model):
> > >     question = models.CharField('Question', max_length=200,
> > > blank=False)
> > >     answer = models.TextField('Answer', blank=False)
> > >     answerer = models.CharField("Expert's Name", max_length=100,
> > > blank=False)
> > >     credentials = models.CharField ("Expert's Credentials",
> > > max_length=100, blank=False)
> > >     published  = models.DateTimeField(auto_now_add=True)
> > >     updated = models.DateTimeField(auto_now=True)
> > >     site = models.ForeignKey(Site)
> > >     section = TagField()
>
> > > Once a site is picked the feed is narrowed down by id (whether single
> > > id, list or range), then by section (single or multiple) and finally
> > > some pagination and count params (I'm not worried about that right
> > > now). Currently, I am stuck on the section portion. I may be going
> > > about this all wrong. What I would like is for some URL like:
>
> > >http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME
>
> > > to produce a JSON output of Questions and Answers under that site with
> > > that section name. Here is my view:
>
> > > def QandAAPI(request, site):
> > >     quest = entry.objects.filter(site__name__icontains=site)
> > >     if 'id' in request.GET:
> > >         id = request.GET.get('id','')
> > >         id = id.split(',')
> > >     else:
> > >         id = quest.values_list('id', flat=True)
> > >     if 'sect' in request.GET:
> > >         sect = request.GET.get('sect','')
> > >     else:
> > >         sect = ''
> > >     quest = quest.filter(id__in=id, section=sect)
> > >     object = serializers.serialize("json", quest)
> > >     json = "%s" % object
> > >     return HttpResponse(json)
>
> > > Basically, I would like the "else: sect=" to be a WILDCARD so if the
> > > sect portion of theAPIisn't explicitly stated then it just pulls
> > > everything.
>
> > > What do you think? Raw SQL? I'm a complete bonehead? All opinions/
> > > advice are welcome.
>
> > I wouldn't call you a bonehead, but the metho

Re: Django 1.2 release candidate available

2010-05-06 Thread Nick Serra
Awesome! Thanks so much!

On May 6, 3:32 am, Federico Capoano  wrote:
> I've been using the beta for a while and it works pretty good for what
> I've seen.
>
> On May 6, 6:40 am, James Bennett  wrote:
>
>
>
>
>
> > Tonight we're proud to announce, finally, the first Django 1.2 release
> > candidate. If all goes well, it will also be the *only* release
> > candidate, and Django 1.2 final will release one week from today.
>
> > For more information, consult:
>
> > * The Django project 
> > weblog:http://www.djangoproject.com/weblog/2010/may/05/12-rc-1/
> > * The release notes:http://docs.djangoproject.com/en/dev/releases/1.2-rc-1/
>
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > correct."
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Working out some custom API stuff

2010-05-06 Thread Nick
Thanks for the help on that portion, it is working wonderfully.

I've been able to power through most of the requests for this project
but there is one outstanding element in regards to pagination.

Here is my view:


def QandAAPI(request, site):
quest = entry.objects.filter(site__name__icontains=site)
if 'id' in request.GET:
ids = request.GET.getlist('id')
quest = quest.filter(id__in=ids)
if 'sect' in request.GET:
sect = request.GET.getlist('sect')
quest = TaggedItem.objects.get_by_model(quest, sect)
if 's' in request.GET:
s = request.GET['s']
search_query = (
Q(question__icontains=s) | Q(answer__icontains=s) |
Q(answerer__icontains=s)
)
quest = quest.filter(search_query)
if 'count' in request.GET and not 'page' in request.GET:
count = request.GET['count']
quest = quest[:count]
if 'count' in request.GET and 'page' in request.GET:
page = int(request.GET['page'])
count = request.GET['count']
paginator = Paginator(quest, count)
try:
page = paginator.page(page)
except ValueError:
page = 1
json = serializers.serialize("json", quest)
return HttpResponse(json)

I am getting the following error when I try to plug a page=1 into the
URL

coercing to Unicode: need string or buffer, int found

I'm not entirely sure how to fix this error, I've tried many times.

The final view should do the following:

Check to see if 'page' and 'coutn' are part of the url. If they are,
then pull up the results of that page with the count declared in the
URL.

There will be another component that will skip the 'count' if it isn't
declared but I haven't got there yet.



On May 5, 4:11 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On May 5, 4:46 am, Nick <nickt...@gmail.com> wrote:
>
>
>
> > Here's the deal. I'm working on a customAPIfor moving information
> > about. I am stuck at a point in creating my view.
> > It might be best just to get into the details.
>
> > Here is the model:
>
> > class entry(models.Model):
> >     question = models.CharField('Question', max_length=200,
> > blank=False)
> >     answer = models.TextField('Answer', blank=False)
> >     answerer = models.CharField("Expert's Name", max_length=100,
> > blank=False)
> >     credentials = models.CharField ("Expert's Credentials",
> > max_length=100, blank=False)
> >     published  = models.DateTimeField(auto_now_add=True)
> >     updated = models.DateTimeField(auto_now=True)
> >     site = models.ForeignKey(Site)
> >     section = TagField()
>
> > Once a site is picked the feed is narrowed down by id (whether single
> > id, list or range), then by section (single or multiple) and finally
> > some pagination and count params (I'm not worried about that right
> > now). Currently, I am stuck on the section portion. I may be going
> > about this all wrong. What I would like is for some URL like:
>
> >http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME
>
> > to produce a JSON output of Questions and Answers under that site with
> > that section name. Here is my view:
>
> > def QandAAPI(request, site):
> >     quest = entry.objects.filter(site__name__icontains=site)
> >     if 'id' in request.GET:
> >         id = request.GET.get('id','')
> >         id = id.split(',')
> >     else:
> >         id = quest.values_list('id', flat=True)
> >     if 'sect' in request.GET:
> >         sect = request.GET.get('sect','')
> >     else:
> >         sect = ''
> >     quest = quest.filter(id__in=id, section=sect)
> >     object = serializers.serialize("json", quest)
> >     json = "%s" % object
> >     return HttpResponse(json)
>
> > Basically, I would like the "else: sect=" to be a WILDCARD so if the
> > sect portion of theAPIisn't explicitly stated then it just pulls
> > everything.
>
> > What do you think? Raw SQL? I'm a complete bonehead? All opinions/
> > advice are welcome.
>
> I wouldn't call you a bonehead, but the method you're using to get all
> the objects when no id is passed in is... well... special.
>
> The key to doing this sort of filtering is to remember that QuerySets
> are lazy, and successive filters can be applied to them without
> hitting the database, until the time comes to actually evaluate them.
> So what you want to do is to set up the base query at the start of the
> method, then further filter it depending on the GET parameters. Then,
> if a particular parameter isn't passed in, you simply don't filter on
> it. Something like:
>
> def QandAAPI(request, site):

Working out some custom API stuff

2010-05-04 Thread Nick
Here's the deal. I'm working on a custom API for moving information
about. I am stuck at a point in creating my view.
It might be best just to get into the details.

Here is the model:


class entry(models.Model):
question = models.CharField('Question', max_length=200,
blank=False)
answer = models.TextField('Answer', blank=False)
answerer = models.CharField("Expert's Name", max_length=100,
blank=False)
credentials = models.CharField ("Expert's Credentials",
max_length=100, blank=False)
published  = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
site = models.ForeignKey(Site)
section = TagField()

Once a site is picked the feed is narrowed down by id (whether single
id, list or range), then by section (single or multiple) and finally
some pagination and count params (I'm not worried about that right
now). Currently, I am stuck on the section portion. I may be going
about this all wrong. What I would like is for some URL like:

http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME

to produce a JSON output of Questions and Answers under that site with
that section name. Here is my view:


def QandAAPI(request, site):
quest = entry.objects.filter(site__name__icontains=site)
if 'id' in request.GET:
id = request.GET.get('id','')
id = id.split(',')
else:
id = quest.values_list('id', flat=True)
if 'sect' in request.GET:
sect = request.GET.get('sect','')
else:
sect = ''
quest = quest.filter(id__in=id, section=sect)
object = serializers.serialize("json", quest)
json = "%s" % object
return HttpResponse(json)

Basically, I would like the "else: sect=" to be a WILDCARD so if the
sect portion of the API isn't explicitly stated then it just pulls
everything.

What do you think? Raw SQL? I'm a complete bonehead? All opinions/
advice are welcome.

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



Re: override a form field, to allow usernames with '@'

2010-05-04 Thread Nick Serra
I just implemented this and it's a hassle. There are heated
discussions about it. I ended up modifying the auth app and completely
eliminating the 'username' field and just using email. Then I modified
the admin app to allow the login, and am basically just completely
overriding both. Good luck!

On May 4, 10:40 am, Bill Freeman  wrote:
> Consider that there may be some third party app which you will
> want to add in the future, and that it may depend on the existing
> nature of usernames.  (E.g.; uses username as a slug and uses
> a simple regular expression in a url pattern to capture the username.
>
> Consider that usernames are currently limited to 30 characters,
> while email addresses are not, so you would also need to modify
> the User model.
>
> Wouldn't it be simpler modify the AuthenticationForm to accept
> an email address instead of a username and in the clean
> method, look up the user by email address, get the username
> from there, and authenticate on that and the collected password?
> You would still want to modify the User model to mark email
> as unique.  And you would have to modify UserCreationForm to
> collect an email address instead of a username, then in the
> clean_email method, check that the email address doesn't
> already exist, create a username that doesn't exist (from the email
> address, or randomly, adding a numeric suffix if necessary to
> make it unique, and modify the save method to set the username
> (since username wouldn't be a field of the form you might have
> to do your own user object creation and saving, rather than
> calling the super-class save method).
>
> Bill
>
>
>
>
>
> On Tue, May 4, 2010 at 1:19 AM, Felippe Bueno  wrote:
> > Btw,
>
> > I read about django don't accept @ in usernames, but I can create a User
> > using
> > User.create_user(m...@email.com, m...@email.com, mypassword)
> > The only problem is, I can't save the user at admin site.
> > I was thinking if the limitation is only at forms.
> > I did not test the authentication yet.
> > Any one know more about this ?
>
> > Thanks
> > ps - sorry my poor english.
> > Cheers
>
> > On Sun, May 2, 2010 at 7:54 AM, Rob  wrote:
>
> >> Hi,
>
> >> I'm trying to allow usernames that have '@' in them, so they can just
> >> be email addresses.  Maybe this is a bad idea.  ...  But putting that
> >> aside for a second... The admin user forms don't validate with '@' in
> >> usernames, so I thought I'd try this, which I copied from an older
> >> post in this group.
>
> >> from django.contrib.auth.admin import User, UserChangeForm,
> >> UserCreationForm, UserAdmin
>
> >> class OurUserChangeForm(UserChangeForm):
> >>    username = forms.EmailField
>
> >> class OurUserCreationForm(UserCreationForm):
> >>    username = forms.EmailField
>
> >> admin.site.unregister(User)
> >> UserAdmin.form = OurUserChangeForm
> >> UserAdmin.add_form = OurUserCreationForm
> >> admin.site.register(User, UserAdmin)
>
> >> But it doesn't work.  The user form is still validating with the
> >> 'username' from the superclass, which is a RegexField.  Is this
> >> working as designed?  Are you not allowed to override a field?
>
> >> thanks,
> >> Rob
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Is it safe to alter Django generated tables in MySQL to have composite PK?

2010-05-02 Thread Nick Arnett
On Sat, May 1, 2010 at 11:13 AM, Continuation <selforgani...@gmail.com>wrote:

>
> On Apr 30, 9:42 pm, Nick Arnett <nick.arn...@gmail.com> wrote:
>
> > If you don't have data in the table, just drop it and use
> "unique_together"
> > in models.py to define your composite key.  You'll find that in the
> Django
> > docs.  Then do syncdb and Django will create the table with your
> composite
> > key.
>
> I don't have data.
>
> Using "unique_together" wouldn't work because I want that composite
> index to be the clustered index. It'd only be the clustered index if
> it is the primary index.
>

Oh, I see now.  I often forget that Django always creates its own PK with
the id.

It should be no problem to make the Django id a unique key and the composite
key from unique_together the primary key.  I can't think of any functional
way in which they are different.  But you are right, you will have to do
this manually after syncdb.  You would still define the composite index with
unique_together, so that Django knows about it.

Just make sure you make the id column, the one that Django expects to be the
primary key, a unique index.

Although I can't think of any reason this wouldn't work, I haven't actually
tried it.  A little voice is whispering that it might affect foreign keys,
but I think they only require indexes, I don't think they have to be primary
keys.  And I think you will have to do this before you add any data, or else
the FKs will make it much harder.

Nick

>
>

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



Re: Is it safe to alter Django generated tables in MySQL to have composite PK?

2010-04-30 Thread Nick Arnett
On Wed, Apr 28, 2010 at 8:09 PM, Continuation <selforgani...@gmail.com>wrote:

> I'm using MySQL with Django.
>
> MySQL uses clustered index. I have a class AuctionBid for which the
> "natural" PK is (user_id, auction_id).
>
> I'd like to set (user_id, aucton_id) as the PK so that it'll be the
> clustered index. I understand that Django doesn't support composite
> PK. But what if after syncdb I just ALTER TABLE to make (user_id,
> aucton_id) the PK. Would that work with Django or would that introduce
> some unwanted behavior under the hood?


If you don't have data in the table, just drop it and use "unique_together"
in models.py to define your composite key.  You'll find that in the Django
docs.  Then do syncdb and Django will create the table with your composite
key.

Otherwise, you can make the change in models.py, as above, and change the PK
manually.

If there are FKs involved, you might also want to make the appropriate
changes if you're not re-creating all the involved tables with syncdb.

One other route, if you have data, is to rename the existing tables (can be
tricky with FKs), then syncdb and then copy your data... or, even easier,
create a whole new database with syncdb and copy your data into it.

Nick

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



Encoding makes text go away in templating; mx.DateTools.strptime v. utf-8

2010-04-30 Thread Nick Arnett
I'm stuck on a problem with encoding (or possibly decoding).

I'm extracting dates from web pages with regular expressions.  Now I want to
parse those dates into Python date objects.  Generally speaking, this is no
big deal.  It takes some effort because I'm dealing with a number of
different date formats, but I expected that.

I'm using mx.DateTime.strptime to parse the datetimes out of the strings
that I've captured with regexes.  That works fine much of the time.  It
fails when the string is utf-8 and there are characters that can't be
converted (a familiar problem).

The weird thing is that when I decode the original date string to latin-1,
Django seems to eat the entire string that I build out of that date.
Perhaps I should clarify.  I have a web page that shows me what text was
captured by the regex (so I can see that it is getting the correct chunk)
and it also shows me the output of strptime (using the pattern string for
the relevant date format).

So... when I display the parsed data via Django, there's nothing there.  But
when I add a character count for what my views.py script is sending to the
template, it shows that there is plenty of text there.  Somewhere in the
templating, that text is getting lost - it doesn't show up at all in on the
resulting page.  I know that my code is producing text because I can run it
stand-alone and see the generated text.

I don't quite even know how to figure out where it is disappearing... but
I'm hoping somebody here has seen something similar - vanishing string after
encoding...?

Thanks in advance for any insights.

Nick

P.S. As often happens, describing the problem helped a bit... it seems to be
related to mixing unicode and non-unicode strings.  When I decode the
results to utf-8, my text is back but I still can't get strptime to work
on these strings, even after decoding to latin-1, which I thought might do
it.  So frustrating that it looks like plain ascii on the page, but I can't
get it to behave like plain ascii!

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



Re: grabbing request while overriding save or in a signal

2010-04-30 Thread Nick Serra
Yeah, I realize this now hah. Instead I am now passing request into a
ModelForm for what I need. Basically I have a comment system, and on
each comment post I wanted to run it through Akismet, which required
the IP and User Agent. So I just passed request into my form.save()
method on comment adds. Works well. Thanks for the input though

On Apr 30, 9:12 am, zinckiwi  wrote:
> > Hey everyone. I'm trying to access the request object while overriding
> > the save or tapping into the post_save on a model. I need request info
> > when someone posts a comment. But I don't just want to handle this in
> > my view, I would like it to be cleaner than that, so that
> > functionality would remain even when i'm testing in the django admin.
>
> You actually do want to handle this in the view (or form, depending).
> Certainly not in the model :)
>
> Say you want to import some comments from another source at some point
> in the future, and you write a little custom manager command to do
> that. Your save() won't work, because you're trying to create objects
> from the command line, not via a HTTP connection, and therefore don't
> have a request object.
>
> The model is the python representation of the data. It shouldn't make
> any assumptions about its environment.
>
> Can you tell me the use case you're trying to solve here? We can
> figure out where that logic best "belongs".
>
> Regards
> Scott
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Setting readonly_fields dynamically

2010-04-29 Thread Nick
Yes that works, totally missed the get_readonly_fields method -
thanks!

Nick


On Apr 29, 4:40 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Apr 29, 3:43 pm, Nick <n...@njday.com> wrote:
>
>
>
>
>
> > Hi,
>
> > I would like to set some fields to be readonly in the Admin app based
> > on some logic, and would like to use the new readonly_fields attribute
> > of ModelAdmin if possible (rather than some other sort of hack).
>
> > I'm trying to access readonly_fields, but get the error "'GalleryForm'
> > object has no attribute 'readonly_fields'"
>
> > My code is currently as follows:
>
> > class GalleryAdminForm(forms.ModelForm):
> >         class Meta:
> >                 model = Gallery
> >         def __init__(self, *args, **kwargs):
> >                 super(GalleryAdminForm, self).__init__(*args, **kwargs)
> >                 print self.readonly_fields
>
> > Any help on how I can access readonly_fields from the ModelForm to
> > override it would be really helpful!
>
> > Thanks,
> > Nick
>
> I haven't played with it myself, but surely readonly_fields is an
> attribute of the ModelAdmin subclass, not the form?
>
> It looks like there's a get_readonly_fields method on the base
> ModelAdmin class, which takes the request as a parameter, so you
> should be able to override that and return a customised tuple as
> required.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Setting readonly_fields dynamically

2010-04-29 Thread Nick
Hi,

I would like to set some fields to be readonly in the Admin app based
on some logic, and would like to use the new readonly_fields attribute
of ModelAdmin if possible (rather than some other sort of hack).

I'm trying to access readonly_fields, but get the error "'GalleryForm'
object has no attribute 'readonly_fields'"

My code is currently as follows:

class GalleryAdminForm(forms.ModelForm):
class Meta:
model = Gallery
def __init__(self, *args, **kwargs):
super(GalleryAdminForm, self).__init__(*args, **kwargs)
print self.readonly_fields

Any help on how I can access readonly_fields from the ModelForm to
override it would be really helpful!

Thanks,
Nick

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



Re: Template composition: Rendering based on permissions

2010-04-28 Thread Nick
The bible for user authentication is found here
http://docs.djangoproject.com/en/1.1/topics/auth/

The quick answer to number 2 is to check for authentication in a
template tag:

{% if user.is_authenticated %}
Welcome back you rotten jerk
{% else %}
Log in, you rotten jerk
{% endif %}

On Apr 28, 2:46 pm, Thomas Allen  wrote:
> I think that template context processors are the answer to my first
> question. As for my second question, I could certainly check for
> permission membership in the provided PermWrapper, but I'm very
> interested in a way to check this based on the view permission
> requirement (implicitly).
>
> Thomas
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: following reverse relationship of an extended model

2010-04-28 Thread Nick Serra
Yeah, that is going to be my fallback, I was just curious on an actual
reverse relationship solution to the situation. Thanks for the input!

On Apr 28, 4:12 pm, zinckiwi  wrote:
> > class Account(models.Model):
> >     name = CharField
>
> > class Entry(models.Model):
> >     account = ForeignKey(Account)
>
> > class Page(Entry):
> >     name = CharField
>
> > There's my simple example. I want to get all pages that belong to
> > Account. account.page_set.all() does not relate, and I can do
> > account.entry_set.all(), but i obviously get all entries, which is a
> > problem because there will be many extended entry classes. Thanks in
> > advance!
>
> Perhaps not the most sophisticated solution, but I would expect
> Page.objects.filter(account=account) to work.
>
> Regards
> Scott
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



following reverse relationship of an extended model

2010-04-28 Thread Nick Serra
Hey, quick query question. I know there has to be an answer for this
one, just don't know the syntax. I need to follow the reverse
relationship for an extended model.

class Account(models.Model):
name = CharField

class Entry(models.Model):
account = ForeignKey(Account)

class Page(Entry):
name = CharField


There's my simple example. I want to get all pages that belong to
Account. account.page_set.all() does not relate, and I can do
account.entry_set.all(), but i obviously get all entries, which is a
problem because there will be many extended entry classes. 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



grabbing request while overriding save or in a signal

2010-04-28 Thread Nick Serra
Hey everyone. I'm trying to access the request object while overriding
the save or tapping into the post_save on a model. I need request info
when someone posts a comment. But I don't just want to handle this in
my view, I would like it to be cleaner than that, so that
functionality would remain even when i'm testing in the django admin.
Kinda stumped here. Thanks in advace!

class Comment(models.Model):
post = models.ForeignKey(Post)
author = models.ForeignKey(User, blank=True, null=True)
name = models.CharField(max_length=255)
email = models.EmailField(blank=True)
body = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
return self.name

def save(self, *args, **kwargs):
#NEED REQUEST IN HERE
super(Comment, self).save(*args, **kwargs)

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



Re: adding foreign key attributes to the admin editing screen

2010-04-26 Thread Nick Serra
Are you trying to interface django with an existing table? Why do you
have the StandardCode class foreign key-ing to the table, instead of
just making a model that references the table exactly?

On Apr 26, 2:43 pm, Jesse  wrote:
> Table LOINCCode has loinc_obr4 (a number) and a description field
> (describing the number).
>
> Model Statement:
> Class StandardCode(models.Model):
>   loinc_obr4 = models.ForeignKey(LOINCCode, null=True, default=1,
> related_name='loinccodeobr4')
>
> In the Admin:
> fieldsets =[
>        (None,      {'fields': [('loinc_obr4')]})
>        ]
>
> The admin template shows the loinc_obr4 field, but I need the
> description to also appear with the loinc_obr4.  How do I expand the
> foreign key in the admin to add more attributes in the drop down?
> ACCESS has this capability when creating a combo box.
>
> Thx,
>
> Jesse
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: M2M Manager -- how to get primary key of join table?

2010-04-26 Thread Nick Serra
You could create a model that references the join table itself.

class ArticlePublicationsJoin(models.Model):
id = models.AutoField()
publicaiton_id = models.IntegerField()
article_id = models.IntegerField()

class Meta:
db_table = 'article_publications'

then just query on that...

query = ArticlePublicationsJoin.objects.get(publication_id='pub_id',
article_id='art_id')
primary_key = query.pk


On Apr 22, 7:13 pm, Info Cascade  wrote:
> Hi --
>
> I have two models with a m2m relationship, and I need to get the value
> of the primary key of the join table.
>
> To use the example from the book:
>
>
>
>
>
> > from django.db import models
>
> > class Publication(models.Model):
> >     title = models.CharField(max_length=30)
>
> >     def __unicode__(self):
> >         return self.title
>
> >     class Meta:
> >         ordering = ('title',)
>
> > class Article(models.Model):
> >     headline = models.CharField(max_length=100)
> >     publications = models.ManyToManyField(Publication)
>
> >     def __unicode__(self):
> >         return self.headline
>
> >     class Meta:
> >         ordering = ('headline',)
>
> Django creates the article_publications join table automatically.
>
> What I need is, for a particular combination of article and publication,
> what is the primary key in the join table?
>
> Any thoughts?
>
> Please Cc: me at liamk -- AT -- numenet --DOT--com if you can help!
>
> Thanks,
> Liam
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: How to return an audio file in django

2010-04-26 Thread Nick Serra
Interesting. If the file is an mp3, maybe try:

file = open("/path/to/my/song.mp3", "rb").read()
response['Content-Disposition'] = 'attachment; filename=filename.mp3'
return HttpResponse(file, mimetype="audio/mpeg")


On Apr 26, 1:20 pm, Dexter  wrote:
> Hi there,
>
> I want to send an audio file via a django view, but I don't know how.
>
> This doesn't seem to work:
>
>     return HttpResponse(open(song.path).read(), mimetype = "audio/mpeg")
>
> Can you guy's help me?
>
> Grtz, Dexter
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: difficulty with 1.2 CSFR processing

2010-04-26 Thread Nick Serra
Include request context:

from django.template import RequestContext

...and then pass it in with the render. That should include the token
in the template.

return render_to_response('add_pair.html', {},
context_instance=RequestContext(request))

On Apr 26, 12:45 pm, jeff  wrote:
> so i have some views and forms done without using the
> CsrfViewMiddleware. now i am converting to a 1.2 project using this
> middleware. read the doc, looked for examples, still can't process the
> POST function from my form.
>
> the example i have is very simple. hoping for someone who knows this
> to take a quick look and tell me where i went wrong:
>
> i get this message:
> ==
> 403 Forbidden
> CSRF verification failed. Request aborted.
> Help
> Reason given for failure:
>     No CSRF or session cookie.
>
> followed the links and instructions provided.
>
> my template now has:
> ==
> {% block other_cont %}
>         
>         page to add a new pair.
>         {% csrf_token %}
>                 
>                         {{ form.as_table }}
>                 
>                 
>         
>         
> {% endblock %}
>
> and my view has this:
> ===
> def add_pair(request):
>         # these are the basic locals we need to set for the template to
> populate
>         page_title='Add a Pair'
>         if request.method == 'POST':
>                 form=SymForm(request.POST)
>                 if form.is_valid():
>                         s1=form.cleaned_data['sym1']
>                         s2=form.cleaned_data['sym2']
>                         s=Pair(sym1=s1,sym2=s2)
>                         s.save()
>                         url='/sym/added/'+s1+"/"+s2+"/"
>                         return HttpResponseRedirect(url)
>         else:
>                 form = SymForm()
>         c = {}
>         c.update(csrf(request))
>         return render_to_response('add_pair.html', locals())
>
> and form was not changed:
> 
> class SymForm(forms.Form):
>         sym1=forms.CharField()
>         sym2=forms.CharField()
>
>         def clean_sym1(self):
>                 cleaned_data = self.cleaned_data
>                 sym1 = cleaned_data.get("sym1")
>                 ok=False
>                 if re.match("^[A-Z.]{1,6}$",sym1):
>                         ok=True
>                 if not ok:
>                         raise forms.ValidationError("A symbol must be 1-6 
> characters in
> length, caps only")
>                 return sym1
>
>         def clean_sym2(self):
>                 cleaned_data = self.cleaned_data
>                 sym2 = cleaned_data.get("sym2")
>                 ok=False
>                 if re.match("^[A-Z.]{1,6}$",sym2):
>                         ok=True
>                 if not ok:
>                         raise forms.ValidationError("A symbol must be 1-6 
> characters in
> length, caps only")
>                 return sym2
>
> my settings.py has the middleware:
> ==
> MIDDLEWARE_CLASSES = (
>     'django.middleware.common.CommonMiddleware',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.middleware.csrf.CsrfViewMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.contrib.messages.middleware.MessageMiddleware',
> )
>
> please could you help???
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: feed decorator

2010-04-26 Thread Nick Serra
Seems very odd how you're trying to implement this. Unless your
pseudocode has me confused. Can you give us the view functions too?
Seems like you're trying to use a decorator function on two views. Why
don't you just bail on the decorator, and just check for
request.GET.get('format') == 'rss', and if true kick out the rss
template instead of the html one.

On Apr 26, 7:05 am, Nuno Maltez  wrote:
> Have you tried invoking the pyhton debugger inside _wrapped to find
> out the actual values of req_format and fmt and what's happening in
> there?
>
> Nuno
>
>
>
>
>
> On Mon, Apr 19, 2010 at 4:15 AM, Streamweaver  wrote:
> > I'm having trouble developing a feed decorator. I feel like the
> > decorator I've come up with should work but isn't and I wanted to ask
> > if someone can spot my error.
>
> > I have two view methods one that returns a normal HTML view and
> > another that returns an rss feed of the same data.  They both take the
> > same arguments.  I am trying to create a decorator that checks the
> > request objects for a format variable in the querystring and returns
> > the feed view instead of the html view.  Like so:
>
> > my_view_feed
>
> > @format_req('rss', my_view_feed)
> > my_view
>
> > So a request for '/site/foo/bar' would return 'my_view' but '/site/foo/
> > bar?format=rss' would return 'my_view_feed'
>
> > This is the decorator method I created and I would think would work
> > but I'm still struggling a bit with decorators with arguments, even
> > after reading Bruce's excellent post (http://www.artima.com/weblogs/
> > viewpost.jsp?thread=240845)
>
> > def format_req(fmt, new_fn):
>
> >    def _decorator(view_fn):
>
> >        def _wraped(request, *args, **kwargs):
> >            req_format = request.GET.get('format', None)
> >            if req_format == fmt:
> >                return new_fn(request, *args, **kwargs)
> >            # Default to returning the original method
> >            return view_fn(request, *args, **kwargs)
>
> >        return _wraped
>
> >    return _decorator
>
> > I would have though a request with 'format=rss' would return new_view
> > but no matter what I do I always get view_fn returned.
>
> > Can anyone point me toward where I'm going wrong.  As usual I'll post
> > the final code once I get it working for reference.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Many-To-Many issue; trying to find a way around conditional id

2010-04-26 Thread Nick Serra
Can you be more clear on the exact result you're trying to achieve? Do
you want to see, for a given high school, how many recruit objects are
foreign keyed to it?

On Apr 26, 7:38 am, Nuno Maltez  wrote:
> Are you saying that:
>
> collegelist = 
> college.current_objects.filter(collegechoices__school=highschoolid).exclude 
> (name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))
>
> gives you the same results as
>
> collegelist = 
> college.current_objects.exclude(name='Undeclared').distinct().annotate(ccou 
> nt=Count('collegechoices'))
>
> ?
>
> I don't think it should behave that way...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Track "before" and "after" state of an object when editing in the Admin?

2010-04-26 Thread Nick Serra
There are a couple ways to do this.  You can either override the model
methods like save and init, or you can use signals and tie into the
pre_save, post_save, etc. Signals are here:
http://docs.djangoproject.com/en/dev/ref/signals/

If using signals, you will have an instance of the object being saved.
Im sure there are better ways to do it, but i'd probably use the
instance variable and do a query for the original. So query for the
sender where pk=instance.pk, and compare it to the instance being
saved. Again, seems sloppy to me, im sure theres a better way.

If you're overriding the model save, you can create a copy of what you
want to compare in the init function. I just did this the other day.
For example, i wanted to check for a different title. Look at my
overridden __init__ and my overridden save and see how I copied the
title to a new variable for comparison.

class Entry(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)
body = models.TextField()
user = models.ForeignKey(User)
created = models.DateTimeField(auto_now_add=True)

def __init__(self, *args, **kwargs):
super(Entry, self).__init__(*args, **kwargs)
#set current title to check for title change on save
self.current_title = self.title

def save(self, *args, **kwargs):
if self.pk: #this save is an update, not a create
if self.title != self.current_title: #new title?
#new title, update slug
self.slug = self.create_unique_slug()
else:
#created new entry, generate slug
self.slug = self.create_unique_slug()
super(Entry, self).save(*args, **kwargs)



On Apr 26, 8:33 am, Derek  wrote:
> The Django docs point to the "hooks" you can use for custom code when
> saving/deleting objects in the Django 
> adminhttp://www.djangoproject.com/documentation/models/save_delete_hooks/
>
> What is not clear is how (or rather, where) to create a copy of an object
> before editing, so that it can be compared to the "revised" version altered
> by the user and appropriate code be executed.
>
> How and where can this be done?
>
> Thanks
> Derek
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Performing an action on model.save() but not on update

2010-04-26 Thread Nick Serra
:)

On Apr 26, 9:48 am, Jim N <jim.nach...@gmail.com> wrote:
> Nick,
>
> Thanks very much.  That worked!  I can't work out why my code didn't
> though (or rather, worked twice).
>
> -Jim
>
> On Apr 23, 6:37 pm, Nick Serra <nickse...@gmail.com> wrote:
>
>
>
>
>
> > Try this out and see what happens:
>
> > def _hook_post_save_answer(instance, created, sender, **kwargs):
> >     if created:
> >         if instance.user:
> >             quser = instance.user.get_profile()
> >             quser.increment_answers()
> >         instance.question.increment_responses()
>
> > post_save.connect(_hook_post_save_answer, sender=Answer)
>
> > On Apr 23, 6:20 pm, Jim N <jim.nach...@gmail.com> wrote:
>
> > > OK, that makes total sense.
>
> > > I've implemented it like so:
>
> > > def _hook_post_save_answer(instance, sender, **kwargs):
> > >     if 'created' in kwargs and kwargs['created'] == True:
> > >         if instance.user:
> > >             quser = instance.user.get_profile()
> > >             quser.increment_answers()
> > >         instance.question.increment_responses()
>
> > > post_save.connect(_hook_post_save_answer, sender=Answer)
>
> > >http://dpaste.de/897o/
>
> > > But now, it increments TWICE!
>
> > > Is there some glaring error in my logic above?
>
> > > On Apr 23, 4:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > > > I didn't even think of that. It's not very common to be specifying
> > > > pk's on create anyway, so yours would probably be fine. I just think
> > > > signals are cleaner and use them when I can :)
>
> > > > On Apr 23, 4:47 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
>
> > > > > Yeah, and I think my suggestion fails for a user-defined rather than
> > > > > auto-incrementing pk.
>
> > > > > On Apr 23, 4:21 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > > > > > A post save signal seems better suited for this. The post save 
> > > > > > signal
> > > > > > has an attribute 'created' that will be true or false depending on 
> > > > > > if
> > > > > > the object is being created or updated. Check out the post_save
> > > > > > documentation:http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.si...
>
> > > > > > On Apr 23, 3:32 pm, Skylar Saveland <skylar.savel...@gmail.com> 
> > > > > > wrote:
>
> > > > > > > On Apr 23, 3:27 pm, Jim N <jim.nach...@gmail.com> wrote:
>
> > > > > > > > Hi,
>
> > > > > > > > I have overridden the default save() on a model so that I can 
> > > > > > > > update
> > > > > > > > some counts every time a save occurs.  Unfortunately, I don't 
> > > > > > > > want to
> > > > > > > > perform these actions every time the model is updated, which 
> > > > > > > > seems to
> > > > > > > > happen.
>
> > > > > > > > Is there another approach I can take that distinguishes between 
> > > > > > > > save
> > > > > > > > and update?
>
> > > > > > > > class Answer(models.Model):
> > > > > > > >     answer = models.TextField()
> > > > > > > >     user = models.ForeignKey(User, null=True)
> > > > > > > >     submit_date = models.DateTimeField('Date Submitted',
> > > > > > > > default=datetime.datetime.now)
> > > > > > > >     question = models.ForeignKey(Question)
> > > > > > > >     permalink = models.CharField(max_length=300, blank=True)
>
> > > > > > > >     def save(self, *args, **kwargs):
> > > > > > > >         super(Answer, self).save(*args, **kwargs) # Call the 
> > > > > > > > "real"
> > > > > > > > save() method.
> > > > > > > >         if(self.user):
> > > > > > > >             quser = self.user.get_profile()
> > > > > > > >             quser.increment_answers()   # <-- I don't want to 
> > > > > > > > do this
> > > > > > > > on an update.
> > > > > > > >             self.question.increment_resp

Re: Performing an action on model.save() but not on update

2010-04-23 Thread Nick Serra
Try this out and see what happens:

def _hook_post_save_answer(instance, created, sender, **kwargs):
if created:
if instance.user:
quser = instance.user.get_profile()
quser.increment_answers()
instance.question.increment_responses()

post_save.connect(_hook_post_save_answer, sender=Answer)

On Apr 23, 6:20 pm, Jim N <jim.nach...@gmail.com> wrote:
> OK, that makes total sense.
>
> I've implemented it like so:
>
> def _hook_post_save_answer(instance, sender, **kwargs):
>     if 'created' in kwargs and kwargs['created'] == True:
>         if instance.user:
>             quser = instance.user.get_profile()
>             quser.increment_answers()
>         instance.question.increment_responses()
>
> post_save.connect(_hook_post_save_answer, sender=Answer)
>
> http://dpaste.de/897o/
>
> But now, it increments TWICE!
>
> Is there some glaring error in my logic above?
>
> On Apr 23, 4:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
>
>
> > I didn't even think of that. It's not very common to be specifying
> > pk's on create anyway, so yours would probably be fine. I just think
> > signals are cleaner and use them when I can :)
>
> > On Apr 23, 4:47 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
>
> > > Yeah, and I think my suggestion fails for a user-defined rather than
> > > auto-incrementing pk.
>
> > > On Apr 23, 4:21 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > > > A post save signal seems better suited for this. The post save signal
> > > > has an attribute 'created' that will be true or false depending on if
> > > > the object is being created or updated. Check out the post_save
> > > > documentation:http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.si...
>
> > > > On Apr 23, 3:32 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
>
> > > > > On Apr 23, 3:27 pm, Jim N <jim.nach...@gmail.com> wrote:
>
> > > > > > Hi,
>
> > > > > > I have overridden the default save() on a model so that I can update
> > > > > > some counts every time a save occurs.  Unfortunately, I don't want 
> > > > > > to
> > > > > > perform these actions every time the model is updated, which seems 
> > > > > > to
> > > > > > happen.
>
> > > > > > Is there another approach I can take that distinguishes between save
> > > > > > and update?
>
> > > > > > class Answer(models.Model):
> > > > > >     answer = models.TextField()
> > > > > >     user = models.ForeignKey(User, null=True)
> > > > > >     submit_date = models.DateTimeField('Date Submitted',
> > > > > > default=datetime.datetime.now)
> > > > > >     question = models.ForeignKey(Question)
> > > > > >     permalink = models.CharField(max_length=300, blank=True)
>
> > > > > >     def save(self, *args, **kwargs):
> > > > > >         super(Answer, self).save(*args, **kwargs) # Call the "real"
> > > > > > save() method.
> > > > > >         if(self.user):
> > > > > >             quser = self.user.get_profile()
> > > > > >             quser.increment_answers()   # <-- I don't want to do 
> > > > > > this
> > > > > > on an update.
> > > > > >             self.question.increment_responses() # <-- I don't want 
> > > > > > to
> > > > > > do this either.
>
> > > > > > Or in more readable form:http://dpaste.de/I2IR/
>
> > > > > Before you call super you can see if bool(self.pk) is True or False.
> > > > > It will be False before the first save.
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups "Django users" group.
> > > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to 
> > > > > django-users+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group 
> > > > > athttp://groups.google.com/group/django-users?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Django users" group.
> > > > To post to this group,

Re: Performing an action on model.save() but not on update

2010-04-23 Thread Nick Serra
I didn't even think of that. It's not very common to be specifying
pk's on create anyway, so yours would probably be fine. I just think
signals are cleaner and use them when I can :)

On Apr 23, 4:47 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
> Yeah, and I think my suggestion fails for a user-defined rather than
> auto-incrementing pk.
>
> On Apr 23, 4:21 pm, Nick Serra <nickse...@gmail.com> wrote:
>
>
>
>
>
> > A post save signal seems better suited for this. The post save signal
> > has an attribute 'created' that will be true or false depending on if
> > the object is being created or updated. Check out the post_save
> > documentation:http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.si...
>
> > On Apr 23, 3:32 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
>
> > > On Apr 23, 3:27 pm, Jim N <jim.nach...@gmail.com> wrote:
>
> > > > Hi,
>
> > > > I have overridden the default save() on a model so that I can update
> > > > some counts every time a save occurs.  Unfortunately, I don't want to
> > > > perform these actions every time the model is updated, which seems to
> > > > happen.
>
> > > > Is there another approach I can take that distinguishes between save
> > > > and update?
>
> > > > class Answer(models.Model):
> > > >     answer = models.TextField()
> > > >     user = models.ForeignKey(User, null=True)
> > > >     submit_date = models.DateTimeField('Date Submitted',
> > > > default=datetime.datetime.now)
> > > >     question = models.ForeignKey(Question)
> > > >     permalink = models.CharField(max_length=300, blank=True)
>
> > > >     def save(self, *args, **kwargs):
> > > >         super(Answer, self).save(*args, **kwargs) # Call the "real"
> > > > save() method.
> > > >         if(self.user):
> > > >             quser = self.user.get_profile()
> > > >             quser.increment_answers()   # <-- I don't want to do this
> > > > on an update.
> > > >             self.question.increment_responses() # <-- I don't want to
> > > > do this either.
>
> > > > Or in more readable form:http://dpaste.de/I2IR/
>
> > > Before you call super you can see if bool(self.pk) is True or False.
> > > It will be False before the first save.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Performing an action on model.save() but not on update

2010-04-23 Thread Nick Serra
A post save signal seems better suited for this. The post save signal
has an attribute 'created' that will be true or false depending on if
the object is being created or updated. Check out the post_save
documentation: 
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save

On Apr 23, 3:32 pm, Skylar Saveland  wrote:
> On Apr 23, 3:27 pm, Jim N  wrote:
>
>
>
>
>
> > Hi,
>
> > I have overridden the default save() on a model so that I can update
> > some counts every time a save occurs.  Unfortunately, I don't want to
> > perform these actions every time the model is updated, which seems to
> > happen.
>
> > Is there another approach I can take that distinguishes between save
> > and update?
>
> > class Answer(models.Model):
> >     answer = models.TextField()
> >     user = models.ForeignKey(User, null=True)
> >     submit_date = models.DateTimeField('Date Submitted',
> > default=datetime.datetime.now)
> >     question = models.ForeignKey(Question)
> >     permalink = models.CharField(max_length=300, blank=True)
>
> >     def save(self, *args, **kwargs):
> >         super(Answer, self).save(*args, **kwargs) # Call the "real"
> > save() method.
> >         if(self.user):
> >             quser = self.user.get_profile()
> >             quser.increment_answers()   # <-- I don't want to do this
> > on an update.
> >             self.question.increment_responses() # <-- I don't want to
> > do this either.
>
> > Or in more readable form:http://dpaste.de/I2IR/
>
> Before you call super you can see if bool(self.pk) is True or False.
> It will be False before the first save.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: New with Django

2010-04-23 Thread Nick Serra
Whenever I use django on my windows box, i use XAMPP, which is a all
in one installer that gets apache and mysql.

So I:
- install XAMPP
- install python
- svn checkout django in the site-packages folder
- install mysql bindings for python
- install python image library

and I think you need to add your python path to the windows paths

hope some of that helps.

On Apr 23, 9:09 am, Anand Agarwal  wrote:
> You can write a file xyz.wsgi with following content in your application
>
> import os
> import sys
>
> sys.path.append("D:\\workspace\\python\\sspl\\src")
> sys.path.append("D:\\workspace\\python\\sspl\\src\\ssplsite")
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> and in https.conf you need to add following entry
>
> LoadModule python_module modules/mod_python.so
>
> and
>
> WSGIScriptAlias 
> >
> Order deny,allow
> Allow from all
>
> 
>
> I think this should work.
>
> Regards
> Anandwww.bootstraptoday.com
>
>
>
>
>
> On Fri, Apr 23, 2010 at 4:38 PM, Mehul  wrote:
> > Hi,
> > Last two days i am trying to set up django on my window machine.
> > I had installed
> > 1>python25.msi on d drive(d:/Python25).
> > 2>django at location :D:\Python25\Lib\site-packages\django.
> >  It showing a successful message on IP :http://127.0.0.1:8000/
> > 3>Apache 2.2
> > 4>mod_python-3.3.1.win32-py2.5-Apache2.2.exe
>
> > Up to here its working fine.
>
> > But i am not able to configure Apache for python
>
> > I added following lines in httpd.conf file
> > LoadModule python_module modules/mod_python.so
>
> > 
> >        SetHandler python-program
> >        PythonHandler django.core.handlers.modpython
> >        SetEnv DJANGO_SETTINGS_MODULE testproject.settings
> >        PythonOption django.root /d:/projects/django/testproject
> >        PythonDebug On
> >        PythonPath "['/d:/projects/django/testproject', '/django'] +
> > sys.path"
> > 
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: import request ? - django debugsqlshell

2010-04-23 Thread Nick Serra
Request is an object that django passes view functions that includes
post data, meta data, and data about the request taking place. Not
sure what your test function is doing, but to start, python is
complaining because you are referencing the variable before it has
been declared. You need to define request first. Your function might
need some valid request data to work. To start, just declare your
request first, request = []. Read up on django's request object here:

http://docs.djangoproject.com/en/dev/ref/request-response/

On Apr 22, 5:08 pm, Daxal  wrote:
> Hi,
>
> I am trying to run a little debug code before I put it on my
> testserver. I am passing in "request" variable in the django code for
> the debugsqlshell but it doesn't seem to work.
>
> >>> sresults=run_search_component(request, 'contacts')
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'request' is not defined
>
> Anyone know what the command is to import request? I checked many
> websites on google and search forums but did not find anything.
>
> Thanks for you help.
>
> Daxal
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: temp url with time limit

2010-04-23 Thread Nick Serra
Just create a model that stores the url and the expiration time. If
the url is hit past the expiration time, delete it, if it's still
within the time limit, display whatever you want to display. Obviously
this is for a small system, since you would be waiting to delete until
the url is hit, but its quick and easy. To expand on it, make a
deletion script that purges all old urls on a set interval, say daily,
on a cron job.

On Apr 23, 10:07 am, daniels  wrote:
> Take a look at this Lighttpd 
> module:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModSecDownload
> You could implement something based on what the module above is doing.
>
> On Apr 23, 12:26 pm, Faizan  wrote:
>
> > Wondering if there is a good way to generate temporary URLs that
> > expire in X days. Would like to email out a URL that the recipient can
> > click to access a part of the site that then is inaccessible via that
> > URL after some time period.
>
> > Thanks,
> > Faizian
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Retrieving an ID from a posted form

2010-04-22 Thread Nick
works like a charm, thanks Ian.

On Apr 22, 10:02 am, Ian Lewis <ianmle...@gmail.com> wrote:
> Nick,
>
> Because you won't get an id for your newly created object before you
> save it you'll need to send the email after you save the form. I'm
> assuming that ArtistFormFinal is a ModelForm but you can get the id
> using something like the following:
>
> myobj = form.save()
> send_mail(subject, "Your id is %d!" % myobj.id, email_address, recipients)
>
> I hope that's what you were looking for.
>
> Ian
>
>
>
> On Thu, Apr 22, 2010 at 11:39 PM, Nick <nickt...@gmail.com> wrote:
> > I am working on a form process with multiple levels of submission. The
> > first is a front facing form with a general set of questions that are
> > to be followed up by someone after the form is submitted (the form
> > submits and entry to the DB).  To cut down on the amount of hunting
> > that those who will be reviewing the forms have to do I'd like to be
> > able to retrieve the ID for the newly created DB entry and attach it
> > to a url that points directly to that entry in the django admin.
>
> > I have the email logic set up so that the form submits all of the
> > information via email to an individual. In the email is the link to
> > the admin. So far it just goes to a full list of entries:
>
> > ex.http://mydjango.site.com/admin/projects/app/model_name/ID
>
> > I can easily send everything up to the ID. How do i retrieve the ID
> > from the submitted form. Since this is adding an entry to the DB it
> > has to be creating an ID somewhere.  Here is my view:
>
> > def short_form(request):
> >if request.method == 'POST':
> >form = ArtistFormFinal(request.POST, request.FILES)
> >if form.is_valid():
> >name = form.cleaned_data['name']
> >year_created = form.cleaned_data['year_created']
> >home_city = form.cleaned_data['home_city']
> >home_state = form.cleaned_data['home_state']
> >genre = form.cleaned_data['genre']
> >email_address = form.cleaned_data['email_address']
> >phone_number = form.cleaned_data['phone_number']
> >website = form.cleaned_data['website']
> >audio = form.cleaned_data['audio_file']
> >subject = 'Static artists submission from %s' % (name)
> >message = render_to_string('static/short_email.txt', {
> >'name': name,
> >'year_created': year_created,
> >'home_city': home_city,
> >'genre': genre,
> >'home_state': home_state,
> >'email_address': email_address,
> >'phone_number': phone_number,
> >'website': website,
> >'audio': audio
> >})
> >recipients = ['ntankers...@opubco.com',
> > 'crobi...@opubco.com']
> >send_mail(subject, message, email_address, recipients,
> > fail_silently=False)
> >form.save()
> >return HttpResponseRedirect('thanks')
> >else:
> >form = ArtistFormFinal()
> >return render_to_response('static/artist_short.html',
> > {'form':form})
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> ===
> 株式会社ビープラウド  イアン・ルイス
> 〒150-0021
> 東京都渋谷区恵比寿西2-3-2 NSビル6階
> email: ianmle...@beproud.jp
> TEL:03-6416-9836
> FAX:03-6416-9837http://www.beproud.jp/
> ===
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



<    1   2   3   4   5   6   7   >