Re: Off-line Django apps / Caching and synchronizing data

2012-05-27 Thread ALJ
Thanks for the link Marcin. To anyone else interested in looking into this, 
it looks like the first stop is to read Mark Pilgrim's chapter "Let's Take 
This Offline " in "Dive Into 
HTML5".

-- 
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/-/n_G3vXkco2IJ.
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: Off-line Django apps / Caching and synchronizing data

2012-05-26 Thread ALJ
Hi Andy, 

Cheers for that. I'll start looking at some JS/HTML5 frameworks.

ALJ

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



Off-line Django apps / Caching and synchronizing data

2012-05-24 Thread ALJ
I've been asked to create an closed web application for our field staff. 
The trouble is is that they are sometimes in areas where there is no cell 
covereage and therefore no data connection. 

Has anyone else had a similar situation and do you have any pointers into 
solution approaches or apps I should be looking at?

My initial thoughts were ...

   - Somehow create a standalone django app that is the same as the online 
   one and then have it synchronize when it goes back online. Something ala 
   Google Gears / HTML5. But not done anything like this and I'm not sure how 
   complicated the synchronizing would be and I'm reluctant to roll out django 
   installations on loads of laptops.
   - Use a non-django app which might be a bit lighter, eg MS Access or 
   some sqlite front end and then have that synchronize. Again, similar issues 
   as above, although.
   - Have them complete a simple spreadsheet when offline which they can 
   upload to the django app and import the data once they get a data 
   connection.
   - Tell them to keep notes until they get a data connection ... although 
   I think this might get me throttled.

It's still early days and I haven't seen any artifacts they currently use 
or what they were hoping to get out of it, but any pointers would be great.

Thanks

ALJ

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



unique_together where one of the fields may be NULL

2012-03-12 Thread ALJ
I'm struggling to get my models to enforce unique_together. We have the 
model below where it is possible to have a budget for a whole group (ie 
there is no break down for a particular sales rep) and therefore the 
sales_rep* *field will be left empty. However, it it possible to enter two 
identical values into the database via the Admin interface where the budget 
and years are the same while the sales_rep is empty.

I have seen some discussion on it in the archives, but wondered if there is 
a work around.

Cheers

ALJ

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class Budget(models.Model):
budget_type = models.ForeignKey(BudgetType, blank=False)
sales_rep = models.ForeignKey(SalesRep, null=True, blank=True)
year = models.IntegerField(blank=False)
amount = models.FloatField(blank=False)

class Meta:
unique_together = (("budget_type","sales_rep", "year"),)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

-- 
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/-/SNZbLLHpJKwJ.
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: More than one project using the same database

2011-07-01 Thread ALJ
Hi all and thanks for the feedback.

I'll elaborate on my situation. The sites have different uses but they
use exactly the same models. Infact the second site has no model.py of
its own. The second site's views simply import the required models
from the first site and, where possible, uses the same form classes
and functions.

Given the above, I hope that I shouldn't get any race issues.

However, if anyone knows of any documentation on recommended setup for
situations like these, it would be good to get a pointer. Secondly, on
how to detect if there is a risk of race conditions.

Cheers

ALJ

-- 
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: More than one project using the same database

2011-06-30 Thread ALJ
Hi Andres, that's what I was hoping was the case. I just wasn't sure.
ALJ

On Jun 30, 1:53 pm, andres.osin...@gmail.com wrote:
> In theory, unless you've disabled transactions, the database should be able 
> to manage all contention issues.
> Enviado desde mi BlackBerry de Movistar (http://www.movistar.com.ar)
>
> -Original Message-----
> From: ALJ <astley.lejas...@gmail.com>
>
> Sender: django-users@googlegroups.com
> Date: Thu, 30 Jun 2011 04:46:15
> To: Django users<django-users@googlegroups.com>
> Reply-To: django-users@googlegroups.com
> Subject: More than one project using the same database
>
> I have an extranet type project that has been running for a year. It
> only has a maximum user base of about 50 people of which probably only
> a few are using it at any one time. The users can add, edit and delete
> items within the application
>
> However, we need to expose the data in that extranet application to a
> another group of users but through another domain. Anonymous users
> will be able to register requests to be contacted, and another group
> of known users  will be able to log in with read only access to see
> the status of those requests.
>
> My question is, what are the issues that I need to think about (are
> race issues one?), is it possible to detect if these issues could
> occur in my particular situation, and how do you mitigate against
> these.
>
> ALJ
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



More than one project using the same database

2011-06-30 Thread ALJ
I have an extranet type project that has been running for a year. It
only has a maximum user base of about 50 people of which probably only
a few are using it at any one time. The users can add, edit and delete
items within the application

However, we need to expose the data in that extranet application to a
another group of users but through another domain. Anonymous users
will be able to register requests to be contacted, and another group
of known users  will be able to log in with read only access to see
the status of those requests.

My question is, what are the issues that I need to think about (are
race issues one?), is it possible to detect if these issues could
occur in my particular situation, and how do you mitigate against
these.

ALJ

-- 
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: Problem reversing urls when calling templates from another project

2011-05-20 Thread ALJ
ok ... still struggling.

While in Public_site.views I can call functions from within the
Extranet_site.views ... but I can't even do a:

return
HttpResponseRedirect(reverse('Extranet_site.application_name.views.function_name',
args=(999,)))

Within my Public_site.settings I have installed
Extranet_site.application_name ... I have also appended the
Extranet_site to the  sys.path  so what have I forgotten?

Gaaah!

-- 
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: Problem reversing urls when calling templates from another project

2011-05-20 Thread ALJ
@Shawn
Cheers. I'm such a c*ck. I am so used to using named URL patterns that
I just assumed that that was how you did it. So yes, I've had a look
at the documentation, although still struggling to get it to find the
reverse, even when using the full path.

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



Problem reversing urls when calling templates from another project

2011-05-20 Thread ALJ
I have two projects that work together. Lets call them Extranet_site
and Public_site. Most of the functionality was developed for
Extranet_site, but we wanted to capture requests from the public, so
we set up Public_site and then just attached to some of the
functionality in Extranet_site.

A scenario would be that :
1. Someone creates a request on the Extranet_site or via the
Public_site
2. This then gets processed using the code within Extranet_site,
regardless of where the request came from.
3. An email gets sent to the relevant field manager to deal with it.

The email templates are stored in Extranet_site, in the same place
that the processing code it. However, the requests that come via the
Public_site break the template URL lookups, because they are looking
at the Public_site URLs.py rather than the Extranet_site URLs.py.

What is the best way for dealing with situations like these? I could
just hard code the templates with the url. Some other solution?

-- 
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: Encrpting urls to hide PKs

2011-05-10 Thread ALJ
Some interesting stuff here. The short URL generator looks
interesting. But yes, I appreciate the thoughts about security. Horses
for courses and all that.

Cheers

ALJ

-- 
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: Encrpting urls to hide PKs

2011-05-09 Thread ALJ
I was really looking for something lightweight. I didn't really want
to have to change the model structure to include a UUID ... although I
realise that this seems to way to go. I really just wanted to avoid
any 'opportunistic' attempts at extracting the data. The data itself
isn't critical and not worth the effort of going to great lengths to
crack any encryption I would put in. I was tempted to just use base64,
perhaps joining the PK and the postcode for example. That might be
enough just to obfuscate the id a bit and have a pseudo dual key.

Oh well.

Thanks anyway.

ALJ

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



Encrpting urls to hide PKs

2011-05-09 Thread ALJ
I have a form that I use to collect contact information from
unregistered users. When they submit the form I want to redirect to a
confirmation page (as the Django documentation suggests). However,
instead of a generic page, I wanted to include the information that
they have submitted and the contact details of the person for their
area. I was also thinking that I could include the current status of
their enquiry. Therefore they could perhaps use the same link to come
back to check the status of their query.

Given that, is there a best practice pattern for handling this
situation? I have a quick demo where the URL is:

http://www.mydomain.com/contact/confirmation/1234

... where '1234' is the pk for the query. Obviously I would want to
encrypt the pk in this case, otherwise someone could just use the pk
to trawl through the database.

Are there any default ways of encrypting django urls?

-- 
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: Invalid values in a form cause validation to fail

2011-03-31 Thread ALJ
Hi Karen,

Thanks. It looks like I need to upgrade. I was putting it off.

Neil

On Mar 31, 2:35 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Wed, Mar 30, 2011 at 6:34 AM, ALJ <astley.lejas...@gmail.com> wrote:
> > Hi Karen,
>
> > Here is an example that I use to replicate the error:
>
> > view >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> > [snip]
>
> > form >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> > class RatingsListFilterForm(forms.Form):
> >    organisation_name = forms.CharField(required=False,
> > widget=forms.TextInput(attrs={'class':'textbox'}))
> >    corporation = forms.ModelChoiceField(required=False,
> > queryset=Corporation.objects.all(),
> > widget=forms.Select(attrs={'class':'selector'}))
> >    
>
> > Traceback>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> > [snip]
> > I'm using Django 1.1 if that makes any difference
>
> This was a bug in Django, the code you post works on 1.3 and 1.2.5. I
> believe the issue was corrected with the fix for ticket #13149.
>
> Karen
> --http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Invalid values in a form cause validation to fail

2011-03-30 Thread ALJ
Hi Karen,

Here is an example that I use to replicate the error:

view >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def myview(request)
filter_form = RatingsListFilterForm(request.GET or None)
if filter_form.is_valid():
return HttpResponse("Worked!")

return render_to_response('ratings_list.html',
  {'filter_form':filter_form,
 
#'current_ratings_list':current_ratings_list,
   #'temp':temp},
   },
 
context_instance=RequestContext(request))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

form >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class RatingsListFilterForm(forms.Form):
organisation_name = forms.CharField(required=False,
widget=forms.TextInput(attrs={'class':'textbox'}))
corporation = forms.ModelChoiceField(required=False,
queryset=Corporation.objects.all(),
widget=forms.Select(attrs={'class':'selector'}))

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Traceback>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\auth\decorators.py"
in __call__
  78. return self.view_func(request, *args, **kwargs)
File "E:\Programming\mysite\svs\views.py" in _function
  25. return function(request,*args, **kwargs)
File "E:\Programming\mysite\svs\views.py" in ratings_list
  36. if filter_form.is_valid():
File "C:\Python26\lib\site-packages\django\forms\forms.py" in is_valid
  120. return self.is_bound and not bool(self.errors)
File "C:\Python26\lib\site-packages\django\forms\forms.py" in
_get_errors
  111. self.full_clean()
File "C:\Python26\lib\site-packages\django\forms\forms.py" in
full_clean
  240. value = field.clean(value)
File "C:\Python26\lib\site-packages\django\forms\models.py" in clean
  993. value = self.queryset.get(**{key: value})
File "C:\Python26\lib\site-packages\django\db\models\query.py" in get
  299. clone = self.filter(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py" in
filter
  498. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py" in
_filter_or_exclude
  516. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in
add_q
  1675. can_reuse=used_aliases)
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in
add_filter
  1614.         connector)
