log file will be overwrite when use prefork?

2012-08-09 Thread DanYun Liu
below is the logging config in setting.py.  only the newest logs in the
output file.. It seems the log file is overwrite when new process been
forked

LOGGING = {
'version': 1,
'disable_existing_loggers': False,

'formatters': {
'standard': {
'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d
%(message)s'
},
'detail': {
'format': '%(levelname)s %(asctime)s %(pathname)s %(lineno)d
%(message)s'
}
},
'handlers': {
'frontend': {
'level': 'INFO',
'formatter': "standard",
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': 'MIDNIGHT',
'filename': '/deploy/logs/log.txt'
},
'error': {
'level': 'INFO',
'formatter': "detail",
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': 'MIDNIGHT',
'filename': '/deploy/logs/error.txt'
},
'stat': {
'level': 'INFO',
'formatter': "standard",
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': 'MIDNIGHT',
'filename': '/deploy/logs/stat.txt'
}
},
'loggers': {
'frontend': {
'handlers': ['frontend'],
'level': 'INFO',
'propagate': True,
},
'error': {
'handlers': ['error'],
'level': 'INFO',
'propagate': True,
},
'stat': {
'handlers': ['stat'],
'level': 'INFO',
'propagate': True,
},
}
}



-- 
Pursuit the freedom of the soul.

-- 
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: Setting APPEND_SLASH = False and PREPEND_WWW = True

2012-08-09 Thread Russell Keith-Magee
On Fri, Aug 10, 2012 at 10:41 AM, JJ Zolper  wrote:
> Hello all,
>
> I am interested in making these two changes to Django: Setting APPEND_SLASH
> = False and PREPEND_WWW = True.
>
> The following links describe what each of these do but do not tell me
> actually where these settings reside so that I can actually change them:
>
> http://djangobook.com/en/2.0/chapter17/
> http://django-book.readthedocs.org/en/latest/appendixD.html
> https://docs.djangoproject.com/en/dev/ref/middleware/#django.middleware.common.CommonMiddleware
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-APPEND_SLASH
>
> I did not see them in my settings.py file where I expected them and I don't
> want to go through my Django source trying to helplessly find it.

When you generate your project, Django generates a sample settings.py
that contains the settings you're most likely going to need to
override -- things that involve paths, the list of apps you want to
install, and so on.

There are *many* other settings that can form part of a Django project
-- they're all documented at the last link you provided. You can put
any of these settings in your own settings.py file. If you don't
provide them, the default value is used; if you do, your value is
used.

If you want, you can even invent your own settings for your own app.
This might be handy for storing things like authentication keys for
third-party services.

So - just put:

APPEND_SLASH = False
PREPEND_WWW = True

in your project's settings.py file, and you'll be off and running.

Yours,
Russ Magee %-)

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



Setting APPEND_SLASH = False and PREPEND_WWW = True

2012-08-09 Thread JJ Zolper
Hello all,

I am interested in making these two changes to Django: Setting APPEND_SLASH 
= False and PREPEND_WWW = True.

The following links describe what each of these do but do not tell me 
actually where these settings reside so that I can actually change them:

http://djangobook.com/en/2.0/chapter17/
http://django-book.readthedocs.org/en/latest/appendixD.html
https://docs.djangoproject.com/en/dev/ref/middleware/#django.middleware.common.CommonMiddleware
https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-APPEND_SLASH

I did not see them in my settings.py file where I expected them and I don't 
want to go through my Django source trying to helplessly find it.

Thanks a lot,

JJ Zolper

-- 
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/-/uhtyGoccsi4J.
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: Middleware manipulating template in response

2012-08-09 Thread Matt Pegler
It sounds like you want to automagically do something like:

if request.is_mobile:
  return render_to_response('test_mobile.html',{})
return render_to_response('test.html',{})

I'm not sure that will be possible without modifying your views.  I did 
something similar by determining which base template all my templates 
should extend.  Here's what I did:

-Set request.is_mobile if the user is using a mobile browser.  I happened 
to use the same middleware you posted but tweaked it to allow viewing the 
desktop version of a page on a mobile device by setting the cookie 
'force_device' - http://pastie.org/4445761
-Add a context processor that defines which base template to use based on 
request.is_mobile - http://pastie.org/4445772
-Chances are your templates currently extend base.html or something. 
 Change all those to {% extends BASE_TEMPLATE %}

Now all your templates will extend either base.html or base_mobile.html 
based on the user agent.  You can tweak the layout for the mobile site by 
doing {% if request.is_mobile %}...{% else %}...{% endif %}, or if you are 
going to have drastically different content if the user is on mobile, you 
can define two content blocks in your test.html template, "content" and 
"content-mobile", and then have base.html and base_mobile.html render each 
of those blocks.

-Matt

On Thursday, August 9, 2012 9:29:46 AM UTC-4, MrMuffin wrote:
>
> Hmmm ... is there any other way to achieve the same result ( using a 
> special template for mobile devices ) without hacking this into each 
> view? MiddleWare using 
>
>
> https://docs.djangoproject.com/en/dev/topics/http/middleware/?from=olddocs/#process-template-response
>  
>
> for instance? 
>
> Anyway, thanks for your input. 
>
> Thomas 
>
> On Thu, Aug 9, 2012 at 3:09 PM, Daniel Roseman 
>  
> wrote: 
> >> On Thursday, 9 August 2012 13:18:36 UTC+1, MrMuffin wrote: 
> >>> 
> >>> I need to change what template to use in a response based on type of 
> >>> user-agent in request. The middleware below works ok to detect mobile 
> >>> client, but I cannot get the template manipulation in the process_view 
> >>> method  to work. 
> >>> 
> >>> The middleware: 
> >>> 
> >>> # Credits: http://djangosnippets.org/snippets/2001/ 
> >>> import re 
> >>> 
> >>> 
> >>> class MobileDetectionMiddleware(object): 
> >>> """ 
> >>> Useful middleware to detect if the user is 
> >>> on a mobile device. 
> >>> """ 
> >>> 
> >>> def process_view(self, request, view_func, view_args, 
> view_kwargs): 
> >>> if not request.is_mobile: 
> >>> return 
> >>> 
> >>> print vars(view_func), view_args,view_kwargs # these are 
> >>> allways blank/empty 
> >>> template = view_kwargs.get("template") 
> >>> if template is None and view_func.func_defaults: 
> >>> for default in view_func.func_defaults: 
> >>> if str(default).endswith(".html"): 
> >>> template = default 
> >>> break 
> >>> 
> >>> if template is not None: 
> >>> template = template.rsplit(".html", 1)[0] + ".mobile.html" 
> >>> try: 
> >>> get_template(template) 
> >>> except TemplateDoesNotExist: 
> >>> return 
> >>> else: 
> >>> view_kwargs["template"] = template 
> >>> 
> >>> return view_func(request, *view_args, **view_kwargs) 
> >>> 
> >>>  
> >>> 
> >>> 
> >>> from django.shortcuts import * 
> >>> 
> >>> def index(request): 
> >>> return render_to_response('testapp/test.html', 
> {'user':request.user}) 
> >>> 
> >>> 
> >>> 
> >>> Any clues? 
> >>> 
> >>> 
> >>> -- 
> >>> Mvh/Best regards, 
> >>> Thomas Weholt 
> >>> http://www.weholt.org 
> >> 
> >> 
> > 
> > I can't imagine how you are expecting this to work. The template in your 
> > view is not a parameter, but is hard-coded into the call to 
> > render_to_response. Your code appears to be wanting to access the 
> default 
> > value of a non-existent view parameter, modify it, and pass it back into 
> a 
> > view that isn't expecting it. 
> > 
> > It seems like you want to make `template` a parameter to the view, and 
> then 
> > your middleware could modify that. 
> > -- 
> > DR. 
>
>
>
> -- 
> Mvh/Best regards, 
> Thomas Weholt 
> http://www.weholt.org 
>

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



Combining django-tables2 with django-filter info ListView?

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

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

First step is to add the tables2 mixin as follows:

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

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

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

Anyone with mixin experience willing to give some directions?

Paul

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



Re: Created & updated date/time in models

