Get the maximum possible ID value for a primary key?

2019-01-09 Thread Stodge
Is there a way to get the maximum value that an ID can be for a model that 
uses AutoField for its primary key? For example, in PostgreSQL I could do:

SELECT maximum_value FROM information_schema.sequences WHERE sequence_name = 
'my_sequence_id_seq';

 maximum_value 
---
 9
(1 row)



I'm looking through the model meta data and the AutoField but I don't see 
anything.

Thanks

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


Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Thanks Simon. It's for an offline tool so high performance isn't the top 
priority.

On Monday, 10 December 2018 11:56:53 UTC-5, Simon Charette wrote:
>
> Given choices are defined at the module level I guess you could
> iterate over objects defined in each `sys.modules` (or the ones
> likely to define choices) and use the `is` operator to compare all
> of them to the field choices.
>
> This will perform badly and shouldn't be used for anything else
> than one off debugging reflection though.
>
> Best,
> Simon
>
> Le lundi 10 décembre 2018 10:33:35 UTC-5, Stodge a écrit :
>>
>> Let's say I take the following code from the Django documentatation:
>>
>>
>> class Student(models.Model):
>> FRESHMAN = 'FR'
>> SOPHOMORE = 'SO'
>> JUNIOR = 'JR'
>> SENIOR = 'SR'
>> YEAR_IN_SCHOOL_CHOICES = (
>> (FRESHMAN, 'Freshman'),
>> (SOPHOMORE, 'Sophomore'),
>> (JUNIOR, 'Junior'),
>> (SENIOR, 'Senior'),
>> )
>> year_in_school = models.CharField(
>> max_length=2,
>> choices=YEAR_IN_SCHOOL_CHOICES,
>> default=FRESHMAN,
>> )
>>
>>
>> But instead I want to do:
>>
>> from student_app import choices
>> class Student(models.Model):
>> year_in_school = models.CharField(
>> max_length=2,
>> choices=choices.YEAR_IN_SCHOOL_CHOICES,
>> default=choices.FRESHMAN,
>> )
>>
>>
>> Is there anyway using reflection to determine which module the choices 
>> are imported from?
>>
>> For example:
>>
>> field = Student._meta.fields.get_field_by_name('year_in_school')
>> choices_source = some_clever_function(field)
>> print("Choices imported from %s." % choices_source)
>>
>> I want the output to be:
>>
>> Choices imported from student_app.
>>
>> Obviously the clever function does not exist but hopefully clarifies what 
>> I'm trying to do.
>>
>> Thanks
>>
>>

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


Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Let's say I take the following code from the Django documentatation:


class Student(models.Model):
FRESHMAN = 'FR'
SOPHOMORE = 'SO'
JUNIOR = 'JR'
SENIOR = 'SR'
YEAR_IN_SCHOOL_CHOICES = (
(FRESHMAN, 'Freshman'),
(SOPHOMORE, 'Sophomore'),
(JUNIOR, 'Junior'),
(SENIOR, 'Senior'),
)
year_in_school = models.CharField(
max_length=2,
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN,
)


But instead I want to do:

from student_app import choices
class Student(models.Model):
year_in_school = models.CharField(
max_length=2,
choices=choices.YEAR_IN_SCHOOL_CHOICES,
default=choices.FRESHMAN,
)


Is there anyway using reflection to determine which module the choices are 
imported from?

For example:

field = Student._meta.fields.get_field_by_name('year_in_school')
choices_source = some_clever_function(field)
print("Choices imported from %s." % choices_source)

I want the output to be:

Choices imported from student_app.

Obviously the clever function does not exist but hopefully clarifies what 
I'm trying to do.

Thanks

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


Suggestions for using a custom pre-login signal to perform custom validation?

2018-03-16 Thread Stodge
I want to add a custom pre-login signal (user_logging_in) that fires just 
before Django's login function is called. This is a snippet from our custom 
account app that may explain what I want:

from django.contrib.auth import login as real_login
def custom_login()
# Allow other apps to perform pre-login validation.
from . import signals
signals.user_logging_in.send(sender=None, request=request, user=user)

# Perform the login using Django's code.
real_login(request, user)

We have a custom licencing engine that we call to in our custom login 
function to validate the user's licence:

return validate_license(user, request, license, **kwargs)

So, if the user's licence has expired then they aren't actually logged in 
and are re-directed back to the login page. This validate_license function 
can return HTTP statuses as required.

The licence engine is currently tightly coupled into our custom account 
app. 

I'm trying to work out if I can get the Licence engine to subscribe to the 
above custom signal so that I can decouple it from our account app. However 
I don't understand how I would get the Licence engine to influence the 
response sent to the browser.

Any suggestions greatly appreciated.
Thanks




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


Re: Are URL namespaces optional or are they used by default by Django?

2018-01-10 Thread Stodge
Problem solved and apparently it was my silly mistake! While experimenting 
I added app_name to my urls files. Apparently this enables namespace 
support. So I removed them from my urls files and it works.

Thanks

On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
>
> I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem 
> with URL namespaces. I don't specifically configure any namespaces in my 
> URLs but Django seems to think that all my app URLs are namespaced. The 
> documentation seems to imply that namespaces are optional and only 
> configured if provided, but my experience suggests otherwise. Would someone 
> be able to confirm if namespaces are optional (opt-in)? I'm really rather 
> confused at the moment about this. Thanks
>

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


Re: Are URL namespaces optional or are they used by default by Django?

2017-12-21 Thread Stodge
Thanks,

My edit license URL is:

url(r'^license/edit/(?P\d+)/$', views.edit_license, name=
'edit_license'),

However, this is what I want and it has been this way for years. My URLs 
are organised:

///

I don't think this explains why my URLs are all namespaced when I haven't 
changed my code and my code doesn't use namespaces. I'm really confused. :)

Thanks again
Mike





On Thursday, 21 December 2017 11:38:42 UTC-5, Andréas Kühne wrote:
>
> Ok,
>
> You have not namespaced anything, but you have added the api name infront 
> of the URLs you are adding.
>
> So for example, I am guessing that you in your urls.py file for the 
> license app have added "/license/edit//" for the license 
> detail page? Because you have already added the license part with the 
> prefix you have added here:
>
> for app in settings.SITE_APPS.get_application_list():
> url_prefix = r'^%s/' % app
> urlpatterns += [
> url(prefix, include(url_include)),
>
> ]
>
>
> So you have added license twice, and therefore you will need to add it 
> twice when you call the urls as well.
>
> You should probably do this instead:
> for app in settings.SITE_APPS.get_application_list():
> url_prefix = r'^%s/' % app
> urlpatterns += [
> url('', include(url_include)),
>
> ]
>
>
>
> If you don't want that extra license part.
>
> Namespace is added the way you suggested via:
> url('', include(url_include, namespace="license"))
>
> Also, it doesn't result in an extra app part (in this case license), it 
> only adds the namespace in the call to reserve, so if you had setup the 
> namespace like i wrote here, you would use: 
> reverse("license:license_detail", args=(1, ))
>
> Hope I have explained it good enough :-)
>
> Regards,
>
> Andréas
>
> 2017-12-21 17:02 GMT+01:00 Stodge <sto...@gmail.com >:
>
>> I am using a prefix when I include the URLs for each app:
>>
>> for app in settings.SITE_APPS.get_application_list():
>> url_prefix = r'^%s/' % app
>> urlpatterns += [
>> url(prefix, include(url_include)),
>>
>> ]
>>
>> I just assumed this isn't using namespaces because I'm not using the 
>> namespace parameter on include()?
>>
>>
>>
>> On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
>>>
>>> I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a 
>>> problem with URL namespaces. I don't specifically configure any namespaces 
>>> in my URLs but Django seems to think that all my app URLs are namespaced. 
>>> The documentation seems to imply that namespaces are optional and only 
>>> configured if provided, but my experience suggests otherwise. Would someone 
>>> be able to confirm if namespaces are optional (opt-in)? I'm really rather 
>>> confused at the moment about this. Thanks
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: Are URL namespaces optional or are they used by default by Django?

2017-12-21 Thread Stodge
I am using a prefix when I include the URLs for each app:

for app in settings.SITE_APPS.get_application_list():
url_prefix = r'^%s/' % app
urlpatterns += [
url(prefix, include(url_include)),

]

I just assumed this isn't using namespaces because I'm not using the 
namespace parameter on include()?



On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
>
> I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem 
> with URL namespaces. I don't specifically configure any namespaces in my 
> URLs but Django seems to think that all my app URLs are namespaced. The 
> documentation seems to imply that namespaces are optional and only 
> configured if provided, but my experience suggests otherwise. Would someone 
> be able to confirm if namespaces are optional (opt-in)? I'm really rather 
> confused at the moment about this. Thanks
>

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


Re: Are URL namespaces optional or are they used by default by Django?

2017-12-21 Thread Stodge
Thanks Andreas,

I'm seeing three things;

1) Reverse URLs are failing until I specifically add the app's name as a 
namespace
2) The show_urls management command from the django_extensions project 
appears to show that all URLs have a namespace:

/license/license/edit// core.decorators.WVCheckLoginPermissions
() license:edit_license

3) All resource URIs in TastyPie are empty, which according to a ticket I 
found there seems to be caused by namespaces.

Thanks
Mike


On Thursday, 21 December 2017 10:47:28 UTC-5, Andréas Kühne wrote:
>
> Hi,
>
> Namespaces are completely optional - you don't have to use it if you don't 
> want to. 
>
> What is happening that makes you think otherwise? What errors are you 
> seeing?
>
> Regards,
>
> Andréas
>
> 2017-12-21 16:38 GMT+01:00 Stodge <sto...@gmail.com >:
>
>> I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem 
>> with URL namespaces. I don't specifically configure any namespaces in my 
>> URLs but Django seems to think that all my app URLs are namespaced. The 
>> documentation seems to imply that namespaces are optional and only 
>> configured if provided, but my experience suggests otherwise. Would someone 
>> be able to confirm if namespaces are optional (opt-in)? I'm really rather 
>> confused at the moment about this. Thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Are URL namespaces optional or are they used by default by Django?

2017-12-21 Thread Stodge
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem 
with URL namespaces. I don't specifically configure any namespaces in my 
URLs but Django seems to think that all my app URLs are namespaced. The 
documentation seems to imply that namespaces are optional and only 
configured if provided, but my experience suggests otherwise. Would someone 
be able to confirm if namespaces are optional (opt-in)? I'm really rather 
confused at the moment about this. Thanks

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


Let the model define the database with a custom router

2017-12-15 Thread Stodge
I'm porting a website from Django 1.6.x to 1.11 and I'm hitting a problem 
with my custom router. Some models define a custom attribute defining which 
database it will reside in:

class MyModel(models.Model):
DATABASE_NAME = "foo"

This worked in our custom router in 1.6.x but not in 1.11. The router 
accesses it like:

if hasattr(model,'DATABASE_NAME'):
return model.DATABASE_NAME == db

Inside the allow_migrate function of my router, the custom attribute 
DATABASE_NAME doesn't exist in the model in 1.11 but it was there in 1.6.x, 
if that makes sense.

Any suggestions for a different implementation? I want my models to define 
the physical database they are in.

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


Re: Unable to use custom StaticFilesStorage

2017-11-02 Thread Stodge
There's a flaw in my plan as STATICFILES_STORAGE is a string and not a 
tuple. 

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


Re: Unable to use custom StaticFilesStorage

2017-11-01 Thread Stodge
As usual, despite working on this for a while, the solution hits me after I 
post here.

I have to define a custom finder that uses my custom storage. Bingo!

class CatalogFinder(AppDirectoriesFinder):

storage_class = AppCatalogStorage

def __init__(self, apps=None, *args, **kwargs):
super(CatalogFinder, self).__init__(*args, **kwargs)


STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"myapp.finders.CatalogFinder"
)