File "C:\Python26\lib\site-packages\django\db\models\sql\where.py" in
add
  56. obj, params = obj.process(lookup_type, value)
File "C:\Python26\lib\site-packages\django\db\models\sql\where.py" in
process
  269. params =
self.field.get_db_prep_lookup(lookup_type, value)
File "C:\Python26\lib\site-packages\django\db\models\fields
\__init__.py" in get_db_prep_lookup
  210. return [self.get_db_prep_value(value)]
File "C:\Python26\lib\site-packages\django\db\models\fields
\__init__.py" in get_db_prep_value
  361. return int(value)

Exception Type: ValueError at /svs/
Exception Value: invalid literal for int() with base 10: 'ww'
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I'm using Django 1.1 if that makes any difference

Regards

ALJ



On Mar 30, 2:10 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Tue, Mar 29, 2011 at 4:40 PM, ALJ <astley.lejas...@gmail.com> wrote:
> > I have a form within a view which allows users to filter results
> > within a database. The request is a GET because I want the users to be
> > able to bookmark the results.
>
> > My querystring looks something like:
>
> >http://127.0.0.1:8001/myapp/?organisation

Invalid values in a form cause validation to fail

2011-03-29 Thread ALJ
I have a form within a view which allows users to filter results
within a database. The request is a GET because I want the users to be
able to bookmark the results.

My querystring looks something like:

http://127.0.0.1:8001/myapp/?organisation_name==4_status=

My view checks the form as it comes in (form.is_valid()) and bounces
them back if they have been messing about with the querystring. The
validation picks up errors if I do something like
"..=99&...", but if I do something like
"...=&" it brings up a traceback

Exception Value:
invalid literal for int() with base 10: ''

I would have expected that the validation process would have picked up
that it isn't valid and just returned field error.

Or am I doing something wrong.

-- 
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: Where does admin.py go?

2011-03-04 Thread ALJ
OK. 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.



Where does admin.py go?

2011-03-04 Thread ALJ
Where does "admin.py" actually go? Do you need one for each of your
applications or just one in the root of the project. Or does it go in
an "admin" directory in your project?

(Sorry, for the stupid question. I'm returning to an old project and
restructuring it. In the process I have, as you imagine, knackered it
up. I originally only used one 'core' application and had it in there.
But now I want to split up the applications into different
directories.)


-- 
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 better way of checking if a record exists

2010-10-01 Thread ALJ
... what is the infamous obj.__dict__.update() hack?

On Oct 1, 11:57 am, bruno desthuilliers
 wrote:
> On 1 oct, 10:29, Shawn Milochik  wrote:
>
>
>
> > For what it's worth, I use the get_or_create with the 'default' keyword to 
> > do this:
>
> > for record in reader:
>
> >     new_values = {
> >         'product_code': slugify(record['Product Code']),
> >         'msrp': record['Suggested Retail'],
> >         #etc...
> >     }
>
> >     product, was_created = Product.objects.get_or_create(source_id = 
> > record['Source ID'], defaults = new_values)
>
> >     if not was_created:
> >         product.product_code = slugify(record['Product Code'])
> >         product.msrp = record['Suggested Retail']
> >         #etc...
>
> Err... What about:
>
>     if not was_created:
>         for attrname, value in new_values.items():
>             setattr(product, attrname, value)
>         product.save()
>
> > I don't like the DRY violation, but a model instance doesn't have an 
> > update() method like a queryset for me to dump the kwargs into -- unless 
> > I'm missing something.
>
> For "direct" model fields you could use the infamous
> obj.__dict.__.update() hack but it's dirty and brittle - and it still
> won't work with foreign keys, m2ms etc.
>
> Now nothing prevents you from providing this model.update method...

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



A better way of checking if a record exists

2010-10-01 Thread ALJ
I'm running through a spreadsheet to update customer info. It takes
quite a while and I was just trying to optimize things a bit. I want
to check if the record is already there and if so update it with the
newer data. If not append it to the table.

Two code snippets below ...


try:
customer = models.Retailer.objects.get(shared_id='1')
except models.Retailer.DoesNotExist:
customer = models.Retailer()


This just seems 'dirty' to me. I mean, using the exceptions this way.
Exceptions to me feel as if they are the last resort when things go
wrong. But on the other hand it is probably quicker than ...


if models.Retailer.objects.filter(shared_id='1'):
customer = models.Retailer.objects.get(shared_id='1')
else:
customer = models.Retailer()


This seems cleaner but doubles the calls to the database.

Is the first really the 'accepted' way of doing this?

ALJ

-- 
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: Patterns / Best practice for automated data refreshes

2010-09-26 Thread ALJ
Hi Shawn,

Thanks for that. I'll have a look at using models then.

Cheers

ALJ

On Sep 26, 7:32 pm, Shawn Milochik <sh...@milochik.com> wrote:
> If you're updating a database created by Django, I recommend that your import 
> script import your Django models and update them with the data. Otherwise you 
> run the risk of running SQL that breaks your Django app (or worse, causes it 
> to run with corrupted data and no errors).
>
> I'd do something with cron (or Celery), use the XLRD module to read the Excel 
> into Python data structures (dictionaries and lists), then use that data to 
> update the models.
>
> Shawn

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



Patterns / Best practice for automated data refreshes

2010-09-26 Thread ALJ
We have an extranet web application (using sqlite) that is hosted
outside our network. One of the tables it uses is an excel report from
our main accounting system that contains a list of our customers. To
begin with this was imported manually but now I want to set up an
automated monthly refresh of the data.

Is there a best way to do this?

I was going to set up a python script run via a cron on the internal
servers to connect to the external ftp site and dump the file there,
and then have another cron on the external site to run through the
spreadsheet updating the sqlite database using standard sql calls.

I also suppose I could convert the spreadsheet to json, and have the
databases restart and automatically import the fixture ... although
this seems more complicated and probably prone to problems than the
above suggestion.

