new user needs some advice setting up a model...

2008-09-24 Thread paul

hi all,

i've thrown myself into developing an animation pipeline using
django.  i'm new to both python and django - but have in the (distant)
past written thousands of lines of c,c++ & perl.  so, please be gentle
- but maybe not too gentle with me.

this first question is quite simple.  i have a job and shot classes
(should i call them tables?).  each job has a unique name, and can
have many shots attached to it.  a shot must have a unique name within
each job.  ie,

job=bmw, shot=1,2,3,looktest
job=goldfrapp, shot=1,2,3,4,5,6,looktest,animtest

currently, i'm using the admin UI to input job and shot information.
my question is what is the best way to make sure that i never have a
two shots of the same name per job?  should this logic be inserted
into the save method of the shot, or could/should it be inserted
elsewhere (ie, within the model itself)?

sorry for the simplicity of the question - i'm still trying to get to
grips with django/pythonific best practice...

regards to all,

paul

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



Re: new user needs some advice setting up a model...

2008-09-24 Thread paul

ah - even easier than i thought it might me.  many thanks for taking
your time to point me in the right direction.  very very much
appreciated!

-p


On Sep 24, 9:40 pm, "Alexander Pugachev"
<[EMAIL PROTECTED]> wrote:
> You can force database to watch after columns to be unique by one or in
> combinations.
> Django admin interface also can watch after this restrictions.
> How to make a model to have few attributes unique together is described
> here:
>  http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
> So you make job and id to be unique together in shot model.
>
> 2008/9/24 paul <[EMAIL PROTECTED]>
>
>
>
> > hi all,
>
> > i've thrown myself into developing an animation pipeline using
> > django.  i'm new to both python and django - but have in the (distant)
> > past written thousands of lines of c,c++ & perl.  so, please be gentle
> > - but maybe not too gentle with me.
>
> > this first question is quite simple.  i have a job and shot classes
> > (should i call them tables?).  each job has a unique name, and can
> > have many shots attached to it.  a shot must have a unique name within
> > each job.  ie,
>
> > job=bmw, shot=1,2,3,looktest
> > job=goldfrapp, shot=1,2,3,4,5,6,looktest,animtest
>
> > currently, i'm using the admin UI to input job and shot information.
> > my question is what is the best way to make sure that i never have a
> > two shots of the same name per job?  should this logic be inserted
> > into the save method of the shot, or could/should it be inserted
> > elsewhere (ie, within the model itself)?
>
> > sorry for the simplicity of the question - i'm still trying to get to
> > grips with django/pythonific best practice...
>
> > regards to all,
>
> > paul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: new user needs some advice setting up a model...

2008-09-25 Thread paul

this works well when i'm editing an individual shot.  however, i get a
error when editing shots inline.  i've had a good look around - and
this was a known problem.  does anyone know if this has been fixed?

another question: right now, i'm using the admin UI to input data.
right now, my app is more of an internal produciton system - so it
doens't need to look pretty.  however, i have also read that 'auto
forms' could/should be used instead.  can anyone set me straight
please?

many thanks again,

paul


On Sep 24, 9:40 pm, "Alexander Pugachev"
<[EMAIL PROTECTED]> wrote:
> You can force database to watch after columns to be unique by one or in
> combinations.
> Django admin interface also can watch after this restrictions.
> How to make a model to have few attributes unique together is described
> here:
>  http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
> So you make job and id to be unique together in shot model.
>
> 2008/9/24 paul <[EMAIL PROTECTED]>
>
>
>
> > hi all,
>
> > i've thrown myself into developing an animation pipeline using
> > django.  i'm new to both python and django - but have in the (distant)
> > past written thousands of lines of c,c++ & perl.  so, please be gentle
> > - but maybe not too gentle with me.
>
> > this first question is quite simple.  i have a job and shot classes
> > (should i call them tables?).  each job has a unique name, and can
> > have many shots attached to it.  a shot must have a unique name within
> > each job.  ie,
>
> > job=bmw, shot=1,2,3,looktest
> > job=goldfrapp, shot=1,2,3,4,5,6,looktest,animtest
>
> > currently, i'm using the admin UI to input job and shot information.
> > my question is what is the best way to make sure that i never have a
> > two shots of the same name per job?  should this logic be inserted
> > into the save method of the shot, or could/should it be inserted
> > elsewhere (ie, within the model itself)?
>
> > sorry for the simplicity of the question - i'm still trying to get to
> > grips with django/pythonific best practice...
>
> > regards to all,
>
> > paul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



seeking help in model design...

2008-10-06 Thread paul

hi,

I'm designing my first django app and would appreciate any advice how
best to organise my models.

I have a hierarchal model called Node.  this allows me to create a
hierarchy of nodes - and perform hierarchal operatoins.  So far so
good.  each node can be of two 'types':
1/ job
2/ shot

I did originally try and make shot & job inherit the Node model.
However, they couldn't 'link' together (ie, using self as a
ForeignKey) - as they're of different types.  So i've made each of
these two node types into seperate models.  each Node should only be
linked to one type at a time.  From the manual/book - i belive that
GenericForeignKey is the way to go.  ie, insert a GenericForeignKey
field into the Node.  Does this sound like a good approach?

Many Thanks in Advance,

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



Re: seeking help in model design...

2008-10-07 Thread paul

hi david,

many thanks for your help there. i initially tried the inheritance
method - buut found that my tree traversal broke when trying to
traverse a tree made of different types (ie, Node & Jobs).  maybe i
did something wrong?  ie, should i be able to make a tree from those
two types if derived from a common model.  or is each derived model
incompatible with each other?

cheers,

paul


On Oct 7, 11:16 am, David Hall <[EMAIL PROTECTED]> wrote:
> Hi Paul,
>
> You've got a couple of options for this.  The first uses inheritance:
>
> class Node(models.Model):
>      parent = models.ForeignKey("Node", blank=True, null=True,
>                      related_name="children")
>
> class Job(Node):
>      pass
>
> class Shot(Node):
>      pass
>
> The second uses generic foreign keys:
>
> class Job(models.Model):
>      parent_type = models.ForeignKey("contenttypes.ContentType")
>      parent_id = models.PositiveIntegerField(db_index=True)
>      parent = GenerticForeignKey("parent_type", "parent_id")
>
> class Shot(models.Model):
>      parent_type = models.ForeignKey("contenttypes.ContentType")
>      parent_id = models.PositiveIntegerField(db_index=True)
>      parent = GenerticForeignKey("parent_type", "parent_id")
>
> Personally, I'd go with the first, as it will integrate better with the
> Djano admin application.  To traverse the tree, use the Node model.
> Once you have got to your required location in the tree, use node.job or
> node.shot to get the rest of the information.
>
> David.
>
>
>
> paul wrote:
> > hi,
>
> > I'm designing my first django app and would appreciate any advice how
> > best to organise my models.
>
> > I have a hierarchal model called Node.  this allows me to create a
> > hierarchy of nodes - and perform hierarchal operatoins.  So far so
> > good.  each node can be of two 'types':
> > 1/ job
> > 2/ shot
>
> > I did originally try and make shot & job inherit the Node model.
> > However, they couldn't 'link' together (ie, using self as a
> > ForeignKey) - as they're of different types.  So i've made each of
> > these two node types into seperate models.  each Node should only be
> > linked to one type at a time.  From the manual/book - i belive that
> > GenericForeignKey is the way to go.  ie, insert a GenericForeignKey
> > field into the Node.  Does this sound like a good approach?
>
> > Many Thanks in Advance,
>
> > Paul
>
> --
>   David Hall
>   Technical Lead
>   Etianen.com
>   Tel: 07896 106290
>
>   Email   [EMAIL PROTECTED]
>   Web      www.etianen.com
> ---
>   Ask for help at [EMAIL PROTECTED]
>   Etianen.com is a small, professional web development agency that
>   specialises in fast-paced, creative development.
> - enlightened website development -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: seeking help in model design...

2008-10-07 Thread paul

hey david,

ah - thanks so much!  i made two mistakes:  using abstract - and
linking to self rather than to Node.  i'm guessing here - butu are two
models/tables created and linked together rather than a single 'uber'
table?

anyway, i'm back up and running on my fledgling project - thanks to
you!  :-)

-p

On Oct 7, 6:23 pm, David Hall <[EMAIL PROTECTED]> wrote:
> Hi Paul,
>
> So long as the common model is not abstract, it should work.  Also, the
> common model must be the one that contains the parent field, and it
> should link to "Node" and not "self".
>
> Using my first example, you should be able to traverse the tree using
> Node.parent and Node.children.  Traversing the tree using Job.parent,
> Job.children, Shot.parent or Shot.children will not work.
>
> I've implemented the first example in one of my own apps, and it does
> work!  :P
>
> David.
>
>
>
> paul wrote:
> > hi david,
>
> > many thanks for your help there. i initially tried the inheritance
> > method - buut found that my tree traversal broke when trying to
> > traverse a tree made of different types (ie, Node & Jobs).  maybe i
> > did something wrong?  ie, should i be able to make a tree from those
> > two types if derived from a common model.  or is each derived model
> > incompatible with each other?
>
> > cheers,
>
> > paul
>
> > On Oct 7, 11:16 am, David Hall <[EMAIL PROTECTED]> wrote:
> >> Hi Paul,
>
> >> You've got a couple of options for this.  The first uses inheritance:
>
> >> class Node(models.Model):
> >>      parent = models.ForeignKey("Node", blank=True, null=True,
> >>                      related_name="children")
>
> >> class Job(Node):
> >>      pass
>
> >> class Shot(Node):
> >>      pass
>
> >> The second uses generic foreign keys:
>
> >> class Job(models.Model):
> >>      parent_type = models.ForeignKey("contenttypes.ContentType")
> >>      parent_id = models.PositiveIntegerField(db_index=True)
> >>      parent = GenerticForeignKey("parent_type", "parent_id")
>
> >> class Shot(models.Model):
> >>      parent_type = models.ForeignKey("contenttypes.ContentType")
> >>      parent_id = models.PositiveIntegerField(db_index=True)
> >>      parent = GenerticForeignKey("parent_type", "parent_id")
>
> >> Personally, I'd go with the first, as it will integrate better with the
> >> Djano admin application.  To traverse the tree, use the Node model.
> >> Once you have got to your required location in the tree, use node.job or
> >> node.shot to get the rest of the information.
>
> >> David.
>
> >> paul wrote:
> >>> hi,
> >>> I'm designing my first django app and would appreciate any advice how
> >>> best to organise my models.
> >>> I have a hierarchal model called Node.  this allows me to create a
> >>> hierarchy of nodes - and perform hierarchal operatoins.  So far so
> >>> good.  each node can be of two 'types':
> >>> 1/ job
> >>> 2/ shot
> >>> I did originally try and make shot & job inherit the Node model.
> >>> However, they couldn't 'link' together (ie, using self as a
> >>> ForeignKey) - as they're of different types.  So i've made each of
> >>> these two node types into seperate models.  each Node should only be
> >>> linked to one type at a time.  From the manual/book - i belive that
> >>> GenericForeignKey is the way to go.  ie, insert a GenericForeignKey
> >>> field into the Node.  Does this sound like a good approach?
> >>> Many Thanks in Advance,
> >>> Paul
> >> --
> >>   David Hall
> >>   Technical Lead
> >>   Etianen.com
> >>   Tel: 07896 106290
>
> >>   Email   [EMAIL PROTECTED]
> >>   Web      www.etianen.com
> >> ---
> >>   Ask for help at [EMAIL PROTECTED]
> >>   Etianen.com is a small, professional web development agency that
> >>   specialises in fast-paced, creative development.
> >> - enlightened website development -
>
> --
>   David Hall
>   Technical Lead
>   Etianen.com
>   Tel: 07896 106290
>
>   Email   [EMAIL PROTECTED]
>   Web      www.etianen.com
> ---
>   Ask for help at [EMAIL PROTECTED]
>   Etianen.com is a small, professional web development agency that
>   specialises in fast-paced, creative development.
> - enlightened website development -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Model formset saving with form.save(commit=False)

2009-07-28 Thread Paul

Hello,

I understand that Django won't let you save incomplete fields in a
single form created from a Model unless you do this:

tmpform = form.save(commit=False)
tmpform.foo = form.cleaned_data['foo']
tmpform.save()

So I want to do this kind of thing with forms in a formset - I am
trying to to iterate through all the fields for each form in the
formset. But the problem is that I'm not sure exactly how to iterate
through all the fields of each form in the formset. I tried this:

for form in formset.forms:
  for name, field in form.fields.items():
tmpform = form.save(commit=False)
tmpform.field[name] = form.cleaned_data[name] # doesn't work,
I get an error
tmpform.save()

But I only get the ERROR message:

'FooForm' object has no attribute 'field'.

My question is: how do I use form.save(commit=False) properly given
that I have multiple fields in a form with different field names?

Thanks in advance!
Paul

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



Re: ModelForm and saving with excluded Fields

2009-07-28 Thread Paul

>From the djangoproject website:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/


If you specify fields or exclude when creating a form with ModelForm,
then the fields that are not in the resulting form will not be set by
the form's save() method. Django will prevent any attempt to save an
incomplete model, so if the model does not allow the missing fields to
be empty, and does not provide a default value for the missing fields,
any attempt to save() a ModelForm with missing fields will fail. To
avoid this failure, you must instantiate your model with initial
values for the missing, but required fields:

author = Author(title='Mr')
form = PartialAuthorForm(request.POST, instance=author)
form.save()

Alternatively, you can use save(commit=False) and manually set any
extra required fields:

form = PartialAuthorForm(request.POST)
author = form.save(commit=False)
author.title = 'Mr'
author.save()


I hope that helps!

Paul






On Jul 28, 4:58 pm, Streamweaver  wrote:
> To be clear.  Essentially I just want to merge the object instance and
> POST data with the POST data overwriting the instance where it's
> supplied.  Right now if I don't supply a field in my POST data it just
> submits null values.
>
> Thanks again and sorry for any repetition or frustration.
>
> On Jul 28, 5:25 pm, Streamweaver  wrote:
>
> > I have been struggling with this for a few weeks without resolution
> > and hope someone can help me.
>
> > I have a model that I edit via a form but the field returned for
> > editing vary depending on the user permissions and group.
>
> > When I bind a form to POST data some fields may or may not be included
> > in that post.  All I really want to do is take the model I'm editing,
> > change anything submitted by the POST data and leave the rest as is
> > but I don't seem to be able to find a way to do this without having to
> > explicitly declare each field.  Is there a way around this or
> > something I'm missing.
>
> > Thanks in advance for any 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model formset saving with form.save(commit=False)

2009-07-28 Thread Paul