On Wednesday, 1 November 2017 14:35:08 UTC-4, Stodge wrote:
>
> I'm trying to add an extra directory for each app that will contain 
> Javascript/CSS files. I created a custom storage.py in my app containing a 
> copy of the code from Django's AppDirectoriesFinder class, but I changed 
> source_dir from "static" to "catalog". I'll include the Django code with 
> the modified source_dir so no-one has to check the source code:
>
> class AppCatalogStorage(FileSystemStorage):
> """
> A file system storage backend that takes an app module and works
> for the ``catalog`` directory of it.
> """
> prefix = None
> source_dir = 'catalog'  <--- changed, was 'static'
>
>
> def __init__(self, app, *args, **kwargs):
> """
> Returns a static file storage if available in the given app.
> """
> # app is the actual app module
> mod = import_module(app)
> mod_path = os.path.dirname(upath(mod.__file__))
> location = os.path.join(mod_path, self.source_dir)
> super(AppCatalogStorage, self).__init__(location, *args, **kwargs)
>
>
>
> I added this to my settings file:
>
> STATICFILES_STORAGE = (
>
> 'myapp.storage.AppCatalogStorage',
> 'django.contrib.staticfiles.storage.StaticFilesStorage'
> )
>
>
> My understanding here is that I can then do:
>
> (Assuming my app name is fred)
>
> fred/catalog/js/someJavascript.js
> fred/catalog/css/someStylesheet.css
>
>
> I also assumed they would then be accessible as:
>
> /static/fred/js/someJavascript.js
> /static/fred/css/someStylesheet.css
>
>
> However, neither file is available at the expected URL. Did I 
> misunderstand something?
>
> Thanks
>

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


Unable to use custom StaticFilesStorage

2017-11-01 Thread Stodge
I'm trying to add an extra directory for each app that will contain 
Javascript/CSS files. I created a custom storage.py in my app containing a 
copy of the code from Django's AppDirectoriesFinder class, but I changed 
source_dir from "static" to "catalog". I'll include the Django code with 
the modified source_dir so no-one has to check the source code:

class AppCatalogStorage(FileSystemStorage):
"""
A file system storage backend that takes an app module and works
for the ``catalog`` directory of it.
"""
prefix = None
source_dir = 'catalog'  <--- changed, was 'static'


def __init__(self, app, *args, **kwargs):
"""
Returns a static file storage if available in the given app.
"""
# app is the actual app module
mod = import_module(app)
mod_path = os.path.dirname(upath(mod.__file__))
location = os.path.join(mod_path, self.source_dir)
super(AppCatalogStorage, self).__init__(location, *args, **kwargs)



I added this to my settings file:

STATICFILES_STORAGE = (

'myapp.storage.AppCatalogStorage',
'django.contrib.staticfiles.storage.StaticFilesStorage'
)


My understanding here is that I can then do:

(Assuming my app name is fred)

fred/catalog/js/someJavascript.js
fred/catalog/css/someStylesheet.css


I also assumed they would then be accessible as:

/static/fred/js/someJavascript.js
/static/fred/css/someStylesheet.css


However, neither file is available at the expected URL. Did I misunderstand 
something?

Thanks

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


Re: How to know when a record is added to or removed from a many to many relationship?

2017-06-13 Thread Stodge
Thanks. Yes I can use the m2m_changed signal but I need to know 
specifically if a record was added or if it was removed, not just that the 
m2m changed.

On Tuesday, 13 June 2017 08:30:43 UTC-4, yingi keme wrote:
>
> I dont particularly understand how you wish to be updated and know when a 
> record is added or removed. 
>
> Nevertheless, you can make use of django signals (Thanks to melvyn). It 
> will be of great help.
>
> Yingi Kem
>
> On 13 Jun 2017, at 12:54 PM, Stodge <sto...@gmail.com > 
> wrote:
>
> I have a model with a many to many relationship. I need to know when a 
> record is added to or removed from the many to many.
>
> Is this possible? Thanks
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/f38aaf2b-fda8-49ff-86db-bfc1a25b1ac1%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/f38aaf2b-fda8-49ff-86db-bfc1a25b1ac1%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

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


How to know when a record is added to or removed from a many to many relationship?

2017-06-13 Thread Stodge
I have a model with a many to many relationship. I need to know when a 
record is added to or removed from the many to many.

Is this possible? Thanks

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


Re: Visiting one Django server logs me out of another Django server, both behind the same proxy

2016-09-30 Thread Stodge
Thanks again. I set a different session cookie name for S1 and it seems to have 
worked.

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


Re: Visiting one Django server logs me out of another Django server, both behind the same proxy

2016-09-30 Thread Stodge
I discovered JSON Web Tokens after I posted my original question. So I'll 
read about how they work.

Thanks
Mike

On Thursday, 29 September 2016 16:50:22 UTC-4, Stodge wrote:
>
> I have two Django servers A1 and S1, which sit behind a simplistic NodeJS 
> proxy. This is a silly attempt at single sign on.
>
> I can log into and out of A1 (authentication server) just fine. If I log 
> into A1, visit S1 (without being logged in to S1) and then revisit A1, I am 
> no longer logged in. The S1 server doesn't set a new session ID in the 
> cookie and I don't think from memory that the CSRF changes. The session ID 
> cookie hasn't changed, the domain is the same etc.
>
> I can't work out why I'm no longer logged into A1. I know this isn't much 
> to go on but I'm assuming something is happening to the cookies set by S1 
> when I visit it. Any suggestions appreciated.
>
>

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


Re: Visiting one Django server logs me out of another Django server, both behind the same proxy

2016-09-30 Thread Stodge
Thanks Michal,

The two servers are on the same domain and use different databases. At the 
moment I'm using the default Django session backend.

It's an experiment, nothing more really. I just wanted to see if I could 
make it work. I haven't really worked out the flow, but it's probably 
something like:

 - admin creates user account on A1, auto replicates it to S1
 - user U1 visits S1, not logged in
 - U1 redirected to A1 to generate auth token, not logged in
 - U1 logs into A1
 - U1 redirected back to S1 to accept authentication
 - S1 logs U1 in, creates session as normal

So the user is logged into both. It's a fairly naive attempt at reinventing 
the wheel, but that's how we learn, right? :)

Cheers
Mike