ALJ

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



Re: values() returning more than values

2010-07-22 Thread ALJ
try:

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

and see if that works. I haven't had a chance to test it but if you
have an order_by in the model it cocks up distinct queries. By putting
in the order_by within the query you clear it. It's also mentioned in
the documentation if you want more info.

Give it a whirl and see how it goes.

ALJ


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

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



Re: Apache causes full path of django.wsgi path written into url?

2010-07-02 Thread ALJ
... actually ... it has to be the mod_rewrite that is causing the
problem with mod_wsgi. But I don't get why.

On Jul 2, 11:00 am, ALJ <astley.lejas...@gmail.com> wrote:
> I successfully set up a django site to redirect all non secure content
> to https. However, I want to bring it back a little and only use https
> for account details and admin ("/accounts" and "/admin").
>
> I've set up a rewrite in apache for those areas and the redirect seems
> to be working, but it writes the full path of the django.wsgi into the
> url!
>
> "https://www.mydomain.net/C:/www/mysite/pdbsite/apache/django.wsgi/
> accounts/login/?next=/promotions/"
>
> (... that knocking sound is me banging my head on the wall ...)
>
> Part of the the httpd.conf is:
>
> --
> 
>
>     ...
>
>    DocumentRoot "C:/www/mydomain/pdbsite/main/site_media"
>
>         #Make sure that all connections to the admin and accounts dirs are
> secure
>         
>         RewriteEngine On
>         RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]
>         
>
>         #Aliases -
>         ...
>         Alias /media "C:/Python26/Lib/site-packages/django/contrib/admin/
> media"
>         WSGIScriptAlias / "C:/www/mysite/pdbsite/apache/django.wsgi"
>
>        ...
> 
>
> 
> The url.py is:
>
> urlpatterns = patterns('',
>     url(r'^admin/', include(admin.site.urls)),
>     url(r'^$','django.views.generic.simple.redirect_to',
> {'url':'promotions'}),
>     url(r'^accounts/login/$', 'django.contrib.auth.views.login',
> {'template_name': 'login.html'}, name="login"),
>     url(r'^accounts/logout/$', 'pdbsite.main.views.logout_view', {},
> name='logout'),
>     url(r'^accounts/change_password/
> $','django.contrib.auth.views.password_change' 
> {"template_name":"password_change.html","post_change_redirect":'password_change_done'},
> name='password_change'),
>     url(r'^accounts/change_password/password_change_done/
> $','django.contrib.auth.views.password_change_done',
> {"template_name":"password_change_done.html"},
> name='password_change_done'),
> ...

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



Apache causes full path of django.wsgi path written into url?

2010-07-02 Thread ALJ
I successfully set up a django site to redirect all non secure content
to https. However, I want to bring it back a little and only use https
for account details and admin ("/accounts" and "/admin").

I've set up a rewrite in apache for those areas and the redirect seems
to be working, but it writes the full path of the django.wsgi into the
url!

"https://www.mydomain.net/C:/www/mysite/pdbsite/apache/django.wsgi/
accounts/login/?next=/promotions/"

(... that knocking sound is me banging my head on the wall ...)


Part of the the httpd.conf is:

--


...

   DocumentRoot "C:/www/mydomain/pdbsite/main/site_media"

#Make sure that all connections to the admin and accounts dirs are
secure

RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]


#Aliases -
...
Alias /media "C:/Python26/Lib/site-packages/django/contrib/admin/
media"
WSGIScriptAlias / "C:/www/mysite/pdbsite/apache/django.wsgi"

   ...



The url.py is:

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$','django.views.generic.simple.redirect_to',
{'url':'promotions'}),
url(r'^accounts/login/$', 'django.contrib.auth.views.login',
{'template_name': 'login.html'}, name="login"),
url(r'^accounts/logout/$', 'pdbsite.main.views.logout_view', {},
name='logout'),
url(r'^accounts/change_password/
$','django.contrib.auth.views.password_change' 
{"template_name":"password_change.html","post_change_redirect":'password_change_done'},
name='password_change'),
url(r'^accounts/change_password/password_change_done/
$','django.contrib.auth.views.password_change_done',
{"template_name":"password_change_done.html"},
name='password_change_done'),
...


-- 
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: Managing the balance between SSL and impact on the server

2010-07-02 Thread ALJ
... having looked through the django documentation, would I be right
in thinking that the protocol is to have a secure login page where the
session cookie is set, drop out of secure connection, but continue to
pass cookies over the secure connection, leaving the pages themselves
to be served over unsecured connection?

So I should be looking at SESSION_COOKIE_SECURE (http://
docs.djangoproject.com/en/dev/topics/http/sessions/)?

ALJ