After fiddling around I think I found the syntax that seems to work
for my purposes:

if formset.is_valid():
   for form in formset.forms:
 tmpform = form.save(commit=False)
 for field in form:
if not field.form.is_bound:
  data = field.form.initial.get(field.name,
field.field.initial)
  if callable(data):
data = data()
else:
  data = field.data

setattr(tmpform, field.name, data)
print "fieldname: %s - value: %s" %(field.name,data)

 tmpform.save()

The reason I just didn't do:

if formset.is_valid():
  formset.save()

is because I wanted to see what the POST was giving me. And it turns
out that I should have included all the hidden fields in my manually
created form in my template. So I had to include this in my template
too to get all the POST data necessary to change the data in my model:

{% for hid in form.hidden_fields %}
{{hid}}
{% endfor %}

On Jul 28, 2:34 am, Paul  wrote:
> Hello,
>
> I understand that Django won't let you save incomplete fields in a
> single form created from a Model unless you do this:
>
>     tmpform = form.save(commit=False)
>     tmpform.foo = form.cleaned_data['foo']
>     tmpform.save()
>
> So I want to do this kind of thing with forms in a formset - I am
> trying to to iterate through all the fields for each form in the
> formset. But the problem is that I'm not sure exactly how to iterate
> through all the fields of each form in the formset. I tried this:
>
>     for form in formset.forms:
>       for name, field in form.fields.items():
>         tmpform = form.save(commit=False)
>         tmpform.field[name] = form.cleaned_data[name] # doesn't work,
> I get an error
>         tmpform.save()
>
> But I only get the ERROR message:
>
>     'FooForm' object has no attribute 'field'.
>
> My question is: how do I use form.save(commit=False) properly given
> that I have multiple fields in a form with different field names?
>
> Thanks in advance!
> Paul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Getting object representing the current user

2010-05-05 Thread Paul
I have the following model (stripped of comments and __unicode__ for
brevity) which defines  a comment in my Django app (I'm not using the
comment module provided with Django for various reasons):

class Comment(models.Model):
  comment = models.TextField()
  added_by = models.ForeignKey(User)
  added_date = models.DateTimeField(auto_now_add = True)
  approved = models.BooleanField()

class CommentForm(ModelForm):
  class Meta:
model = Comment
fields = ['comment']

I also have a simple template which just displays the CommentForm
(i.e. a textarea within a form element) and the action of the form is
set to the following view:

def add_comment(request):
  if request.method == 'POST' and request.user.is_authenticated():
comment = Comment()
comment.added_by = request.user
comment.approved = False

comment_form = CommentForm(request.POST, instance = comment)

if comment_form.is_valid():
  comment.save()
  return HttpResponseRedirect('/')

However, when I submit the form I get the following error:

(1048, "Column 'added_by_id' cannot be null")

I'm sure request.user must be set, because it is being accessed
earlier in the code (request.user.is_authenticated), so I'm not sure
why this error is appearing. Am I doing something obviously wrong? I'm
new to both Django and Python so I am picking things up as I go along.

Thanks in advance for any pointers.

-- 
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: Getting object representing the current user

2010-05-09 Thread Paul
On May 5, 10:12 pm, Daniel Roseman  wrote:
> On May 5, 9:30 pm, Paul  wrote:
>
>
>
> > I have the following model (stripped of comments and __unicode__ for
> > brevity) which defines  a comment in my Django app (I'm not using the
> > comment module provided with Django for various reasons):
>
> > class Comment(models.Model):
> >   comment = models.TextField()
> >   added_by = models.ForeignKey(User)
> >   added_date = models.DateTimeField(auto_now_add = True)
> >   approved = models.BooleanField()
>
> > class CommentForm(ModelForm):
> >   class Meta:
> >     model = Comment
> >     fields = ['comment']
>
> > I also have a simple template which just displays the CommentForm
> > (i.e. a textarea within a form element) and the action of the form is
> > set to the following view:
>
> > def add_comment(request):
> >   if request.method == 'POST' and request.user.is_authenticated():
> >     comment = Comment()
> >     comment.added_by = request.user
> >     comment.approved = False
>
> >     comment_form = CommentForm(request.POST, instance = comment)
>
> >     if comment_form.is_valid():
> >       comment.save()
> >       return HttpResponseRedirect('/')
>
> > However, when I submit the form I get the following error:
>
> > (1048, "Column 'added_by_id' cannot be null")
>
> > I'm sure request.user must be set, because it is being accessed
> > earlier in the code (request.user.is_authenticated), so I'm not sure
> > why this error is appearing. Am I doing something obviously wrong? I'm
> > new to both Django and Python so I am picking things up as I go along.
>
> > Thanks in advance for any pointers.
>
> What's probably happening is that because you're instantiating the
> object first, then passing it to the form, the form is overwriting all
> the attributes. There are two ways of fixing this: either exclude the
> added_by field in the form Meta class:
>   exclude = ('added_by',)
> or, and this is probably better, set the added_by and approved fields
> when you come to save:
>     if comment_form.is_valid():
>       comment.save(commit=False)
>       comment.added_by = request.user
>       comment.approved = False
>       comment.save()

Thanks for the pointer, I managed to get the code to work as so (just
for reference in case anyone else comes across this post):

comment_form = CommentForm(request.POST)

if comment_form.is_valid():
  comment = comment_form.save(commit = False)
  comment.added_by = request.user
  comment.approved = False

  comment.save()

Ever so slightly different from your suggestion (i.e. I don't set
comment until after I've checked for validity) but it works as I
expect.

-- 
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 template tag extends works

2010-05-21 Thread paul

hi -- given this example template:

{% for item in items %}
   {% extends "example.html" %}
{% endfor %}

When this block is evaluated during template rendering, does the file
"example.html" get opened for every iteration of the loop, or might
the contents of "example.html" get cached the first time it's opened?

-- 
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 template tag extends works

2010-05-21 Thread paul

sorry -- I made a mistake -- I meant include instead of extends  :-p

{% for item in items %}
{% include "example.html" %}
{% endfor %}

does example.html get opened for every iteration of the loop, or just
at the first iteration, and then perhaps cached?


On May 21, 12:36 am, paul  wrote:
> hi -- given this example template:
>
> {% for item in items %}
>    {% extends "example.html" %}
> {% endfor %}
>
> When this block is evaluated during template rendering, does the file
> "example.html" get opened for every iteration of the loop, or might
> the contents of "example.html" get cached the first time it's opened?
>
> --
> 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 template tag extends works

2010-05-21 Thread paul



On May 21, 12:46 am, Marcus Carlsson 
wrote:
> Does example.html print the data in `item` and if so, why not make the
> loop in example.html and just use include one time in your "main"
> template?
>
> Concerning your actual question. Even if it's cached it seems like bad
> practice to me so I would avoid using this method but without more info
> about what example.html holds it's hard to say.

Let's say example.html outputs a html block showing some attributes of
item:

{% for item in items %}
{% include "example.html" %}
{% endfor %}

example.html:

{{ item.id }} {{ item.name }}



Obviously another solution is:
{% for item in items %}

{{ item.id }} {{ item.name }}

{% endfor %}


but in my case, it's useful for me to use example.html with other
templates.  I thought about this some more and I'd suspect {% include
%} opens a file every time, as it's within a generic {% for %} loop,
unless {% include %} is structured to be able to reference a file it's
already opened.  The reason I'm asking is because there would be a
performance penalty if the file has to be opened for every loop
iteration?




> On 21 May 12:40, paul wrote:
>
>
>
>
>
>
>
> > sorry -- I made a mistake -- I meant include instead of extends  :-p
>
> > {% for item in items %}
> >     {% include "example.html" %}
> > {% endfor %}
>
> > does example.html get opened for every iteration of the loop, or just
> > at the first iteration, and then perhaps cached?
>
> > On May 21, 12:36 am, paul  wrote:
> > > hi -- given this example template:
>
> > > {% for item in items %}
> > >    {% extends "example.html" %}
> > > {% endfor %}
>
> > > When this block is evaluated during template rendering, does the file
> > > "example.html" get opened for every iteration of the loop, or might
> > > the contents of "example.html" get cached the first time it's opened?
>
> > > --
> > > 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: Django architecture question

2010-06-15 Thread Paul


On 15 Jun., 06:55, Joel Klabo  wrote:
> I am working on a simple site right now and the views are pretty easy.
> Usually just iterate a loop of objects. But, I am trying to figure out
> how a website with all different kinds of data, including a sign in
> form, is setup in django. Is that all in one big view? Or, is there
> some way to combine them?
>
> Any insight would be helpful, thank you.

Hi Joel,

very good question, I take it you want to know how "composition" is
done at the "page level" without dragging all the logic into one view.
In django you can generate recurring elements with template tags, for
adding variables to the request or generate markup directly.

say you want a list of users that joined your site recently:

class RecentUsersNode(template.Node):
def __init__(self, limit):
try: self.limit = int(limit)
except ValueError: self.limit = 10

def render(self, context):
profiles = UserProfile.objects.order_by('user__date_joined')
[:self.limit]
context['recent_users'] = profiles
return ''

@register.tag
def recent_users(parser, token):
args = token.split_contents()
if len(args) <= 1:
return RecentUsersNode(10)

num = args[1]
if(num[0] == num[-1] and num[0] in ('"', "'")):
num = num[1:-1] # strip quotes
return RecentUsersNode(num)



{% recent_users %} will add a list of UserProfile objects to your
request and you can use it like:

{% for profile in recent_users %}
  
{% endfor %}


In the old days of web 1.0 there was a natural 1:1 mapping from the
page to a script/function which generates the content. With ajax it's
becoming more like a desktop app where you have many parts/widgets
with callbacks or events. If you want the page to display without JS,
you still have to generate the page with one request though...

cheers
 Paul

-- 
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 architecture question

2010-06-15 Thread Paul


On 15 Jun., 18:17, Joel Klabo  wrote:
> Thanks, good info. So the template tag can do the DB query and all
> that without going through a view function?
Yes, see the query in the example code I posted:
 profiles = UserProfile.objects.order_by('user__date_joined')
[:self.limit]

cheers
 Paul

>
> On Jun 15, 8:09 am, Paul  wrote:
>
>
>
> > On 15 Jun., 06:55, Joel Klabo  wrote:
>
> > > I am working on a simple site right now and the views are pretty easy.
> > > Usually just iterate a loop of objects. But, I am trying to figure out
> > > how a website with all different kinds of data, including a sign in
> > > form, is setup in django. Is that all in one big view? Or, is there
> > > some way to combine them?
>
> > > Any insight would be helpful, thank you.
>
> > Hi Joel,
>
> > very good question, I take it you want to know how "composition" is
> > done at the "page level" without dragging all the logic into one view.
> > In django you can generate recurring elements with template tags, for
> > adding variables to the request or generate markup directly.
>
> > say you want a list of users that joined your site recently:
>
> > class RecentUsersNode(template.Node):
> >     def __init__(self, limit):
> >         try: self.limit = int(limit)
> >         except ValueError: self.limit = 10
>
> >     def render(self, context):
> >         profiles = UserProfile.objects.order_by('user__date_joined')
> > [:self.limit]
> >         context['recent_users'] = profiles
> >         return ''
>
> > @register.tag
> > def recent_users(parser, token):
> >     args = token.split_contents()
> >     if len(args) <= 1:
> >         return RecentUsersNode(10)
>
> >     num = args[1]
> >     if(num[0] == num[-1] and num[0] in ('"', "'")):
> >         num = num[1:-1] # strip quotes
> >     return RecentUsersNode(num)
>
> > {% recent_users %} will add a list of UserProfile objects to your
> > request and you can use it like:
>
> > {% for profile in recent_users %}
> >   
> > {% endfor %}
>
> > In the old days of web 1.0 there was a natural 1:1 mapping from the
> > page to a script/function which generates the content. With ajax it's
> > becoming more like a desktop app where you have many parts/widgets
> > with callbacks or events. If you want the page to display without JS,
> > you still have to generate the page with one request though...
>
> > cheers
> >  Paul

-- 
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 architecture question

2010-06-15 Thread Paul


On 15 Jun., 18:21, Joel Klabo  wrote:
> I guess what I'm am trying say is that I was under the impression that
> when you go to a URL, a view is called. And only one view can be
> called per URL.
Yes, one page -> one URL. Some page elements can have their own URL
, ,   etc...

> And that view needs to serve all of the data for that
> page. It seems like there is a way to have multiple views being
> rendered simultaneously. Is it all javascript or just a huge view
> with: user login, feeds of current data, etc...
Ajax solves this. Without javascript it should be possible to base a
layout on  and the initial view only sets the src attribute of
all iframes. When I learned HTML, it was generally accepted that
frames are bad. Unfortunately I don't remember the exact reason and
haven't used them since ;)

cheers
 Paul
>
> On Jun 15, 8:09 am, Paul  wrote:
>
>
>
> > On 15 Jun., 06:55, Joel Klabo  wrote:
>
> > > I am working on a simple site right now and the views are pretty easy.
> > > Usually just iterate a loop of objects. But, I am trying to figure out
> > > how a website with all different kinds of data, including a sign in
> > > form, is setup in django. Is that all in one big view? Or, is there
> > > some way to combine them?
>
> > > Any insight would be helpful, thank you.
>
> > Hi Joel,
>
> > very good question, I take it you want to know how "composition" is
> > done at the "page level" without dragging all the logic into one view.
> > In django you can generate recurring elements with template tags, for
> > adding variables to the request or generate markup directly.
>
> > say you want a list of users that joined your site recently:
>
> > class RecentUsersNode(template.Node):
> >     def __init__(self, limit):
> >         try: self.limit = int(limit)
> >         except ValueError: self.limit = 10
>
> >     def render(self, context):
> >         profiles = UserProfile.objects.order_by('user__date_joined')
> > [:self.limit]
> >         context['recent_users'] = profiles
> >         return ''
>
> > @register.tag
> > def recent_users(parser, token):
> >     args = token.split_contents()
> >     if len(args) <= 1:
> >         return RecentUsersNode(10)
>
> >     num = args[1]
> >     if(num[0] == num[-1] and num[0] in ('"', "'")):
> >         num = num[1:-1] # strip quotes
> >     return RecentUsersNode(num)
>
> > {% recent_users %} will add a list of UserProfile objects to your
> > request and you can use it like:
>
> > {% for profile in recent_users %}
> >   
> > {% endfor %}
>
> > In the old days of web 1.0 there was a natural 1:1 mapping from the
> > page to a script/function which generates the content. With ajax it's
> > becoming more like a desktop app where you have many parts/widgets
> > with callbacks or events. If you want the page to display without JS,
> > you still have to generate the page with one request though...
>
> > cheers
> >  Paul

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