2012-08-09 Thread Lachlan Musicman
On Thu, Aug 9, 2012 at 3:33 PM, Dennis Lee Bieber  wrote:
> On Thu, 9 Aug 2012 09:02:39 +1200, Lachlan Musicman 
> declaimed the following in gmane.comp.python.django.user:
>>
>> From what I can see, the admin interface already keeps this data for
>> each object (exception: no create_date for data imported via fixtures
>> apparently).
>>
> Pardon? So far as I know, if the admin interface is displaying data
> related to a database table (django "model"), then ONLY data in that
> table is displayed. There is no auxiliary table created just for the
> admin interface to store date records.

Ah, sorry - to clarify, I wasn't looking at the table structures - I
was looking at the results from the "history" link on each model's
admin edit form...

cheers
L.

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



Re: Middleware manipulating template in response

2012-08-09 Thread Kurtis Mullins
I saw this in one of the previous Python newsletters (I think) and it
looked pretty interesting: https://github.com/gregmuellegger/django-mobile

On Thu, Aug 9, 2012 at 9:29 AM, Thomas Weholt wrote:

> Hmmm ... is there any other way to achieve the same result ( using a
> special template for mobile devices ) without hacking this into each
> view? MiddleWare using
>
>
> https://docs.djangoproject.com/en/dev/topics/http/middleware/?from=olddocs/#process-template-response
>
> for instance?
>
> Anyway, thanks for your input.
>
> Thomas
>
> On Thu, Aug 9, 2012 at 3:09 PM, Daniel Roseman 
> wrote:
> >> On Thursday, 9 August 2012 13:18:36 UTC+1, MrMuffin wrote:
> >>>
> >>> I need to change what template to use in a response based on type of
> >>> user-agent in request. The middleware below works ok to detect mobile
> >>> client, but I cannot get the template manipulation in the process_view
> >>> method  to work.
> >>>
> >>> The middleware:
> >>>
> >>> # Credits: http://djangosnippets.org/snippets/2001/
> >>> import re
> >>>
> >>>
> >>> class MobileDetectionMiddleware(object):
> >>> """
> >>> Useful middleware to detect if the user is
> >>> on a mobile device.
> >>> """
> >>>
> >>> def process_view(self, request, view_func, view_args, view_kwargs):
> >>> if not request.is_mobile:
> >>> return
> >>>
> >>> print vars(view_func), view_args,view_kwargs # these are
> >>> allways blank/empty
> >>> template = view_kwargs.get("template")
> >>> if template is None and view_func.func_defaults:
> >>> for default in view_func.func_defaults:
> >>> if str(default).endswith(".html"):
> >>> template = default
> >>> break
> >>>
> >>> if template is not None:
> >>> template = template.rsplit(".html", 1)[0] + ".mobile.html"
> >>> try:
> >>> get_template(template)
> >>> except TemplateDoesNotExist:
> >>> return
> >>> else:
> >>> view_kwargs["template"] = template
> >>>
> >>> return view_func(request, *view_args, **view_kwargs)
> >>>
> >>> 
> >>>
> >>>
> >>> from django.shortcuts import *
> >>>
> >>> def index(request):
> >>> return render_to_response('testapp/test.html',
> {'user':request.user})
> >>>
> >>>
> >>>
> >>> Any clues?
> >>>
> >>>
> >>> --
> >>> Mvh/Best regards,
> >>> Thomas Weholt
> >>> http://www.weholt.org
> >>
> >>
> >
> > I can't imagine how you are expecting this to work. The template in your
> > view is not a parameter, but is hard-coded into the call to
> > render_to_response. Your code appears to be wanting to access the default
> > value of a non-existent view parameter, modify it, and pass it back into
> a
> > view that isn't expecting it.
> >
> > It seems like you want to make `template` a parameter to the view, and
> then
> > your middleware could modify that.
> > --
> > DR.
>
>
>
> --
> Mvh/Best regards,
> Thomas Weholt
> http://www.weholt.org
>
> --
> 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.
>
>

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



ordering of post_syncdb signals?