On Jul 1, 10:32 pm, ALJ <astley.lejas...@gmail.com> wrote:
> Thanks for that Euan.
>
> Steven, you say you have login on SSL and then have the cookie passed
> over unencrypted channel for the rest of the site. Is there any risk
> with this or mitigating steps that should be taken?
>
> (Sorry ... don't have my head around it)
>
> ALJ
>
> On 1 July, 15:20, steven314 <stevenredtrous...@gmail.com> wrote:
>
> > It's a very common pattern to use SSL for login and private profile
> > details and then have the cookie passed over an unencrypted channel
> > for the rest of the site.
>
> > I have implemented an approach where nginx handles all the SSL and
> > proxies requests to apache (which directly serves non-SSL requests).
> > Transitions between SSL and non-SSL are achieved with rewrites at the
> > nginx and apache level, which also means that SSL can be made optional
> > on, say, the admin URLs.
>
> > This breaks request.is_secure() as it stands but this is easy to work
> > around.
>
> > Bear in mind that IE may give you loud warnings about insecure content
> > if you don't also adjust the MEDIA_URL to use SSL where
> > appropriate.
>
> > Steven.

-- 
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: Managing the balance between SSL and impact on the server

2010-07-01 Thread ALJ
Thanks for that Euan.

Steven, you say you have login on SSL and then have the cookie passed
over unencrypted channel for the rest of the site. Is there any risk
with this or mitigating steps that should be taken?

(Sorry ... don't have my head around it)

ALJ

On 1 July, 15:20, steven314 <stevenredtrous...@gmail.com> wrote:
> It's a very common pattern to use SSL for login and private profile
> details and then have the cookie passed over an unencrypted channel
> for the rest of the site.
>
> I have implemented an approach where nginx handles all the SSL and
> proxies requests to apache (which directly serves non-SSL requests).
> Transitions between SSL and non-SSL are achieved with rewrites at the
> nginx and apache level, which also means that SSL can be made optional
> on, say, the admin URLs.
>
> This breaks request.is_secure() as it stands but this is easy to work
> around.
>
> Bear in mind that IE may give you loud warnings about insecure content
> if you don't also adjust the MEDIA_URL to use SSL where
> appropriate.
>
> Steven.

-- 
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: Managing the balance between SSL and impact on the server

2010-07-01 Thread ALJ
Hi Erik,

Thanks for the advice. I'll certainly have a look at the servers.

I just wanted to know really whether it was an "all or none" situation
with SSL. If it was possible blend secure and non secure connections.

ALJ

On Jul 1, 11:13 am, Erik Cederstrand <e...@cederstrand.dk> wrote:
> Den 01/07/2010 kl. 11.02 skrev ALJ:
>
> > I have an extranet for staff and known partners. It has absolutely no
> > public content. I've installed SSL so it should be secure, but I also
> > heard that SSL can have a big impact on the server.
>
> Just measure it instead of guessing. Enable system monitoring on your server 
> for a couple of days and run one day with SSL and the next day without.
>
> We can't tell you if your data and your login credentials are worth 
> protecting with SSL - you need to make that decision yourself. If your server 
> is choking on the load of SSL processing, then either upgrade the server or 
> decide to not use SSL if you need to save the money.
>
> Erik
>
>  smime.p7s
> 2KViewDownload

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



Managing the balance between SSL and impact on the server

2010-07-01 Thread ALJ
I have an extranet for staff and known partners. It has absolutely no
public content. I've installed SSL so it should be secure, but I also
heard that SSL can have a big impact on the server.

While login and password changes need to be secure, the content itself
is not particularly sensitive. But actions and views will be user
specific, therefore users will need to be logged in at all times.

Given the above, I was wondering if it is necessary to use SSL at all
times or is possible to use it only for login? Presumably if I dropped
out of SSL after login, the cookies would still be vulnerable to
hijacking. My gut feel is that I have to use SSL all the time and just
accept the hit on the server, but I wondered there were any django
tools (CSRF protection) or best practices anyone has on managing the
balance of SSL and the impact on the server.

- Are they passing logins and passowords? Yes, then SSL
- Is the content sensitive (like bank details or commercial stuff) ?
If yes then SSL.
- Are the content and actions user specific? If yes then SSL.

ALJ

-- 
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 much would you charge for this? £5k? £15k? £50k?

2010-06-21 Thread ALJ
Hi Euan,

Cheers for that. It's my first Django project and I think in hindsight
I should have started on something a little easier. Nevermind. It's
been a good learning experience.

Before they told me the spec, they said they thought it would cost
about £3k!

Cheers

ALJ

On Jun 21, 4:12 pm, "euan.godd...@googlemail.com"
<euan.godd...@gmail.com> wrote:
> It sounds like your project is pretty fully featured and if you claim
> to be "inexperienced" in Django development this much work is pretty
> impressive on a part-time basis over 6 months!
>
> Currently the Django project I am working on has taken over 2.5 years
> (and is ongoing). Although we don't just do Django, it's what we do
> most of the time. Our application has 213 models with 78742 lines of
> python code. I would estimate (although this is a bit of a guess) that
> the developer cost for this has been approximately £350k.
>
> You might be able to scale that to your workload.
>
> Hope that helps, Euan
>
> On Jun 21, 10:12 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > I'm just starting out with Django so using an hourly rate isn't really
> > applicable because I'm going to be much slower that a 'real'
> > developer. So far I've spent about 6 months part time.
>
> > What kind of ballpark amounts would people suggest this is worth?
>
> > I'm not going to tell you how much they think it was ... well maybe
> > I'll tell you later. I'm trying to help them out so it's considerably
> > cheaper than I think it should be.
>
> > What is it?
> > The application is helps the sales staff organize product
> > demonstrations around the country. They can book demonstrators to do
> > an event. The demonstrators do the events and then enter the details
> > of how it went. The system provides invoice generation, event tracking
> > and custom reporting.
>
> > Features
> > - Dynamic questionnaire and report form generation into pdf.
> > - Dynamic invoice generation into pdf.
> > - Work-flow with page locking, rollback and automatic email generation
> > on status change.
> > - Daily (and horribly complex) automatic summary excel reports
> > - Sales and questionnaire summary reports
>
> > - Designing and building the site
> > -- Models (about 32)
> > -- Setting up the admin interface
> > -- 12 key views plus goodness knows how many auxiliary views.
> > -- Look and feel
>
> > Other activities
> > - Weekly automatic importing of data from another accounting database
> > - Importing of existing event data.
> > - Importing of product prices and rates, existing staff details,
> > demonstrator details,
> > - Finding and setting up a VPS host
> > - Installing and configuring the site
> > - Support for a year (occasional changes, bug fixes and helping them
> > settle in)
> > - Training materials
>
> > ... and this doesn't even take into account the changes they made
> > halfway though. I should have been more formal with the spec but I
> > know them and didn't think it would be necessary. Once bitten 
>
> > Appreciate this is a bit finger in the air, but like I said ...
> > ballparking.
>
> > ALJ

-- 
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 much would you charge for this? £5k? £15k? £50k?

2010-06-21 Thread ALJ
... I've just noticed the title and hope this doesn't look too much
like spam!!

On Jun 21, 11:12 am, ALJ <astley.lejas...@gmail.com> wrote:
> I'm just starting out with Django so using an hourly rate isn't really
> applicable because I'm going to be much slower that a 'real'
> developer. So far I've spent about 6 months part time.
>
> What kind of ballpark amounts would people suggest this is worth?
>
> I'm not going to tell you how much they think it was ... well maybe
> I'll tell you later. I'm trying to help them out so it's considerably
> cheaper than I think it should be.
>
> What is it?
> The application is helps the sales staff organize product
> demonstrations around the country. They can book demonstrators to do
> an event. The demonstrators do the events and then enter the details
> of how it went. The system provides invoice generation, event tracking
> and custom reporting.
>
> Features
> - Dynamic questionnaire and report form generation into pdf.
> - Dynamic invoice generation into pdf.
> - Work-flow with page locking, rollback and automatic email generation
> on status change.
> - Daily (and horribly complex) automatic summary excel reports
> - Sales and questionnaire summary reports
>
> - Designing and building the site
> -- Models (about 32)
> -- Setting up the admin interface
> -- 12 key views plus goodness knows how many auxiliary views.
> -- Look and feel
>
> Other activities
> - Weekly automatic importing of data from another accounting database
> - Importing of existing event data.
> - Importing of product prices and rates, existing staff details,
> demonstrator details,
> - Finding and setting up a VPS host
> - Installing and configuring the site
> - Support for a year (occasional changes, bug fixes and helping them
> settle in)
> - Training materials
>
> ... and this doesn't even take into account the changes they made
> halfway though. I should have been more formal with the spec but I
> know them and didn't think it would be necessary. Once bitten 
>
> Appreciate this is a bit finger in the air, but like I said ...
> ballparking.
>
> ALJ

-- 
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 much would you charge for this? £5k? £15k? £5 0k?

2010-06-21 Thread ALJ
I'm just starting out with Django so using an hourly rate isn't really
applicable because I'm going to be much slower that a 'real'
developer. So far I've spent about 6 months part time.

What kind of ballpark amounts would people suggest this is worth?

I'm not going to tell you how much they think it was ... well maybe
I'll tell you later. I'm trying to help them out so it's considerably
cheaper than I think it should be.

What is it?
The application is helps the sales staff organize product
demonstrations around the country. They can book demonstrators to do
an event. The demonstrators do the events and then enter the details
of how it went. The system provides invoice generation, event tracking
and custom reporting.

Features
- Dynamic questionnaire and report form generation into pdf.
- Dynamic invoice generation into pdf.
- Work-flow with page locking, rollback and automatic email generation
on status change.
- Daily (and horribly complex) automatic summary excel reports
- Sales and questionnaire summary reports

- Designing and building the site
-- Models (about 32)
-- Setting up the admin interface
-- 12 key views plus goodness knows how many auxiliary views.
-- Look and feel

Other activities
- Weekly automatic importing of data from another accounting database
- Importing of existing event data.
- Importing of product prices and rates, existing staff details,
demonstrator details,
- Finding and setting up a VPS host
- Installing and configuring the site
- Support for a year (occasional changes, bug fixes and helping them
settle in)
- Training materials

... and this doesn't even take into account the changes they made
halfway though. I should have been more formal with the spec but I
know them and didn't think it would be necessary. Once bitten 

Appreciate this is a bit finger in the air, but like I said ...
ballparking.

ALJ

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



Caching a queryset

2010-06-20 Thread ALJ
Noob question 

I have a queryset that holds some very static information (workflow
descriptions and attributes) but is used widely throughout by models
and views.

Is it automatically cached or should I specifically declare somewhere
that I want it cached?

-- 
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: inlineformset_factory - minimum number of completed forms and custom validation

2010-06-19 Thread ALJ
... sorry ... I forgot to use formset.non_form_errors()

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



inlineformset_factory - minimum number of completed forms and custom validation

2010-06-19 Thread ALJ
Can anyone point me in the right direction regarding customer
validation of forms via an inlineformset_factory? I want to make sure
at least one form is completed and that no two forms have the same
date.

(I have to admit, I'm getting confused by how all the different
classes relate to each other)

I tried this below, but it doesn't even look as if it is getting
triggered when I'm debugging.

>>
'''Source : 
http://stackoverflow.com/questions/877723/inline-form-validation-in-django/1884760#1884760'''

class BaseAppointmentFormset(BaseInlineFormSet):
def is_valid(self):
return super(BaseAppointmentFormset, self).is_valid() and not
any([bool(e) for e in self.errors])

def clean(self):
# get forms that actually have valid data
count = 0
for form in self.forms:
try:
if form.cleaned_data and not
form.cleaned_data.get('DELETE', False):
count += 1
except AttributeError:
# annoyingly, if a subform is invalid Django explicity
raises
# an AttributeError for cleaned_data
pass
if count < 1:
raise forms.ValidationError('You must have at least one
order')

AppointmentFormFactory = inlineformset_factory(Event, Appointment,
extra=7, max_num=7, can_delete=True, form=AppointmentForm,
formset=BaseAppointmentFormset)

formset = AppointmentFormFactory(instance=current_event)




-- 
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: Templates: Looping, ifs and defaults

2010-03-24 Thread ALJ
Hi again Paulo,

Ok. I'll also have a look at that.

I agree that the business logic should be in the views. However, it
feels that we need a little more flexibility with the templates when
things are truely just a presentation problem. When you have to start
constructing your own dictionaries / lists it can start to get a bit
of a mess. Lists rely on the order/index. So if you need to add
another piece of data that you might have forgotten about you have to
make sure you don't mess up the order/indexes. You can also use
dictionaries, which can be slightly easier (once you have created a
dictionary lookup tag!) but you still have a lot of messing about to
do creating the dictionary in the first place. It feels that creating
the data in this way misses out on a lot of the power of using ORM
within the templates.

Oh well.

-- 
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: Templates: Looping, ifs and defaults

2010-03-24 Thread ALJ
Just as a matter of interest ... is there a 'best way' of formatting
the data if you do decide to process it all in the view and then pass
to the template? I seem to have dictionaries coming out of my ears if
I construct the data myself.

-- 
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: Templates: Looping, ifs and defaults

2010-03-24 Thread ALJ
Hi Dalore,

Thanks for that. I changed it a bit because it was still within that
{% for sale in sales %} loop. It works. But it really makes the raw
html pretty ugly with loads of spaces in it. Never mind. I suppose no-
one is going to see it.

{% for rate in rates %}

{{ rate.cost_item.name }}
{% for appointment in appointments %}



{% endfor %}

{% endfor %}

-- 
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: Templates: Looping, ifs and defaults

2010-03-24 Thread ALJ
Hi Paulo,

The 'if' test has to fall within the "for sale in sales" loop, because
it's testing the values of the the sale. However, if there is no
match, then the default is triggered. Therefore I will get as many
defaults as there are sales (-1 if there is a match). Nesting {% if %}
's won't work.

I suppose I have to move the logic away. But it seems a bit peculiar
to me.

Thanks

ALJ

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



Templates: Looping, ifs and defaults

2010-03-24 Thread ALJ
I have a template that shows a matrix table of form text input boxes.
When the form is new, then it should be just empty text boxes. If data
already exists, then the form gets repopulated with data.

What I am looking for it this:

PRODUCTS | DAY1 | DAY2 | DAY3
POLO | Empty text box | 3 |  3
PASSAT | 1 | 0 | 0
SCIROCCO | Empty text box | Empty text box |  1

What I get is this:

PRODUCTS | DAY1 | DAY2 | DAY3
POLO | No box | 3 |  3
PASSAT | 1 | 0 | 0
PASSAT | No box | No box |  1

My template is:



{{ rate.cost_item.name }}
{% for appointment in appointments %}

{% for sale in sales %}
{% if sale.appointment.id == appointment.id and
rate.cost_item.id == sale.cost_rate.cost_item.id %}

{% endif %}
{% endfor %}

{% endfor %}



Obviously, if try to put an 'else' anywhere in that sales loop to say
put an empty text input box, I'll get as many boxes as there are sales
within each table cell.

Is there anyway to get around this?
Or with I need to create my own filter to do this?

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



Event more complicated forms / templates

2010-03-22 Thread ALJ
Is there any to have a table type form will variable rows and columns?

I have events. For each event there might be several appointment days.
And a set of questions to measure how many people the rep had contact
with.

My expected form output would be something like:

Question,  Day1, Day2,
Day3
How many people did you see?   20, 30, 40
How many bought stuff? 2,   1,   4
How many samples did you give away?   15, 17, 20

... which they could fill in and submit.

Has anyone else done anything like this?

(Again, I think I might have bitten off more than I can chew here!)

ALJ


>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
models.py

class Appointment(models.Model):
event = models.ForeignKey(Event)
date = models.DateField("Date")
time_start = models.TimeField("Start Time")
time_end = models.TimeField("End Time")

class Meta:
ordering = ['date','time_start']

class CustomerContactQuestion(models.Model):
description = models.CharField("Question",max_length=200)
order = models.IntegerField("Presentation Order", null=True,
blank=True)

class Meta:
ordering = ['order','description']

class CustomerContactAnswer(models.Model):
event= models.ForeignKey(Event)
customer_contact_question =
models.ForeignKey(CustomerContactQuestion)
appointment = models.ForeignKey(Appointment)
amount = models.IntegerField()


-- 
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: Multiple polls on a single form

2010-03-18 Thread ALJ
Thanks john.

I can't believe it's not there. And I also seem to have gone head
first into the difficult stuff. As usual. I'm going to have to hack it
a bit and then come back and tidy it up once I learn a bit more.

(Oh bugg*r!)

On Mar 18, 12:02 pm, john2095 <john...@pobox.com> wrote:
> Sounds like you're building a "multiple choice questionnaire".
>
> Googling around everyone seems to be indicating the perfect blog post
> for you was 
> at:http://www.pointy-stick.com/blog/2009/01/23/advanced-formset-usage-dj...
> but the site seems to have dropped off the internet. At the end of the
> day I'd say you've got a learning curve in front of you. First forms,
> then formsets, then validating them.
>
> Enjoy.
>
> On Mar 18, 7:26 pm, ALJ <astley.lejas...@gmail.com> wrote:
>
> > I have a list of questions and for each a group of potential answers.
> > I want to display the questions and have radio buttons for answers. In
> > addition, if they have any other comments, there is a free text box.
> > I've managed to do this ok so far excluding the comment boxes and can
> > iterate over the questions and answers and pull them into the
> > database. I can also re-populate the form if they decide later they
> > need to change the answers. I'm now trying to look at checking for
> > errors.
>
> > However, I haven't been using any of the form or formset classes. It's
> > all very much written from scratch and I have to do a number of these
> > (all with slightly different layouts of course). I therefore wondered:
>
> > - has anyone else done anything similar to this?
> > - are there any examples of how to do it?
>
> > (I'm not even sure what to call this so I can search for myself.)
>
> > ALJ

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



Multiple polls on a single form

2010-03-18 Thread ALJ
I have a list of questions and for each a group of potential answers.
I want to display the questions and have radio buttons for answers. In
addition, if they have any other comments, there is a free text box.
I've managed to do this ok so far excluding the comment boxes and can
iterate over the questions and answers and pull them into the
database. I can also re-populate the form if they decide later they
need to change the answers. I'm now trying to look at checking for
errors.

However, I haven't been using any of the form or formset classes. It's
all very much written from scratch and I have to do a number of these
(all with slightly different layouts of course). I therefore wondered:

- has anyone else done anything similar to this?
- are there any examples of how to do it?

(I'm not even sure what to call this so I can search for myself.)

ALJ

-- 
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: More tutorials and recipes?

2010-03-18 Thread ALJ
Hi, yes I've had a look at Django book, but was looking for something
a bit more advanced than that .

Cheers

Alj

On Mar 18, 2:21 am, Continuation <selforgani...@gmail.com> wrote:
> Check out the online Django book:
>
> http://www.djangobook.com/
>
> It's somewhat outdated but it covers all the basics.
>
> On Mar 17, 5:48 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > I've done the tutorial. This is great. It's practical. You can see how
> > things fit together. But the application is quite simple.
>
> > I've read the documentation. This tells you how the bits work. But
> > it's quite detailed.
>
> > What I am looking for is something that goes beyond the tutorials to
> > bridge the gap to the detail of the modules. Are there any?

-- 
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: More tutorials and recipes?

2010-03-17 Thread ALJ
Thanks Alastair ... I'll check it out.

On Mar 17, 12:57 pm, Alastair Campbell  wrote:
> > On Mar 17, 11:23 am, Jirka Vejrazka  wrote:
> >> > What I am looking for is something that goes beyond the tutorials to
> >> > bridge the gap to the detail of the modules. Are there any?
>
> I found the best next step was the "Practical Django Projects" 
> book:http://apress.com/book/view/1430219386
>
> (I need to get the 2nd Ed though). The first edition was really good
> at taking your through practical projects, and helping you learn the
> django way. I assume the 2nd edition just brings it upto date.
>
> Kind regards,
>
> -Alastair

-- 
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: More tutorials and recipes?

2010-03-17 Thread ALJ
Hi Jirka,

Cheers for that. I like the cookbook (http://code.djangoproject.com/
wiki/CookBook)

ALJ

On Mar 17, 11:23 am, Jirka Vejrazka <jirka.vejra...@gmail.com> wrote:
> > What I am looking for is something that goes beyond the tutorials to
> > bridge the gap to the detail of the modules. Are there any?
>
>   Hi,
>
>   how about checking out some existing applications to learn how those
> work? Many of them are small enough to get the useful tips and tricks
> from them in 10 minutes (per app ;-)
>
>  http://code.djangoproject.com/wiki/DjangoResources
>
>   HTH
>
>     Jirka

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



More tutorials and recipes?

2010-03-17 Thread ALJ
I've done the tutorial. This is great. It's practical. You can see how
things fit together. But the application is quite simple.

I've read the documentation. This tells you how the bits work. But
it's quite detailed.

What I am looking for is something that goes beyond the tutorials to
bridge the gap to the detail of the modules. Are there any?

-- 
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: A bit of a modeling question

2010-03-17 Thread ALJ
Hi,

Thanks. I can't see the wood for the trees at the moment.

Neil

On Mar 17, 2:57 am, aditya <bluemangrou...@gmail.com> wrote:
> ALJ,
> In that case, I think you need multiple models, without inheritance...
>
> Aditya
>
> On Mar 16, 1:48 pm, ALJ <astley.lejas...@gmail.com> wrote:
>
> > Hi aditya,
>
> > I wasn't aware of the editable parameter (which means I've learnt
> > something) but I still don't think it will help me.
>
> > The user will create an 'invoice' for want of a better word, that will
> > be made up of lots of different entries. Some of these are fixed
> > (description and unit price) and therefore selected from a list of
> > options, some are classified (description) but can enter a unit price,
> > and some are unclassified so they will need to enter free text
> > description and unit cost. Eg
>
> > Type, Description, unit price, units
> > Fixed, Commission on Product XXX, £20, [12]
> > Fixed, Commission on Product YYY, £18, [4]
> > Fixed, Inconvenience allowance, £30, [2]
> > Classified, Parking fees, [£10], [1]
> > Classified, Hotel, [£100], [2]
> > Unclassified, [Emergency Courier we didn't think we'd need], [£50],
> > [1]
>
> > [] = user entered,
>
> > > How will the model be used? It looks to me like what you're after is
> > > the 'editable' parameter, as in something like:
> > > class Unclassified(models.Model):
> > >   name = models.CharField(max_length=50)
> > >   cost = models.DecimalField(max_digits=5,decimal_places=2)
>
> > > class Classified(Unclassified):
> > >   name =
> > > models.CharField(default="Hotels",editable=False,max_length=50)
>
> > > class Fixed(Unclassified):
> > >   name = models.Charfield(editable=False,max_length=50)
> > >   cost =
> > > models.DecimalField(max_digits=5,decimal_places=2,editable=False)
>
> > > On Mar 16, 9:36 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > > > Hi Preston,
>
> > > > Sorry, I don't get it.
>
> > > > The certainly do have the same fields, but sometimes the fields are
> > > > derived from a linked table, or are a foreign key or sometimes text.
> > > > So I don't understand how having the interface adapt to what the
> > > > current type is would work.
>
> > > > ALJ
>
> > > > On Mar 16, 3:04 pm, Preston Holmes <pres...@ptone.com> wrote:
>
> > > > > On Mar 16, 3:21 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > > > > > This is a bit of a modeling question that I am struggling to get my
> > > > > > head around. How would you model this scenario?
>
> > > > > > I have to record expenses that are of 3 different types.
>
> > > > > > 1. Fixed - The name of the expense and unit amount are fixed. For
> > > > > > example, "inconvenience allowance" of £30 per day.
> > > > > > 2. Classified - The name of the expense is fixed, but the actual 
> > > > > > unit
> > > > > > amount isn't. For example "Hotel expenses". The actual unit amount
> > > > > > will depend on the hotel they stay at. They'll need to enter that
> > > > > > themselves.
> > > > > > 3. Unclassified - The name of the expense and the amount is 
> > > > > > arbitrary.
> > > > > > So they may have an expense we haven't thought of before but it 
> > > > > > needs
> > > > > > to go in.
>
> > > > > > Of course I'll need to create a summary that tots up the total
> > > > > > expenses for the particular event.
>
> > > > > whether you subclass a base model, or simply have a "type" field on
> > > > > your expense object is going to depend on the details and nuance of
> > > > > the rest of your business logic in your app.  I would only say that
> > > > > simple is better unless you have a reason or need for the complexity.
>
> > > > > Given that the fields between them are identical, I would probably
> > > > > just use a "type" choice field and have the interface adapt as needed.
>
> > > > > -Preston
>
> > > > > > Would the best way of doing this be:
>
> > > > > > a) Have a base model and then build on that for the 3 different
> > > > > > scenarios?
> > > > > > b) Have three different tables and then

Re: A bit of a modeling question

2010-03-16 Thread ALJ
Hi aditya,

I wasn't aware of the editable parameter (which means I've learnt
something) but I still don't think it will help me.

The user will create an 'invoice' for want of a better word, that will
be made up of lots of different entries. Some of these are fixed
(description and unit price) and therefore selected from a list of
options, some are classified (description) but can enter a unit price,
and some are unclassified so they will need to enter free text
description and unit cost. Eg

Type, Description, unit price, units
Fixed, Commission on Product XXX, £20, [12]
Fixed, Commission on Product YYY, £18, [4]
Fixed, Inconvenience allowance, £30, [2]
Classified, Parking fees, [£10], [1]
Classified, Hotel, [£100], [2]
Unclassified, [Emergency Courier we didn't think we'd need], [£50],
[1]

[] = user entered,


> How will the model be used? It looks to me like what you're after is
> the 'editable' parameter, as in something like:
> class Unclassified(models.Model):
>   name = models.CharField(max_length=50)
>   cost = models.DecimalField(max_digits=5,decimal_places=2)
>
> class Classified(Unclassified):
>   name =
> models.CharField(default="Hotels",editable=False,max_length=50)
>
> class Fixed(Unclassified):
>   name = models.Charfield(editable=False,max_length=50)
>   cost =
> models.DecimalField(max_digits=5,decimal_places=2,editable=False)
>
> On Mar 16, 9:36 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > Hi Preston,
>
> > Sorry, I don't get it.
>
> > The certainly do have the same fields, but sometimes the fields are
> > derived from a linked table, or are a foreign key or sometimes text.
> > So I don't understand how having the interface adapt to what the
> > current type is would work.
>
> > ALJ
>
> > On Mar 16, 3:04 pm, Preston Holmes <pres...@ptone.com> wrote:
>
> > > On Mar 16, 3:21 am, ALJ <astley.lejas...@gmail.com> wrote:
>
> > > > This is a bit of a modeling question that I am struggling to get my
> > > > head around. How would you model this scenario?
>
> > > > I have to record expenses that are of 3 different types.
>
> > > > 1. Fixed - The name of the expense and unit amount are fixed. For
> > > > example, "inconvenience allowance" of £30 per day.
> > > > 2. Classified - The name of the expense is fixed, but the actual unit
> > > > amount isn't. For example "Hotel expenses". The actual unit amount
> > > > will depend on the hotel they stay at. They'll need to enter that
> > > > themselves.
> > > > 3. Unclassified - The name of the expense and the amount is arbitrary.
> > > > So they may have an expense we haven't thought of before but it needs
> > > > to go in.
>
> > > > Of course I'll need to create a summary that tots up the total
> > > > expenses for the particular event.
>
> > > whether you subclass a base model, or simply have a "type" field on
> > > your expense object is going to depend on the details and nuance of
> > > the rest of your business logic in your app.  I would only say that
> > > simple is better unless you have a reason or need for the complexity.
>
> > > Given that the fields between them are identical, I would probably
> > > just use a "type" choice field and have the interface adapt as needed.
>
> > > -Preston
>
> > > > Would the best way of doing this be:
>
> > > > a) Have a base model and then build on that for the 3 different
> > > > scenarios?
> > > > b) Have three different tables and then do a union on them?
>
> > > > Just for interest ... this is where I got so far, but am now stumped
>
> > > > class CostType(models.Model):
> > > >     name = models.CharField("Name", max_length=30) 'e.g. commission,
> > > > subsistence ...
>
> > > > class CostItem(models.Model):
> > > >     name = models.CharField("Name", max_length=50) 'e.g. product x,
> > > > inconvenience allowance, ...
> > > >     cost_type = models.ForeignKey(CostType, verbose_name="Type")
>
> > > > class Rate(models.Model):
> > > >     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
> > > >     valid_from = models.DateField("From")
> > > >     valid_till = models.DateField("Till")
> > > >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > > > decimal_places=2)
>
> > > > 'Costs with a fixed description an