user authentication

2010-12-09 Thread Paul
Long story short have several django projects running

I log in ok and the projects run fine using the admin interface.

However :

I have added users and given them access to only certian applications
on the django site using the admin interface, however when i log in
with out supervisor access checked all is blank aka no applications
etc  and a message that says You have no permission to access anything
on this site.

Is there a different login link for normal users to use? (aka no /
admin but something else)

Is there setup required (which is probable) - I can not find any
documentation on this directly.

I consider myself pretty clever but i am stumpped.

Would like to use the admin site to manage how user login and what
they get access to


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



"current transition aborted" not sure if this is a bug

2010-02-11 Thread paul

hello -- just let me know if my description below sounds like a bug.
If so, I can try to put together a decent bug report...

I am working on fleshing out the integration of a custom
authentication backend.  Basically I have a OpenLDAP directory that is
used to store user names and passwords (in conjunction with Samba --
entries are inputted using smbldap-tools).  I have the backend working
just fine -- I can get a login screen, enter an appropriate username
and password, and can confirm that the password is being authenticated
correctly through a comparison with the password stored in the LDAP
server.

Now the weird part... the next step after logging in is obviously to
redirect to another HTML page.  I was originally using PostgreSQL
(8.4, via psycopg2) while coding, and was never able to get redirected
to a new page and instead got a traceback (see below) printed to my
WWW browser.  I decided to try switching to MySQL (5.0), and did not
replicate this issue -- while running MySQL I'm redirected to a web
page after logging in.  The Django server shows a HTTP GET command for
the web page to be redirected to when MySQL is the database engine,
but I don't see this GET with PostgreSQL.

If this sounds like a bug, I'll try to submit a bug report.  I'm using
Django 1.1.1

thanks,

Paul

The traceback with PostgreSQL:

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 651, in __call__
return self.application(environ, start_response)
  File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
wsgi.py", line 245, in __call__
response = middleware_method(request, response)
  File "/usr/local/lib/python2.6/site-packages/django/contrib/sessions/
middleware.py", line 36, in process_response
request.session.save()
  File "/usr/local/lib/python2.6/site-packages/django/contrib/sessions/
backends/db.py", line 56, in save
sid = transaction.savepoint()
  File "/usr/local/lib/python2.6/site-packages/django/db/
transaction.py", line 190, in savepoint
connection._savepoint(sid)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/
__init__.py", line 62, in _savepoint
self.cursor().execute(self.ops.savepoint_Traceback (most recent
call last):
  File "/usr/local/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 651, in __call__
return self.application(environ, start_response)
  File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
wsgi.py", line 245, in __call__
response = middleware_method(request, response)
  File "/usr/local/lib/python2.6/site-packages/django/contrib/sessions/
middleware.py", line 36, in process_response
request.session.save()
  File "/usr/local/lib/python2.6/site-packages/django/contrib/sessions/
backends/db.py", line 56, in save
sid = transaction.savepoint()
  File "/usr/local/lib/python2.6/site-packages/django/db/
transaction.py", line 190, in savepoint
connection._savepoint(sid)
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/
__init__.py", line 62, in _savepoint
self.cursor().execute(self.ops.savepoint_create_sql(sid))
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/
util.py", line 19, in execute
return self.cursor.execute(sql, params)
InternalError: current transaction is aborted, commands ignored until
end of transaction block
create_sql(sid))
  File "/usr/local/lib/python2.6/site-packages/django/db/backends/
util.py", line 19, in execute
return self.cursor.execute(sql, params)
InternalError: current transaction is aborted, commands ignored until
end of transaction block


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



can't authenticate in template

2010-02-12 Thread paul

hi -- after I do a login that successfully goes through a custom
authenticate() and django login(), I get redirected to a web page that
is build off of a template that prints out the value of
{{ user.is_authenticated }}.  This always returns False, and after
more interrogation I discovered that user is AnonymousUser.  I have
read the Django docs several times over (TEMPLATE_CONTEXT_PROCESSORS
has django.core.context_processors.auth, and I'm sending the
successful login web page as render_to_response(template, directory,
context_instance(RequestContext(request)).  This has been perplexing
because as far as I can tell, I've successfully logged in a user and
created a session that has an user_id corresponding to the user, but
an AnonymousUser is being used to generate the template...  any of
this sound familiar?

This is Django 1.1.1, running off python 2.6.4, on a linux box.

thanks,

paul

-- 
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: can't authenticate in template

2010-02-12 Thread paul


On Feb 12, 1:54 am, bruno desthuilliers
 wrote:
> On Feb 12, 9:40 am, paul  wrote:
>
> > hi -- after I do a login that successfully goes through a custom
> > authenticate() and django login(), I get redirected to a web page that
> > is build off of a template that prints out the value of
> > {{ user.is_authenticated }}.  This always returns False, and after
> > more interrogation I discovered that user is AnonymousUser.  I have
> > read the Django docs several times over (TEMPLATE_CONTEXT_PROCESSORS
> > has django.core.context_processors.auth,
>
> Do you have the required middlewares  too ?

Yes, the middlewares are installed

> > and I'm sending the
> > successful login web page as render_to_response(template, directory,
> > context_instance(RequestContext(request)).
>
> From the view doing the auth and login ?

I'm using the Django-provided view to do the auth & login.  When the
login is successful, it sends out a HttpResponseRedirect.  The login
page then asks for the URL to the next page, which goes through
urls.py and to another view that provides the RequestContext to
provide the "successful login page".

paul

-- 
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: can't authenticate in template

2010-02-12 Thread paul

some more info...

I added "django.core.context_processors.request" to
TEMPLATE_CONTEXT_PROCESSORS

Based on my code below, it seems like the session is storing the
correct user ID for the user that just logged in (I confirmed this by
changing the user ID in the database manually), but for some reason
the user bound to the request is still AnonymousUser.  Did I overlook
something?

views.py:

def home(request):  # called after a successful authentication & login
context = {}
template = 'accounts/home.html'
rc = RequestContext(request)
print request.user  # prints "AnonymousUser"
print request.session['_auth_user_id']  # prints out the correct
ID for the user who just logged in
return render_to_response(template, context, context_instance=rc)

the home.html is just very basic right now:

{{ user.is_authenticated }} # returns False
{{ request.session.items }} # output includes the correct ID for the
user who just logged in

-- 
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: can't authenticate in template

2010-02-12 Thread paul

Another post because I think I explain my issue a little better
here...

in my case:

1) a successful log in results in a call to a HttpResponseRedirect
that goes straight to the web page I'm specifying.

2) I checked right before this HttpResponseRedirect is called, and the
User object that was returned by login() is returning True (based on
user.is_authenticated())

3) The View that handles the URL specified by HttpResponseRedirect has
a request.session object that has an _auth_user_id corresponding to
the user that just successfully logged in.

4) that same view has a request.user that corresponds to an
AnonymousUser instance.

It would help me to know whether this is *normal* behavior -- right
after a user successfully logs in, the view handling the rendering of
the next web page has a request.session tied to this user, but the
request.user is AnonymousUser.  Do I need to do something like the
following instead?:

views.py:
def show_page_after_successful_login(request):
uid = request.session.get('_auth_user_id')
user = User.objects.get(pk=uid)
request.user = user
rc = RequestContext(request)
return render_to_response(template, context, context_instance=rc)

thanks again...

-- 
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: can't authenticate in template

2010-02-12 Thread paul


On Feb 12, 3:57 pm, pbzRPA  wrote:
> It's going to be difficult to help you out if you using a custom
> authentication.
>
> Take a look at this comment from the django site and tell me if you
> following these rules in your custom authentication.
>


yes, django.contrib.auth.authenticate() is called first, then
django.contrib.authenticate.login() is called.  I can confirm this by
placing print statements at the appropriate places within the django
base code to tell me the code execution order.

In the function django.contrib.auth.views.login, if I put in a print
statement to show the result of request.user.is_authenticated() right
before returning HttpResponseRedirect, I get "True".

However, the view that handles the URL requested by
HttpResponseRedirect returns False when I check
request.user.is_authenticated().

I hope I'm being clear... thanks for responding,

Paul


> """
> Calling authenticate() first
>
> When you're manually logging a user in, you must call authenticate()
> before you call login(). authenticate() sets an attribute on the User
> noting which authentication backend successfully authenticated that
> user (see the backends documentation for details), and this
> information is needed later during the login process.
> """

-- 
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: can't authenticate in template

2010-02-12 Thread paul


On Feb 12, 4:33 pm, pbzRPA  wrote:
> Can you please add a dump of your MIDDLEWARE_CLASSES as it is in your
> settings file.


Sure, here it is:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

-- 
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: can't authenticate in template

2010-02-12 Thread paul


On Feb 12, 5:03 pm, pbzRPA  wrote:
> The middleware looks good. Is your browser maybe not blocking cookies?
> I have really though hard about it, but without code it's really
> difficult to get a picture of where the problem may lie. You also said
> you do custom authentication, then why is it that you printing out the
> request in the django.contrib,auth.views.login?


In settings.py, I also have:

AUTHENTICATION_BACKENDS = ('auth.backends.ldap_backend',)

The following code represents the backend that authenticates against a
LDAP directory.  It is working correctly (if the supplied username and
password match, it returns a User -- I've verified this.  I'm trying
to not overflow this message with code, hopefully I'm including enough
code to be informative.  So basically my understanding is that if I
want to use a different authentication backend, I just specify it
under AUTHENTICATION BACKENDS, and Django will abstract the
authentication and login process as long as my authentication backend
returns a User instance if an entered username and password are
validated.  Please see the following code, I'll add some more comments
after it:

class ldap_backend(ModelBackend):
def authenticate(self, username=None, password=None):
if username is not None and password is not None:


if valid:  # valid = True if username & password matched
the LDAP entry
return self.get_user(username)

def get_user(self, username):
try:
return User.objects.get(username=username)
except User.DoesNotExist:
return None

The following is a portion of the django.contrib.auth.login function.
If I supply the correct username and password, the function executes
all the way to returning HttpResponseRedirect.  I am showing where I
put in a print statement to show request.user.is_authenticated().
This prints "True".

def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME):
"Displays the login form and handles the login action."
redirect_to = request.REQUEST.get(redirect_field_name, '')
if request.method == "POST":

print "end %s" % request.user.is_authenticated()  # will
be True if username & pw are validated
return HttpResponseRedirect(redirect_to)


Now, here is the code of the view that handles redirect_to:

view.py
def home(request):
context = {'title_prefix' : 'Account Home'}
template = 'accounts/home.html'
rc = RequestContext(request)
return render_to_response(template, context, context_instance=rc)

In this code, if I check request.user.is_authenticated, it returns
False.  request.user is actually AnonymousUser.  However, if I look at
request.session.items, I see the correct _auth_user_id for the user
that just logged in.

I hope that my code might be helpful.  I'm quite perplexed about
what's wrong.

thanks again,

Paul

-- 
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: can't authenticate in template

2010-02-16 Thread paul


On Feb 13, 1:38 am, pbzRPA  wrote:
> Just as a suggestion, if you don't need to customize the get_user()
> method then simply don't have a get_user() method in your custom
> authentication class.


Great, thank you for helping me out.  I actually didn't realize there
was a get_user function in ModelBackend (whoops), and I managed to
name my function for returning an authenticated User the same way.  I
have it working now.

paul

-- 
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 render date and time separately with newforms.SplitDateTimeWidget

2007-06-13 Thread Paul

Is this possible?  The old forms module allowed you to render the date
and time separately in the template for the form.  Now it seems this
is no longer possible.  So it isn't possible for instance to render
the date on one row of a table and the time on the following row just
below it like:
{{form.blah}}{{form.mydate.date}}
{{form.blah2}}{{form.mydate.time}}

-Paul


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



Re: How to render date and time separately with newforms.SplitDateTimeWidget

2007-06-14 Thread Paul

I don't think that is possible.  When you reference the field inside
the template (with form.my_field) you are accessing a BoundField that
is tied to the formfield in question.  From this BoundField you don't
actually have access to the widget.  Rather you call as_widget or
as_hidden (or __unicode__ which calls as_widget).  I don't see any way
in there to access anything that I add to my widget.  Even if I could
access the widget directly, I wouldn't have the data to render since
that is in the BoundField.  It seems to me that the only way to get
this to work is to make changes to BoundField (maybe adding some
BoundWidget class even) to allow you to get sub-widgets out of a
MultiWidget.  Otherwise there simply isn't any way to access the sub-
widget while also passing the data and attrs to that widget.

-Paul

On Jun 14, 12:32 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-06-14 at 00:12 +, Paul wrote:
> > Is this possible?  The old forms module allowed you to render the date
> > and time separately in the template for the form.  Now it seems this
> > is no longer possible.  So it isn't possible for instance to render
> > the date on one row of a table and the time on the following row just
> > below it like:
> > {{form.blah}}{{form.mydate.date}}
> > {{form.blah2}}{{form.mydate.time}}
>
> It's not possible with the default SplitDateTime widget, but it would be
> easy enough to subclass it to provide the functionality you want.
> Newforms are designed around encouraging people to subclass things as
> they need to add new features, rather than trying to provide everything
> by default (which becomes too difficult to use in the common cases).
>
> Create a SplitDateTimeWidget subclass and add date() and time() methods
> that return the respective widgets (would replicate some of the logic in
> MultiWidget.render)
>
> Or your could write a patch for MultiWidget that allowed access to the
> n-th widget in the sequence and post that to Trac. I can't think of
> another generic method on MultiWidget that would help, since it's meant
> to be able to handle an arbitrary number of contained values, not just
> the date+time case.
>
> Regards,
> Malcolm


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



Re: Trying to dynamically generate labels in newforms

2008-01-30 Thread Paul

The BaseForm.__init__ sets self.fields to self.base_fields.copy()
before your __init__ is run.  The correct way to change the label is:

class TestForm(forms.Form):
somefield = forms.IntegerField(label='foo')