On Friday, 30 September 2016 04:30:04 UTC-4, Michal Petrucha wrote:
>
> On Thu, Sep 29, 2016 at 01:50:22PM -0700, Stodge wrote: 
> > I have two Django servers A1 and S1, which sit behind a simplistic 
> > NodeJS proxy. This is a silly attempt at single sign on. 
> > 
> > I can log into and out of A1 (authentication server) just fine. If I 
> > log into A1, visit S1 (without being logged in to S1) and then 
> > revisit A1, I am no longer logged in. The S1 server doesn't set a 
> > new session ID in the cookie and I don't think from memory that the 
> > CSRF changes. The session ID cookie hasn't changed, the domain is 
> > the same etc. 
> > 
> > I can't work out why I'm no longer logged into A1. I know this isn't 
> > much to go on but I'm assuming something is happening to the cookies 
> > set by S1 when I visit it. Any suggestions appreciated. 
>
> Are those two applications sitting on the same domain? If yes, then 
> you should probably configure them to use different session cookies. 
> Logging in or out causes the session to be reset, and if they try to 
> use the same session cookie, resetting for either application will 
> reset it for both. 
>
> It's hard to give you any more specific advice, because there are many 
> ways to go about implementing SSO, some of which would be affected by 
> this. 
>
> You might want to share some more information, such as: 
>
> - Are those two applications sharing one database? 
> - What session backend are you using? 
> - Are they on the same domain? (this one I've already asked above) 
> - Could you describe the SSO flow in a bit more detail? 
>
> Cheers, 
>
> Michal 
>

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


Visiting one Django server logs me out of another Django server, both behind the same proxy

2016-09-29 Thread Stodge
I have two Django servers A1 and S1, which sit behind a simplistic NodeJS 
proxy. This is a silly attempt at single sign on.

I can log into and out of A1 (authentication server) just fine. If I log into 
A1, visit S1 (without being logged in to S1) and then revisit A1, I am no 
longer logged in. The S1 server doesn't set a new session ID in the cookie and 
I don't think from memory that the CSRF changes. The session ID cookie hasn't 
changed, the domain is the same etc.

I can't work out why I'm no longer logged into A1. I know this isn't much to go 
on but I'm assuming something is happening to the cookies set by S1 when I 
visit it. Any suggestions appreciated.

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


Re: How to get Django to log all uncaught exceptions?

2016-09-02 Thread Stodge
Ok, so I discovered after searching through lots of code that the problem 
occurs  because I haven't run compilemessages, so Django was trying to 
format an error message that accepted parameters.

On Friday, 2 September 2016 11:06:58 UTC-4, Stodge wrote:
>
> I'm getting an exception during a TastyPie request for one of my 
> resources. The exception is:
>
> Error: not all arguments converted during string formatting
>
> I know what causes the exception, but I have no idea where it is 
> happening, as there is no trackback or indication of which module or 
> function it occurs in. I'm 99% sure the exception is occurring in my code, 
> not TastyPie of Django. I just have no idea how to find out where it's 
> happening. I've tried adding a custom middleware that displays an 
> exception, but Django doesn't catch this one, so it never logs anything.
>
> Any ideas how to get Django to log all exception, even uncaught ones?
>
> Thanks!!
>

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


How to get Django to log all uncaught exceptions?

2016-09-02 Thread Stodge
I'm getting an exception during a TastyPie request for one of my resources. 
The exception is:

Error: not all arguments converted during string formatting

I know what causes the exception, but I have no idea where it is happening, 
as there is no trackback or indication of which module or function it 
occurs in. I'm 99% sure the exception is occurring in my code, not TastyPie 
of Django. I just have no idea how to find out where it's happening. I've 
tried adding a custom middleware that displays an exception, but Django 
doesn't catch this one, so it never logs anything.

Any ideas how to get Django to log all exception, even uncaught ones?

Thanks!!

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


Re: Signal handling when deleting lots of objects?

2016-09-01 Thread Stodge
Thanks Erik.

I forgot to say that the Group model has an "active" flag on it, so I'm 
seeing if I can use this.


On Thursday, 1 September 2016 14:55:05 UTC-4, Erik Cederstrand wrote:
>
>
> > Den 1. sep. 2016 kl. 20.14 skrev Stodge <sto...@gmail.com >: 
>
> > 
> > I have two models, Volume and Group. The Volume model has a foreign key 
> to Group. 
> > 
> > When a user deletes a Volume the post_delete signal handler sends an 
> HTTP DELETE request (/volume) to another server process. This works great. 
> However, when the user deletes a Group, the cascading delete also deletes 
> all volumes in that group. That means I get lots (I'm talking <100) of 
> post_delete signals for the Volume model and therefore lots of HTTP 
> requests. 
> > 
> > Is there anyway to avoid this? Ideally, I'd like to send the HTTP DELETE 
>  request (/volume) when a volume is deleted, but send a different HTTP 
> DELETE request (/group) when the group is deleted and avoid sending any 
> volume HTTP DELETE requests. 
>
> You could disconnect the post_delete signal for Volume temporarily, but 
> that's a hack. 
>
> You probably have to abandon signals on the Volume model. I would attach 
> the post_delete signals logic directly to the Volume.delete() method and 
> add an option to disable signaling: 
>
> class Volume(models.Model): 
> [] 
> def my_signal_logic(self): 
> do_whatever() 
>
> def delete(self, *args, **kwargs): 
>with_signal = kwargs.pop('signal', True) 
>if with_signal: 
>self.my_signal_logic() 
>super().delete(*args, **kwargs) 
> 
>
> Then in the post_delete signal for Group, you delete the Volumes 
> explicitly, telling delete() not to signal: 
>
> for v in instance.volumes.all(): 
> v.delete(signal=False) 
>
> requests.delete('/group/%s' % instance.pk) 
>
>
> Erik

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


Signal handling when deleting lots of objects?

2016-09-01 Thread Stodge
I have two models, Volume and Group. The Volume model has a foreign key to 
Group.

When a user deletes a Volume the post_delete signal handler sends an HTTP 
DELETE request (/volume) to another server process. This works great. 
However, when the user deletes a Group, the cascading delete also deletes 
all volumes in that group. That means I get lots (I'm talking <100) of 
post_delete signals for the Volume model and therefore lots of HTTP 
requests.

Is there anyway to avoid this? Ideally, I'd like to send the HTTP DELETE  
request (/volume) when a volume is deleted, but send a different HTTP 
DELETE request (/group) when the group is deleted and avoid sending any 
volume HTTP DELETE requests.

Thanks

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


Any way to force Django to commit a write so another process can read the correct data from DB?

2016-07-27 Thread Stodge
My website uses a combination of Django + Java apps to function. For this 
particular problem, a record is deleted from the DB via a TastyPie resource 
DELETE operation. A Django signal post_delete handleris invoked, which 
submits a DELETE request to Jetty running in the Java app. The Java app 
then performs a query using Hibernate.

What appears to be happening is that Django thinks the record was deleted:

DynamicVolume.objects.filter(user=instance.user).count()

Returns ZERO.

However, the Java app thinks the record still exists unless I make it sleep 
for several seconds before asking Hibernate to query the DB.

I've tried forcing Hibernate to clear its cache with no success. Is there a 
way to force Django to commit the deletion (flush the cache)?

Thanks

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


Django app that adds multiple inheritance for Django auth groups?

2016-04-01 Thread Stodge
Is anyone aware of a Django app that adds multiple inheritance to Django 
auth groups? I know about django-hierarchical-auth but I want the ability 
to specify multiple parents for a group to make it easier to manage and 
group permissions. Thanks

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


Re: Session recycling during login times out

2016-02-27 Thread Stodge
The title is misleading; it should probably be "Session recycling stalls 
during login".

I also noticed that logout stalls.

On Saturday, February 27, 2016 at 3:12:08 PM UTC-5, Stodge wrote:
>
> I'm trying to diagnose a problem where noone can login to my django site. 
> The login attempt times out as NGINX (proxy) gives up waiting for Apache to 
> respond. There are no errors in the logs anywhere. I copied the Django code 
> into my app to debug:
>
> def this_real_login(request, user):
>> """
>> Persist a user id and a backend in the request. This way a user 
>> doesn't
>> have to reauthenticate on every request. Note that data set during
>> the anonymous session is retained when the user logs in.
>> """
>> if user is None:
>> user = request.user
>> # TODO: It would be nice to support different login methods, like 
>> signed cookies.
>> if SESSION_KEY in request.session:
>> if request.session[SESSION_KEY] != user.pk:
>> # To avoid reusing another user's session, create a new, empty
>> # session if the existing session corresponds to a different
>> # authenticated user.
>> print("DEBUG: Flushing session")
>> request.session.flush()
>> print("DEBUG: Flushed session")
>> else:
>> print("DEBUG: Cycling session")
>> request.session.cycle_key()
>> print("DEBUG: Cycled session")
>> request.session[SESSION_KEY] = user.pk
>> request.session[BACKEND_SESSION_KEY] = user.backend
>> if hasattr(request, 'user'):
>> request.user = user
>> print("DEBUG: Rotating token")
>> rotate_token(request)
>> print("DEBUG: Rotated token")
>
>
> It appears to stall inside:
>
>  request.session.cycle_key()
>
> Does anyone have any ideas why this might be? I'm scouring this code but I 
> can't see anything amiss.
>
> Thanks
>
>

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


Session recycling during login times out

2016-02-27 Thread Stodge
I'm trying to diagnose a problem where noone can login to my django site. 
The login attempt times out as NGINX (proxy) gives up waiting for Apache to 
respond. There are no errors in the logs anywhere. I copied the Django code 
into my app to debug:

def this_real_login(request, user):
> """
> Persist a user id and a backend in the request. This way a user doesn't
> have to reauthenticate on every request. Note that data set during
> the anonymous session is retained when the user logs in.
> """
> if user is None:
> user = request.user
> # TODO: It would be nice to support different login methods, like 
> signed cookies.
> if SESSION_KEY in request.session:
> if request.session[SESSION_KEY] != user.pk:
> # To avoid reusing another user's session, create a new, empty
> # session if the existing session corresponds to a different
> # authenticated user.
> print("DEBUG: Flushing session")
> request.session.flush()
> print("DEBUG: Flushed session")
> else:
> print("DEBUG: Cycling session")
> request.session.cycle_key()
> print("DEBUG: Cycled session")
> request.session[SESSION_KEY] = user.pk
> request.session[BACKEND_SESSION_KEY] = user.backend
> if hasattr(request, 'user'):
> request.user = user
> print("DEBUG: Rotating token")
> rotate_token(request)
> print("DEBUG: Rotated token")


It appears to stall inside:

 request.session.cycle_key()

Does anyone have any ideas why this might be? I'm scouring this code but I 
can't see anything amiss.

Thanks

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


Re: Django imports models for apps that aren't enabled?

2016-01-05 Thread Stodge
Carl, thanks. You were right - I was experiencing "b".

Thanks again
Mike

On Tuesday, 5 January 2016 11:02:24 UTC-5, Carl Meyer wrote:
>
> Hi Stodge, 
>
> On 01/05/2016 08:57 AM, Stodge wrote: 
> > I'm using Django 1.6.9. When the dev server (and hence Apache) starts, 
> > is Django supposed to import models for apps that exist on disk, but 
> > aren't enabled in the settings? I'm seeing this behaviour and I wasn't 
> > expecting it. Thanks 
>
> Django shouldn't do that on its own. AFAIK the only reason a models file 
> should be imported is a) because it's listed in INSTALLED_APPS, or b) 
> because something else that is imported imports it (possibly also c) an 
> installed model has an FK linking to it with a string reference?). 
>
> My first guess would be that you're seeing case (b). If you just add an 
> "assert False" at module-level in the models file in question, the 
> resulting traceback should show you the import chain leading to its 
> import. 
>
> Carl 
>
>

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


Django imports models for apps that aren't enabled?

2016-01-05 Thread Stodge
I'm using Django 1.6.9. When the dev server (and hence Apache) starts, is 
Django supposed to import models for apps that exist on disk, but aren't 
enabled in the settings? I'm seeing this behaviour and I wasn't expecting 
it. Thanks

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


Re: Managing and synchronising users on multiple sites

2015-11-08 Thread Stodge
The servers are in DMZs in different cities. I don't control the firewall 
configuration and I'm not allowed to open extra ports.

On Sunday, 8 November 2015 14:18:37 UTC-5, Gergely Polonkai  wrote:
> How about an SSO solution hosted at one of the sites? When the user logs in, 
> the site authenticates them against the SSO, and fetches user data. See Stack 
> Exchange sites (Stack Overflow, Server Fault, etc) as an example.
> 
> On 8 Nov 2015 18:24, "Stodge" <sto...@gmail.com> wrote:
> I have several Django sites and I need to synchronize user accounts across 
> them all. I need the ability to create the same user on all sites at the same 
> time and also to keep their info in sync. The servers are in different 
> locations in DMZs and can't open connections to external servers. So no third 
> party access. I thought I could write a Java app that uses a REST API to 
> query and update accounts to synchronize them but that opens a security issue 
> as I have to expose the ability to read/write passwords. I can't think of any 
> other solutions - any ideas? Thanks
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> 
> To post to this group, send email to django...@googlegroups.com.
> 
> Visit this group at http://groups.google.com/group/django-users.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/c05af7b9-965c-47d9-9106-524a1e6cd46d%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

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


Managing and synchronising users on multiple sites

2015-11-08 Thread Stodge
I have several Django sites and I need to synchronize user accounts across them 
all. I need the ability to create the same user on all sites at the same time 
and also to keep their info in sync. The servers are in different locations in 
DMZs and can't open connections to external servers. So no third party access. 
I thought I could write a Java app that uses a REST API to query and update 
accounts to synchronize them but that opens a security issue as I have to 
expose the ability to read/write passwords. I can't think of any other 
solutions - any ideas? Thanks

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


Re: Dango signal can't delete directory

2014-11-06 Thread Stodge
Tom, you might be right about the sticky bit. If I store the tile cache 
elsewhere, the signal can successfully delete it.

On Thursday, 6 November 2014 10:55:03 UTC-5, Tom Evans wrote:
>
> On Thu, Nov 6, 2014 at 3:08 PM, Stodge <sto...@gmail.com > 
> wrote: 
> > I have a separate daemon running as root that generates cached image 
> tiles 
> > per user for a map. For now it creates them under /tmp/tile_cache. When 
> it 
> > creates a new tile cache it changes the UID and GID to the apache user 
> (on 
> > Fedora) and also gives everyone access to the directory, e.g. 
> permissions 
> > are rwxrwxrwx. 
> > 
> > My Django app runs under mod_wsgi using Apache. I have a Django view 
> > triggers a signal and the signal is supposed to delete a cache for the 
> > requesting user. However, the signal uses os.path.isdir and refuses to 
> "see" 
> > the directory. os.path.exists fails to see the directory as well. 
> Attempts 
> > to delete the directory using shutils.rmtree also fail because I assume 
> it 
> > can't for some reason stat the directory. 
> > 
> > I have no idea why the signal can't delete the directory - can anyone 
> point 
> > anything obvious out? Thanks 
>
> /tmp always has the sticky bit set, which means only the owner of a 
> file can remove it, regardless of permissions. 
>
> Cheers 
>
> Tom 
>

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


Re: Dango signal can't delete directory

2014-11-06 Thread Stodge
I added:

try:
> mode = os.stat(path).st_mode
> print(str(S_ISDIR(mode)))
> except Exception, e:
> print("Error stating tile cache %s" % str(e))

 
Which gives:

Error stating tile cache [Errno 2] No such file or directory: 
> '/tmp/tile_cache/mike'


But ls -al /tmp/tile_cache shows the "mike" directory clearly exists. So 
I'm assuming the Python code under Apache can't stat the directory.

ls /tmp/tile_cache -al 
> total 0
> drwxr-xr-x  3 apache apache   60 Nov  6 11:07 .
> drwxrwxrwt 58 root   root   1380 Nov  6 11:07 ..
> drwxrwxrwx  2 apache apache  860 Nov  6 11:07 mike


Oh but I just noticed that the total is '0'. Weird.


On Thursday, 6 November 2014 11:02:15 UTC-5, Stodge wrote:
>
> I'll see if the python code under Apache can stat /tmp. Thanks.
>
> On Thursday, 6 November 2014 10:56:39 UTC-5, Tom Evans wrote:
>>
>> On Thu, Nov 6, 2014 at 3:54 PM, Tom Evans <teva...@googlemail.com> 
>> wrote: 
>> > On Thu, Nov 6, 2014 at 3:08 PM, Stodge <sto...@gmail.com> wrote: 
>> >> I have a separate daemon running as root that generates cached image 
>> tiles 
>> >> per user for a map. For now it creates them under /tmp/tile_cache. 
>> When it 
>> >> creates a new tile cache it changes the UID and GID to the apache user 
>> (on 
>> >> Fedora) 
>>
>> Oops, missed that bit! 
>>
>> Can you run stat as the user running the deletion for each component 
>> in the path up to /tmp. 
>>
>> Eg, if it is /tmp/tile_cache/1234/567: 
>>
>> stat /tmp 
>> stat /tmp/tile_cache 
>> stat /tmp/tile_cache/1234 
>>
>> etc 
>>
>> Cheers 
>>
>> Tom 
>>
>

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


Re: Dango signal can't delete directory

2014-11-06 Thread Stodge
I'm debug printing the directory I'm trying to delete, so I'm sure it's 
correct. But you raise a valid point!

I also change permissions and ownership of /tmp/tile_cache.

Thanks.

On Thursday, 6 November 2014 10:59:35 UTC-5, Bruno Barcarol Guimarães wrote:
>
> > os.path.exists fails to see the directory as well.
>
> This is strange. Are you sure you are referencing the right directory (it
> happens...)? The only other reason I can think of is your program or 
> apache (or
> both) running with mount namepsace on /tmp.
>
> That said:
>
> > When it creates a new tile cache it changes the UID and GID to the 
> apache user (on Fedora) and also gives everyone access to the directory, 
> e.g. permissions are rwxrwxrwx.
>
> Remember you need write permission on the *parent* directory to remove a 
> file
> inside it. E.g.: to remove `a/b` you need write permission on `a` 
> (permissions
> on `b` don't matter, in this case).
>

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


Re: Dango signal can't delete directory

2014-11-06 Thread Stodge
I'll see if the python code under Apache can stat /tmp. Thanks.

On Thursday, 6 November 2014 10:56:39 UTC-5, Tom Evans wrote:
>
> On Thu, Nov 6, 2014 at 3:54 PM, Tom Evans <teva...@googlemail.com 
> > wrote: 
> > On Thu, Nov 6, 2014 at 3:08 PM, Stodge <sto...@gmail.com > 
> wrote: 
> >> I have a separate daemon running as root that generates cached image 
> tiles 
> >> per user for a map. For now it creates them under /tmp/tile_cache. When 
> it 
> >> creates a new tile cache it changes the UID and GID to the apache user 
> (on 
> >> Fedora) 
>
> Oops, missed that bit! 
>
> Can you run stat as the user running the deletion for each component 
> in the path up to /tmp. 
>
> Eg, if it is /tmp/tile_cache/1234/567: 
>
> stat /tmp 
> stat /tmp/tile_cache 
> stat /tmp/tile_cache/1234 
>
> etc 
>
> Cheers 
>
> Tom 
>

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


Dango signal can't delete directory

2014-11-06 Thread Stodge
I have a separate daemon running as root that generates cached image tiles 
per user for a map. For now it creates them under /tmp/tile_cache. When it 
creates a new tile cache it changes the UID and GID to the apache user (on 
Fedora) and also gives everyone access to the directory, e.g. permissions 
are rwxrwxrwx.

My Django app runs under mod_wsgi using Apache. I have a Django view 
triggers a signal and the signal is supposed to delete a cache for the 
requesting user. However, the signal uses os.path.isdir and refuses to 
"see" the directory. os.path.exists fails to see the directory as well. 
Attempts to delete the directory using shutils.rmtree also fail because I 
assume it can't for some reason stat the directory.

I have no idea why the signal can't delete the directory - can anyone point 
anything obvious out? Thanks

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


How to use natural keys when dumping/loading fixture data for models that use generic relations?

2014-10-02 Thread Stodge
I'm trying to create fixtures for my Django application. We have our own 
app that provides per-object permissions. It uses a GenericForeignKey to 
assign permissions to many different models. I need the ability to define 
fixtures for these custom permissions. However, I'm having trouble 
understanding how to do this properly. All of my own models have natural 
keys defined. My object permission model has a uuid field, which is 
auto-generated in the overridden save function. It's also defined as the 
natural key for this model. When I dump existing object permissions, the 
JSON includes the object_id so it's not using the natural key. Here's an 
example:

{
>
> "pk": 7, 
>
> "model": "vault.vault", 
>
> "fields": {
>
> "groups": [], 
>
> "uuid": "11d62a7b-6e38-4baf-8938-fb475d8aca52", 
>
> "system": true, 
>
> "object_id": 3, 
>>
> "content_type": [
>
> "myapp", 
>
> "mymodel"
>
> ], 
>
> "permissions": [], 
>
> "public": false, 
>
> "users": []
>
> }
>
> }
>
>
>
I can't use this fixture as it's referencing an object ID. How do I use 
natural keys when dumping/loading fixture data for models that use generic 
relations? Thanks

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


Re: Upgrading Django (to 1.7)

2014-10-02 Thread Stodge
I will read this thanks. Does it cover this issue?

django.core.exceptions.AppRegistryNotReady: The translation infrastructure 
> cannot be initialized before the apps registry is ready. Check that you 
> don't make non-lazy gettext calls at import time.
>

I don't know if this has been a pain to many people, but I had to rollback 
to 1.6. That's a post for another day but I'm curious if you hit it.

On Wednesday, 24 September 2014 22:09:20 UTC-4, Andrew Pinkham wrote:
>
> Hi, 
> I am writing a series of articles based on the presentation I gave at 
> DjangoCon US 2014. I put the first article online earlier today, and 
> figured members of this list might be interested in the material. 
>
> For all of the material: 
> afrg.co/updj17/ 
>
> For the article: 
> afrg.co/updj17/a1/ 
>
> I plan to post the next three in the series on each of the coming 
> Wednesdays. 
>
> Any feedback appreciated. I hope you find the material helpful. 
>
> Andrew 
>
>

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


Retrieving recurring events using Django queries

2014-09-19 Thread Stodge
I have the following to model a calendar entry (recurring event). I need 
the ability to retrieve all events from the database between a start and 
end date. This has to include one off events and also recurring "virtual" 
events that occur because of an event in the database. Do you think this is 
possible using Django queries? Or do I need to retrieve the objects from 
the DB and then calculate the recurring events in the range in plain python 
using something like dateutil? I've been racking my brains but I can't seem 
to work out how to do it. Any suggestions appreciated.

class CalendarEntry(models.Model):

REPEAT_CHOICES = (
('NONE',_('None')),
('DAILY',_('Daily')),
('WEEKDAY',  _('Every weekday')),
('WEEKLY',   _('Weekly')),
('BIWEEKLY', _('Fortnightly')),
('MONTHLY',  _('Monthly')),
('YEARLY',   _('Yearly')),
)

# Mappings between content and an event entry.
content_type= models.ForeignKey(ContentType, verbose_name='content 
type')
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type', 'object_id')
field   = models.CharField(max_length=64)

# Basic event information.
start_date = TimestampGMT(blank=True, null=True)
end_date = TimestampGMT(blank=True, null=True)

# Recurrence information.
all_day = models.BooleanField()
repeat = models.CharField(max_length=15, choices=REPEAT_CHOICES, 
default='NEVER')
end_repeat = models.DateTimeField(_("end repeat"), null=True, 
blank=True)





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


Auto generating API documentation for SoapLib 0.8 + Django?

2014-09-16 Thread Stodge
We implemented a simple SOAP service using SoapLib 0.8 in our Django 
project a long time ago. We think he created an API document that we want 
to send to clients. I have a vague recollection that he somehow 
auto-generated the APIs from the source code. However, we can't find the 
document and the developer isn't here anymore. Is anyone aware of a tool 
that auto-generates API documentation for SoapLib with Django?

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


Re: post_save doesn't work

2014-08-14 Thread Stodge
I've had good success with placing the import at the end of the models file.

On Tuesday, 12 August 2014 20:06:41 UTC-4, chedi toueiti wrote:
>
> Hi Neto,
>
> Just make sure that your callback is loaded, the most easy way to do it is 
> to import the function in models.py if you have a single models file or in 
> the __init__.py of the models if you have it as a module.
>
> in https://docs.djangoproject.com/en/1.6/topics/signals/:
>
>
> Where should this code live?
>>
>> You can put signal handling and registration code anywhere you like. 
>> However, you’ll need to make sure that the module it’s in gets imported 
>> early on so that the signal handling gets registered before any signals 
>> need to be sent. This makes your app’s models.py a good place to put 
>> registration of signal handlers.
>>
>
> On Monday, August 11, 2014 10:02:18 PM UTC+1, Neto wrote:
>>
>> I'm trying to do a post_save but he doesn't work, I am using* 
>> objects.create()*:
>>
>> *views:*
>>
>> Usuario.objects.create(name='')
>>
>> *models:*
>>
>> @receiver(models.signals.post_save, sender=Usuario)
>> def auto_abc(sender, instance, **kwargs):
>> ...
>>
>>
>>
>> Why my post_save doesn't work with objects.create()? How I do?
>>
>

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


Re: Custom management commands provided as only .pyc files?

2014-08-14 Thread Stodge
Thanks - there are some great suggestions here. Much appreciated.

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


Custom management commands provided as only .pyc files?

2014-08-12 Thread Stodge
As explained in https://code.djangoproject.com/ticket/14952, Django doesn't 
support custom management commands that are only provided as .pyc files. I 
have a requirement with my project that I cannot distribute the .py files - 
only the .pyc. It's a roundabout way of not providing the source code when 
we install our software on a client's server. Is the only recommended way 
around this to hack django/core/management/init.py? Is it acceptable to 
monkey patch the file instead? I don't want to hack the Django source as it 
will break when I upgrade Django in the future. Thanks

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


AppRegistryNotReady trying to access model's verbose name

2014-08-06 Thread Stodge
I'm trying to port my Django project to Dango 1.7rc2 but I'm hitting the 
app registry error. I know that this is mentioned in the Troubleshooting 
section of the documentation but I don't understand why this is happening.

__init__.py", line 44, in register_layer
layer['verbose_name'] = model._meta.verbose_name.capitalize()
  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 
132, in __wrapper__
res = func(*self.__args, **self.__kw)
  File 
"/usr/lib/python2.7/site-packages/django/utils/translation/__init__.py", 
line 83, in ugettext
return _trans.ugettext(message)
  File 
"/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
line 325, in ugettext
return do_translate(message, 'ugettext')
  File 
"/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
line 306, in do_translate
_default = translation(settings.LANGUAGE_CODE)
  File 
"/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
line 209, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
  File 
"/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
line 189, in _fetch
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure 
cannot be initialized before the apps registry is ready. Check that you 
don't make non-lazy gettext calls at import time.


The model's verbose name is a translated string, but models.py uses 
ugettext_lazy so I don't understand why it ends up using ugettext. Thanks

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


Using Django as a centralised auth server?

2014-07-29 Thread Stodge
I have several Django websites and I want to create a centralized auth 
provider. The auth provider site would contain the user accounts and be the 
only repository for user details and passwords. Users would log into the 
auth provider site and when they visit each satellite website for the first 
time, an account is created on that site. Subsequent visits to the 
satellite site would result in them being sent to the auth provider site to 
login first. On returning they are automatically logged in to the satellite 
site. My only difficulty is that the auth provider site would be on the 
internet and the satellite sites are in DMZs on private networks with 
access to the internet. So the satellite sites cannot establish any 
outgoing connections to the auth provider.

Is oauth2 the right solution? I just found the cas-provider so I'll read up 
on that. Are there any better or more appropriate alternatives?

Thanks

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


SVG attribute is not transformed

2014-07-10 Thread Stodge
I'm adding map data from a new source that needs to be projected so I 
transform the query set like this:

 q = 
Polyline.objects.filter(overlay='63979e90-a578-4d18-af0a-8bd75279d923').transform(93997).svg()


The resulting SVG attribute isn't transformed. The documentation says:

Attaches a SVG attribute to every model in the queryset that contains the 
Scalable 
Vector Graphics (SVG)  path data of the 
geometry fields.


Which seems to confirm my suspicion - at least how I read it. Printing the 
query confirms that the SVG attribute isn't transformed:

print q.query
SELECT (ST_AsSVG("airmap_polyline"."the_geom",0,8)) AS "svg", 
"airmap_polyline"."id", "airmap_polyline"."overlay_id", 
ST_Transform("airmap_polyline"."the_geom", 93997) FROM "airmap_polyline" 
WHERE "airmap_polyline"."overlay_id" = 63979e90-a578-4d18-af0a-8bd75279d923


Is there a way to apply the transform to the SVG attribute? I can get it 
working using raw SQL but I thought I should be able to use the ORM. Thanks


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


How to filter generic foreign keys?

2014-06-21 Thread Stodge
I have these models:

class EventEntry(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
start_date =  models.DateTimeField(...)
end_date = models.DateTimeField(...)
field = models.CharField(max_length=64)

class ObjectPerm(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
public = models.BooleanField(...)
users = models.ManyToManyField(User...)
groups = models.ManyToManyField(Group...)

class Meeting(models.Model):
scheduled_time = generic.GenericRelation(EventEntry)
room = models.CharField(max_length=8)


class Milestone(models.Model):
due_date = generic.GenericRelation(Proof)
title = models.CharField(max_length=128)

The EventEntry class is used to attach scheduling information to any 
object, such as Meeting and Milestone.

The ObjcetPerm class provides object level permissions to any model that 
needs protection.

When I create an instance of Meeting, I assign an EventEntry instance for 
the schedule information. I also assign ObjectPerm instances to specify 
which users can access the meeting object.

There are more models like Meeting and Milestone.

Now, what I want to do is retrieve EventEntry instances, but only those for 
related objects the user has permission to access, based on the ObjectPerm 
model. For example all EventEntry instances where public == True or the 
user is in the EventEntry field "users". This way I can pull out all the 
events to display in a calendar but I don't need to filter the meetings, 
milestones etc. Except I can't work out how to write this filter in Python 
using Django's ORM. Any suggestions appreciated. Thanks

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


Re: Language code issue - Django thinks default is en-us?

2014-06-20 Thread Stodge
This always confuses me - the language code is always lower case according 
to the docs. Which is specified in the settings - language codes or 
locales? I've always assumed the former.

locale nameA locale name, either a language specification of the form ll or 
a combined language and country specification of the form ll_CC. Examples: 
it, de_AT, es, pt_BR. The language part is always in lower case and the 
country part in upper case. The separator is an underscore.language 
codeRepresents 
the name of a language. Browsers send the names of the languages they 
accept in the Accept-Language HTTP header using this format. Examples: it, 
de-at, es, pt-br. Both the language and the country parts are in lower 
case. The separator is a dash.
On Friday, 20 June 2014 08:47:13 UTC-4, Vernon D. Cole wrote:
>
> (*cough*)
> Excuse me, everyone, but many of the locale names mentioned in this 
> discussion have been invalid.
>
> https://docs.djangoproject.com/en/1.6/topics/i18n/#term-locale-name says:
>
>> locale nameA locale name, either a language specification of the form ll 
>> or a combined language and country specification of the form ll_CC. 
>> Examples: it, de_AT, es, pt_BR. The language part is always in lower 
>> case and the country part in upper case. The separator is an underscore.
>
>
> so 'en-gb' should not be recognized.
> 'en_GB' ought to be.
>
>
> On Thursday, June 19, 2014 3:18:32 PM UTC+1, Stodge wrote:
>>
>> My problem seems to be this:
>>
>>  * run custom management command
>>  * activate language from settings, which is "en-gb"
>>  * dynamically import module for a Django app and invoke custom bootstrap 
>> function
>>  * calling get_language() in bootstrap function returns "en-gb"
>>  * bootstrap function calls loaddata management command (using 
>> management.call_command)
>>  * data created in DB, which triggers a post_save signal
>>  * get_language() in post_save signal always returns "en-us"
>>
>>
>>
>>
>> On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote:
>>>
>>> My settings for languages are:
>>>
>>> LANGUAGE_CODE = 'en'
>>>
>>> USE_I18N = True
>>> LANGUAGE_COOKIE_NAME='django_language'
>>> ugettext = lambda s: s
>>> LANGUAGES = (
>>> ('en', ugettext('English')),
>>> ('de', ugettext('German')),
>>> ('fr', ugettext('French'))
>>> )
>>>
>>>
>>> I have a post-save signal that creates instances of a model and gets the 
>>> current Django language. The language returned is for some reason "en-us", 
>>> but I have no idea where this is coming from. My default as shown above is 
>>> "en". get_language() is called from within a signal so the language isn't 
>>> being taken from a cookie or request header. Any ideas why Django thinks 
>>> the current (default) language is "en-us"? Thanks
>>>
>>>

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


Using forms/template to enter recurring events - how to avoid duplicate and redundant forms?

2014-06-20 Thread Stodge
I'm trying to make a template and form to let a user define a recurring 
event. I want to present different fields depending on whether they want 
daily, weekly, monthly or yearly recurrence. I'm not sure how to define the 
forms to do this so that the submitted data isn't duplicated or redundant.

Are there any examples of the best practice for this? I'm Googling for 
examples Thanks

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


Re: Language code issue - Django thinks default is en-us?

2014-06-19 Thread Stodge
My problem seems to be this:

 * run custom management command
 * activate language from settings, which is "en-gb"
 * dynamically import module for a Django app and invoke custom bootstrap 
function
 * calling get_language() in bootstrap function returns "en-gb"
 * bootstrap function calls loaddata management command (using 
management.call_command)
 * data created in DB, which triggers a post_save signal
 * get_language() in post_save signal always returns "en-us"




On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote:
>
> My settings for languages are:
>
> LANGUAGE_CODE = 'en'
>
> USE_I18N = True
> LANGUAGE_COOKIE_NAME='django_language'
> ugettext = lambda s: s
> LANGUAGES = (
> ('en', ugettext('English')),
> ('de', ugettext('German')),
> ('fr', ugettext('French'))
> )
>
>
> I have a post-save signal that creates instances of a model and gets the 
> current Django language. The language returned is for some reason "en-us", 
> but I have no idea where this is coming from. My default as shown above is 
> "en". get_language() is called from within a signal so the language isn't 
> being taken from a cookie or request header. Any ideas why Django thinks 
> the current (default) language is "en-us"? Thanks
>
>

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


Re: Language code issue - Django thinks default is en-us?

2014-06-19 Thread Stodge
No that's the code from the Django documentation.

https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#management-commands-and-locales

On Thursday, 19 June 2014 09:39:34 UTC-4, Tom Evans wrote:
>
> On Thu, Jun 19, 2014 at 1:41 PM, Stodge <sto...@gmail.com > 
> wrote: 
> > Yes I'm aware of this thanks. However, the documentation also states 
> that I 
> > can activate a different language in my custom command: 
> > 
> > If, for some reason, your custom management command needs to use a fixed 
> > locale different from ‘en-us’, you should manually activate and 
> deactivate 
> > it in your handle() or handle_noargs() method using the functions 
> provided 
> > by the I18N support code: 
> > 
> > 
> > Using the code: 
> > 
> > # Activate a fixed locale, e.g. Russian 
> > translation.activate('ru') 
> > 
> > 
> > However, this doesn't appear to change anything. 
> > 
>
> From an earlier email, 'ru' is not an enabled language in your settings. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/297585e5-9e71-4d39-90d6-868dfc289bd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Language code issue - Django thinks default is en-us?

2014-06-19 Thread Stodge
Sorry, this is using Django 1.6.2.

On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote:
>
> My settings for languages are:
>
> LANGUAGE_CODE = 'en'
>
> USE_I18N = True
> LANGUAGE_COOKIE_NAME='django_language'
> ugettext = lambda s: s
> LANGUAGES = (
> ('en', ugettext('English')),
> ('de', ugettext('German')),
> ('fr', ugettext('French'))
> )
>
>
> I have a post-save signal that creates instances of a model and gets the 
> current Django language. The language returned is for some reason "en-us", 
> but I have no idea where this is coming from. My default as shown above is 
> "en". get_language() is called from within a signal so the language isn't 
> being taken from a cookie or request header. Any ideas why Django thinks 
> the current (default) language is "en-us"? Thanks
>
>

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


Re: Database problem in Django

2014-06-19 Thread Stodge
Read the documentation:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by

On Wednesday, 18 June 2014 08:06:18 UTC-4, Ashu Singh wrote:
>
> Hello everyone. My doubt is how to fetch the recent two database entries 
> in django. User may enter into database anytime but the query should always 
> fetch last two entries. 
>

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


Re: Language code issue - Django thinks default is en-us?

2014-06-19 Thread Stodge
Yes I'm aware of this thanks. However, the documentation also states that I 
can activate a different language in my custom command:

*If, for some reason, your custom management command needs to use a fixed 
locale different from ‘en-us’, you should manually activate and deactivate 
it in your handle() 
<https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#django.core.management.BaseCommand.handle>
 or handle_noargs() 
<https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#django.core.management.NoArgsCommand.handle_noargs>
 method 
using the functions provided by the I18N support code:*


Using the code:

# Activate a fixed locale, e.g. Russian
translation.activate('ru')


However, this doesn't appear to change anything.

On Thursday, 19 June 2014 08:38:31 UTC-4, Tom Evans wrote:
>
> On Wed, Jun 18, 2014 at 7:10 PM, Stodge <sto...@gmail.com > 
> wrote: 
> > By override I mean I add this at the start of my handle() function in my 
> > custom management command: 
> > 
> > from django.utils import translation 
> > translation.activate(settings.LANGUAGE_CODE) 
> > 
> > Where settings.LANGUAGE_CODE = "en-gb". 
> > 
> > Calling get_language in my custom management command still returns 
> "en-us". 
> > 
>
> In a management command, django will always set the language to "en-us": 
>
>
> https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#management-commands-and-locales
>  
>
> Cheers 
>
> Tom 
>
> . 
>

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


Re: Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
By override I mean I add this at the start of my handle() function in my 
custom management command:

from django.utils import translation
translation.activate(settings.LANGUAGE_CODE)

Where settings.LANGUAGE_CODE = "en-gb".

Calling get_language in my custom management command still returns "en-us".

On Wednesday, 18 June 2014 13:58:05 UTC-4, James Bennett wrote:
>
> On Wed, Jun 18, 2014 at 10:21 AM, Stodge <sto...@gmail.com > 
> wrote:
>
>> Even when I override the language code in my custom command 
>> get_language() still returns "en-us". Weird. Guess I'll have to use 
>> settings.LANGUAGE_CODE instead of get_language().
>>
>
> Define what you mean by "override the language code". Are you doing what 
> the documentation you linked to says to do in order to activate the locale 
> you want? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/277681e8-81c0-466f-814e-e55b8315019c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
This has nothing to do with the browser - it's a post save signal that 
executes inside a custom management command.

Thanks again

On Wednesday, 18 June 2014 13:48:41 UTC-4, Ilya Kazakevich wrote:
>
> LocaleMiddleware sets your language to one, provided by your webbrowser. 
> Tty to disable LocaleMiddleware or configure your browser to use different 
> language (
> http://stackoverflow.com/questions/7769061/how-to-add-custom-accept-languages-to-chrome-for-pseudolocalization-testing)
>  
>
>
>
> Ilya Kazakevich, 
> JetBrains PyCharm (Best Python/Django IDE) 
> http://www.jetbrains.com/pycharm/ 
> "Develop with pleasure!" 
>
>
> >-Original Message- 
> >From: django...@googlegroups.com  
> >[mailto:django...@googlegroups.com ] On Behalf Of Stodge 
> >Sent: Wednesday, June 18, 2014 9:42 PM 
> >To: django...@googlegroups.com  
> >Cc: ilya.ka...@jetbrains.com  
> >Subject: Re: Language code issue - Django thinks default is en-us? 
> > 
> >Thanks. I am using LocaleMiddleware. I changed my languages to: 
> > 
> >LANGUAGE_CODE = 'en-gb' 
> >USE_I18N = True 
> >LANGUAGES = ( 
> > 
> >('en-gb', ugettext('English')), 
> >('de', ugettext('German')), 
> >('fr', ugettext('French')) 
> >) 
> > 
> >But I'm still getting en-us. 
> > 
> >On Wednesday, 18 June 2014 13:29:45 UTC-4, Ilya Kazakevich wrote: 
> > 
> >1) Try to debug your code. Django is open source and sources are 
> available:) 
> >2) Do you have LocaleMiddleware installed? 
> >3) Do not use bare language, use language-region 
> >(http://www.i18nguy.com/unicode/language-identifiers.html 
> ><http://www.i18nguy.com/unicode/language-identifiers.html> ) : en-gb, 
> en-us, 
> >en-bb and so on 
> >4) It is generally bad idea to depend on LANGUAGE_CODE. You 
> should use 
> >get_language() to support I18N 
> > 
> >Ilya Kazakevich, 
> >JetBrains PyCharm (Best Python/Django IDE) 
> >    http://www.jetbrains.com/pycharm/ 
> ><http://www.jetbrains.com/pycharm/> 
> >"Develop with pleasure!" 
> > 
> > 
> >>-Original Message- 
> >>From: django...@googlegroups.com  
> >>[mailto:django...@googlegroups.com  ] On Behalf Of 
> Stodge 
> >>Sent: Wednesday, June 18, 2014 9:21 PM 
> >>To: django...@googlegroups.com  
> >>Subject: Re: Language code issue - Django thinks default is 
> en-us? 
> >> 
> >>Even when I override the language code in my custom command 
> >get_language() 
> >>still returns "en-us". Weird. Guess I'll have to use 
> >settings.LANGUAGE_CODE 
> >>instead of get_language(). 
> >> 
> >>On Wednesday, 18 June 2014 13:02:37 UTC-4, Stodge wrote: 
> >> 
> >>Oh. 
> >> 
> >> 
> >https://docs.djangoproject.com/en/dev/howto/custom-management-com 
> ><https://docs.djangoproject.com/en/dev/howto/custom-management-com> 
> >>mands/#management-commands-and-locales 
> >><
> https://docs.djangoproject.com/en/dev/howto/custom-management-co 
> >mman 
> ><https://docs.djangoproject.com/en/dev/howto/custom-management-comman 
> >> 
> >>ds/#management-commands-and-locales> 
> >> 
> >>I forgot to mention that the signal is executed as a 
> result of a 
> >loaddata 
> >>management command. So management commands don't respect 
> >>settings.LANGUAGE_CODE? That makes no sense. 
> >> 
> >>On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote: 
> >> 
> >>My settings for languages are: 
> >> 
> >> 
> >>LANGUAGE_CODE = 'en' 
> >> 
> >> 
> >>USE_I18N = True 
> >> 
> >LANGUAGE_COOKIE_NAME='django_language' 
> >>ugettext = lambda s: s 
> >>LANGUAGES = ( 
> >>('en', ugettext('English')), 
> >>('de', ugettext('German')), 
> >>('fr', ugettext('French')) 
> >>) 
> >> 
> > 

Re: Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
Thanks. I am using LocaleMiddleware. I changed my languages to:

LANGUAGE_CODE = 'en-gb'
USE_I18N = True
LANGUAGES = (
('en-gb', ugettext('English')),
('de', ugettext('German')),
('fr', ugettext('French'))
)

But I'm still getting en-us.

On Wednesday, 18 June 2014 13:29:45 UTC-4, Ilya Kazakevich wrote:
>
> 1) Try to debug your code. Django is open source and sources are 
> available:) 
> 2) Do you have LocaleMiddleware installed? 
> 3) Do not use bare language, use language-region (
> http://www.i18nguy.com/unicode/language-identifiers.html) : en-gb, en-us, 
> en-bb and so on 
> 4) It is generally bad idea to depend on LANGUAGE_CODE. You should use 
> get_language() to support I18N 
>
> Ilya Kazakevich, 
> JetBrains PyCharm (Best Python/Django IDE) 
> http://www.jetbrains.com/pycharm/ 
> "Develop with pleasure!" 
>
>
> >-Original Message- 
> >From: django...@googlegroups.com  
> >[mailto:django...@googlegroups.com ] On Behalf Of Stodge 
> >Sent: Wednesday, June 18, 2014 9:21 PM 
> >To: django...@googlegroups.com  
> >Subject: Re: Language code issue - Django thinks default is en-us? 
> > 
> >Even when I override the language code in my custom command 
> get_language() 
> >still returns "en-us". Weird. Guess I'll have to use 
> settings.LANGUAGE_CODE 
> >instead of get_language(). 
> > 
> >On Wednesday, 18 June 2014 13:02:37 UTC-4, Stodge wrote: 
> > 
> >Oh. 
> > 
> >https://docs.djangoproject.com/en/dev/howto/custom-management-com 
> >mands/#management-commands-and-locales 
> ><https://docs.djangoproject.com/en/dev/howto/custom-management-comman 
> >ds/#management-commands-and-locales> 
> > 
> >I forgot to mention that the signal is executed as a result of a 
> loaddata 
> >management command. So management commands don't respect 
> >settings.LANGUAGE_CODE? That makes no sense. 
> > 
> >On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote: 
> > 
> >My settings for languages are: 
> > 
> > 
> >LANGUAGE_CODE = 'en' 
> > 
> > 
> >USE_I18N = True 
> >LANGUAGE_COOKIE_NAME='django_language' 
> >ugettext = lambda s: s 
> >LANGUAGES = ( 
> >('en', ugettext('English')), 
> >('de', ugettext('German')), 
> >('fr', ugettext('French')) 
> >) 
> > 
> > 
> >I have a post-save signal that creates instances of a 
> model and gets the 
> >current Django language. The language returned is for some reason 
> "en-us", but 
> >I have no idea where this is coming from. My default as shown above is 
> "en". 
> >get_language() is called from within a signal so the language isn't being 
> taken 
> >from a cookie or request header. Any ideas why Django thinks the current 
> >(default) language is "en-us"? Thanks 
> > 
> > 
> >-- 
> >You received this message because you are subscribed to the Google Groups 
> >"Django users" group. 
> >To unsubscribe from this group and stop receiving emails from it, send an 
> email to 
> >django-users...@googlegroups.com . 
> >To post to this group, send email to django...@googlegroups.com 
> . 
> >Visit this group at http://groups.google.com/group/django-users. 
> >To view this discussion on the web visit 
> >
> https://groups.google.com/d/msgid/django-users/d5dcf509-a634-4f46-940c-8e0 
> >ee6c0ee69%40googlegroups.com 
> ><
> https://groups.google.com/d/msgid/django-users/d5dcf509-a634-4f46-940c-8e 
> >0ee6c0ee69%40googlegroups.com?utm_medium=email_source=footer> . 
> >For more options, visit https://groups.google.com/d/optout. 
>
>
>

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