2012-08-09 Thread carrier24sg
Hi folks, I am a little confused with the ordering of the post_syncdb
signal? (using 1.2.4)

Looking at the code in auth and contenttype, what makes
auth.permission so sure that the appropriate content type was created
before the necessary permission is created?

Similarly, I have another app called 'payment', and inside my
management/__init__.py, i have the following:

from django.contrib.auth.models import Group, Permission
import payment.models as payModels

def init_permissions(sender, **kwargs):
""" initialization when appliation starts """
agents = Group.objects.get(name = "agents")
import pdb
pdb.set_trace()
if not
agents.permissions.filter(codename="can_buy_package").exists():
perm = Permission.objects.get(codename="can_buy_package")
agents.permissions.add(perm)

post_syncdb.connect(init_permissions, sender=payModels)

I couldn't get this to work because the permissions were not created
for my models at this stage. So, how is the ordering of the
post_syncdb executed?

-- 
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: Nullable User email

2012-08-09 Thread Demian Brecht
Thanks for the feedback guys..

What I ended up doing was adding the following lines to my models module:

from django.contrib.auth.models import User as BaseUser

BaseUser._meta.get_field("username")._unique = False
BaseUser._meta.get_field("email").null = True

Melvin: I tried your suggestion and it worked like a charm for the email 
field. However, it didn't work for the username. I'm assuming that ORM 
introspection during syncdb doesn't use an instantiated model and as such, 
the "UNIQUE" attribute was still applied to the auth User model. Doing it 
this way allows me to override the default behavior during database 
creation.

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



Pure python-alternative to Gunicorn/NGINX/Serving static content

2012-08-09 Thread Thomas Weholt
I'm using gunicorn and nginx on ubuntu when deploying my django
projects, but now I need to run a project on several platforms,
including windows. Is there a similar pure python configuration ( with
the expected reduced performance for serving static content )?

-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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: Middleware manipulating template in response

2012-08-09 Thread Thomas Weholt
Hmmm ... is there any other way to achieve the same result ( using a
special template for mobile devices ) without hacking this into each
view? MiddleWare using

https://docs.djangoproject.com/en/dev/topics/http/middleware/?from=olddocs/#process-template-response

for instance?

Anyway, thanks for your input.

Thomas

On Thu, Aug 9, 2012 at 3:09 PM, Daniel Roseman  wrote:
>> On Thursday, 9 August 2012 13:18:36 UTC+1, MrMuffin wrote:
>>>
>>> I need to change what template to use in a response based on type of
>>> user-agent in request. The middleware below works ok to detect mobile
>>> client, but I cannot get the template manipulation in the process_view
>>> method  to work.
>>>
>>> The middleware:
>>>
>>> # Credits: http://djangosnippets.org/snippets/2001/
>>> import re
>>>
>>>
>>> class MobileDetectionMiddleware(object):
>>> """
>>> Useful middleware to detect if the user is
>>> on a mobile device.
>>> """
>>>
>>> def process_view(self, request, view_func, view_args, view_kwargs):
>>> if not request.is_mobile:
>>> return
>>>
>>> print vars(view_func), view_args,view_kwargs # these are
>>> allways blank/empty
>>> template = view_kwargs.get("template")
>>> if template is None and view_func.func_defaults:
>>> for default in view_func.func_defaults:
>>> if str(default).endswith(".html"):
>>> template = default
>>> break
>>>
>>> if template is not None:
>>> template = template.rsplit(".html", 1)[0] + ".mobile.html"
>>> try:
>>> get_template(template)
>>> except TemplateDoesNotExist:
>>> return
>>> else:
>>> view_kwargs["template"] = template
>>>
>>> return view_func(request, *view_args, **view_kwargs)
>>>
>>> 
>>>
>>>
>>> from django.shortcuts import *
>>>
>>> def index(request):
>>> return render_to_response('testapp/test.html', {'user':request.user})
>>>
>>>
>>>
>>> Any clues?
>>>
>>>
>>> --
>>> Mvh/Best regards,
>>> Thomas Weholt
>>> http://www.weholt.org
>>
>>
>
> I can't imagine how you are expecting this to work. The template in your
> view is not a parameter, but is hard-coded into the call to
> render_to_response. Your code appears to be wanting to access the default
> value of a non-existent view parameter, modify it, and pass it back into a
> view that isn't expecting it.
>
> It seems like you want to make `template` a parameter to the view, and then
> your middleware could modify that.
> --
> DR.