On Jan 30, 1:06 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> I'm using a Newforms subclass, and trying to dynamically generate the labels
> for each field at runtime (long story, but it really does make sense for
> what we're doing).  Apparently I'm doing something wrong, though, because I
> always end up with the default label text and not what I'm specifying.  For
> example:
>
> class TestForm(forms.Form):
>     def __init__(self, *args, **kwargs):
>         super(ArrivalForm, self).__init__(*args, **kwargs)
>         self.base_fields['somefield'].label = 'foo'
>
>     somefield = forms.IntegerField()
>
> This doesn't have the behavior I'd expect of changing somefield's label
> from 'Somefield' to 'foo'.  Is this possible?
> --
> Kirk Strauser
>
>  signature.asc
> 1KDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Access context from with a custom filter

2008-01-30 Thread Paul

I need to access the context from within a filter.  The filter needs
to change its behavior based on the target browser
(context.request.META.HTTP_USER_AGENT).

There doesn't appear to be any way to access this information from
inside the filter.  Nor is there any way to pass this info into the
filter.

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



Multiple ForeignKey Relationship

2008-02-21 Thread paul

I'm trying to work out how I'm going to setup a model structure a
video section of my website. Say I have this scenario.

- Each video belongs to a set of 4-5 videos.
- Depending on the set the video belongs too, certain information will
need to be attached to that video (ie> recipe/chef information, wines
to drink with this recipe. Etc.)
- Videos need to be able to be independent as well, in case the set is
removed but the video is still wanted on the site. Same goes for
Recipes as they will exist independently on the site.
- In the future Videos will reside within different sets and require
different information then these.

So, my situation is this:

I have a Video model setup as a ForeignKey to my VideoSet model. I
then have Recipe and Chef information each setup as a ForeignKey to
Video. This is great for adding Recipe and Chef info to a video
directly through the admin, however the Recipe and Chef information do
not get attached to the Video within the VideoSet admin interface.

Is there a way to nest ForeignKey relationships?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Multiple ForeignKey Relationship

2008-02-21 Thread paul

Hi Michael,

Thanks a lot. That query made me realize I've got to re-think this.

http://groups.google.com/group/django-users/browse_thread/thread/477915b60c5d160e/ff677bbbf87ea9b3?lnk=gst&q=django+edit+inline#ff677bbbf87ea9b3


On Feb 21, 8:21 am, Michael Newman <[EMAIL PROTECTED]> wrote:
> http://www.djangoproject.com/documentation/model-api/#many-to-one-rel...
>
> look at the edit inline option. The blogosphere is also nice enough to
> have posted hundreds of examples and test cases that might meet your
> purposes. Google django edit inline for these examples.
>
> On Feb 21, 9:56 am, [EMAIL PROTECTED] wrote:
>
> > I'm trying to work out how I'm going to setup a model structure a
> > video section of my website. Say I have this scenario.
>
> > - Each video belongs to a set of 4-5 videos.
> > - Depending on the set the video belongs too, certain information will
> > need to be attached to that video (ie> recipe/chef information, wines
> > to drink with this recipe. Etc.)
> > - Videos need to be able to be independent as well, in case the set is
> > removed but the video is still wanted on the site. Same goes for
> > Recipes as they will exist independently on the site.
> > - In the future Videos will reside within different sets and require
> > different information then these.
>
> > So, my situation is this:
>
> > I have a Video model setup as a ForeignKey to my VideoSet model. I
> > then have Recipe and Chef information each setup as a ForeignKey to
> > Video. This is great for adding Recipe and Chef info to a video
> > directly through the admin, however the Recipe and Chef information do
> > not get attached to the Video within the VideoSet admin interface.
>
> > Is there a way to nest ForeignKey relationships?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ManyToMany field on User object

2006-06-30 Thread Paul

Hi all,

I'm trying to write a model to extend the standard Django user model,
which will add (among other things) the ability to have a list of users
recorded as your friends (like Flickr, or Digg).

The model looks like this (stripped down to just the relevant fields)

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

class UserProfile(models.Model):
"""Extra fields to add to the User Model"""

User   = models.OneToOneField(User)
Friends= models.ManyToManyField(User)

--

When I add the second line I get this trace-back...

--
Dr-Stupid: pauls$ ./manage.py sql myapp
Traceback (most recent call last):
  File "./manage.py", line 11, in ?
execute_manager(settings)
  File ".../django/core/management.py", line 1297, in execute_manager
execute_from_command_line(action_mapping, argv)
  File ".../django/core/management.py", line 1255, in
execute_from_command_line
mod_list = [models.get_app(app_label) for app_label in args[1:]]
  File ".../django/db/models/loading.py", line 40, in get_app
mod = load_app(app_name)
  File ".../django/db/models/loading.py", line 51, in load_app
mod = __import__(app_name, '', '', ['models'])
  File "/Users/pauls/mysite/myapp/models.py", line 119, in ?
class UserProfile(models.Model):
  File ".../django/db/models/base.py", line 49, in __new__
new_class.add_to_class(obj_name, obj)
  File ".../django/db/models/base.py", line 131, in add_to_class
value.contribute_to_class(cls, name)
  File ".../django/db/models/fields/related.py", line 662, in
contribute_to_class
super(ManyToManyField, self).contribute_to_class(cls, name)
  File ".../django/db/models/fields/related.py", line 69, in
contribute_to_class
self.do_related_class(other, cls)
  File ".../django/db/models/fields/related.py", line 79, in
do_related_class
self.contribute_to_related_class(other, related)
  File ".../django/db/models/fields/related.py", line 672, in
contribute_to_related_class
if related.model != related.parent_model or not
self.rel.symmetrical:
  File ".../django/db/models/fields/__init__.py", line 97, in __cmp__
return cmp(self.creation_counter, other.creation_counter)
AttributeError: type object 'UserProfile' has no attribute
'creation_counter'
--

(Sorry if that wraps at the wrong place, Google Groups posting window
wraps things)

Any ideas why this is causing a problem? Has anybody else tried this
type of structure?

Thanks

Paul


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Unicode strings through Database API

2006-06-30 Thread Paul

Hi,

I'm in need of a little education. This may be a python issue rather
than a Django one, but is anybody can help I'd appreciate it.

I've written an a little script which gets external data and inserts it
into the database using the Django models. Unfortunately (or
fortunately, depending on your point of view) somebody has put the word
'Résumé' into the data source that I'm using and those accented
charactered are causing an exception when I call the save method on my
object.

The field is declared as a CharField, and the data assigned is a

Traceback (most recent call last):
  File "", line 1, in ?
  File "/Users/pauls/Documents/Web Development/myapp/myscript.py", line
37, in main
e.save()
  File ".../django/db/models/base.py", line 199, in save
','.join(placeholders)), db_values)
  File ".../django/db/backends/util.py", line 19, in execute
self.db.queries.append({
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position
991: ordinal not in range(128)

I understand that it's having problems because the string is identified
as an ASCII string and that character is beyond that, but how would I
identify this string as (probably) ISO8859-1?

Paul


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode strings through Database API

2006-06-30 Thread Paul

Ok, I've dug a little more and I realised I'd got the wrong end of the
stick.

The string I'm assigning to the field is a unicode string. Django is
trying to do a .encode('ascii') on it and failing. Understandable
really

I assume I have to do a .encode('utf-8') on it before I store it. Does
that tend to be the standard?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode strings through Database API

2006-06-30 Thread Paul


Jeremy Dunck wrote:

> I've seen some situations where multiple encodings were stuck into the
> same column, and you don't want to go there.

I can believe that :-/

That for the advice. Things seem to be working now I've encoded into
utf-8. Even Django's admin interface seems to understand utf-8
implicitly :-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Is it worth caching results obtainable via SQL?

2006-07-09 Thread Paul

Hi,

My application has a subscription model. Users can subscribe to
objects, and these subscriptions are contained in a ManyToMany field in
a per-user object



e.g.
class UserProfile(models.Model):
"""Extra fields to add to the User Model"""

related_user   = models.OneToOneField(User, ...)
subscriptions  = models.ManyToManyField(StorySection, ...)
   [blah blah snipped]



When I display my (in this case) StorySections, I may want to display a
subscription count. As far as I can see this can be done in two ways.

1) do something like
'UserProfile.objects.filter(subscriptions=obj).count()'
2) Keep a subscription count on each StorySection object. Adding one
when somebody subscribes and subtracting when they unsubscribe.

1 is obviously simpler, pushing work onto the database
2 seems to me that it would be faster, but you're updating objects more
often.

Is counting the number of objects that meet a particular criterea
likley to be a heavyweight task for the database (say to a maximum
table size of about 100K rows)

I can see the same question for comments on a blog entry, or posts
under a forum topic, so what have other people done?
If I'm letting the database do the work should I tell the database that
I'm going to be doing this type of operation on it in some way?

Thanks

Paul


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Loose coupling of objects.

2006-07-16 Thread Paul

I'm trying to come up with a way of writing re-useable code for certain
common features on two-point-oh-y sites. This might become a long post,
so apologies in advance.

Say your building the standard blog application. It's conceivable that
you'd want your users to add comments, add tags, and rate posts.

You might have a model for comments which looks slightly like this.

class Comment(models.Model):
post = models.ForeignKey(BlogPost)
author   = models.ForeignKey(User)
comment_text = models.TextField(blank=True)

something similar for tags and ratings.

Then you expand your site to add your photos, and you'd like to allow
the same features to be used, and, in fact, the same code to be used.
Trouble is, the models you've defined specifies that Comments work with
BlogPosts.

Now looking at the django.contrib.comments code I see that the author
there decided to use an integer object id rather than a ForeignKey

class Comment(models.Model):
parent   = models.IntegerField(('object ID'))
author   = models.ForeignKey(User)
comment_text = models.TextField(blank=True)

Ok, this means that the Comment can be used with any other item
(assuming it has an integer primary key), but we've got BlogPosts and
Photos on our site, and their object ids are not guaranteed to be
unique (in fact they're likely not to be). Also we've lost the nice
django DB API for traversing this relationship.

I can think of a few solutions, but don't know how to implement them.

1) Add a type_id field to the Comment model, which identifies which
table the object_id should be looked up in. I think most SQL databases
have a 'Table of Tables', but my SQL isn't good enough to know if this
is standard or not, and my django isn't good enough to know how to get
at it. Maybe it would need to be the name of the table in a varchar.

2) Have two tables containing Comments (one for BlogPosts and one for
Photos). I don't think django supports this at the moment as 1 class
appears to equal 1 table.

3) implement a 'Super'Key field which behaves like a foreignkey (i.e.
preserves the django DB API), but is able to refer to any object in any
table (possibly by storing info like (1))

Does anybody have any suggestion as to how any of these could be done?
I know this isn't really something that SQL supports, but I'm hopeful
it's possible to fake.

Thanks

Paul


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Loose coupling of objects.

2006-07-16 Thread Paul

Thanks Malcolm, I thought people must have solved this problem. I just
didn't realise what the ContentType field was.