Re: A bit of a modeling question

2010-03-16 Thread ALJ
Hi Preston,

Sorry, I don't get it.

The certainly do have the same fields, but sometimes the fields are
derived from a linked table, or are a foreign key or sometimes text.
So I don't understand how having the interface adapt to what the
current type is would work.

ALJ

On Mar 16, 3:04 pm, Preston Holmes <pres...@ptone.com> wrote:
> On Mar 16, 3:21 am, ALJ <astley.lejas...@gmail.com> wrote:
>
>
>
> > This is a bit of a modeling question that I am struggling to get my
> > head around. How would you model this scenario?
>
> > I have to record expenses that are of 3 different types.
>
> > 1. Fixed - The name of the expense and unit amount are fixed. For
> > example, "inconvenience allowance" of £30 per day.
> > 2. Classified - The name of the expense is fixed, but the actual unit
> > amount isn't. For example "Hotel expenses". The actual unit amount
> > will depend on the hotel they stay at. They'll need to enter that
> > themselves.
> > 3. Unclassified - The name of the expense and the amount is arbitrary.
> > So they may have an expense we haven't thought of before but it needs
> > to go in.
>
> > Of course I'll need to create a summary that tots up the total
> > expenses for the particular event.
>
> whether you subclass a base model, or simply have a "type" field on
> your expense object is going to depend on the details and nuance of
> the rest of your business logic in your app.  I would only say that
> simple is better unless you have a reason or need for the complexity.
>
> Given that the fields between them are identical, I would probably
> just use a "type" choice field and have the interface adapt as needed.
>
> -Preston
>
>
>
> > Would the best way of doing this be:
>
> > a) Have a base model and then build on that for the 3 different
> > scenarios?
> > b) Have three different tables and then do a union on them?
>
> > Just for interest ... this is where I got so far, but am now stumped
>
> > class CostType(models.Model):
> >     name = models.CharField("Name", max_length=30) 'e.g. commission,
> > subsistence ...
>
> > class CostItem(models.Model):
> >     name = models.CharField("Name", max_length=50) 'e.g. product x,
> > inconvenience allowance, ...
> >     cost_type = models.ForeignKey(CostType, verbose_name="Type")
>
> > class Rate(models.Model):
> >     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
> >     valid_from = models.DateField("From")
> >     valid_till = models.DateField("Till")
> >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > decimal_places=2)
>
> > 'Costs with a fixed description and unit amount
> > class FixedCostList(models.Model):
> >     markettingevent= models.ForeignKey(Event)
> >     rate = models.ForeignKey(Rate)
> >     units = models.IntegerField()
>
> > 'Costs with a fixed description but arbitrary amount
> > class StructuredCostList(models.Model):
> >     markettingevent= models.ForeignKey(Event)
> >     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
> >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > decimal_places=2)
> >     units = models.IntegerField()
>
> > 'Costs with both a arbitrary description and amount
> > class OtherCostList(models.Model):
> >     markettingevent= models.ForeignKey(Event)
> >     description = models.CharField("Name", max_length=30)
> >     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> > decimal_places=2)
> >     units = models.IntegerField()