-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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: Middleware manipulating template in response

2012-08-09 Thread Daniel Roseman

>
> On Thursday, 9 August 2012 13:18:36 UTC+1, MrMuffin wrote:
>>
>> I need to change what template to use in a response based on type of 
>> user-agent in request. The middleware below works ok to detect mobile 
>> client, but I cannot get the template manipulation in the process_view 
>> method  to work. 
>>
>> The middleware: 
>>
>> # Credits: http://djangosnippets.org/snippets/2001/ 
>> import re 
>>
>>
>> class MobileDetectionMiddleware(object): 
>> """ 
>> Useful middleware to detect if the user is 
>> on a mobile device. 
>> """ 
>>
>> def process_view(self, request, view_func, view_args, view_kwargs): 
>> if not request.is_mobile: 
>> return 
>>
>> print vars(view_func), view_args,view_kwargs # these are 
>> allways blank/empty 
>> template = view_kwargs.get("template") 
>> if template is None and view_func.func_defaults: 
>> for default in view_func.func_defaults: 
>> if str(default).endswith(".html"): 
>> template = default 
>> break 
>>
>> if template is not None: 
>> template = template.rsplit(".html", 1)[0] + ".mobile.html" 
>> try: 
>> get_template(template) 
>> except TemplateDoesNotExist: 
>> return 
>> else: 
>> view_kwargs["template"] = template 
>>
>> return view_func(request, *view_args, **view_kwargs) 
>>
>> 
>>
>> from django.shortcuts import * 
>>
>> def index(request): 
>> return render_to_response('testapp/test.html', {'user':request.user}) 
>>
>>
>>
>> Any clues? 
>>
>>
>> -- 
>> Mvh/Best regards, 
>> Thomas Weholt 
>> http://www.weholt.org 
>>
>
>
I can't imagine how you are expecting this to work. The template in your 
view is not a parameter, but is hard-coded into the call to 
render_to_response. Your code appears to be wanting to access the default 
value of a non-existent view parameter, modify it, and pass it back into a 
view that isn't expecting it. 

It seems like you want to make `template` a parameter to the view, and then 
your middleware could modify that.
--
DR. 

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

2012-08-09 Thread Satinderpal Singh
On Thu, Aug 9, 2012 at 4:49 PM, Pervez Mulla  wrote:
> Hi,
>
> Please tell me how can I know ,the details about user login and logout
> details , and how can I store that data in DB in Django.
There are many registration modules already made in django, you just
download it and install to your system by following the instruction in
readme file present with that package. Follow the links like
http://docs.b-list.org/django-registration/0.8/quickstart.html
http://forum.webfaction.com/viewtopic.php?id=2230

-- 
Satinderpal Singh
http://satindergoraya.blogspot.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.



Middleware manipulating template in response

2012-08-09 Thread Thomas Weholt
I need to change what template to use in a response based on type of
user-agent in request. The middleware below works ok to detect mobile
client, but I cannot get the template manipulation in the process_view
method  to work.

The middleware:

# Credits: http://djangosnippets.org/snippets/2001/
import re


class MobileDetectionMiddleware(object):
"""
Useful middleware to detect if the user is
on a mobile device.
"""

def process_view(self, request, view_func, view_args, view_kwargs):
if not request.is_mobile:
return

print vars(view_func), view_args,view_kwargs # these are
allways blank/empty
template = view_kwargs.get("template")
if template is None and view_func.func_defaults:
for default in view_func.func_defaults:
if str(default).endswith(".html"):
template = default
break

if template is not None:
template = template.rsplit(".html", 1)[0] + ".mobile.html"
try:
get_template(template)
except TemplateDoesNotExist:
return
else:
view_kwargs["template"] = template

return view_func(request, *view_args, **view_kwargs)

def process_request(self, request):
is_mobile = False