I also found Luke Plant's tagging app
(http://groups.google.com/group/django-users/browse_thread/thread/a7cbd4fd843583be)
in which he has a GenericForeignKey, but I'll investigate the core
version first.

Thanks again.

Paul


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Everyone should read the tests directory (was Re: Loose coupling of objects.)

2006-07-17 Thread Paul


[EMAIL PROTECTED] wrote:
> The core version was built using Luke Plant's work and Ian Holsman's
> work, kind of the best of both worlds.

Yeah, once I started looking at the code I saw the commit logs that
said the same thing. Good to see things growing that quickly.

It's nice to think I was having ideas about solving it in a similar
way. I must be starting to think Django, but I'd have had no clue about
implementing it

Can I just say thanks again to Malcolm for pointing me at the unit
tests. I'd never realized they were there and they're a great resource
for learning how to use particular features, especially in the database
API. A number of things which don't appear to be documented in the
normal documentation have tests with good explanations as to how they
work.

I've worked out how to do a number of things I was unclear on from
looking at those.

http://code.djangoproject.com/browser/django/trunk/tests/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



How to generate common blocks?

2012-02-27 Thread Paul
I have a question regarding the use of the template mechanism.

Say i'm using a common website layout with header, footer and in the
center three columns. Only the center is specific to the request (so
the specific view function will generate the center block), i'm not
sure however what the best way is to generate the common blocks in the
side bars. Lets say i want to have multiple blocks with dynamic
contents (such as a random selected review or frequently searched
items). I guess is can call specific functions to generate the common
blocks but i would have to do so for each view function? This doesn't
make sense to me because quickly blocks will be generated that are not
actually used; would it be possible to do something smart? Like
specifying block-functions inside the template code?

Many thanks for any directions!

Paul

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



Need some directions howto insert image processing

2012-03-08 Thread Paul
I have a model with an ImageField and would like to add some image
processing using PIL. Problem is that i don't know how to do this
best.
My approach would be to do it in the view function (indicated below
with "Processing here?"); some concrete questions:
- How can i best reuse code to do the same thing from admin?
- Can i do the processing also from the overloaded save method in the
model? I thought no because i don't have the UploadedFile object there
any more?
- I wanted to make it efficient so since i have an
InMemoryUploadedFile object here, i would like to feed the in memory
data to a PIL image; how to do this?
Thanks for any direction,
Paul
PS: I did read a lot already on google but found no consistent
direction on this.


class rusk(models.Model):
image = models.ImageField(upload_to='uploadedImages')

class RuskForm(ModelForm):
class Meta:
model = rusk
fields = ('image')

def add(request):
if request.method == 'POST':
form = RuskForm(request.POST, request.FILES)
if form.is_valid():
---> Processing here?
rusk = form.save(commit=False)
rusk.save() #Hier pas wordt
return HttpResponseRedirect('/latest')
else:
form = RuskForm()
return render_to_response('add.html', {'form': form,},
context_instance=RequestContext(request))

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



Can i specify a different set of global context processors for admin?

2012-03-09 Thread Paul
Nearly all views of an application i'm working on have the same
sidebars with dynamic contents. So i generate these in a custom global
context processor so it is available to any view without having to
specify the custom processor each time.

It turns out that also in admin views the same processors are used
(from TEMPLATE_CONTEXT_PROCESSORS) which is not desired. So i'm
starting to doubt whether this was such a good idea or not

How could i solve this?

Paul

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



Crispy form: how to disable/readonyl all fields?

2012-05-06 Thread Paul
I have a model that i would like to create/read/update and delete
(CRUD); i'm using generic views (create_update) to do that. Also i'm
using crispy forms to do the form (layout) styling icw twitter-
bootstrap styling. Now the thing i'm not sure about is how to do the
'read' function. I prefer to show a similar page as the update
function but then without a button and with all fields set to readonly
mode (or disabled). How could i do that with crispy forms?

I'm half way there:
- I created a form class that has the FornHelper
- From the urlconf i first route to my own view function to retrieve
the object (to read)
- Then i call object_detail (from generic views) with extra_context
that has the form initialized with the object to read: extra_context =
{'form': ReadForm(instance = object)},
- Then in the template i simply invoke crispy forms to display the
'form'

This all works but the only thing left is to disable/readonly all the
fields... how can i do that?

Thanks for any idea's
Paul

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



Re: Crispy form: how to disable/readonyl all fields?

2012-05-07 Thread Paul
I have a sort of solution (but don't like it). I subclassed the crispy-
tag to change the input's into span's/uneditable's. This is done using
re's which is the part i don't like, it will only work as long as the
raw html is compatible with the re's

I know a better solution is to create custom templates for the field
for example but i'm missing complete and working examples to do that;
anyone advise?

Paul



class CrispyUneditable(UniFormNode):
'''subclass the crispy tag to modify the tags output: each input
field shall be uneditable using bootstraps uneditable styling'''
def render(self, context):
import re
value = super(CrispyUneditable, self).render(context)
return  re.sub(
r'',
r'\2', value)

# {% crispy-uneditable %} tag
@register.tag(name="crispy-uneditable")
def do_crispy_uneditable_form(parser, token):
token = token.split_contents()
form = token.pop(1)

try:
helper = token.pop(1)
except IndexError:
helper = None

return CrispyUneditable(form, helper)

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



Generic views create_object and prefill form data?

2012-05-19 Thread Paul
I have a model like this:

class Website(models.Model):
user = models.ForeignKey(User)
name = models.CharField(unique=True, max_length=32)

And use a generic view to create new items:

def website_create(request):
return create_update.create_object(
request = request,
form_class = WebsiteCreateForm)

This works except i want to prefill (and hide) the user field. Hiding
is no problem with crispy forms, but how do i prefill the user field
based on request.user?

The generic view doesn't except any initial data or pre-validate
callables.

Any help is greatly appreciated!

Paul

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



Re: Generic views create_object and prefill form data?

2012-05-23 Thread Paul
Solved it by migrating to the class based generic views, then fed
initial form data to the constructor of the form by overloading
get_initial on the view class.
Paul

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



Question object permission approach

2012-05-23 Thread Paul
Assume i have a model as follows:

class Website(models.Model):
user = models.ForeignKey(User)
name = models.CharField(unique=True, max_length=32)
url = models.URLField(unique=True)

Now i have a generic (detail) view as follows:

class WebsiteRead(DetailView):
model = Website

@method_decorator(login_required())
def dispatch(self, *args, **kwargs):
return super(WebsiteRead, self).dispatch(*args, **kwargs)

I want users to only be able to view an object when they have created
it; [self.request.user == Website.user].

What is the best approach to create this?
- I could overload get_object to query for the object based on the pk
and the fk of the user.
- Or should i use a package (from http://www.djangopackages.com/grids/g/perms/)
such as django-guardian?

Paul

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



Re: Question object permission approach

2012-05-24 Thread Paul
Thanks for thinking along.

Guardian sounds really well, also given the recent commits

However, such 'dynamic' authentication method (meaning users shall be
explicitly authorized or not) is overhead in my case since the
permission is 'static'; its simply dependent on the user field of the
model.

I followed your example by overloading the get_queryset and that
really a simple solution to this issue.

Tests are running now; all 404's; great!

Paul

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



Can i use mongodb for product/catalog?

2012-07-24 Thread Paul
I'm developing an application that receives products through product-feeds. 
Now each product will have specific attributes; a t-shirt will for example 
have a size attribute and maybe color, while a bottle of shampoo will have 
an attribute specifying the contents or weight. I could solve this in an 
rdbms using a many to many relation between a products table and an 
attributes (item) table and even an attributes (values) table.

The other day however i was reading about mongodb and now i'm wondering if 
it would be a good idea to put the products (catalog) in a mongodb.

Can anyone with more experience than me :) give any directions how this 
could look like? How can i work with mysql alongside mongodb in django for 
example?

Paul

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



Form validation using model data?

2012-07-29 Thread Paul
I have a model for Websites that has 3 fields: name, url and authenticated. 
With a form both the name and url can be changed, but when the website is 
authenticated i don't want to allow that the url changes.

I'm thinking about making the url (form) field readonly but in html the 
field becomes still an input field (just with readonly="True"), so i have 
doubts whether hackers will be able to post a changed value anyhow (i'll 
need to test this).

Another approach is to add some custom form validation against the 
(current) model, but i have doubts whether validation is the solution for 
this?

Thanks for any directions
Paul

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



Re: Form validation using model data?

2012-07-30 Thread Paul
That would be an option as well indeed. In fact i have 1 (base)-form for 
the model that i subclass for create, read and update operations. The 
difference is that create and update have a submit button, read doesn't, 
and in the read view, the fields are read-only.

The website becomes authenticated using a background process, the idea is 
that as soon as it becomes authenticated the url cannot be changed any more.

I have tested with readonly=True which works correctly apart from the fact 
that i don't think it's safe to only make the field readonly, i want to add 
some logic in the post-logic as well (so for example using custom 
validation).

A simpler alternative is to remove the 'update' button altogether, but also 
in this case the view should also throw a 404 or 500 just in case someone 
manually modifies the url (which is by the way very easy to do so).

Paul



Op maandag 30 juli 2012 00:00:48 UTC+2 schreef Kurtis het volgende:
>
> Just to get some more information about the problem; Do you allow your 
> users to initially insert the Name+URL? When does this become 
> "authenticated"?
>
> Maybe you could have two forms. One that allows users to add new Name+URL 
> Objects (not sure what your object/Model is called) and another to allow 
> them to edit (Using Django's 'fields' meta attribute to limit them to only 
> modify the "Name" of the object)
>
> On Sun, Jul 29, 2012 at 5:47 PM, Paul wrote:
>
>> I have a model for Websites that has 3 fields: name, url and 
>> authenticated. With a form both the name and url can be changed, but when 
>> the website is authenticated i don't want to allow that the url changes.
>>
>> I'm thinking about making the url (form) field readonly but in html the 
>> field becomes still an input field (just with readonly="True"), so i have 
>> doubts whether hackers will be able to post a changed value anyhow (i'll 
>> need to test this).
>>
>> Another approach is to add some custom form validation against the 
>> (current) model, but i have doubts whether validation is the solution for 
>> this?
>>
>> Thanks for any directions
>> Paul
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/urE06kkuNBIJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

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



Combining django-tables2 with django-filter info ListView?

2012-08-09 Thread Paul
I have a listview using the generic class based ListView. I have 
get_queryset overloaded in my view:

class WebsiteList(ListView):
model = Website
def get_queryset(self):
return Website.objects.all()

First step is to add the tables2 mixin as follows:

class WebsiteList(tables.SingleTableMixin, ListView):
model = Website
table_class = WebsiteTable #tables2 related
def get_queryset(self):
return Website.objects.all()

The mixin adds the table object to the context and adds an order_by clause 
to the queryset.

Now i don't know how to add a second mixin for django-filter; i have a 
mixin available but since it also fetches the queryset from get_queryset 
i'm expecting that either the ordering or the filtering won't work!?

Anyone with mixin experience willing to give some directions?

Paul

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



Re: Easy way to make all form fields read only?

2012-10-31 Thread Paul
I used to invest something similar; i wanted to to built a read view next 
to an update view that looks identical except for that read is obviously 
read-only. I used crispy-forms to do just that; recently an UneditableField 
(Layout) was added next to Field.
You do however either need to enumerate the model fields in a layout
Paul Bormans

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



Django sub-sites/user groups

2013-06-17 Thread Paul
Hey all,

I'm just beginning to look into using django for a personal project. What 
I'm wondering is if there are any plugins available or guides which could 
help achieve the following functionality. 

I want to develop a website with 'sub-sites'/user groups which users may 
create and join. These groups should be private and only accessible to 
group members. 

Is there anything like this for django at the moment or if not could 
someone point me in the right direction for how to develop such 
functionality ? 

Thank you very much. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Displaying a custom field (PickledObjectField) in the admin

2013-09-10 Thread Paul
If you just want to see (read) the contents you could do this:

class Example(models.Model):
value = PickledObjectField()

def value_unpacked(self):
return u'{value}'.format(value=self.value)
filter_link.allow_tags = True

class ExampleAdmin(admin.ModelAdmin):
list_display = ('id', 'value_unpacked',)
 
Actually modifying it is obviously more difficult as it can be ... anything 
indeed

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Manage.py not found when deploying using chef (application_python cookbook)

2015-03-27 Thread Paul
I'm trying to deploy a django application on ec2 using chef. I followed 
blogs that got me to the point where the application(_python) cookbook has 
setup a clone of the repo to shared-copy and the chef client invokes the 
first command to syncdb. Then however a problem occurs that is easy to 
explain: manage.py cannot be found and the reason is because manage.py is 
not in the tip of the repo, it is in fact two levels lower.

I'm wondering what the best approach is to solve this;
- Can i change the cwd that the application cookbook uses?
- Symlink manage.py?
- Wrap manage somehow?

Thanks for any tips,
Paul Bormans

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2ba07b14-8a8f-4e3c-a261-aad1015da932%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ManytoMany field in Django admin not appearing

2017-11-03 Thread Paul
 

I have a Product model, an Image Model and a Category Model.

A Product can have multiple Images(Foreign Key) and a Product can be in 
multiple Categories a Category can contain multiple Products.

A Category can have multiple subcategories(key to itself).


class Category(MetaData): 
 parent = models.ForeignKey('self', blank=True, null=True, verbose_name='parent 
category', on_delete=models.CASCADE) 

class ProductMetaData): 
  categories = models.ManyToManyField(Category) 

class ProductImage(models.Model):  
  product = models.ForeignKey(Product, related_name='image', on_delete=
models.CASCADE)



In Product Django Admin: 

class ProductDocumentInline(admin.TabularInline): 
 model = ProductDocument class ProductAdmin(MetaData):
 inlines = [ProductImageInline]
 fieldsets = (
 ('Product Data', {
 'fields': ('name', 'short_description', 'description')
 }),
 ('SEO', {
 'classes': ('collapse',),
 'fields': ('meta_title', 'meta_description', 'slug', 'canonical')
 }),
 ('MetaData', {
 'classes': ('collapse',),
 'fields': (('created_at', 'created_by'), ('updated_at', 'updated_by'))
 }),
 )
 readonly_fields = ('created_at', 'updated_at', 'created_by', 'updated_by')
 list_display = ('name', 'updated_at')
 ordering = ('-updated_at',)
 search_fields = ('name',)


admin.site.register(Product, ProductAdmin)
admin.site.register(ProductImage)



Issues:

   1. 
   
   If I don't customize fieldsets (grouped, ordered) the Categories appear 
   like default in the middle of the form. If there are customized as in my 
   example they don't appear.
   2. 
   
   If they don't appear Products without Categories can be created and I 
   don't want that. I want a product to have at least one category.
   3. 
   
   Now the inline Images appear below all Product fields. 
   
I want the Categories to appear first, then normal fields for 
Product(grouped,ordered), Images inline and at the end the SEO and metadata 
fields. How can this be done ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37bf83ae-cdca-4c73-8ace-747386513e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What is the role of __deepcopy__ in Python class and Django widget

2017-11-04 Thread Paul
 

First, I know how copy and deepcopy from copy module work for a list.


I'm interested the role of __deepcopy special method inside a class.


I need to create custom widgets in Django and I try to understand the 
python code behind.


class Widget(metaclass=MediaDefiningClass):

needs_multipart_form = False  # Determines does this widget need multipart 
form
is_localized = False
is_required = False
supports_microseconds = True  # for data and time values

def __init__(self, attrs=None):
if attrs is not None:
self.attrs = attrs.copy()
else:
self.attrs = {}

def __deepcopy__(self, memo):
obj = copy.copy(self)
obj.attrs = self.attrs.copy()
memo[id(self)] = obj
return obj

What is happening with *__deepcopy__* when I make an instance of Widget, or 
and instance of a subclass of Widget ? Looks like is making a shallow copy 
of attributes and the object itself , but what is the purpose ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d313c90-4407-4f9f-9518-de5327d14178%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ManytoMany Relation and Custom widget in Django

2017-11-13 Thread Paul

I have two models Categories and Products.

A Product can have multiple Categories, a Category can have multiple 
Products.

The Categories have a circular Foreign key, to itself.

class Product:
categories = models.ManyToManyField(Category)
name = models.CharField(max_length=255)

class Category:
categories = models.ManyToManyField(Category)
name = models.CharField(max_length=255)

Not all Categories have the same depth level. A Category can have no 
children and a Category can have multiple grandchildren.

*What I want to achieve:*

When a user add/create a Product, only a select-box containing the parents 
will appear. 

After the parent is selected, if the parent has children another select 
will appear with that parent children. Also the possibility to add more 
categories.

When a user what to edit a product the select boxes for what was already 
chosen should be available.

*From where I start:*

I know that to ManyToMany relation corresponds a ModelMultipleChoiceField 
Field.

To a ModelMultipleChoiceField corresponds a SelectMultiple widget.

I thought of creating an widget that inherits from SelectMultiple and 
change the templates manipulating the get_context_data on the Widget.

But my problem is that in context I don't have (know to find) the parent 
relation inside categories. 

What are my options ? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a0c5ab1-8297-41f4-befa-3d0063f100d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ManytoMany Relation and Custom widget in Django

2017-11-17 Thread Paul
I have two models Category and Products.

- a Product can have multiple Categories 
- a Category can have multiple Products.
- Categories have a circular Foreign key, to itself.
- not all Categories have the same depth level

Example:

Category A
- Category A_1
- category A_2
- Category A_2_1
Category B
Category C
- Category C_1


class Product:
categories = models.ManyToManyField(Category)
name = models.CharField(max_length=255)

class Category:
categories = models.ForeignKey(self)
name = models.CharField(max_length=255)

As Form I use a ModelForm:

class ProductForm(ModelForm):



class Meta:
model = Product
fields = ['categories', 'name', 'short_description', 
'description']
widgets = {
'categories': MyWidget,
}

**What I want to achieve:**

I want to implement a conditional select (narow options):

1. Only top parent Categories(level 0 A,B,C) are available
2. The user select a parent Category.  If the parent has children a new 
Select box appear with his children(category level 1 A1,C1) 
3. The user select a level 1 Category (A1,C1). If the parent has children a 
new Select box appear with his children(level 2 A2)

- The process is repeated until no children are availavable(recursive), an 
user select the "smallest" category in the tree
- A new button is available for the user to add more categories and start 
the 1-3 process again
- I want to do the select,add new select using JavaScript
- On Form Submit I want to send only the last children categories


Options I thought:

1. Change the ManyToMany coresponding default Fields - looks like there are 
no good hooks and/or inheritance
2. Use a non-default custom Field instean of ManytoMany(like Charfield) - 
more complex on clean,saving Form
3. Change/Inherit the widget. My issues is how to send the data to the 
default Field on submit, and get/show it on edit 
 
I need some help as code and indication how to do this.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc81ac05-b0b7-4653-9779-70998dc86370%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Issues with image.path being reported wrong causing failing of a Celery task

2018-01-17 Thread Paul
 

I have the following model:


class Image(models.Model): image = models.ImageField(upload_to=
file_upload_to)


I have a dynamic file_upload function:


def file_upload_to(instance, filename): 
  base = '_'.join([str(instance.item.pk), instance.item.slug])
  return os.path.join('accounts', base, 'item', base_2, 'images', filename)

and in a ModelForm:


class ImageModelForm(ModelForm) 
 def save(self, commit=True): 
  image_obj = super().save(commit=commit) 
  product_image__task.delay(image_obj.image.path, image_obj.image.name, 
image_obj.product_id) return image_obj



I tried also to wait for transaction:


transaction.on_commit( lambda: 
product_image_crop_task.delay(image_obj.image.path, image_obj.image.name, 
image_obj.product_id))



The file is saved properly in a path like:


media/account/12_blue/images/image_name.jpeg



The problem is that image_obj.image.path is not reporting the correct path, 
but this path:


media/image_name.jpeg


I use the image path, further passing it as an argument to a task, but 
because I received the wrong path, it will fail.


How can I fix this, and receive the correct path ?  I tried also using 
time.sleep(), nothing works, the path/location returned is wrong, even if 
is saved to the correct one.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d57595e-95b5-49f4-a29a-34f73e30620d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues with image.path being reported wrong causing failing of a Celery task

2018-01-17 Thread Paul
I did, is not celery related. 

The only thing, that maybe is influencing the path, is that the Image model 
is used in an inlineformset.



On Wednesday, January 17, 2018 at 6:37:40 PM UTC+2, Matemática A3K wrote:
>
>
> b
> On Wed, Jan 17, 2018 at 12:17 PM, Paul > 
> wrote:
>
>> I have the following model:
>>
>>
>> class Image(models.Model): image = models.ImageField(upload_to=
>> file_upload_to)
>>
>>
>> I have a dynamic file_upload function:
>>
>>
>> def file_upload_to(instance, filename): 
>>   base = '_'.join([str(instance.item.pk), instance.item.slug])
>>   return os.path.join('accounts', base, 'item', base_2, 'images', filename)
>>
>> and in a ModelForm:
>>
>>
>> class ImageModelForm(ModelForm) 
>>  def save(self, commit=True): 
>>   image_obj = super().save(commit=commit) 
>>   product_image__task.delay(image_obj.image.path, image_obj.image.name, 
>> image_obj.product_id) return image_obj
>>
>>
>>
>> I tried also to wait for transaction:
>>
>>
>> transaction.on_commit( lambda: 
>> product_image_crop_task.delay(image_obj.image.path, image_obj.image.name, 
>> image_obj.product_id))
>>
>>
>>
>> The file is saved properly in a path like:
>>
>>
>> media/account/12_blue/images/image_name.jpeg
>>
>>
>>
>> The problem is that image_obj.image.path is not reporting the correct 
>> path, but this path:
>>
>>
>> media/image_name.jpeg
>>
>>
>> I use the image path, further passing it as an argument to a task, but 
>> because I received the wrong path, it will fail.
>>
>>
>> How can I fix this, and receive the correct path ?  I tried also using 
>> time.sleep(), nothing works, the path/location returned is wrong, even if 
>> is saved to the correct one.
>>
>
> The first thing I would do is to comment out all the celery tasks to see 
> if those are messing with path property (you are not using a custom 
> storage, right?) Also, the upload_to function you posted does not 
> correspond to the path generated, try to post the latest code :)
>  
>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/7d57595e-95b5-49f4-a29a-34f73e30620d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/7d57595e-95b5-49f4-a29a-34f73e30620d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ac7266a-b913-4135-8a34-12ae22c15ee5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


InlineFormset Updating issues, after changing the value in the input

2018-01-18 Thread Paul


I have 2 models Product and Image:

class Image(models.Model):
product = models.ForeignKey(Product, related_name='images', on_delete=
models.CASCADE)
parent = models.ForeignKey('self', blank=True, null=True, 
verbose_name='original 
image', on_delete=models.CASCADE)
image = models.ImageField(upload_to=file_upload_to)
image_type = models.CharField(max_length=50)



parent is a Foreign Key to the original image

I use the Image Model in a formset:

ImageFormSet = inlineformset_factory(parent_model=Product, model=Image,
form=ImageModelForm, min_num=1, max_num=4, can_delete=True)



Steps:

Set the Product Form with the inlineformset for Image
Show and submit the creation form
save the original image(s)
after the original image is saved, create multiple image by cropping 
the original image, using a task
Edit/Update Form, show as image one of the cropped image (instead of 
original) by modifying(filter by image_type) the Formset queryset

An here appear the issue:

The {{form.id}} value in case of update, is the pk(id) of the cropped 
image, instead of the original image:





and when the image is updated, is replacing the cropped image in database 
instead of the original image, and the 'cropped' tasks after and insertion 
in database is wrong.

I tried to replace the value(using a custom widget) instead of the cropped 
image with the pk(id) of the original(parent_id).

but if I do, this, on updating/replacing an older image, the new replacing 
image, is ignored; the form submit with no errors, but the replace image is 
not replaced; the other new images are ok.

So I think is a mechanism that compares the value in the the input with 
what was passed to the form, and if doesn't correspond is jut ignoring.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb636da0-293e-4427-9da4-966fc652dcc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Populating more than one model from the same form ?

2016-07-09 Thread Paul
thanks, outside not in admin, I will check the links provided

On Saturday, July 9, 2016 at 10:52:38 PM UTC+3, ludovic coues wrote:
>
> If you are trying to do it outside of the admin, the previous link 
> might not be exactly what you are look for. The doc on inlines formset 
> [1] might be more usefull. It's the same thing, but as a generic form 
> instead of a part of the admin. 
>
>
> [1] 
> https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/#inline-formsets
>  
>
> 2016-07-09 21:47 GMT+02:00 ludovic coues >: 
>
> > Have you done the django tutorial ? 
> > 
> > Part 7 [1] Should answer your question. 
> > 
> > [1] https://docs.djangoproject.com/en/1.9/intro/tutorial07/ 
> > 
> > 2016-07-09 18:03 GMT+02:00  >: 
> >> I have a 2 Models, Product and Image. Image has a foreign key to 
> Product. 
> >> 
> >> In the form I want to appear information from both the Product and the 
> >> Image, because are related. 
> >> 
> >> I use also GCBV for views, and model for forms. 
> >> 
> >> How can be done ? 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> Groups 
> >> "Django users" group. 
> >> To unsubscribe from this group and stop receiving emails from it, send 
> an 
> >> email to django-users...@googlegroups.com . 
> >> To post to this group, send email to django...@googlegroups.com 
> . 
> >> Visit this group at https://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/django-users/b4e9613b-e7b0-4a21-adb2-d3a3d468aa1f%40googlegroups.com.
>  
>
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > 
> > -- 
> > 
> > Cordialement, Coues Ludovic 
> > +336 148 743 42 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3199cfc6-7f6c-4f69-ac49-d26496694f7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Class-based Views with Multiple Forms

2016-07-11 Thread Paul
By default Django’s class-based views support just a single form per view. 

I need more forms per view because I want to combine a ForeignKey relations 
with various ModelForm instances and also to appear in the FormModel.

In Django documentation and other tutorials I found formsets, but in the 
default examples you repeat the same form multiple times, which is not what 
I need.

Inline formsets looks like what I need , but I didn't found an example for 
GBV like CreateView. Can you give me some examples, link to a tutorial ?

Thanks. 




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0cd0a748-1d47-4750-b566-1e8451d8b530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - File or Image Delete

2016-07-11 Thread Paul
thanks

On Monday, July 11, 2016 at 11:16:27 AM UTC+3, Mstislav Kazakov wrote:
>
> Try to override `delete` method in your model. You should do something 
> like this:
>
> class Example(models.Model):
> f = models.FileField(null=True, blank =True)   
>
>
> def delete(self,*args,**kwargs):
> if os.path.isfile(self.f.path):
> os.remove(self.f.path)
>
> super(Example, self).delete(*args,**kwargs)
>
>
> 2016-07-09 21:04 GMT+05:00 >:
>
>> This way the Image is removed from database, not from the server.
>>
>> On Friday, July 8, 2016 at 6:41:57 PM UTC+3, Mstislav Kazakov wrote:
>>>
>>> Just pass empty value in file field.
>>> If blank=True and null=True, everything should work fine and image will 
>>> be removed.
>>>
>>> пятница, 8 июля 2016 г., 17:23:42 UTC+5 пользователь sevenr...@gmail.com 
>>> написал:

 The user has the possibility to add/delete image and documents.


 I used GCBV UpdateView and a FormModel for this. 


 How can I offer the possibility to the user to delete the file/image ?

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bdd2edd2-d232-416e-9ff4-b5b3519e6c1e%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c672d36c-8c89-4b7c-94e2-64e7da28d014%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


inlineformset_factory Tutorial

2016-07-11 Thread Paul
I'm searching for a good tutrial regarding "inlineformset_factory". the 
information about it od Django site is very scarce.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dbf621bb-5a5f-47cd-b4e9-0112439a24b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django : InlineFomsets with FileField, overwrite forms.ModelForm Function

2016-07-19 Thread Paul
 

I have a model Product and a model Document. The document has a foreign key 
to the product. 


I want the user to upload multiple files in the same form for 
adding/editing Product.


I modified and example from net, it is working, but not with a FileField. 


I know that I need to add request.File but until now I didn't added where 
is needed, because is not working.


*models*


class Product( models.Model):

   #default attributes
   name = models.CharField(max_length=200,db_index=True)
   short_description = models.CharField(max_length=160)
   description = models.TextField()
class Document(models.Model):

product = models.ForeignKey('products.Product', on_delete=models.CASCADE)
document = models.FileField(upload_to=upload_to)


*forms*


class DocumentModelForm(forms.ModelForm):
   class Meta:
   model = Document
   fields = ['document']

DocumentInlineFormSet = forms.inlineformset_factory(
   Product,
   Document,
   fields=('document', 'id'),
   extra=0,
   can_delete=False,
   min_num=1, validate_min=True,
max_num=3, validate_max=True,

)


class ProductModelForm(forms.ModelForm):
   class Meta:
   model = Product
   fields = [
'name',
'short_description',
'description',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.checks = DocumentInlineFormSet(
instance=self.instance, prefix='checks',
data=self.data if self.is_bound else None)
def is_valid(self, commit=True):
product_valid = super().is_valid()
checks_valid = self.checks.is_valid()
return product_valid and checks_valid
def save(self,commit=True):
product = super().save(commit=commit)
product._checks = self.checks.save(commit=commit)
return product

*template*



{% csrf_token %}
{{ form}}
{{ form.checks.management_form }}
{{ form.checks }}

 
 

*views are normal*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eb6d1b67-ad71-42fd-a826-af2669c470a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Add form fields/values at ModelForm level or at CBV level.

2016-11-29 Thread Paul

I have a model Product which a Foreign Key to a Company model. The Company 
Model has a OneToOne Relationship to user.

When a user submits a form to add product I need to associate the product 
with the company of the user (the user doesn't need to add manually the 
company in the form)

There are 2 methods:

1) adding a new user field in the ModelForm  __init__ method:

self.company = kwargs.pop('company') 

and then at the CBV level using get_form_kwargs

kwargs['company'] = self.get_company()


2) or directlly at the CBV level using form_valid:

self.instance.company = self.get_company()



Which one is better (besides more lines for the first one) as 
implementation ? What is the difference ?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90e88059-7405-484e-987a-ead89954fe9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Djago URL conf error

2016-11-30 Thread Paul
 

I have the following message when I try to use reverse or reverse_lazy:

The included URLconf 'ph.urls' does not appear to have any patterns in it. 
If you see valid patterns in the file then the issue is probably caused by 
a circular import 


*When I use the urls (without using reverse or reverse lazy) is working 
with no issue. I tried different combination of urls the same results*


*What I'm doing wrong ?*

ph is the project. In the project I include the urls for the application:

url(r'^account/', include('accounts.urls', namespace='accounts')),
url(r'^companies/', include('companies.urls', namespace='companies')),
url(r'^products/', include('products.urls', namespace='products')),
url(r'^admin/', admin.site.urls)



The app involved:

1)accounts:

from django.conf.urls import url from .views import AccountDetailView

urlpatterns = [
 url(r'$', AccountDetailView.as_view(), name='dashboard'),



2) products:

class ProductCreateView(AccountMixin, CreateView):
model = Product
form_class = ProductModelForm
url = reverse_lazy('accounts:dashboard')
url2 = reverse_lazy('products:list')
#print(url)
template_name = 'accounts/product_form.html'
#success_url = reverse_lazy('accounts:product_detail')



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7355569-cd47-4ad8-8f22-68d63a677010%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django: UpdateView - dispatch() : reduce the number of queries

2016-11-30 Thread Paul

I have a Product Model, foreign key to Company Model, onetoone key to User.

I override the dispatch(method) to check if the user has rights to edit the 
object(product).

I'm trying to optimize the queries to the database because some of them are 
duplicates.

def dispatch(self, request, *args, **kwargs):
obj = self.get_object()
if obj.company.user != request.user:
raise PermissionDenied
else:
print('ok')
return super().dispatch(request, *args, *kwargs)



query to products

obj = self.get_object() 



query to company and query to user twice

if obj.company.user != request.user:



query to products again

 return super().dispatch(request, *args, *kwargs)



How can I optimize and remove duplicated queries ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/725caa3d-4686-418a-b947-db4be442f0fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Automatic reverse migrations

2017-04-14 Thread paul
In a modern Continuous Delivery environment, it's expected that there is an 
automated process for deploying code, and therefore performing database 
migrations. This is all straightforward.

I haven't been able to find any good solutions for automatic rollback 
though. The main problem that I see is that there is (AFAIK) no easy way to 
definitively know which migrations to unapply to roll back to the previous 
verison. If you try to rollback from the new N+1 version, you have the 
migrations, but no recording of the previous version's state. If you 
rollback from the previous N version, you don't have the new migration 
files to do the DB rollback.

What I'd really like is a way of recording a 'db migration checkpoint' 
which could be generated per-release (or whenever else you care to 
checkpoint your migration state), and would say something like `v1: 
{app1:0002,0003, app2: 0004}, v2: {app1:0004, app2: 0005, 0006}`, thus 
letting me roll back all of the migrations in the v2 deploy with a single 
command.

Does anyone have suggestions or references here? I may try rolling the 
above solution if there is no prior art, but I want to avoid reinventing 
the wheel here, as it seems that this issue must have been hit by many 
other users before me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6cafecca-2c71-4a6f-b93b-fe3e64847bc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatic reverse migrations