-- 
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: A bit of a modeling question

2010-03-16 Thread ALJ
... I suppose this would be the approach for extending a base model.
My question is ... does it really matter which approach to take? Does
one approach have advanteages or pitfalls?

>>.

class BaseCost(models.Model):
markettingevent = models.ForeignKey(Event)
units = models.IntegerField()

class FixedCost(baseCost):
rate = models.ForeignKey(Rate)

class StructuredCost(baseCost):
cost_item = models.ForeignKey(CostItem, verbose_name="Item")
unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
decimal_places=2)

class OtherCost(baseCost):
description = models.CharField("Name", max_length=30)
unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
decimal_places=2)

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



A bit of a modeling question

2010-03-16 Thread ALJ
This is a bit of a modeling question that I am struggling to get my
head around. How would you model this scenario?

I have to record expenses that are of 3 different types.

1. Fixed - The name of the expense and unit amount are fixed. For
example, "inconvenience allowance" of £30 per day.
2. Classified - The name of the expense is fixed, but the actual unit
amount isn't. For example "Hotel expenses". The actual unit amount
will depend on the hotel they stay at. They'll need to enter that
themselves.
3. Unclassified - The name of the expense and the amount is arbitrary.
So they may have an expense we haven't thought of before but it needs
to go in.

Of course I'll need to create a summary that tots up the total
expenses for the particular event.