Re: Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
Even when I override the language code in my custom command get_language() 
still returns "en-us". Weird. Guess I'll have to use settings.LANGUAGE_CODE 
instead of get_language().

On Wednesday, 18 June 2014 13:02:37 UTC-4, Stodge wrote:
>
> Oh.
>
>
> https://docs.djangoproject.com/en/dev/howto/custom-management-commands/#management-commands-and-locales
>
> I forgot to mention that the signal is executed as a result of a loaddata 
> management command. So management commands don't respect 
> settings.LANGUAGE_CODE? That makes no sense.
>
> On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote:
>>
>> My settings for languages are:
>>
>> LANGUAGE_CODE = 'en'
>>
>> USE_I18N = True
>> LANGUAGE_COOKIE_NAME='django_language'
>> ugettext = lambda s: s
>> LANGUAGES = (
>> ('en', ugettext('English')),
>> ('de', ugettext('German')),
>> ('fr', ugettext('French'))
>> )
>>
>>
>> I have a post-save signal that creates instances of a model and gets the 
>> current Django language. The language returned is for some reason "en-us", 
>> but I have no idea where this is coming from. My default as shown above is 
>> "en". get_language() is called from within a signal so the language isn't 
>> being taken from a cookie or request header. Any ideas why Django thinks 
>> the current (default) language is "en-us"? Thanks
>>
>>

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