2017-04-17 Thread paul
Thanks Andrew, will see what I can rustle up.

Camilo -- blue/green deploys don't really help with this problem. As each 
application deployment still talks to the same database, once you have run 
the migration you can't just abandon your deployment, you need to unwind 
the db migration first.

On Saturday, April 15, 2017 at 6:01:03 PM UTC-7, Camilo Torres wrote:
>
> Hi,
> May both of you try to implement "blue-green deployments", and switch only 
> if all tests are OK.
> You may also be interested in running a test deployment in a testing 
> environment prior to production.
> Don't know of a solution integrated into django.
>
> On Friday, April 14, 2017 at 2:26:51 PM UTC-4, Andrew Godwin wrote:
>>
>> Hi Paul,
>>
>> I have tried this in the past, but it's basically an unsolvable problem 
>> in the generic case. Databases do not take well to snapshotting or changing 
>> schema, and some operations are naturally irreversible. If you find a way 
>> that works well, I suggest you write it up so others can learn from it!
>>
>> Andrew
>>
>> On Fri, Apr 14, 2017 at 10:33 AM,  wrote:
>>
>>> In a modern Continuous Delivery environment, it's expected that there is 
>>> an automated process for deploying code, and therefore performing database 
>>> migrations. This is all straightforward.
>>>
>>> I haven't been able to find any good solutions for automatic rollback 
>>> though. The main problem that I see is that there is (AFAIK) no easy way to 
>>> definitively know which migrations to unapply to roll back to the previous 
>>> verison. If you try to rollback from the new N+1 version, you have the 
>>> migrations, but no recording of the previous version's state. If you 
>>> rollback from the previous N version, you don't have the new migration 
>>> files to do the DB rollback.
>>>
>>> What I'd really like is a way of recording a 'db migration checkpoint' 
>>> which could be generated per-release (or whenever else you care to 
>>> checkpoint your migration state), and would say something like `v1: 
>>> {app1:0002,0003, app2: 0004}, v2: {app1:0004, app2: 0005, 0006}`, thus 
>>> letting me roll back all of the migrations in the v2 deploy with a single 
>>> command.
>>>
>>> Does anyone have suggestions or references here? I may try rolling the 
>>> above solution if there is no prior art, but I want to avoid reinventing 
>>> the wheel here, as it seems that this issue must have been hit by many 
>>> other users before me.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/6cafecca-2c71-4a6f-b93b-fe3e64847bc2%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/6cafecca-2c71-4a6f-b93b-fe3e64847bc2%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8d8f46a7-8819-4d18-908d-9681d8b6a39e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Some reversible migrations cannot be reversed in practice?

2017-04-19 Thread paul
I've just hit a tricky migration case, and I'd like to check I'm not 
missing something. The summary is that merge migrations make it possible to 
add migrations which cannot be unapplied, even if they are the latest 
migration to be run.

With the migration graph:

M1
|
+--+
|  |
M2a   M2b
|  |
+--+
|
M3(merge)

Now, as far as a can tell, if I want to revert M2b, I have to run 
`manage.py migrate app M1`. If M2a is not reversible, then it's impossible 
to un-apply M2b, even though the dependency graph would allow it. Or to 
consider another pathological case, imagine a long-running series of 
deployed migrations (M2a, M3a, M4a, ...) instead of an immediate merge 
commit; the M2b migration could be impossible to revert without reverting 
many other migrations in the other branch, which could delete user data if 
run in production.

It seems there's a missing command, `manage.py revertmigration M2b`, which 
would walk the dependency graph backwards to figure out which later 
migrations needed to be unapplied (in this case M2b and M3). Absent this 
command, it seems that merge migrations aren't safe to use, and should be 
avoided.

Am I missing something here? Appreciate any insights or workarounds anyone 
has on this subject.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7093f0ed-f927-4010-988c-de93f9bd9a3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django - Image crop using a widget as a field in the form

2017-08-23 Thread Paul


I have a Product Model and Image Model with a Foreign key to the product 
model. 


So in a form for Product creation I will have/need multiple Image File 
Upload inputs. 


I want to replace the default Image file-upload form field with a Image 
(like a plus sign, like add a new image, using a widget). 


When the user click on a add a new image a pop-up will apear with a 
javascript crop. I need to get the data(coordinates) from the javascript 
crop back to Django, use Pillow to crop and fill the Image Model field.


What is the best approach for this mechanism for the form field(will not be 
a real upload) ? , maybe a link to a tutorial 


(I know there are some Django package that do something like that but are 
really what I want regarding crop control)









-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dca42a40-1bb2-4912-a91c-4e8225a34ed4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django - Best option to check file types, even fake or without extensions

2017-09-21 Thread Paul
 

I'm trying to validate mime types of files uploaded with a predefined list 
of validate mime types. 


I need to do the check the file in the buffer before save, even if they are 
faked or no extensions.



1. python own  mimetypes package seems to "guess" only base on extension


2. magic-python looks ok, but has OS dependencies because is using UNIX 
libmagic.

 I had a lot of trouble with it on Windows 64 bit, and even after I fixed 
the dependencies error other issue appears and it couldn't identify files.

 This also is a issue because is hard to install OS related filed on a 
predefined hosting.


3. I found filetype package but it only checks "magic numbers" for a 
limited file types, and docx and other identifies them as zip file(wich are 
archive as technology),

 but I need to identify them as what they really are.


What other non OS dependent solutions that can check if the file is faked 
or with no extension exist ? (pdf,doc,docs,csv,xls,xlsx, ods,odt,odm)










-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5280e1b-ef5c-4749-a243-c75b3275c897%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django: Form validation strange behaviour

2017-09-29 Thread Paul
 

I want to do file validation(size,type) on a field on inlineformset. 


class ProductDocumentModelForm(ModelForm): 

  class Meta: model = ProductDocument 
   fields = ['document'] 

  def clean_document(self): 
   file = self.cleaned_data['document'] 
   validate_file(file, 'document')



Because I want to use the same validation in multiple application I created 
a separate function.


def validate_file(file, for_model, max_size=5000): 
 if for_model == 'document': 
  max_size = FILE_MAX_DOC_SIZE 
 
 if file.size > max_size: 
  raise ValidationError('Please keep file size under {}. Current file size is 
{}' .format(filesizeformat(FILE_MAX_DOC_SIZE), filesizeformat(file.size)))



The file size validation works as intended but introduce a strange behavior.


If this validation is in place and is passed the "This field cannot be 
blank." default validation is triggered even if the fields are not empty.


Without the file size validation in place there are no issue even if the 
fields are empty.


I don't understand what is the cause. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a470e4e3-3cb9-489e-930c-8adc6b6210c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Implementation Advice: Categories and Product Specifications

2017-10-02 Thread Paul
 

I have Product and Categories. A product can be in multiple categories and 
off course a Category have multiple products.


The Categories can have Subcategories’ which can have Subcategories. I used 
a Category Model with a circular Foreign Key.


Each Product can have specifications/attributes based in which Categories 
is. 


So the specifications are of the products but depends on the Categories.


I can’t add the specifications as Products attributes because they depend 
on categories, and the user can change categories.


I can’t add them as attributes per Category because the value are/can be 
different for each product.


Also an attribute/specification can appear in multiple Categories.


I want also to search for a Product filtering by attributes.


I think I need a separate Attribute Model that is linked (foreign key) to 
both Product and Category.


Also a way of “protection” in case a Product change categories, a Product 
and/or a Category is deleted.


What is the optimal approach as flexibility and performance ? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/adf6c608-45fd-4c5f-a8c1-7a11b67fc3b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django InlineFormset : Customize inputs and widget

2017-10-04 Thread Paul


I’m using inlineformsets for an Image Model in combination with a Product 
Model.


For the Image Model (using javascript):


1) a remove/delete button will be available to remove an image; the image 
can be remove not only on edit, but also on creation(the use upload the 
image, but before saving doesn’t like the image and removes it) 2) An add 
button, when the user clicks a new input and corresponding fields are added


By default the inlineformset code is like this:


Document: File 
type: Delete:


Using inputs I can do it with javascript, but things get a little more 
complicated for what I want to do:


The user should click on an image button a modal window will appear with 
the option to crop. 

Now the Upload button is in the modal window. The user is cropping, I 
select and save the coordinates with javascript, also show a cropped image 
(simulated using css).


How do I transfer all this mechanism to Django inputs so formsets can 
understand what I want to do ?








-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69728ba1-1462-4f41-8064-a46e05287ea8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How Django inlineformsets works internally

2017-10-10 Thread Paul
 I have a form with two inline formsets.
. 

At the HTML level Django use the hidden fields for the formset management, 
and use the prefix to know which fields are related to a formset.

Also it has ids in the html id, to group like in a virtual form the fields.


 
 




On retrieve by default I get the path to the file in a paragraph and the 
inputs (html elements) are empty.



 Currently: 
Test 
Insieme/documents/sdsasa7

Change:





On Browse(upload a different file) Django knows to update the same record 
in the database. Similar for click on checkbox.


*How Django make the correlation between the paragraph that show the path, 
the html id of the element and what is in the database?*


I want to change the UI (make it dynamic with JavaScript, use button 
instead of checkbox) and I want to understand how the mechanism is working.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d5e2106e-ee4d-4272-8b37-d22ace33ed63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible to use raw_admin_fields with inlineformset_factory for a create page?

2008-12-03 Thread Paul Childs

Hi folks,

I am a newforms newbie who is currently porting a .96 project over to
1.0

I have been trying to coerce the examples in the Django documentation
to
accommodate creating a "Document" .

I have three models:
Document, DocPart --> These are in the doc module. DocPart is an
intermediary
Part --> This is in the ipl module. There are hundreds of thousands of
parts.

<><><><><><><><><><>
Simplified models
--
class Document(models.Model):
number = models.CharField(max_length=30)
title = models.CharField(max_length=30)

class DocPart(models.Model):
part = models.ForeignKey(mysite.ipl.models.Part)
document = models.ForeignKey(Document)

# in mysite.ipl.models
class Part(models.Model):
number = models.CharField(max_length=30)
description = models.CharField(max_length=30)

<><><><><><><><><>
Forms
-
DocumentForm(ModelForm):
class Meta:
model = Document

<><><><><><><><><><><>
If the user visits the document create page for the first time, in the
view I use:

form = DocumentForm()
DocPartFormset = inlineformset_factory(Document, DocPart)
formset = DocPartFormset()
.
.
.
return render_to_response('document_form.html','form':form,
'formset':formset)

<><><><><><><><><><><>
As expected the page takes a very long time to load since each select
for the DocPart is filled with hundreds of thousands of part numbers.

Since the raw_id_admin has been separated out of the model in 1.0 how
do I get the inlineformset_factory to understand that I want to use
raw_admin_field for part?





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



Re: SOAPpy and pyxml installation/usage

2008-12-11 Thread Paul Nendick

Hello Steve,
SOAPy appears to be moribund. I was once using it within a Python SOA
I'd worked with and chose to abandon it when we moved that system to
Python 2.5. It wasn't an issue for us as SOAP was going nowhere (for
us anyway).
Good news for you (possibly) is the SOAP infrastructure generally
discussed by the Twisted Matrix community: ZSI.

Relevant code:
http://tinyurl.com/betterthansoapy

Full project:
http://pywebsvcs.sourceforge.net/

What I feel is the best XML library for Python:
http://uche.ogbuji.net/tech/4suite/amara/


regards,

/p


2008/12/11 Steve <[EMAIL PROTECTED]>
>
> This may be a more of a generic Python question, but I'm working with
> Django so thought that I'd see if there's a Django specific solution
> to it.
>
> I'm trying to work with SOAP. I'm new to it and a Jr. programmer as
> well. From Dive into Python it has this great example about how to
> handle SOAP calls.
> http://www.diveintopython.org/soap_web_services/index.html
>
> The problem is that I'm trying to install the SOAPpy module and it
> requires pyxml, which appears to be no longer available or supported.
> http://pyxml.sourceforge.net/
>
> My main goal is to configuremy system to get this code, from the dive
> into python link above, to run. Or to find an equivalent set of
> packages that work instead. I'm working on windows with python 2.5.1,
> with Django .96. I deploy on ubuntu linux. Any thoughts?
>
> ...
> from SOAPpy import WSDL
>
> # you'll need to configure these two values;
> # see http://www.google.com/apis/
> WSDLFILE = '/path/to/copy/of/GoogleSearch.wsdl'
> APIKEY = 'YOUR_GOOGLE_API_KEY'
>
> _server = WSDL.Proxy(WSDLFILE)
> def search(q):
>"""Search Google and return list of {title, link, description}"""
>results = _server.doGoogleSearch(
>APIKEY, q, 0, 10, False, "", False, "", "utf-8", "utf-8")
>return [{"title": r.title.encode("utf-8"),
> "link": r.URL.encode("utf-8"),
> "description": r.snippet.encode("utf-8")}
>for r in results.resultElements]
>
>
>
>
> >

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



Getting Form Field Values in a template

2008-12-12 Thread Paul Childs

I am converting from .96 to 1.0.

In a template using 0.96, if I wanted to get the value that a
particular field was holding I would use:
{{ form.data.field_name }}

This doesn't work anymore and is breaking my code.

I have tried a number of other ways (guessing mostly), consulted the
docs and browsed the Django source and still can't figure it out.

Can anyone help me out here?

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



Re: Getting Form Field Values in a template

2008-12-12 Thread Paul Childs

Found answer here:
http://groups.google.com/group/django-users/browse_thread/thread/99f6fa5ce32dd824/460a1c563a3a851b?lnk=gst&q=template+form+values#460a1c563a3a851b

form.data.fieldname (this is pre-cleaned bound data)  ---> Did not
work
form.cleaned_data.fieldname (post clean if valid) ---> Didn't apply so
I didn't try it
form.initial.fieldname (values set for initial) ---> WORKED!!! Thank
you Doug B

On Dec 12, 12:47 pm, Paul Childs  wrote:
> I am converting from .96 to 1.0.
>
> In a template using 0.96, if I wanted to get the value that a
> particular field was holding I would use:
> {{ form.data.field_name }}
>
> This doesn't work anymore and is breaking my code.
>
> I have tried a number of other ways (guessing mostly), consulted the
> docs and browsed the Django source and still can't figure it out.
>
> Can anyone help me out here?
>
> Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SOAPpy and pyxml installation/usage

2008-12-12 Thread Paul Nendick
Does anyone know of a better/newer module for creating SOAP services
and not just a client?

BTW, nice find with Suds - this is most helpful!

regards,

/p