if request.META.has_key('HTTP_USER_AGENT'):
user_agent = request.META['HTTP_USER_AGENT']

# Test common mobile values.
pattern =
"(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows
ce|pda|mobile|mini|palm|netfront)"
prog = re.compile(pattern, re.IGNORECASE)
match = prog.search(user_agent)

if match:
is_mobile = True
else:
# Nokia like test for WAP browsers.
#
http://www.developershome.com/wap/xhtmlmp/xhtml_mp_tutorial.asp?page=mimeTypesFileExtension

if request.META.has_key('HTTP_ACCEPT'):
http_accept = request.META['HTTP_ACCEPT']

pattern = "application/vnd\.wap\.xhtml\+xml"
prog = re.compile(pattern, re.IGNORECASE)

match = prog.search(http_accept)

if match:
is_mobile = True

if not is_mobile:
# Now we test the user_agent from a big list.
user_agents_test = ("w3c ", "acs-", "alav", "alca",
"amoi", "audi",
"avan", "benq", "bird", "blac",
"blaz", "brew",
"cell", "cldc", "cmd-", "dang",
"doco", "eric",
"hipt", "inno", "ipaq", "java",
"jigs", "kddi",
"keji", "leno", "lg-c", "lg-d",
"lg-g", "lge-",
"maui", "maxo", "midp", "mits",
"mmef", "mobi",
"mot-", "moto", "mwbp", "nec-",
"newt", "noki",
"xda",  "palm", "pana", "pant",
"phil", "play",
"port", "prox", "qwap", "sage",
"sams", "sany",
"sch-", "sec-", "send", "seri",
"sgh-", "shar",
"sie-", "siem", "smal", "smar",
"sony", "sph-",
"symb", "t-mo", "teli", "tim-",
"tosh", "tsm-",
"upg1", "upsi", "vk-v", "voda",
"wap-", "wapa",
"wapi", "wapp", "wapr", "webc",
"winw", "winw",
"xda-",)

test = user_agent[0:4].lower()
if test in user_agents_test:
is_mobile = True

request.is_mobile = is_mobile


The view:


from django.shortcuts import *

def index(request):
return render_to_response('testapp/test.html', {'user':request.user})



Any clues?


-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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: Login/ Logout user details

2012-08-09 Thread Aljoša Mohorović
On Thu, Aug 9, 2012 at 1:19 PM, Pervez Mulla  wrote:
> Please tell me how can I know ,the details about user login and logout
> details , and how can I store that data in DB in Django.

User model (auth.models.User) has last_login and if you need custom
data stored you can try using:
https://docs.djangoproject.com/en/1.4/topics/signals/
it will enable you to "catch" events on models and get data from
request/response.
based on that you should have enough data to start.

Aljosa
--
https://twitter.com/maljosa
https://github.com/aljosa

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



email as username best practice in 1.4

2012-08-09 Thread Gordon Wrigley
What is the recommended best approach for using emails as usernames in 
Django 1.4?

I've looked in the FAQ and couldn't find anything, I see there is this 
issue https://code.djangoproject.com/ticket/3011 which is likely to be 
addressed in 1.5 but I can't wait for 1.5. Searching here, stackoverflow 
and the wider web turns up a variety of solutions but many of them 
reference older versions of Django and it's hard for me to judge which of 
them is the better approach.

I do need a reasonably complete solution, it needs to work with the admin 
and with the built in authentication systems.

Regards
G

-- 
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/-/W64zBF95vdcJ.
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/ Logout user details

2012-08-09 Thread Pervez Mulla
Hi,

Please tell me how can I know ,the details about user login and logout
details , and how can I store that data in DB in Django.

Thank You
Pervez

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



showing many-to-many field in admin interface

2012-08-09 Thread Mo Mughrabi
hello everyone,

am trying to build a single model that will be used for uploaded
images/files. Am trying to use it in the best way in the admin pages, so
when i associate it with a specific model as a many-to-many field it would
appear in a friendly way for users to upload images.

My attachment model is as following

class Attachment(models.Model):
_attachment_types = (
('I', ('Image')),
('P', ('PDF'))  ,
)