Re: Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
Oh.

https://docs.djangoproject.com/en/dev/howto/custom-management-commands/#management-commands-and-locales

I forgot to mention that the signal is executed as a result of a loaddata 
management command. So management commands don't respect 
settings.LANGUAGE_CODE? That makes no sense.

On Wednesday, 18 June 2014 12:48:47 UTC-4, Stodge wrote:
>
> My settings for languages are:
>
> LANGUAGE_CODE = 'en'
>
> USE_I18N = True
> LANGUAGE_COOKIE_NAME='django_language'
> ugettext = lambda s: s
> LANGUAGES = (
> ('en', ugettext('English')),
> ('de', ugettext('German')),
> ('fr', ugettext('French'))
> )
>
>
> I have a post-save signal that creates instances of a model and gets the 
> current Django language. The language returned is for some reason "en-us", 
> but I have no idea where this is coming from. My default as shown above is 
> "en". get_language() is called from within a signal so the language isn't 
> being taken from a cookie or request header. Any ideas why Django thinks 
> the current (default) language is "en-us"? Thanks
>
>

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


Language code issue - Django thinks default is en-us?

2014-06-18 Thread Stodge
My settings for languages are:

LANGUAGE_CODE = 'en'

USE_I18N = True
LANGUAGE_COOKIE_NAME='django_language'
ugettext = lambda s: s
LANGUAGES = (
('en', ugettext('English')),
('de', ugettext('German')),
('fr', ugettext('French'))
)