2008/12/12 Steve :
>
> Hello Jarek,
>
> That did the trick! I'm still curious to get ZSI working but suds was
> simpler. Here's my first functioning webservice call.
>
> from suds.client import Client
>
> url = 'http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl'
> client = Client(url)
> result = client.service.GetCityWeatherByZIP('94552')
> print result.Temperature
>
> Thanks!
>
> On Dec 12, 12:24 am, Jarek Zgoda  wrote:
>> Wiadomość napisana w dniu 2008-12-11, o godz. 09:31, przez Steve:
>>
>> > This may be a more of a generic Python question, but I'm working with
>> > Django so thought that I'd see if there's a Django specific solution
>> > to it.
>>
>> > I'm trying to work with SOAP. I'm new to it and a Jr. programmer as
>> > well. From Dive into Python it has this great example about how to
>> > handle SOAP calls.
>> >http://www.diveintopython.org/soap_web_services/index.html
>>
>> Drop SOAPpy and ZSI, they are not documented and nearly dead. Try suds.
>>
>> --
>> We read Knuth so you don't have to. - Tim Peters
>>
>> Jarek Zgoda, R&D, Redefine
>> jarek.zg...@redefine.pl
> >
>

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



RE: how to add more params in url

2008-12-17 Thread Wayper, Paul

 

> -Original Message-
> From: django-users@googlegroups.com 
> [mailto:django-us...@googlegroups.com] On Behalf Of mono
> Sent: Thursday, 18 December 2008 15:14
> To: Django users
> Subject: how to add more params in url
> 
> 
> eg.
> 
> in my list.html
> 
> {%if is_extend %}
> extend
> 
> {# pagination code #}
> 
> next previous
> 
> as result, there is only one param add in url, either 
> is_extend or page
> 
> so, how to bind all them in url?
> 
> thanks





Should be fairly obvious.

Have fun,

--
Paul Wayper
SYSTEMS ENGINEER
TransACT

Telephone: 02 6229 8026
Mobile: 0422 392 081

PO Box 1006, Civic Square  ACT  2608

www.transact.com.au

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



RE: how to add more params in url

2008-12-18 Thread Wayper, Paul

> From: mono
> Sent: Thursday, 18 December 2008 22:10
> To: Django users
> Subject: Re: how to add more params in url
> 
> 
> I don't know whether it is a good answer because only two 
> page links is here and the aim of is_extend flag is to show 
> entire or part of columns.
> 
> so I could not tell a page linkto 
> is_extend=shrink&page=next_page and 
> is_extend=shrink&page=previous_page
> 
> maybe I need more page links, like the first, the last ,or 
> some exactly page number, maybe I need more params like asp 
> or jsp, I hope to how to django dispatch the url with more 
> than one param.

I'm not sure quite what you're wanting to do here or what your problem
is.

The whole idea of query parameters - those things after the '?' symbol
in key=value pairs - is that they're optional to the page.  You don't
need to recognise these in your URL, so they don't need to be named
arguments to your view.  You can simply say (e.g.):

if 'is_extend' in request.GET:
is_extend = request.GET['is_extend']
if is_extend == 'shrink':
# shrink the page
elif is_extend == 'expand':
# expand the page

Then you have a similar piece of code to handle the 'page' parameter and
so forth.

IMO you shouldn't have too many parameters in the path part of the URL -
the bit before any '?'.

Hope this helps,

--
Paul Wayper
SYSTEMS ENGINEER
TransACT

Telephone: 02 6229 8026
Mobile: 0422 392 081

PO Box 1006, Civic Square  ACT  2608

www.transact.com.au

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



RE: A Top-Level Django Index for the root URL

2008-12-21 Thread Wayper, Paul
 



From: Ben Pritchard
Subject: A Top-Level Django Index for the root URL

The intention is that this page will list all my of sandbox
projects.  So at the moment it just links to http://localhost:8000/polls
but (a) coding the link seems like a HTML solution rather than a Django
solution and (b) it will be tedious to update this html template file
each time I add a new subsection to my site.

So, is there a Django solution that can list the available
mini-sites that are available? 

 
 
Hi Ben,
 
I'm in that same boat, and I'm considering my options:
 
My first attempt was to change the way the INSTALLED_APPS is built - as
detailed in
http://www.mabula.net/tbfw/2008/11/07#2008-11-07-dont-repeat-yourself-tn
g - and to write a middleware which presented the 'shown apps' as a
structure to read in the template.  Following the principle of Don't
Repeat Yourself, this then lists each application once along with all
the information relevant to it.  This is, however, a fairly heavy-handed
approach in my opinion as it means re-jiggering things in settings.py.
 
My second idea, not yet implemented, is to write a middleware which
introspects the list of URLs.  If it finds one named 'index' (where
'named' means 'named or with a view named'), that's taken to be the root
URL.  Anything with '(.*)_index' that is in the same directory as the
root URL is taken to be an application - that URL becomes the
application URL path.  Once you're in that application, anything with
'(.*)_index' in the same directory as the application's URL path is a
sub-menu of that application and so forth.  That makes it relatively
easy to list URLs in a structure that most projects follow without
repeating the application structure elsewhere or having to do terrible
things to settings.py.
 
My question is: is the second idea Django-ish enough?  I'd like some
feedback from the list before I start work on it as to whether it's a
dead end, whether there's a better way, or just to hear any improvements
on that scheme.
 
Your thoughts?

-- 
Paul Wayper 
SYSTEMS ENGINEER 
TransACT 

Telephone: 02 6229 8026 
Mobile: 0422 392 081 

PO Box 1006, Civic Square  ACT  2608 

www.transact.com.au 


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



RE: Language code prefix in url

2008-12-21 Thread Wayper, Paul

> From: Tirta K. Untario
> Subject: Language code prefix in url
> 
> /en/my_app/something_here/1/2/3/4/
> /de/my_app/something_here/1/2/3/4/
> /fr/my_app/something_here/1/2/3/4/

My suggestion would be to look at e.g. Apache's URL rewriting rules.
Take those URLs and produce
/my_app/something_here/1/2/3/4/?lang={en,de,fr}, then pick that up in
your environment.  Maybe make some middleware that picks that out of the
GET parameters automatically and gives you it in some useful way.  I'm
guessing what you want to use it for is to select which directory you
pick your templates from.

Just a thought,

--
Paul Wayper
SYSTEMS ENGINEER
TransACT

Telephone: 02 6229 8026
Mobile: 0422 392 081

PO Box 1006, Civic Square  ACT  2608

www.transact.com.au

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



RE: Newbie Help with Models and Views

2008-12-22 Thread Wayper, Paul

> From: Mike Albert
> Subject: Newbie Help with Models and Views
> 
> I have a couple test rows of data in my database.  From the 
> interactive shell (manage.py shell), I can return data correctly with
> Post.objects.filter(id=1).

You'll notice that that data is coming back as ['row 1'].  It's in a
list.

> When I attempt to return the same 
> data with my view, it does not appear to work.  Here is the view:
> 
> from django.http import HttpResponse
> from board.models import Post
> 
> def current_board(request):
>   posts = Post.objects.filter(id=1)
>   html = " %s" % posts
>   return HttpResponse(html)
> 
> 
> The above simply prints "[ ]"  Any thoughts?  I'm a django 
> newbie with no programming experience, so I'm sure it's 
> something basic.  Thanks in advance for the help!

.filter returns a list of the items that match the query.  So you're
trying to stringify a list.  That's where the '[' and ']' are coming
from.

I don't know why you're not seeing any of the items in that list,
because my testing:

>>> foo = [1,2,3]
>>> print 'x%sx' % foo
x[1, 2, 3]x

shows that stringifying a list should print the list as you'd expect.
But this may lead you to a solution.

Hope this helps,

--
Paul Wayper
SYSTEMS ENGINEER
TransACT

Telephone: 02 6229 8026
Mobile: 0422 392 081

PO Box 1006, Civic Square  ACT  2608

http://www.transact.com.au
Please avoid printing this email!

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



RE: Newbie Help with Models and Views

2008-12-22 Thread Wayper, Paul

> .filter returns a list of the items that match the query.  So 
> you're trying to stringify a list.  That's where the '[' and 
> ']' are coming from.

I should have mentioned that the get method (e.g. Post.objects.get(id =
1)) will return a single object, or raise a DoesNotExist error.  You may
want to look into the 'get_object_or_404' helper.

Have fun,

--
Paul Wayper
SYSTEMS ENGINEER
TransACT

Telephone: 02 6229 8026
Mobile: 0422 392 081

PO Box 1006, Civic Square  ACT  2608

www.transact.com.au

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



how to set up google docs-like sharing

2008-12-28 Thread Paul Franz

I'm trying to set up a system where you can create a document and add 
collaborators (well, watchers) similar to google docs.  Here's my model right 
now:

class Poll(models.Model):
title = models.CharField(max_length="250")
owner = models.ForeignKey(User, null=True, related_name="%(class)s_poll", 
editable=False)
watchers = models.ManyToManyField(User)
created_date = models.DateTimeField(default=datetime.now, editable=False)
expiration_date = models.DateTimeField()
def __unicode__(self):
return self.title
class Meta:
ordering = ['title']

A ModelForm, by default, gives me a multi-select box for watchers.  Is my best 
approach to write my own widget to have them type in a comma separated list of 
emails?  How could I handle email addresses for accounts that aren't set up yet?

-Paul


  

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



? Import Error for admin djangobook

2009-01-06 Thread Paul Campbell
Working examples in djangobook /1.0 chapter06

Can not get the Admin Interface to display using suggested urls.py /
settings.py

#urls
from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^admin/', include('django.contrib.admin.urls')),
)

#settings.py - # snip

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or
"C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.auth',
'django.contrib.admin',
#'django.contrib.admindocs',
'mysite.books',
)
Fedora 8 -

 django.VERSION
(1, 0, 2, 'final', 0)
['django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.auth', 'django.contrib.admin', 'mysite.books']

Funny when I used admindocs, I could get the login screen but then it failed

Suggestions ?
Change versions of python or django ?

Portion of output -


Request URL: http://127.0.0.1:8000/admin/  Exception Type: ImportError
 Exception
Value:

No module named urls

 Exception Location:
/usr/lib/python2.5/site-packages/django/core/urlresolvers.py
in _get_urlconf_module, line 198  Python Executable: /usr/bin/python  Python
Version: 2.5.1  Python Path: ['/home/pwc/django/mysite',
'/usr/lib/python25.zip', '/usr/lib/python2.5',
'/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk',
'/usr/lib/python2.5/lib-dynload', '/usr/lib/python2.5/site-packages',
'/usr/lib/python2.5/site-packages/Numeric',
'/usr/lib/python2.5/site-packages/PIL',
'/usr/lib/python2.5/site-packages/gst-0.10',
'/usr/lib/python2.5/site-packages/gtk-2.0']

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



Session Object Dropping Key Value Pairs

2008-09-04 Thread Paul Childs

Django 0.96 / mySQL / Apache2 / Ubuntu 8.04

I have created a "wizard" for data input. Rather than have one huge
form I have spread it out over a number of views/templates. After the
user submits data and it has been validated, each view places the
"new_data" into the request.session and redirects the user to the next
form. On submission of the last form, all the data is retrieved from
session, objects are built and then saved.

The code works flawlessly but every so often it will start to
consistently throwing a KeyError exception on one of the following
lines:

data1 = request.session['new_data_1']
data3 = request.session['new_data_3']
data4 = request.session['new_data_4']

Each of the above should be there. I haven't seen this exception
thrown on my development machine, or the development server. Only on
our production box.

The exception is not always consistent. It could be a KeyError for any
of the keys. This was tested with the same data each time.

If I restart the web server and reenter the data it will work. The
problem seems to go away but will resurfaces after (in one case) 15
data entry sessions. This leads me to think that it might be a
hardware issue.

Can anybody suggest how I can pin down the cause of this?

Thanks in advance.


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



Complex Form Widgets

2009-01-28 Thread Paul Johnston

Hi,

Is it possible to use more complex form widgets than the documentation
mentions? For example, with ToscaWidgets, it's possible to use
components like popup calendars and rich text editors in forms (at
least vaguely possible - if you can figure it out with the zero
docs :) Is this possible with Django too?

Paul

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



Re: How can import the Widgets of Admin.

2009-02-07 Thread Paul Nema

How to I get the value from a class verbose_name in a models.Model
based generic list?

I.E. I want to use the value in a class element verbose_name for a table header

Thanks

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



Re: Faster Database?

2009-02-25 Thread Paul Nema
One option is to create a new table that is a mirror of the target table
except the new table should NOT have any of the keys enabled.  Using a bulk
load tool add the data to the new table.  Then add the keys to the new
table.  Drop the old table and rename the new table to the original target
table name. This technique usually saves a bunch of time.

On Wed, Feb 25, 2009 at 1:00 PM, Sean  wrote:

>
> Hi,
>
> I am using django+MySql.
> My job involves to write a huge number of products codes into the
> MySql, code such as: ABCDEFGHI10, it is typically between 1 million up
> to 50 million codes within 1 file, which need to be uploaded/
> downloaded into MySql.
>
> The problem for this is it takestoo much time to insert data into the
> database, a typical 10 million code file will take 3 hours at least to
> load/download into MySql, it is even took a night time to process a 50
> million code file, which is a nightmare. So I want to make it faster.
>
> I got a powerful Core2 workstation and Xeron Server, which are almost
> the most powerful machin I can get in the market, so hardware is not a
> issue.
>
> I guess the slow down is caused by I/O to hard-disk.
>
> Anyone have any suggestion how can I make this process faster, or
> there is any other superfast database engine than MySql?
>
> Sean

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



Admin/Application Integration and Automatic Actions

2009-02-25 Thread Paul Waldo

Hi all,

I am brand new to Django, so forgive me if my questions are naive :-)

I have read the tutorials and I'm starting my first learning 
application.  This is a small time-tracking application.  As you can 
imagine, the majority of the application is basic CRUD data entry.  The 
other significant part is that I want to automatically create reports on 
a regular basis and email them.  I have two questions:

* The Admin application is great for my CRUD functionality; Django does 
a really fine job of creating this interface automatically.  
Unfortunately, using the Admin app. for data entry does not provide a 
seamless experience; the URLs are different, the look and feel is 
different, and the Admin is much more polished than my hand-crafted 
pages :-).  Do people use the Admin for regular users, or do they 
duplicate all that CRUD in their own pages?  Is there a way to make the 
Application/Admin more seamless?

* Is there a standard model for running automated tasks?  I was thinking 
about a cron task that uses lynx or curl to call a URL that performs the 
task, but that gets kind of ugly.  Is there a better way to do this?

Thanks in advance for your insights!

Paul

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



  1   2   3   4   5   6   >