Would the best way of doing this be:

a) Have a base model and then build on that for the 3 different
scenarios?
b) Have three different tables and then do a union on them?

>>
Just for interest ... this is where I got so far, but am now stumped

class CostType(models.Model):
name = models.CharField("Name", max_length=30) 'e.g. commission,
subsistence ...

class CostItem(models.Model):
name = models.CharField("Name", max_length=50) 'e.g. product x,
inconvenience allowance, ...
cost_type = models.ForeignKey(CostType, verbose_name="Type")

class Rate(models.Model):
cost_item = models.ForeignKey(CostItem, verbose_name="Item")
valid_from = models.DateField("From")
valid_till = models.DateField("Till")
unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
decimal_places=2)

'Costs with a fixed description and unit amount
class FixedCostList(models.Model):
markettingevent= models.ForeignKey(Event)
rate = models.ForeignKey(Rate)
units = models.IntegerField()

'Costs with a fixed description but arbitrary amount
class StructuredCostList(models.Model):
markettingevent= models.ForeignKey(Event)
cost_item = models.ForeignKey(CostItem, verbose_name="Item")
unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
decimal_places=2)
units = models.IntegerField()

'Costs with both a arbitrary description and amount
class OtherCostList(models.Model):
markettingevent= models.ForeignKey(Event)
description = models.CharField("Name", max_length=30)
unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
decimal_places=2)
units = models.IntegerField()

-- 
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: Passing parameters from child models

2010-02-20 Thread ALJ
Hi Bruno,

Thanks for you candor. Yeah. I appreciate I'm not that that great at
the moment.

By having the usertype id would therefore make the usertype specific
attributes much easier to access, such as showing the usertype name in
the templates. So if my usertype model is this:

class UserType(models.Model):
id = models.CharField(max_length=3, primary_key=True)
name = models.CharField(max_length=30)

def __unicode__(self):
return u'%s' % (self.name)

I just have to use this (using a userprofile this time):

{{ user.get_profile.usertype }}

... rather than this...

if hasattr('user','teacher'):
current_type = "Teacher"
elif hasattr('user','student'):
   current_type = "Student"
elif .

everytime I want to find out what type of user I am dealing with.

Anyway. Cheers for the code.

ALJ

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



Passing parameters from child models

2010-02-19 Thread ALJ
I want to set a value in a parent model based on the child class. So,
in this case, I would set the ExtendedUser.usertype depending on
whether its "Teacher" or "Student".

I tried looking at using '%(class)s' to get the class name, but that
didn't work. Or can you explicitly pass values from the child classes?

>>.

def set_user_type():
'''somehow find and return the user type based on the child
class'''