I have a post-save signal that creates instances of a model and gets the 
current Django language. The language returned is for some reason "en-us", 
but I have no idea where this is coming from. My default as shown above is 
"en". get_language() is called from within a signal so the language isn't 
being taken from a cookie or request header. Any ideas why Django thinks 
the current (default) language is "en-us"? Thanks

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


Re: Action without URL

2014-05-08 Thread Stodge
Yes it is possible - think of the actions that need to take place.

 * The user clicks the button in the browser.
 * The browser sends an Ajax request to Django
 * The Django view processes the Ajax request, updates the database and 
sends a response to the browser

These are web fundamentals and I think you need to do some reading on the 
basic server/client architecture.

On Thursday, 8 May 2014 07:35:22 UTC-4, Karino Kang wrote:
>
> Dear all,
>
> I'm a relatively new user of Django and I'm struggling to do something I'm 
> not sure is possible with Django.
>
> I wanted to develop a "like" app which act pretty much like the facebook 
> "like" except that you can dislike.
>
> My main problem is that I want to have a button or image for liking and 
> disliking and I want to execute an action only in the database.
>
> for example, for the like, I would have something in the template like :
>
> 
>
> And I would have a python function defined somewhere in the app which 
> would be the following :
>
> def like(model):
> like_object = Like.objects.get(model=model, model_id=model_id)
>
> if like_object:
> like_object = Like(model=model, model_id=model_id, like_count=1)
>
> like_object.like_count = like_count + 1
> like_object.save()
>
>
> I want this action to be executed when I click on the image like.png but I 
> don't want the page to be change. There will be a like count displayed on 
> the page but it will be updated using javascript.
>
> Is this possible with Django?
>
> Regards,
> Karino KANG
>

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


Location of non-app-specific static files?

2012-11-04 Thread Stodge
I have two project static directories, STATIC and STATIC_FILES. STATIC contains 
non-app specific static files. STATIC_FILES is where static files are 
"collected".

-- 
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/-/9UEcLvEzvPUJ.
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.



Permissions and the sites framework

2012-11-04 Thread Stodge
Are there any plans to change the Permissions to use the sites framework? To 
support multi-site on my site, I need the ability to assign different 
permissions to the same user on different sites. Alternatively, any suggestions 
how to achieve this? Thanks

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



How to make my custom AdminSite class use my custom login/logout views?

2012-09-06 Thread Stodge
I have a custom AdminSite class working but now I'm trying to work out the 
best way to make it use my custom login and logout views. I supposed I 
could copy chunks of code from Django's admin sites.py and make it use my 
views. But this is a hack. Is there a standard way of using custom 
login/logout views in the admin site? Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/1vT_ZqXoSHcJ.
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.



Do I create an instance of my custom AdminSite in every admin.py?

2012-09-06 Thread Stodge
I'm experimenting with creating a custom admin site but I'm confused about 
something. Do I create an instance of my admin site in every admin.py or do 
I only create a single instance somewhere, and if so, where?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/C1UT4bEY6wAJ.
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: call_command('syncdb') in virtualenv failing: Error: No module named staticfiles

2012-04-23 Thread Stodge
Bah - I completely forgot that my gen.py script had this :

#!/usr/bin/python