attachment_type = models.CharField(max_length=2, default='I')
description = models.TextField(null=True, blank=True)
file= models.FileField(upload_to='%Y/%m/%d')


my other model is

class LawCaseImage(models.Model):
bonanza = models.ForeignKey('LawCase')
image   = models.ForeignKey(Attachment)
primary_photo   = models.BooleanField(default=False)




class LawCase(models.Model):
"""  """
user_profile= models.ForeignKey(UserProfile,
limit_choices_to={'profile_type' : 'C'}, help_text=_('Only corporate
accounts will appear in the drop down.'))
name= models.CharField(max_length=20, )
description = models.TextField()
created_at  = models.DateTimeField(auto_now_add=True)
created_by  = models.ForeignKey(User, editable=False)
image   = models.ManyToManyField(Attachment, through=LawCaseImage)


I tried to use inline associate in my admin.py as following

class LawCaseImageForm(admin.TabularInline):
model = LawCaseImage


class LawCaseForm(admin.ModelAdmin):
inlines = [LawCaseImageForm, ]


but all i got was a grid with the many-to-many table. I would like to be
able to upload images right away when creating a new record and they will
be uploaded to attachment model and relation will be created on that base..

Is there a way to configure admin to work on that behavior? and if not, is
there a plugin out there i could use for that purpose?

regards,

-- 
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: 回复: login or login_decorator issue

2012-08-09 Thread mapapage
I saw it but I think that this isn't what I need for what I wanna do. I 
shouldn't use django's authentication module. I should make my own backend 
work.

-- 
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/-/4ZvNR1Mh1vMJ.
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 or login_decorator issue

2012-08-09 Thread Pengfei Xue
http://www.djangobook.com/en/2.0/chapter14/  

take a quick look at this article, i think it will help you out  

--  
Sincerely,
Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig)

已使用 Sparrow (http://www.sparrowmailapp.com/?sig)  

在 2012年8月9日星期四,下午3:39,mapapage 写道:

>  
>  
> On Thursday, August 9, 2012 10:39:07 AM UTC+3, mapapage wrote:
> > >  
> > >  I'm working with a legacy database so I should use another model 
> > > (Owners) instead of the default Djangoconstrib.auth.models.User for 
> > > authentication.
> > >  
> > >  
> >  
> > That's why I wrote my own and custom authentication backend.  
> > >  
> > > My model has an id field (id = models.DecimalField(...)) that is used for 
> > > username and a field for password(password = models.CharField(...))
> > >  
> > >  
> >  
> >  What's more, the password that is stored in the Owners.password is not an 
> > encrypted string but plain text and when I use if 
> > user.check_password(password): I get  
> > Unknown password hashing algorithm '123'. Did you specify it in the 
> > PASSWORD_HASHERS setting?  That seems to be some kind of bug 
> > (https://code.djangoproject.com/ticket/18182#comment:8).
> > If I didn't misunderstood sth, I don't know what to do and therefore I'm 
> > asking for a guideline..
> >  
>  
>  
> --  
> 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/-/WmODCM0Zj2sJ.
> To post to this group, send email to django-users@googlegroups.com 
> (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto:django-users+unsubscr...@googlegroups.com).
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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

2012-08-09 Thread mapapage


On Thursday, August 9, 2012 10:39:07 AM UTC+3, mapapage wrote:
>
>  I'm working with a legacy database so I should use another model (Owners) 
>> instead of the default Djangoconstrib.auth.models.User for 
>> authentication.
>>
> That's why I wrote my own and custom authentication backend. 
>
>> My model has an id field (id = models.DecimalField(...)) that is used 
>> for username and a field for password(password = models.CharField(...))
>>
>  What's more, the password that is stored in the Owners.password is not an 
> encrypted string but plain text and when I use if 
> user.check_password(password): I get 
> Unknown password hashing algorithm '123'. Did you specify it in the 
> PASSWORD_HASHERS setting?  That seems to be some kind of 
> bug
> .
> If I didn't misunderstood sth, I don't know what to do and therefore I'm 
> asking for a guideline..
>

-- 
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/-/WmODCM0Zj2sJ.
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: 回复: login or login_decorator issue

2012-08-09 Thread mapapage

>
>  I'm working with a legacy database so I should use another model (Owners) 
> instead of the default Djangoconstrib.auth.models.User for authentication.
>
That's why I wrote my own and custom authentication backend. 

> My model has an id field (id = models.DecimalField(...)) that is used for 
> username and a field for password(password = models.CharField(...))
>
 What's more, the password that is stored in the Owners.password is not an 
encrypted string but plain text and when I use if 
user.check_password(password): I get 
Unknown password hashing algorithm '123'. Did you specify it in the 
PASSWORD_HASHERS setting?  That seems to be some kind of 
bug
.
If I didn't misunderstood sth, I don't know what to do and therefore I'm 
asking for a guideline..

-- 
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/-/ay0IIbv4s1IJ.
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 or login_decorator issue

2012-08-09 Thread Pengfei Xue


--  
Sincerely,
Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig)

已使用 Sparrow (http://www.sparrowmailapp.com/?sig)  

在 2012年8月9日星期四,下午2:33,mapapage 写道:

> > I wrote this custom authentication backend:
>  
> from django.contrib.auth.models import User, check_password
> from auth.models import Owners
> class AuthBackend(object):
> 
>  
> def authenticate(self, username=None, password=None):
> 
> try:
> user = Owners.objects.get(id=username)
>  
>  

what's your definition for user, that's your user model  
> #if user.check_password(password):
> if user.password == password:  
>  
>  

you should user user.check_password instead of simple string comparison,  
user.password is a encrypted string other than plain text
> return user
> except User.DoesNotExist:
> return None  
>  
> def get_user(self, user_id):
> """ Get a User object from the user_id. """
> try:
> return User.objects.get(pk=user_id)
> except User.DoesNotExist:
> return None
>  
> but still the decorator doesn't work..even if a user is not logged in he can 
> access another's page just by modifying the  url(r'^(?P\d+)/$', 
> 'auth.views.main', name='main'),(putting his id)
have you followed the django's documentation about how to use the 
login_requried decorator? have you installed the required app in setting ?  
>  
> --  
> 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/-/HsS1FtrjJ5IJ.
> To post to this group, send email to django-users@googlegroups.com 
> (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto:django-users+unsubscr...@googlegroups.com).
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Created & updated date/time in models

2012-08-09 Thread Mike Dewhirst

On 9/08/2012 7:02am, Lachlan Musicman wrote:

Hola,

I've got a bunch of date dependent data that I will need to analyse as
the years go by. So adding create_date and update_date fields seems
like the thing to do.

I go researching I and I see that there are debates about whether
auto_now_add and auto_now are useful or whether they should be hated.
Plus there are various work arounds offered with various degrees of
DRY.


From what I can see, the admin interface already keeps this data for

each object


I think you might be thinking of the date/times in the admin log or the 
date_joined and last_login in the user table.


Otherwise you need to include such fields yourself in your own tables. I 
have been using auto_now_add and auto_now quite happily for some time in 
all my own tables and I don't hate them. If they are ever dropped, 
someone will likely contribute a replacement so I'm not going to worry 
just yet.


(exception: no create_date for data imported via fixtures

apparently).

In an effort to reduce duplicating data, how would I go about getting
at that data from within my model's view?


In the same way as any other data. There is plenty of date-time 
formatting in Django templates.


Mike



cheers
L.



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



Re: 回复: login or login_decorator issue

2012-08-09 Thread mapapage

>
> I wrote this custom authentication backend:
>
from django.contrib.auth.models import User, check_password
from auth.models import Owners
class AuthBackend(object):
   

def authenticate(self, username=None, password=None):
   
try:
user = Owners.objects.get(id=username)
#if user.check_password(password):
if user.password == password:
return user
except User.DoesNotExist:
return None 

def get_user(self, user_id):
""" Get a User object from the user_id. """
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

but still the decorator doesn't work..even if a user is not logged in he 
can access another's page just by modifying the 
 url(r'^(?P\d+)/$', 'auth.views.main', name='main'),(putting his 
id)

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