class ExtendedUser(models.Model):
user = models.OneToOneField(User, blank=True, related_name='%
(class)s')
usertype = models.ForeignKey(UserType, default=set_user_type())
landline = models.CharField(blank=True, max_length=20)
mobile = models.CharField(blank=True, max_length=20)

class Teacher(ExtendedUser):
teacherinfo = models.CharField(max_length=20)

class Student(ExtendedUser):
studentinfo = models.CharField(max_length=20)

>

-- 
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: Managing different user types

2010-02-19 Thread ALJ
Hi Hanne,

Thanks for this and apologies for not looking at this sooner. I
thought the thread was gone dead.

I also found this thread which might be of use to some other numpties
out there.

http://groups.google.com/group/django-users/browse_thread/thread/f3f1a51bd1a465d9/df45ba7044caae41?lnk=gst=multiple+user+profiles#df45ba7044caae41

So ... I think .. that what you are suggestion is having multiple
profiles that can be linked to a user one a one to one basis. I also
found this, which uses profile inheritance, which I also like.

http://stackoverflow.com/questions/1796556/django-multi-table-inheritance-vs-specifying-explicit-onetoone-relationship-in-mo

ALJ

-- 
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: Multiple user types

2010-02-19 Thread ALJ
... here's a solution I found really useful. It uses a base profile
with inheritance.

http://stackoverflow.com/questions/1796556/django-multi-table-inheritance-vs-specifying-explicit-onetoone-relationship-in-mo

ALJ

-- 
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: User permissions to see a view

2010-02-19 Thread ALJ
I am restricting access to particular pages. The reports page doesn't
have a particular model. It's going to have some 'flat' content and
links to lots of other reports. So that is why I was confused. There
is no underlying data model for that page.

I was going to query rebus's suggestion. I didn't get how putting the
permissions there would help. It's not associated with the model that
is underlying the reports page.

However ... I tried it anyway and then checked the admin and sure
enough the permissions "can do stuff" are there. So, are you saying
that I could just create the permissions in any old model (like
UserType) and then in the User Admin create a group, associate the
relevant permissions with each group and then associate the users with
the group?

   class Meta:
permissions = (
("can_view_reports", "Can view reports"),
("can_view_appointments", "Can view appointments"),
("can_view_other_sensitive_stuff", "Can view other
sensitive stuff"),
)

(Sorry. I realise that some of you might be banging your head against
the wall, laughing ... or both. )

-- 
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: User permissions to see a view

2010-02-18 Thread ALJ
Hi Rebus,

Yeah, I got that, but where do I put the meta permissions? In which
model? The user?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#models.py
class UserType(models.Model):
id = models.CharField(max_length=3, primary_key=True)
name = models.CharField(max_length=30)

def __unicode__(self):
return u'%s' % (self.name)

class UserProfile(models.Model):

user = models.ForeignKey(User, unique=True)
usertype = models.ForeignKey(UserType)
address01 = models.CharField(max_length=50, null=True)
address02 = models.CharField(max_length=50, null=True)
...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.


On Feb 18, 2:19 pm, rebus_ <r.dav...@gmail.com> wrote:
> On 18 February 2010 13:29, ALJ <astley.lejas...@gmail.com> wrote:
>
>
>
> > Hi Alexey,
>
> > But how do you set a permission for a view? There's no underlying
> > model to which to add the custom meta permissions.
>
> > ALJ
>
> > On Feb 18, 12:48 pm, Alexey Kostyuk <akost...@kaluga.ru> wrote:
> >> On Thu, 2010-02-18 at 02:30 -0800, ALJ wrote:
> >> > First project and struggling a bit.
>
> >> > I have some views that I want to restrict access to, depending on user
> >> > type. How do I do that?
>
> >> > For example, I have a 'reports' view that I only want teachers to
> >> > see ... not students. I can't see how to create a custom permission
> >> > because there is no underlying model for the view. So do I need to
> >> > create a custom user model or would it be better to just use
> >> > profiles?
>
> >> > :-(
>
> >> You can use decorator @permission_required in your views.
> >> See link[1] for details.
>
> >> [1]http://docs.djangoproject.com/en/dev/topics/auth/#the-permission-requ...
>
> >> --
> >> Alexey Kostyuk <akost...@kaluga.ru>
>
> > --
> > 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.
>
> same page...
>
> http://docs.djangoproject.com/en/dev/topics/auth/#id2

-- 
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: User permissions to see a view

2010-02-18 Thread ALJ
Hi Alexey,

But how do you set a permission for a view? There's no underlying
model to which to add the custom meta permissions.

ALJ

On Feb 18, 12:48 pm, Alexey Kostyuk <akost...@kaluga.ru> wrote:
> On Thu, 2010-02-18 at 02:30 -0800, ALJ wrote:
> > First project and struggling a bit.
>
> > I have some views that I want to restrict access to, depending on user
> > type. How do I do that?
>
> > For example, I have a 'reports' view that I only want teachers to
> > see ... not students. I can't see how to create a custom permission
> > because there is no underlying model for the view. So do I need to
> > create a custom user model or would it be better to just use
> > profiles?
>
> > :-(
>
> You can use decorator @permission_required in your views.
> See link[1] for details.
>
> [1]http://docs.djangoproject.com/en/dev/topics/auth/#the-permission-requ...
>
> --
> Alexey Kostyuk <akost...@kaluga.ru>

-- 
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 permissions to see a view

2010-02-18 Thread ALJ
First project and struggling a bit.

I have some views that I want to restrict access to, depending on user
type. How do I do that?

For example, I have a 'reports' view that I only want teachers to
see ... not students. I can't see how to create a custom permission
because there is no underlying model for the view. So do I need to
create a custom user model or would it be better to just use
profiles?

:-(

-- 
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: Managing different user types

2010-02-11 Thread ALJ
OK ... It was raving a bit there. I didn't actually expect anyone
to answer all those questions.

On Feb 10, 1:27 pm, ALJ <astley.lejas...@gmail.com> wrote:
> I appreciate that this is a very common question. I have searched
> through the forums and now totally confused. There seems to be loads
> of different methods you could use, but I wondered if there is a
> pattern for managing different user types.
>
> 1. The best way to do a simple extension of user information?
> As far as I can tell, the best way is to use User Profiles. Ok. I get
> that.
> - "Storing Additional Information About Users" (http://
> docs.djangoproject.com/en/1.1/topics/auth/#storing-additional-
> information-about-users)
>
> 2. How about controlling how different user types show up in the admin
> interface?
> If you have someone administering the database, wouldn't it be better
> to have a clear distinction between the user types? So for example,
> instead of just users, would you have Teachers and Students split into
> different sections. Or would you just have a single user interface,
> but with the ability to define the user type. Would you subclass in
> this instance? Perhaps create a custom Manager? Perhaps another
> example. If you had a tutorial appointment form where one teacher and
> one student meet. Maybe you'd use a filter the foreign key looking at
> the user type in the profile.
> - Managers (http://docs.djangoproject.com/en/1.1/topics/db/managers/)
>
> 3. How do you extend beyond simple profiles?
> But what happens if not all users have the same profile types. For
> example, Students may have course info and education history, whereas
> Teachers won't need that. And how do you manage where information is
> required for one group, but not the other, such as teachers bank
> details or this years performance grade ... (ok not a great example
> but you get the idea).
>
> 4. How do you manage the link between User Types and Authorisation
> Groups?
> Lets say for example I want teachers to have access to one type of
> interface and students access to another. Would you define a user type
> in the profile and check the profile when rendering the interface?
> Would you just use Authorisation Groups and check if they are
> authorised to see the page? Would you do both, so for example, when a
> new teacher is added to users, you code so that they are automatically
> set to the Teachers Authorisation Group?
>
> - "Authentication data in templates" (http://docs.djangoproject.com/en/
> 1.1/topics/auth/#authentication-data-in-templates)
>
> [ah!!!]
>
> ALJ

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



Managing different user types

2010-02-10 Thread ALJ
I appreciate that this is a very common question. I have searched
through the forums and now totally confused. There seems to be loads
of different methods you could use, but I wondered if there is a
pattern for managing different user types.

1. The best way to do a simple extension of user information?
As far as I can tell, the best way is to use User Profiles. Ok. I get
that.
- "Storing Additional Information About Users" (http://
docs.djangoproject.com/en/1.1/topics/auth/#storing-additional-
information-about-users)

2. How about controlling how different user types show up in the admin
interface?
If you have someone administering the database, wouldn't it be better
to have a clear distinction between the user types? So for example,
instead of just users, would you have Teachers and Students split into
different sections. Or would you just have a single user interface,
but with the ability to define the user type. Would you subclass in
this instance? Perhaps create a custom Manager? Perhaps another
example. If you had a tutorial appointment form where one teacher and
one student meet. Maybe you'd use a filter the foreign key looking at
the user type in the profile.
- Managers (http://docs.djangoproject.com/en/1.1/topics/db/managers/)

3. How do you extend beyond simple profiles?
But what happens if not all users have the same profile types. For
example, Students may have course info and education history, whereas
Teachers won't need that. And how do you manage where information is
required for one group, but not the other, such as teachers bank
details or this years performance grade ... (ok not a great example
but you get the idea).

4. How do you manage the link between User Types and Authorisation
Groups?
Lets say for example I want teachers to have access to one type of
interface and students access to another. Would you define a user type
in the profile and check the profile when rendering the interface?
Would you just use Authorisation Groups and check if they are
authorised to see the page? Would you do both, so for example, when a
new teacher is added to users, you code so that they are automatically
set to the Teachers Authorisation Group?

- "Authentication data in templates" (http://docs.djangoproject.com/en/
1.1/topics/auth/#authentication-data-in-templates)

[ahhhhhhhhh!!!]

ALJ

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