On Monday, 23 April 2012 07:26:55 UTC-5, Stodge wrote:
>
> I'm trying to port an existing app to Django 1.4 so I'm using virtualenv. 
> ./manage.py syncdb works but my old script that calls syncdb and creates 
> dummy data doesn't. My code:
>
> os.environ["DJANGO_SETTINGS_MODULE"]="settings"
> call_command('syncdb', interactive=False)
>
> is giving:
>
> Error: No module named staticfiles
>
> I assume it's using Django installed in /usr/lib64/python instead of the 
> virtualenv? Any ideas how to fix this? Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/FcjZ7RfYnR8J.
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.



call_command('syncdb') in virtualenv failing: Error: No module named staticfiles

2012-04-23 Thread Stodge
I'm trying to port an existing app to Django 1.4 so I'm using virtualenv. 
./manage.py syncdb works but my old script that calls syncdb and creates 
dummy data doesn't. My code:

os.environ["DJANGO_SETTINGS_MODULE"]="settings"
call_command('syncdb', interactive=False)

is giving:

Error: No module named staticfiles

I assume it's using Django installed in /usr/lib64/python instead of the 
virtualenv? Any ideas how to fix this? Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0vZ9QQkEq3MJ.
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: Accessing MEDIA_ROOT in templates, always blank/missing

2012-03-22 Thread Stodge
All good points thanks. I'm only experimenting and learning so this
won't hit production. Point taken though. :)

On Mar 22, 7:30 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Thu, Mar 22, 2012 at 12:25 PM, Stodge <sto...@gmail.com> wrote:
> > No I need MEDIA_ROOT, I want to experiment with:
>
> > 
>
> > Thanks
>
> MEDIA_ROOT is a file-system location, not a URL-space location, and
> should not be exposed in templates. It is nonsense to use media root
> as a prefix to the URL-space location of your javascript files.
>
> Cheers
>
> Tom

-- 
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: Accessing MEDIA_ROOT in templates, always blank/missing

2012-03-22 Thread Stodge
No I need MEDIA_ROOT, I want to experiment with:



Thanks

On Mar 22, 7:22 am, kenneth gonsalves <law...@thenilgiris.com> wrote:
> On Thu, 2012-03-22 at 05:11 -0700, Stodge wrote:
> > In my template:
>
> > MEDIA_ROOT: {{MEDIA_ROOT}}
>
> > But all I see is:
>
> > MEDIA_ROOT:
>
> > So MEDIA_ROOT is blank or doesn't exist. Did I miss something?
>
> https://docs.djangoproject.com/en/1.0/ref/templates/api/#django-core-...
>
> you need MEDIA_URL
> --
> regards
> Kenneth Gonsalves

-- 
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: Accessing MEDIA_ROOT in templates, always blank/missing

2012-03-22 Thread Stodge
Oh that's surprising; the media context processor only creates
MEDIA_URL.

On Mar 22, 7:11 am, Stodge <sto...@gmail.com> wrote:
> I'm trying to reference MEDIA_ROOT in my template but it's blank. I
> have MEDIA_ROOT defined in settings.py:
>
> MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)),
> 'static')
>
> I have the correct context processor:
>
> TEMPLATE_CONTEXT_PROCESSOR = (
>     'django.core.context_processors.i18n',
>     'django.core.context_processors.auth',
>     'django.core.context_processors.media',
> )
>
> In my template:
>
> MEDIA_ROOT: {{MEDIA_ROOT}}
>
> But all I see is:
>
> MEDIA_ROOT:
>
> So MEDIA_ROOT is blank or doesn't exist. Did I miss something? This is
> Django 1.2.3, thanks. Oh and I realise there is a newer version of
> Django out there but I can't upgrade my app... yet..
>
> Thanks again

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



Accessing MEDIA_ROOT in templates, always blank/missing

2012-03-22 Thread Stodge
I'm trying to reference MEDIA_ROOT in my template but it's blank. I
have MEDIA_ROOT defined in settings.py:

MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'static')

I have the correct context processor:

TEMPLATE_CONTEXT_PROCESSOR = (
'django.core.context_processors.i18n',
'django.core.context_processors.auth',
'django.core.context_processors.media',
)

In my template:

MEDIA_ROOT: {{MEDIA_ROOT}}

But all I see is:

MEDIA_ROOT:

So MEDIA_ROOT is blank or doesn't exist. Did I miss something? This is
Django 1.2.3, thanks. Oh and I realise there is a newer version of
Django out there but I can't upgrade my app... yet..

Thanks again

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Any way to not create default Django permissions?

2012-01-18 Thread Stodge
Awesome - thanks for the description.

On Jan 18, 9:45 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, Jan 18, 2012 at 1:50 PM, Stodge <sto...@gmail.com> wrote:
> > I have a particular use case where the default permissions don't work
> > for me. I know I can create a custom auth backend, but if I do that,
> > is there a clean, legal way to not create the default model
> > permissions? Thanks
>
> If you have the django.contrib.auth app installed, it installs a
> signal handler to be called post syncdb to create the permissions. The
> handler is defined and the signal is connected in
> django.contrib.auth.management (in the __init__.py).
>
> If you want to disable this behaviour, you should be able to do so by
> disconnecting the signal:
>
> https://docs.djangoproject.com/en/1.3/topics/signals/#disconnecting-s...
>
> This signal has the uid 'django.contrib.auth.management.create_permissions'.
>
> Your signal de-registering code must run after the signal is
> registered, and before syncdb runs. Adding it to the management
> commands __init__.py of an app that appears after django.contrib.auth
> in settings.INSTALLED_APPS should suffice.
>
> Obviously, if you do this no permissions will ever be created by
> calling syncdb - default, custom or otherwise. You will have to
> manually create the permissions you want for the models you want them
> for.
>
> Without the default permissions, lots of things, like the admin, won't
> work. They would still work for superusers, as superusers have every
> permission, even ones that don't exist.
>
> Cheers
>
> Tom

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



Any way to not create default Django permissions?

2012-01-18 Thread Stodge
I have a particular use case where the default permissions don't work
for me. I know I can create a custom auth backend, but if I do that,
is there a clean, legal way to not create the default model
permissions? 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.



One To One relationship with a generic relation?

2012-01-14 Thread Stodge
I've used generic relations and they worked, but in one particular
case I need a one-to-one generic relation. Is this possible?

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



Django pub/sub with filtering?

2012-01-09 Thread Stodge
I'm trying to design a pub/sub event system for my site. The inputs
will be Django signals (e.g. User logged in), views and external POST
requests. I can easily create subscriptions:

Event type, e.g. Auth.login
Instance, e.g. User object for Fred
Data, nothing for this example
User, subscribing user, I.e. me

I could use this to know when a particular user logs in. I can use the
Django user logged I signal to do:

Publish(event="auth.login", instance=user)

However, what if I wanted this silly subscription:

Subscribe(event="auth.login", filter={ "field": "age", "operator":
">", "value": 20})

The problem is that the filter applies to an instance not a query set
as this is evaluated in the publish function.

Infinitely more flexible yet infinitely more complex! I want to store
subscriptions in one table and they have to flexible enough to be
usable for any type of data.

Has anyone tried something like this in Django before? This must be
the craziest feature I've tried to implement!

-- 
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: Logging into CSRF protected Django site using Curl?

2012-01-08 Thread Stodge

Thanks, appreciate it.


On Jan 8, 12:16 pm, creecode <creec...@gmail.com> wrote:
> Hello Stodge,
>
> It seems a bit convoluted on the command line but in reallity not much more
> convoluted if you consider all that a browser does for us in this regard.
> :-)
>
> I've used a similar technique to the one you describe on my Crowdsourcing
> Nutrition Facts website.  Here is an extract from the 
> documentation<%20http://www.crowdsourcingnutritionfacts.info/about/#rest-api-authentic...>
> ...
>
> Get the login webpage and parse the csrf token into the data shell
> variable.
>
> $ data=$(curl -s -c 
> cookies.txthttp://www.crowdsourcingnutritionfacts.info/accounts/login/| grep 
> -o "name=['\"]csrfmiddlewaretoken['\"] value=['\"][^'\"]*" | sed -e 
> "s/name='//" -e "s/' value='/=/")\=*user name*\=*password*
>
>  Log in to the website.
>
> $ curl -b cookies.txt -c cookies.txt -d $data -X POST -H 'Content-Type: 
> application/x-www-form-urlencoded'http://www.crowdsourcingnutritionfacts.info/accounts/login/
>
>  Get brands containing the search term "ea".
>
> $ curl -b 
> cookies.txthttp://www.crowdsourcingnutritionfacts.info/api/auto-complete/brand/?...
>
> This is not a best practices or anything just a sample to show programmers
> the mechanics of interacting with the website with whatever tools they
> choose to use.  I attempted to use tools that I thought would be
> available/familiar to a wide variety of systems/programmers.
>
> Toodle-l...
> creecode

-- 
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: Authentication over JSON

2012-01-08 Thread Stodge
This link is giving me a Page Not Found.

On Jan 7, 1:10 pm, Michael Elkins  wrote:
> On Sat, Jan 07, 2012 at 11:52:26AM -0500, Kevin Anthony wrote:
> >I have a small exposed json API, currently it doesn't require
> >authentication, but i'd like to integrate it with django's authentication.
> > A quick google search came up empty, and i was wondering if anyone had
> >any recommendations on how to do this?
>
> I've done this before using forms and POST, but you could easily
> put the user credentials in your json object and use
> django.contrib.auth as described here:
>
> https://docs.djangoproject.com/en/1.3/topics/Aauth/#authentication-in...

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



Logging into CSRF protected Django site using Curl?

2012-01-08 Thread Stodge
I want to log in to my Django app using something like curl. I know
that I could send a GET to get the login form and the CSRF token and
then submit a POST with the username, password and CSRF token. But
this seems awfully convoluted. Is this the only to login to a Django
site that uses CSRF protection?

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



Duplicate translation strings in project/app1/locale and project/locale

2011-12-16 Thread Stodge
I'm reworking my translations, but I'm having a problem with duplicate
strings. I'm running make messages in the project directory and also
in each applications's directory, I'm seeing strings used in an
application (found in project/app1/locale) duplicated in project/
locale. This seems counter intuitive as I have to twice as much work.
Am I missing something or is this expected behavior?

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.



How to remember that I dynamically added a form to the form wizard?

2011-05-26 Thread Stodge
Quick form wizard question. I create my wizard with one form. When
that one is submitted, I add a second form to the form list. This
second form/step is displayed. When I submit this one, the wizard
suddenly thinks it only has one form, not two. I realise that when I
create the form wizard in my view after the second POST, the second
form is missing. But how do I retain the knowledge that that form was
added?

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.



Using generic_inlineformset_factory to inline a form for categories?

2011-05-13 Thread Stodge
I have the following models:

class Category(models.Model):
type = models.CharField(max_length=128)

class CategoryTerm(models.Model):
term = models.CharField(max_length=128)
type = models.ForeignKey(Category, related_name='terms')

class CategoryMap(models.Model):
term = models.ForeignKey(CategoryTerm, db_index=True)
type = models.ForeignKey(Category, db_index=True)

content_type = models.ForeignKey(ContentType,
verbose_name='content type', db_index=True)
object_id = models.PositiveIntegerField(db_index=True)
content_object = generic.GenericForeignKey('content_type',
'object_id')

I have another class called StaticPage, so I can do:

form = CreatePageForm()

Then I do:

CategoryMapFormSet = generic_inlineformset_factory(CategoryMap,
extra=1, can_delete=False)
cat_formset = CategoryMapFormSet(instance=StaticPage())
gfs = generic_inlineformset_factory(CategoryMap)
print gfs.form().as_p()

u'Term: \n-
\nEngland\nNews
\nLoblaws\n\nType: \n-\nCountry\nTopic\nStore\n'

This means that a user can select a term for a category it doesn't
belong to.

So how does one use generic_inlineformset_factory properly?

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.



Overriding templates for the inclusion_tag

2011-05-12 Thread Stodge
Is there any interest in changing the inclusion template functionality
to let the function return the template name in the dictionary to the
inclusion_tag  decorator? This would let the developer override the
template filename:

{{{
@register.inclusion_tag('block/render_region.html')
def render_region(slug):

# Some random code that does nothing.
if len(slug) == 0:
return {'template': 'block/empty_region.html'}

return {'region': region, 'blocks': blocks}
}}}

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



Question about GenericRelation

2011-05-05 Thread Stodge
I have a Page model, with a generic foreign key. I have a Story model,
which has a generic relation to Page. If I do:

sp=StaticPage.objects.get(id=1)

I have to do this to get the Page object:

sp.content.all()[0]

However, there will only ever be on Story linked to one Page model. Is
there anyway to do:

sp=StaticPage.objects.get(id=1) and then this to get the Page object:

sp.content

Thanks

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



Re: django-cas-consumer template question

2011-04-29 Thread Stodge
Of course! Thanks - I have the template working, now I need to get the
login functionality working for the consumer.



On Apr 29, 9:35 am, Alex Kamedov <kame...@gmail.com> wrote:
> Your user must be redirected from django-cas-consumer login view to
> django-cas-provider
> login. Login form is shown on service with django-cas-provider.
>
> On Fri, Apr 29, 2011 at 7:30 PM, Stodge <sto...@gmail.com> wrote:
> > django-cas-consumer
>
> --
> Alex Kamedov
> skype: kamedov    www: kamedov.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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-cas-consumer template question

2011-04-29 Thread Stodge
I installed django-cas-provider and django-cas-consumer. I configured
the consumer to use the CAS service offered by the provider and I
added a base.html template for the consumer. Is this base template
supposed to contain the login form? Or is the login form supposed to
be available on teh provider? The documentation doesn't mention the
login form at all.

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.



Is there any way to get the ip address of the user in the post_save signal?

2011-02-07 Thread Stodge
Is there any way to get the ip address of the user in the post_save signal? 
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.



Is there a way to know which user changed a particular model through the admin site?

2011-02-07 Thread Stodge
I need to know who changed a particular model through the admin site so I 
can create a log entry. The post_save signal has no knowledge of the user 
that changed the model and overriding the model's save method won't tell me 
the user either. Is there a way to know which user changed a particular 
model through the admin site? 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.



Login support for external applications?

2011-01-11 Thread Stodge
I need to let client applications, primarily written in Java and Python 
login to my Django site. What's the best way? Request the form, parse it and 
POST the username, password and csrf token? Or provide an Ajax login view?

-- 
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: Limit number of concurrent non-admin/non-superuser users

2010-12-16 Thread Stodge
I added an ajax call to log the user out when they close the browser.
It works in Firefox and Chrome but is this an acceptable/safe
practice?

I experimented with

SESSION_SAVE_EVERY_REQUEST=True
SESSION_COOKIE_AGE = 300

which works but I can't guarantee that requests are sent frequently
enough to ensure a user remains logged in. Typically with my site,
requests are sent at least every minute to refresh displayed data.



On Dec 10, 10:45 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Dec 10, 3:07 pm, Stodge <sto...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > I'm trying to limit the number of concurrent users attached to my
> > Django website. For example I need to implement a floating license
> > system. I've seen a few snippets but so far I think they all implement
> > a middleware. I'm trying to avoid using a middleware because I don't
> > want the overhead on every request and because I want to try to limit
> > this when the user tries to login. I only want to restrict the number
> > of non-admin and non-superuser users.
>
> > I thought I could check all current sessions with expiry times in the
> > future but this makes the assumption that a session's expiry time will
> > be set to the current time when the user logs out of when they close
> > their browser (SESSION_EXPIRE_AT_BROWSER_CLOSE = True). However, my
> > understanding of the session system was incorrect and this isn't
> > possible.
>
> > Any ideas how this can be implemented?
> > Thanks
>
> The problem is the stateless nature of HTTP. Between requests, there's
> nothing that identifies to the server that the browser is still
> 'connected', so you can't identify how many people are passively
> browsing a page, and how many have turned off their computer or even
> just gone to another site.
>
> You're not going to be able to do it without some sort of overhead. I
> would suggest something like a bit of Javascript, which pings the
> server every 20 seconds or so while the user is on a logged-in page,
> to show that it is still active. But that certainly has non-trivial
> overhead.
> --
> DR.

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



Limit number of concurrent non-admin/non-superuser users

2010-12-10 Thread Stodge
I'm trying to limit the number of concurrent users attached to my
Django website. For example I need to implement a floating license
system. I've seen a few snippets but so far I think they all implement
a middleware. I'm trying to avoid using a middleware because I don't
want the overhead on every request and because I want to try to limit
this when the user tries to login. I only want to restrict the number
of non-admin and non-superuser users.

I thought I could check all current sessions with expiry times in the
future but this makes the assumption that a session's expiry time will
be set to the current time when the user logs out of when they close
their browser (SESSION_EXPIRE_AT_BROWSER_CLOSE = True). However, my
understanding of the session system was incorrect and this isn't
possible.

Any ideas how this can be implemented?
Thanks

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



Re: SESSION_EXPIRE_AT_BROWSER_CLOSE = True, session expiry date wrong when browser closed?

2010-12-10 Thread Stodge
Ok thanks. I'm trying to limit the number of concurrent users using
sessions.

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



SESSION_EXPIRE_AT_BROWSER_CLOSE = True, session expiry date wrong when browser closed?

2010-12-10 Thread Stodge
I have SESSION_EXPIRE_AT_BROWSER_CLOSE set to True in my settings.
When the user visits my custom login page a new session is created for
them in the database. The expiry time is set to two weeks.

If I then close the browser, the expiry hour/minute are adjusted but
it's still set to two weeks in the future. Shouldn't the expiry date
be set to the current date?

If I re-open the browser, login and then close the browser, the
session expiry time is still set to two weeks. Shouldn't the expiry
date be set to the current date? The session is expired because I have
to re-login when I visit the site again.

Thanks

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



Re: Multiple database issue v1.2.3 - Django reading the wrong database

2010-10-26 Thread Stodge
Pasted misleading traceback, as I created the scene table in the
default database to verify this.

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 336, in get
num = len(clone)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 81, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 269, in iterator
for row in compiler.results_iter():
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
compiler.py", line 672, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
compiler.py", line 727, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
line 15, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/
postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: relation "scene" does not exist
LINE 1: ...le", "scene"."datasets", "scene"."transform" FROM "scene"
WH...


On Oct 26, 1:13 pm, Stodge <sto...@gmail.com> wrote:
> I have two PostgreSQL (postgresql_psycopg2) databases defined in my
> settings; default and scenes.
>
> If I perform a filter using the 'scenes' DB I get the expected
> results:
>
> Scene.objects.filter(name__contains='ME').using('scenes')
> [, ]
>
> If I perform a get(), Django seems to get completely confused and
> tries to read the data from the default database:
>
> Scene.objects.get(id=3).using('scenes')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line 132, in get
>     return self.get_query_set().get(*args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 341, in get
>     % self.model._meta.object_name)
> DoesNotExist: Scene matching query does not exist.
>
> Anyone else seen this?
>
> Thanks

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



Multiple database issue v1.2.3 - Django reading the wrong database

2010-10-26 Thread Stodge
I have two PostgreSQL (postgresql_psycopg2) databases defined in my
settings; default and scenes.

If I perform a filter using the 'scenes' DB I get the expected
results:

Scene.objects.filter(name__contains='ME').using('scenes')
[, ]

If I perform a get(), Django seems to get completely confused and
tries to read the data from the default database:


Scene.objects.get(id=3).using('scenes')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 341, in get
% self.model._meta.object_name)
DoesNotExist: Scene matching query does not exist.

Anyone else seen this?

Thanks

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



Re: Delete the FileField record but keep the file?

2010-10-14 Thread Stodge
That's basically all I've done unless I can find a cleaner solution. I
copy the files elsewhere, delete the records and then copy the files
back.

On Oct 13, 2:13?am, Jonathan Barratt 
wrote:
> On 12 ?.?. 2010, at 22:42,Stodgewrote:
>
> > Short of creating my own custom FileField class, is there anyway to
> > pass an optional "delete" flag to a custom file system storage?
>
> Not AFAIK.
>
> > I have a case where I want to delete the FileField record, but not the file.
>
> If it were me, I would just save a copy of the file to a different directory, 
> or rename it without going through Django, and then call delete on the 
> original object.
>
> But I Am A Django Noob, so others may have better suggestions for you...
> Jonathan
>
>
>
>
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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



Delete the FileField record but keep the file?

2010-10-12 Thread Stodge
Short of creating my own custom FileField class, is there anyway to
pass an optional "delete" flag to a custom file system storage? I have
a case where I want to delete the FileField record, but not the file.

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



Problem with FileField and FileSystemStorage and upload_to

2010-10-06 Thread Stodge
I'm trying to use the FileField with a custom FileSystemStorage class.
I have my location and upload_to set:

location = /opt/files/
upload_to = mike

I want files to upload to /opt/files/mike but the filenames are
prefixed in the database with /mike, which I don't want. So based on
the docs I changed my settings to:


location = /opt/files/mike
upload_to = /

But when I upload a file I get a SuspiciousOperation exception because
it's trying to upload the file to /. Huh? How would I upload the files
to /opt/files/mike without having /mike prefixed to the filename?

Thanks

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



Re: What's the best way to implement project permissions in a project management app?

2010-10-05 Thread Stodge
Thanks. I just found django-authority. That might work.

http://packages.python.org/django-authority/

On Oct 5, 11:47 am, Godshall <michaelgodsh...@gmail.com> wrote:
> I would recommend looking at the projects app in Pinax for a good
> approach for 
> this:http://github.com/pinax/pinax/blob/master/pinax/apps/projects/models.py
>
> Basically, it uses a ManyToMany "members" field that you can add and
> remove users to/from the project.  That particular example uses an
> intermediary User model called ProjectMember to store extra info for
> the user, but that's optional.  If you don't use an intermediary User
> model, you will need to change the user_is_member method to something
> like:
>
> def user_is_member(self, user):
>     return user in self.member_queryset() # where
> self.member_queryset() returns self.members.all()
>
> This approach will give you per-project permissions like you
> requested.
>
> On Oct 5, 5:23 am, Stodge <sto...@gmail.com> wrote:
>
>
>
> > That looks like what I need. Thanks. Though I also need per-project
> > permissions; so user 'bob' can access tickets on Project A but not on
> > Project B. I'll have to re-read django-todo's code when I have more
> > time to see if they implement per group permissions.
>
> > On Oct 4, 9:03 pm, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
>
> > > On 5/10/2010 11:32am, Stodge wrote:
>
> > > >   What's the best way to implement project permissions in a project
> > > > management app? Should I just create the concept of membership and
> > > > have a function is_member on the project model?
>
> > > Have a look at django-todo. A quick read the other day indicated to me
> > > that it has what you are looking for. I'm planning to look more closely
> > > but haven't had time yet.
>
> > > Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: What's the best way to implement project permissions in a project management app?

2010-10-05 Thread Stodge
That looks like what I need. Thanks. Though I also need per-project
permissions; so user 'bob' can access tickets on Project A but not on
Project B. I'll have to re-read django-todo's code when I have more
time to see if they implement per group permissions.

On Oct 4, 9:03 pm, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 5/10/2010 11:32am, Stodge wrote:
>
> >   What's the best way to implement project permissions in a project
> > management app? Should I just create the concept of membership and
> > have a function is_member on the project model?
>
> Have a look at django-todo. A quick read the other day indicated to me
> that it has what you are looking for. I'm planning to look more closely
> but haven't had time yet.
>
> Mike

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



What's the best way to implement project permissions in a project management app?

2010-10-04 Thread Stodge
 What's the best way to implement project permissions in a project
management app? Should I just create the concept of membership and
have a function is_member on the project model?

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



  1   2   >