Re: Installing/implementing a Python-based API on my website

2013-06-21 Thread Derek
CND

Your question seems obscure - what exactly do you mean " implementing it on 
a site"?  If you have Django up-and-running (and I assume you do, because 
why else would you be here?), then the specialised code you write can be 
added to a file (e.g. "mycode.py") and saved, for example, in the same 
directory that your models.py and views.py files are.  Then you can import 
those functions into your view file... so that you can then use the 
functions as part of the view logic.  Until you can phrase a more specific 
question, its hard to give a more specific answer.


On Thursday, 20 June 2013 04:16:00 UTC+2, C. N. Desrosiers wrote:
>
> Hi,
>
> I recently completed the Capitol Words API course at codecademy.com and I 
> have experience building websites in HTML + CSS, but I have never installed 
> an API before.  I can manipulate the Python code on its own, but I don't 
> understand the steps between having the Python code in order and actually 
> implementing it on a site.  I can't seem to find any helpful tutorials. 
>  Everything I find seems to assume that the user knows how to complete this 
> final step.  Does this have to be done via Django?  Can anyone point me to 
> a tutorial?
>
> Thanks in advance.
>
> CND
>

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




Restrict access to one device per user at any given time

2013-06-21 Thread mjh
Hi,

I am trying to figure out the best way of restricting access to a given 
django project so that a single user can login as normal but then has to 
logout again if they want to access it from a different session.

I am thinking just to set a flag in the userprofile table upon login and 
then remove the flag when the user logs out, however, I'm sure this is a 
prone to the situation where a user is thrown out of their session for 
whatever reason and the code doesn't reset the flag. In this case the user 
will not be able to login ever again!

Is there a way to store device level details so that I can check against 
that sort of data - this may be a more robust solution I'm guessing.


How have people tackled this and what are the things to look out for?

Regards,

mjh

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




Re: Low Level Cache Issue

2013-06-21 Thread Max Vizard
Figured this out now. The problem is that Django automatically prepends 
':1:' to the key, where 1 is the VERSION setting from the CACHES dict. 

I didn't think this was made particularly clear in the documentation when I 
first went through it but sure enough, it is quite clearly stated here:
https://docs.djangoproject.com/en/1.4/topics/cache/#cache-versioning

The solution for me was to use the KEY_FUNCTION setting to provide my own *
make_key* function.

Note to self and future readers of this: up the logging verbosity of 
memcache to *-vvv *to get useful level of logging.

On Thursday, June 20, 2013 6:00:04 PM UTC+1, Max Vizard wrote:
>
> Hi there,
>
> I'm having some issues with the low level cache functionality in Django 
> 1.4 and I can't seem to find info relevant to my exact problem.
>
> I'm running a separate Python script to check on the status of a Master 
> and Slave MySQL db pair, which then inserts some values into a local 
> Memcache instance.
> I know for certain that the values are being inserted into the cache, as I 
> can access them from another Python interpreter using pylibmc.
>
> However, when I try to access those same keys from a Django view, the 
> results are None. I've configured the CACHES setting to point at the same 
> local 
> Memcache instance and tried with both django.core.cache.MemcachedCache and 
> django.core.cache.PyLibMCCache.
>
> Perhaps my understanding is flawed and Django shouldn't be able to access 
> cache values inserted by another process? I would think that this is not 
> the case because otherwise the use of such a cache would be quite limited.
>
> I haven't checked that Django can write to the cache and read back for 
> itself yet, that is a task for tomorrow.
>
> Any thoughts or input is much appreciated.
>
> Thanks,
> Max
>

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




Re: Restrict access to one device per user at any given time

2013-06-21 Thread Mark Robson
Hi,

You should not prohibit the user from logging on, rather, you should "log 
out" their previous session when they start a new one (e.g. on a different 
device). You might want to notify the user when this happens, to enable 
them to detect if their account has been compromised (more easily).

As Django already has session management, you should be able to use this. 
You can store a table of current logins by user, and store the session ID 
in there. If the current session ID is not the latest one for the user, 
then your code should automatically log them out (because they've logged on 
elsewhere). 

I doesn't sound very difficult to me.

Mark

On Friday, June 21, 2013 10:40:39 AM UTC+1, mjh wrote:
>
> Hi,
>
> I am trying to figure out the best way of restricting access to a given 
> django project so that a single user can login as normal but then has to 
> logout again if they want to access it from a different session.
>
> I am thinking just to set a flag in the userprofile table upon login and 
> then remove the flag when the user logs out, however, I'm sure this is a 
> prone to the situation where a user is thrown out of their session for 
> whatever reason and the code doesn't reset the flag. In this case the user 
> will not be able to login ever again!
>
> Is there a way to store device level details so that I can check against 
> that sort of data - this may be a more robust solution I'm guessing.
>
>
> How have people tackled this and what are the things to look out for?
>
> Regards,
>
> mjh
>

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




Doubt the split()

2013-06-21 Thread Hélio Miranda
Hi
I do not know how to spit ()
Having this string [], how can I get 
just the number?

Someone can help me?

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




Re: Project settings and application settings.

2013-06-21 Thread piir . dk

I don't really want the settings to be adjusted at runtime, I would like my 
application to reset some django "core" settings like the 
MIDDLEWARE_CLASSES during the project configuration, once for all.
It is just to ease the deployment of the project and because the 
applications knows which settings it needs.

But if as you said settings are immutable then I'm doing it wrong, a 
management command would be a better place to do this settings.


Thank you for your answer

Le jeudi 20 juin 2013 17:00:19 UTC+2, Jacky Tian a écrit :
>
> Django settings are meant to be immutable, so your issues might be 
> stemming from the way you're changing settings at runtime. Most Django 
> projects that need to adjust settings at runtime do so by keeping the 
> mutable settings in the database (e.g. a separate app in the project), so 
> that's an approach you could try.
>
> On Thursday, June 20, 2013 5:32:31 AM UTC-4, pii...@gmail.com wrote:
>>
>> Hello all,
>>
>> I want to have an application settings modifying the project settings but 
>> it doesn't seems to work.
>>
>> For development purpose I need to authenticate users against my 
>> application database. In Production
>> the authentication is done by Apache, it then sends the REMOTE_USER, 
>> correctly.
>>
>> To realize the authentication in production, i am using one middleware, 
>> and one backend as found in
>> django documentation.
>>
>> I would like to have only one setting in the project thesite/settings.py, 
>> a boolean called EXTERNAL_AUTH,
>> controling the content of AUTHENTICATION_BACKENDS and MIDDLEWARE_CLASSES.
>>
>> The code modifying those two variables will stand in my application 
>> my/settings.py, It would then look like this
>>
>> from django.conf import settings
>> if settings.EXTERNAL_AUTH == False:
>> # Disabling standard login/logout.
>> settings.LOGIN_REDIRECT_URL='/'
>> settings.LOGIN_URL='/my/accounts/login/'
>> settings.LOGOUT_URL='/my/accounts/logout/'
>> else:
>> settings.AUTHENTICATION_BACKENDS = (
>> ('my.backends.LDAPUserBackend', ) +
>> settings.AUTHENTICATION_BACKENDS)
>>
>> # Insert LDAPUserMiddleware right after AuthenticationMiddleware
>> index = settings.MIDDLEWARE_CLASSES.index(
>> "django.contrib.auth.middleware.AuthenticationMiddleware")
>> settings.MIDDLEWARE_CLASSES = (settings.MIDDLEWARE_CLASSES[:index+1] +
>> ('my.backends.LDAPUserMiddleware', ) +
>> settings.MIDDLEWARE_CLASSES[index+1:])
>>
>> EXTERNAL_AUTH is used at different locations in my application, for 
>> example I use it to decide whether or not
>> I display the "change password" link.
>>
>> When I start testing, toggling EXTERNAL_AUTH, the behavior is fuzzy. It 
>> inconsitently redirect me to the accounts/login
>> even if I'm authenticated through apache. I guess the middleware isn't 
>> called but when I raise an error, the debug page
>> contradicts this.
>>
>> I'm a bit lost. Do you have any hint?
>>
>> Regards,
>>
>>
>>
>>

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




Re: Project settings and application settings.

2013-06-21 Thread Drew Ferguson
On Fri, 21 Jun 2013 04:38:33 -0700 (PDT)
piir...@gmail.com wrote:

> 
> I don't really want the settings to be adjusted at runtime, I would like
> my application to reset some django "core" settings like the 
> MIDDLEWARE_CLASSES during the project configuration, once for all.
> It is just to ease the deployment of the project and because the 
> applications knows which settings it needs.
> 
> But if as you said settings are immutable then I'm doing it wrong, a 
> management command would be a better place to do this settings.

Sounds like you want to modify settings during deployment; a tool like
django-buildout is maybe what you are after

https://github.com/bchhun/django-buildout

> 
> 
> Thank you for your answer
> 
> Le jeudi 20 juin 2013 17:00:19 UTC+2, Jacky Tian a écrit :
> >
> > Django settings are meant to be immutable, so your issues might be 
> > stemming from the way you're changing settings at runtime. Most Django 
> > projects that need to adjust settings at runtime do so by keeping the 
> > mutable settings in the database (e.g. a separate app in the project),
> > so that's an approach you could try.
> >
> > On Thursday, June 20, 2013 5:32:31 AM UTC-4, pii...@gmail.com wrote:
> >>
> >> Hello all,
> >>
> >> I want to have an application settings modifying the project settings
> >> but it doesn't seems to work.
> >>
> >> For development purpose I need to authenticate users against my 
> >> application database. In Production
> >> the authentication is done by Apache, it then sends the REMOTE_USER, 
> >> correctly.
> >>
> >> To realize the authentication in production, i am using one
> >> middleware, and one backend as found in
> >> django documentation.
> >>
> >> I would like to have only one setting in the project
> >> thesite/settings.py, a boolean called EXTERNAL_AUTH,
> >> controling the content of AUTHENTICATION_BACKENDS and
> >> MIDDLEWARE_CLASSES.
> >>
> >> The code modifying those two variables will stand in my application 
> >> my/settings.py, It would then look like this
> >>
> >> from django.conf import settings
> >> if settings.EXTERNAL_AUTH == False:
> >> # Disabling standard login/logout.
> >> settings.LOGIN_REDIRECT_URL='/'
> >> settings.LOGIN_URL='/my/accounts/login/'
> >> settings.LOGOUT_URL='/my/accounts/logout/'
> >> else:
> >> settings.AUTHENTICATION_BACKENDS = (
> >> ('my.backends.LDAPUserBackend', ) +
> >> settings.AUTHENTICATION_BACKENDS)
> >>
> >> # Insert LDAPUserMiddleware right after AuthenticationMiddleware
> >> index = settings.MIDDLEWARE_CLASSES.index(
> >> "django.contrib.auth.middleware.AuthenticationMiddleware")
> >> settings.MIDDLEWARE_CLASSES =
> >> (settings.MIDDLEWARE_CLASSES[:index+1] +
> >> ('my.backends.LDAPUserMiddleware', ) +
> >> settings.MIDDLEWARE_CLASSES[index+1:])
> >>
> >> EXTERNAL_AUTH is used at different locations in my application, for 
> >> example I use it to decide whether or not
> >> I display the "change password" link.
> >>
> >> When I start testing, toggling EXTERNAL_AUTH, the behavior is fuzzy.
> >> It inconsitently redirect me to the accounts/login
> >> even if I'm authenticated through apache. I guess the middleware
> >> isn't called but when I raise an error, the debug page
> >> contradicts this.
> >>
> >> I'm a bit lost. Do you have any hint?
> >>
> >> Regards,
> >>
> >>
> >>
> >>
> 



-- 
Drew Ferguson
AFC Commercial
http://www.afccommercial.co.uk

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




get django with ftp

2013-06-21 Thread Larry Martell
Is there a ftp site I can download django 1.4 and 1.5 from? Usually I
get it from https://www.djangoproject.com/download/1.5.1/tarball/
but now I have to install it on a remote machine that I only have
putty access to, so I can't run a browser.

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




Re: get django with ftp

2013-06-21 Thread David Markey
No wget or curl command available?

wget https://www.djangoproject.com/download/1.5.1/tarball/ -O django.tar.gz

curl -L https://www.djangoproject.com/download/1.5.1/tarball/ >
django.tar.gz



On 21 June 2013 13:54, Larry Martell  wrote:

> Is there a ftp site I can download django 1.4 and 1.5 from? Usually I
> get it from https://www.djangoproject.com/download/1.5.1/tarball/
> but now I have to install it on a remote machine that I only have
> putty access to, so I can't run a browser.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: get django with ftp

2013-06-21 Thread Larry Martell
On Fri, Jun 21, 2013 at 6:58 AM, David Markey  wrote:
> No wget or curl command available?
>
> wget https://www.djangoproject.com/download/1.5.1/tarball/ -O django.tar.gz
>
> curl -L https://www.djangoproject.com/download/1.5.1/tarball/ >
> django.tar.gz
>

Thanks!


> On 21 June 2013 13:54, Larry Martell  wrote:
>>
>> Is there a ftp site I can download django 1.4 and 1.5 from? Usually I
>> get it from https://www.djangoproject.com/download/1.5.1/tarball/
>> but now I have to install it on a remote machine that I only have
>> putty access to, so I can't run a browser.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

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




Re: get django with ftp

2013-06-21 Thread Sebastian Goll
On Fri, 21 Jun 2013 06:54:11 -0600
Larry Martell  wrote:

> Is there a ftp site I can download django 1.4 and 1.5 from? Usually I
> get it from https://www.djangoproject.com/download/1.5.1/tarball/
> but now I have to install it on a remote machine that I only have
> putty access to, so I can't run a browser.

When you have wget or curl available on the remtoe machine, you can simply do

  $ wget -O Django-1.5.1.tar.gz 
https://www.djangoproject.com/download/1.5.1/tarball/

or

  $ curl -L -o Django-1.5.1.tar.gz 
https://www.djangoproject.com/download/1.5.1/tarball/

to download it via HTTP.

Sebastian.

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




File Path Question

2013-06-21 Thread Nigel Legg
New to Django(ish).  I'm not sure whether my error is coding or OS related:
I am getting the following error message:

IOError at /myapp/file_view/4/

[Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv'

 Request Method: GET  Request URL:
http://127.0.0.1:8000/myapp/file_view/4/  Django
Version: 1.5.1  Exception Type: IOError  Exception Value:

[Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv'

 Exception Location: C:\stats_portal\myproject\myproject\myapp\fileview.py
in filedata, line 5  Python Executable: c:\python27\python.exe  Python
Version: 2.7.5  Python Path:

['C:\\stats_portal\\myproject',
 'c:\\python27\\lib\\site-packages\\python_dateutil-1.5-py2.7.egg',
 'c:\\python27\\lib\\site-packages\\django_directupload-0.0.11-py2.7.egg',
 'C:\\windows\\system32\\python27.zip',
 'c:\\python27\\DLLs',
 'c:\\python27\\lib',
 'c:\\python27\\lib\\plat-win',
 'c:\\python27\\lib\\lib-tk',
 'c:\\python27',
 'c:\\python27\\lib\\site-packages']

 Server time: Fri, 21 Jun 2013 14:09:20 +0100
Is the file not found problem because the upload has recorded it as
documents/2013/06/... even though I am working on Windows, so python /
django should have ... documents\\2013\\06\\... etc? I am developing on
Windows, but will deploy on Linux.
Or have I made an error elsewhere?


Regards,
Nigel Legg
07914 740972
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg

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




Re: How to divide my apps? Good practices?

2013-06-21 Thread Mayukh Mukherjee
Just some generic advice -- keep each app focused on one individual task,as
a rule of thumb you'd want maybe 5 +/- 2 models per app. Better to have
multiple apps that each do one thing well than one large app that does
everything.


Best



On Thu, Jun 20, 2013 at 5:01 PM, galgal  wrote:

> Hi,
> I'm starting my new project. It's sport-connected.
> The main part of my app will be league, matches, teams and players. There
> will be many relations.
>
> So, how to make apps and models. I plan to make models:
>
>- Season
>- League (FK to Season)
>- Team
>- Match (FK to League and 2FK to Teams)
>- Players (FK to Team)
>- and many more to present teams history in each season etc.
>
> Is it better, to make it all in 1 app, called for example Game, or divide
> it into smaller apps?
> Thanks for help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Mayukh Mukherjee
http://www.linkedin.com/in/mayukhmmukherjee

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




Re: Project settings and application settings.

2013-06-21 Thread Tom Evans
On Fri, Jun 21, 2013 at 12:38 PM,   wrote:
>
> I don't really want the settings to be adjusted at runtime, I would like my
> application to reset some django "core" settings like the MIDDLEWARE_CLASSES
> during the project configuration, once for all.
> It is just to ease the deployment of the project and because the
> applications knows which settings it needs.
>
> But if as you said settings are immutable then I'm doing it wrong, a
> management command would be a better place to do this settings.
>

Settings should be immutable outside of settings. That is to say, you
can do anything - ANYTHING - you want to do in your project settings
file, but you should not change settings from outside that file.
django.confg.settings are imported from your project's settings file,
so whatever you want to change should happen in there.

This would mean your settings will be determined once at run time,
when the server starts up. If you don't care about changing settings
at run time, and these decisions are only made once, when you deploy
the box, use buildout or any of the many other deployment management
tools.

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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to divide my apps? Good practices?

2013-06-21 Thread galgal
@Mayukh Mukherjee yes, I have that in mind. That's why I'm asking about 
it:) I'm confused now and need any advice if that all models should be in 1 
app, or in couple of apps.

I'm rather convinced to make couple of apps

   - teams (models with teams - at least 2 models. team as global in my 
   app, and team in the season (its name, etc))
   - players (the same as above)
   - leagues with different competitions systems
   - etc...

It should be better in future to develop new features.

On Friday, June 21, 2013 3:30:48 PM UTC+2, Mayukh Mukherjee wrote:
>
> Just some generic advice -- keep each app focused on one individual 
> task,as a rule of thumb you'd want maybe 5 +/- 2 models per app. Better to 
> have multiple apps that each do one thing well than one large app that does 
> everything.
>
>
> Best
>
>
>
> On Thu, Jun 20, 2013 at 5:01 PM, galgal 
> > wrote:
>
>> Hi,
>> I'm starting my new project. It's sport-connected.
>> The main part of my app will be league, matches, teams and players. There 
>> will be many relations.
>>
>> So, how to make apps and models. I plan to make models:
>>
>>- Season
>>- League (FK to Season)
>>- Team
>>- Match (FK to League and 2FK to Teams)
>>- Players (FK to Team)
>>- and many more to present teams history in each season etc.
>>
>> Is it better, to make it all in 1 app, called for example Game, or divide 
>> it into smaller apps?
>> Thanks for help.
>>
>> -- 
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Mayukh Mukherjee
> http://www.linkedin.com/in/mayukhmmukherjee
>
>
>  

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




Mongoengine delete file gridfs

2013-06-21 Thread Hélio Miranda


I am using mongoengine to insert images in mongodb's GridFS. Insert 
everything is ok, but I now want to delete, and I'm not getting. I am using 
version 0.8.2 and I'm mongoengine to do so:

class Animal(Document):

 genus = StringField()
 family = StringField()
 photo = FileField()

marmot = Animal(genus='Marmota')

marmot.photo.delete()

Only he did not delete anything or gives error. What am I doing wrong? 
Someone can help me?

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




Re: File Path Question

2013-06-21 Thread Nigel Legg
In the path shown in my previous email, documents is a subdirectory of the
media directory, which is set in settings.py.

views.py:
from myproject.myapp.forms import DocumentForm

def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()

# Redirect to the document list after POST
return
HttpResponseRedirect(reverse('myproject.myapp.views.list'))
else:
form = DocumentForm() # A empty, unbound form

# Load documents for the list page
documents = Document.objects.all()

# Render list page with the documents and the form
return render_to_response(
'myapp/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)

models.py:
from django.db import models

class Document(models.Model):
docfile = models.FileField(upload_to='documents/%Y/%m/%d')

this section works fine - ie files yesterday were uploaded to
c:\\\\myproject\\media\\documents\\2013\\06\\20\\file.csv.
I need now to be able to access them.  This error suggests I need to
convert  documents/%Y/%m/%d' to documents\\2013\\06\\20\\ to be able to do
so.  Is that correct?

Regards,
Nigel Legg
07914 740972
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg



On 21 June 2013 16:25, Jacky Tian  wrote:

> What does your project directory tree look like? I suspect the error has
> to do with where your documents/ directory is located in relation to the
> working directory. Try loading the document using a path relative to your
> project root.
>
> -Jacky Tian
>
>
>
> On Friday, June 21, 2013 9:29:20 AM UTC-4, Nigel Legg wrote:
>>
>> New to Django(ish).  I'm not sure whether my error is coding or OS
>> related:
>> I am getting the following error message:
>>
>> IOError at /myapp/file_view/4/
>>
>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv'
>>
>>  Request Method: GET  Request URL: http://127.0.0.1:8000/myapp/**
>> file_view/4/   Django Version:
>> 1.5.1  Exception Type: IOError  Exception Value:
>>
>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv'
>>
>>  Exception Location: C:\stats_portal\myproject\**myproject\myapp\fileview.py
>> in filedata, line 5  Python Executable: c:\python27\python.exe  Python
>> Version: 2.7.5  Python Path:
>>
>> ['C:\\stats_portal\\myproject'**,
>>  'c:\\python27\\lib\\site-**packages\\python_dateutil-1.5-**py2.7.egg',
>>  
>> 'c:\\python27\\lib\\site-**packages\\django_directupload-**0.0.11-py2.7.egg',
>>  'C:\\windows\\system32\\**python27.zip',
>>  'c:\\python27\\DLLs',
>>  'c:\\python27\\lib',
>>  'c:\\python27\\lib\\plat-win',
>>  'c:\\python27\\lib\\lib-tk',
>>  'c:\\python27',
>>  'c:\\python27\\lib\\site-**packages']
>>
>>  Server time: Fri, 21 Jun 2013 14:09:20 +0100
>> Is the file not found problem because the upload has recorded it as
>> documents/2013/06/... even though I am working on Windows, so python /
>> django should have ... documents\\2013\\06\\... etc? I am developing on
>> Windows, but will deploy on Linux.
>> Or have I made an error elsewhere?
>>
>>
>> Regards,
>> Nigel Legg
>> 07914 740972
>> http://twitter.com/nigellegg
>> http://uk.linkedin.com/in/**nigellegg
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: File Path Question

2013-06-21 Thread Jacky Tian
What does your project directory tree look like? I suspect the error has to 
do with where your documents/ directory is located in relation to the 
working directory. Try loading the document using a path relative to your 
project root.

-Jacky Tian


On Friday, June 21, 2013 9:29:20 AM UTC-4, Nigel Legg wrote:
>
> New to Django(ish).  I'm not sure whether my error is coding or OS related:
> I am getting the following error message:
>
> IOError at /myapp/file_view/4/ 
>
> [Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv'
>
>  Request Method: GET  Request URL: 
> http://127.0.0.1:8000/myapp/file_view/4/  Django Version: 1.5.1  Exception 
> Type: IOError  Exception Value: 
>
> [Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv'
>
>  Exception Location: C:\stats_portal\myproject\myproject\myapp\fileview.py 
> in filedata, line 5  Python Executable: c:\python27\python.exe  Python 
> Version: 2.7.5  Python Path: 
>
> ['C:\\stats_portal\\myproject',
>  'c:\\python27\\lib\\site-packages\\python_dateutil-1.5-py2.7.egg',
>  'c:\\python27\\lib\\site-packages\\django_directupload-0.0.11-py2.7.egg',
>  'C:\\windows\\system32\\python27.zip',
>  'c:\\python27\\DLLs',
>  'c:\\python27\\lib',
>  'c:\\python27\\lib\\plat-win',
>  'c:\\python27\\lib\\lib-tk',
>  'c:\\python27',
>  'c:\\python27\\lib\\site-packages']
>
>  Server time: Fri, 21 Jun 2013 14:09:20 +0100
> Is the file not found problem because the upload has recorded it as 
> documents/2013/06/... even though I am working on Windows, so python / 
> django should have ... documents\\2013\\06\\... etc? I am developing on 
> Windows, but will deploy on Linux. 
> Or have I made an error elsewhere?  
>
>
> Regards,
> Nigel Legg
> 07914 740972
> http://twitter.com/nigellegg
> http://uk.linkedin.com/in/nigellegg
>
>  

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




Re: How to divide my apps? Good practices?

2013-06-21 Thread Christian Schmitt
You shouldn't divine things that should be together. Better make things 
together like, game, forum, blog. Don't make a app for too many things.

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




How to access request/session information from model.clean?

2013-06-21 Thread Richard E. Cooke
 I'm trying to pass the request object, which includes the session object, 
to a chunk of Django 1.5 code that is tied to the model (model.clean). When 
running the Admin app, it does not have access to the request object.

So I tried stashing it in RAM using thread.local(), only to get a crash 
course in how "shared" RAM is between active sessions!

I have several choices I'm trying to figure out the one with the least 
amount of work. I would not be working in Automation if I weren't lazy.

My goal is to auto-fill the company division the current session belongs 
to. This allows us to use the same business software for multiple 
divisions. Django 1.4 and 1.5 Admin has a lovely built-in easy method to 
filter records before they are displayed (ModelAdmin.queryset), the example 
given in the docs shows how to limit records to the user that "owns" them. 
I just changed that to "company division" (the list is stored in Site 
database), and presto! All data displayed anyplace inside the admin is 
restricted and the operation is totally transparent to the user. 

What I need to do now is have an automatic method to populate each record's 
"site" field with the "site" value inside the current session.  Note that 
this is different from how the "site" framework and "SITE_ID" field are 
used.

   1. I can copy the admin view and make changes to it. Since it is passed 
   the request, I can access the session object to get the seed value. This 
   would be the "best practice" when I (eventually) get approval to replace 
   the admin with our own task-based system. But I suspect its a lot of work 
   to try it inside of the admin framework, It might have a domino effect 
   resulting in the editing of a lot more related files. The html templates, 
   for example.
   2. Which brings me to copying just the templates and changing them, 
   since I think they are sent the session data as part of the request object. 
   I have not learned how to work with templates, so I cannot judge how much 
   effort this represents.
   3. Find some other mechanism within the admin framework. Find a place 
   where I have access to both the data instance and the session data. Or a 
   way I can pass one or the other to some code where I can make use of it.

Its the 3rd possibility I'm trolling for here. Since I don't have time to 
do choice #1 - at least the full custom version. And I dunno about #2.

There is another Django 1.4/1.5 feature I might be able to use: 
ModelAdmin.get_form. This is called to "get" the add, change or delete 
form. And it is passed the request object. I just have to learn if it also 
has access to the data instance. Or maybe I can pass "default" values as a 
keyword argument? I have a vague memory reading something about that. Have 
to dig back into the Admin docs and/or read the source code

As always, any input, thoughts, or suggestions welcome!

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




Re: 'SafeText' object has no attribute 'status_code'

2013-06-21 Thread Bill Freeman
Try using render or render_to_response instead of render_to_string.  A view
needs to return and HttpResponse object, not a string.


On Thu, Jun 20, 2013 at 4:59 PM, der_fenix  wrote:

> **
>
> Hello I have problem with render_to_string
>
> django it's showme this error message :
>
> 'SafeText' object has no attribute 'status_code'
>
>
> my view :
>
> def html(request):
>
> context = {'inf':  Itype.objects.all()}
>
> return render_to_string('smg/owl.html',context)
>
>
> Views must return Response object. You should use render_to_response in
> your 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to divide my apps? Good practices?

2013-06-21 Thread galgal
But I can see now that there will be a massive amount of models. Each player 
should have his own statistics for each games, there will also be a part for 
referees. Referee work will be rated by users so - many models is planned. If I 
put it in one app, I will have at least 15 models in it and I think it will 
increase in some time

Division in my example will clarify it, for example players app with all models 
for players like player base, player in season, player statistics and of course 
all logic in it.

In 1 app there will be a many many lines of code and after some time it will be 
hard to develop I think.

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




Re: How to divide my apps? Good practices?

2013-06-21 Thread Tom Evans
On Fri, Jun 21, 2013 at 5:29 PM, galgal  wrote:
> But I can see now that there will be a massive amount of models. Each player 
> should have his own statistics for each games, there will also be a part for 
> referees. Referee work will be rated by users so - many models is planned. If 
> I put it in one app, I will have at least 15 models in it and I think it will 
> increase in some time
>
> Division in my example will clarify it, for example players app with all 
> models for players like player base, player in season, player statistics and 
> of course all logic in it.
>
> In 1 app there will be a many many lines of code and after some time it will 
> be hard to develop I think.
>

Welcome to software development.


In general, draw a diagram of your models and how they relate to each
other. Separate models which logically are only slightly related into
different packages - literally draw a line around the models in the
diagram.

For example, in your sports models, you have primitive objects like a
Game, a Player, a League, a Team and so on. All these are highly
coupled together, and belong together. Later on, you discuss
statistics on one of these things. Statistics are only loosely related
to the primitive game objects, and so should be in a separate package.

A useful rule of thumb is that if you have a package "A", it can
import from "B", but "B" should not import from "A". If they do, they
are tightly coupled and should belong in the same package (or,
potentially, your design is unclean - tight coupling is not a desired
trait of software components).

If you are more interested in this topic, I'd read "Software
Engineering - a Practitioners Approach" by Pressman.

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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to divide my apps? Good practices?

2013-06-21 Thread Tom Evans
On Fri, Jun 21, 2013 at 5:29 PM, galgal  wrote:
> In 1 app there will be a many many lines of code and after some time it will 
> be hard to develop I think.

Sorry, I just wanted to reply to just this line as well!

There is no problem with having apps with a lot of code. Each part of
an app - models, views, templates, tests, urls etc - can easily be
split up into smaller logical components. If there is not a good
reason to split it into separate apps, then do not do it.

For instance, in your proposed sport/league project, you *could*
separate each model in to a separate app. This would work fine, but be
completely pointless.

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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt the split()

2013-06-21 Thread Tomas Neme
a regex?

something like re.match("\[http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Doubt the split()

2013-06-21 Thread Gustavo Carneiro
But note that this question is completely off-topic for the django-users
list.


On Fri, Jun 21, 2013 at 5:47 PM, Tomas Neme  wrote:

> a regex?
>
> something like re.match("\[ yourstring).groups()[0]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic." -- Frank Herbert

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




Re: Doubt the split()

2013-06-21 Thread Bill Freeman
import re

hexnum = re.search(r': ?([0-9a-fA-F]+)>', the_string).group(1)

It is worth you while to learn about regular expressions:
http://docs.python.org/2.7/library/re.html

There are ways to do this without regular expressions, and there are
simpler patterns for this specific formatting, more fussy about format, or
less fussy.


On Fri, Jun 21, 2013 at 6:29 AM, Hélio Miranda  wrote:

> Hi
> I do not know how to spit ()
> Having this string [], how can I
> get just the number?
>
> Someone can help me?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: File Path Question

2013-06-21 Thread Bill Freeman
On Fri, Jun 21, 2013 at 11:34 AM, Nigel Legg  wrote:

> In the path shown in my previous email, documents is a subdirectory of the
> media directory, which is set in settings.py.
>

No it's not a subdirectory.  It begins with '/', so it is sought at the
root of the filesystem.

>
>
>>> IOError at /myapp/file_view/4/
>>>
>>

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




Re: How to access request/session information from model.clean?

2013-06-21 Thread Jason Arnst-Goodrich
If you want to update the initially selected value (but still allow the 
user to select a different site)I think you're on the right track with 
ModelAdmin.get_form

If you want to completely restrict them to their current session's site 
you'll want to use a combination of ModelAdmin.get_form (to exclude the 
field from the form or maybe make it read only) and ModelAdmin.save_model 
(to set the site to the session site before calling save).


In case you've never used either method this is a decent starting point to 
see some examples:
http://stackoverflow.com/questions/687829/django-overriding-get-form-to-customize-admin-forms-based-on-request

Note that get_form can pass back a form class which which can be handy but 
you can also set ModelAdmin options and call super() - you'll see examples 
of both there.


On Friday, June 21, 2013 9:03:22 AM UTC-7, Richard E. Cooke wrote:
>
> I'm trying to pass the request object, which includes the session object, 
> to a chunk of Django 1.5 code that is tied to the model (model.clean). When 
> running the Admin app, it does not have access to the request object.
>
> So I tried stashing it in RAM using thread.local(), only to get a crash 
> course in how "shared" RAM is between active sessions!
>
> I have several choices I'm trying to figure out the one with the least 
> amount of work. I would not be working in Automation if I weren't lazy.
>
> My goal is to auto-fill the company division the current session belongs 
> to. This allows us to use the same business software for multiple 
> divisions. Django 1.4 and 1.5 Admin has a lovely built-in easy method to 
> filter records before they are displayed (ModelAdmin.queryset), the example 
> given in the docs shows how to limit records to the user that "owns" them. 
> I just changed that to "company division" (the list is stored in Site 
> database), and presto! All data displayed anyplace inside the admin is 
> restricted and the operation is totally transparent to the user. 
>
> What I need to do now is have an automatic method to populate each 
> record's "site" field with the "site" value inside the current session.  
> Note that this is different from how the "site" framework and "SITE_ID" 
> field are used.
>
>1. I can copy the admin view and make changes to it. Since it is 
>passed the request, I can access the session object to get the seed value. 
>This would be the "best practice" when I (eventually) get approval to 
>replace the admin with our own task-based system. But I suspect its a lot 
>of work to try it inside of the admin framework, It might have a domino 
>effect resulting in the editing of a lot more related files. The html 
>templates, for example.
>2. Which brings me to copying just the templates and changing them, 
>since I think they are sent the session data as part of the request 
> object. 
>I have not learned how to work with templates, so I cannot judge how much 
>effort this represents.
>3. Find some other mechanism within the admin framework. Find a place 
>where I have access to both the data instance and the session data. Or a 
>way I can pass one or the other to some code where I can make use of it.
>
> Its the 3rd possibility I'm trolling for here. Since I don't have time to 
> do choice #1 - at least the full custom version. And I dunno about #2.
>
> There is another Django 1.4/1.5 feature I might be able to use: 
> ModelAdmin.get_form. This is called to "get" the add, change or delete 
> form. And it is passed the request object. I just have to learn if it also 
> has access to the data instance. Or maybe I can pass "default" values as a 
> keyword argument? I have a vague memory reading something about that. Have 
> to dig back into the Admin docs and/or read the source code
>
> As always, any input, thoughts, or suggestions welcome!
>

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




Re: How to divide my apps? Good practices?

2013-06-21 Thread Christian Schmitt
That is fine in one app. just seperate them. delete models.py and make a 
package named models. import every model in the __init__.py file from 
models.py, make sure u set a class Meta: app_label = 'your app name' to 
every model and you have a very clean app structure.

Am Freitag, 21. Juni 2013 18:29:44 UTC+2 schrieb galgal:
>
> But I can see now that there will be a massive amount of models. Each 
> player should have his own statistics for each games, there will also be a 
> part for referees. Referee work will be rated by users so - many models is 
> planned. If I put it in one app, I will have at least 15 models in it and I 
> think it will increase in some time
>
> Division in my example will clarify it, for example players app with all 
> models for players like player base, player in season, player statistics 
> and of course all logic in it.
>
> In 1 app there will be a many many lines of code and after some time it 
> will be hard to develop I think.
>
>

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




Re: File Path Question

2013-06-21 Thread Jacky Tian
Have you set your MEDIA_ROOT appropriately in settings.py? Since 
fileview.py is where your original exception originated, can you post the 
relevant parts of the source in that file (whatever function line 5 belongs 
to). Did you get the exception under runserver or a "real" webserver?

You shouldn't need to change the slashes in your path, Python handles that 
for you.

-Jacky Tian

On Friday, June 21, 2013 11:34:16 AM UTC-4, Nigel Legg wrote:
>
> In the path shown in my previous email, documents is a subdirectory of the 
> media directory, which is set in settings.py. 
>
> views.py:
> from myproject.myapp.forms import DocumentForm
>
> def list(request):
> # Handle file upload
> if request.method == 'POST':
> form = DocumentForm(request.POST, request.FILES)
> if form.is_valid():
> newdoc = Document(docfile = request.FILES['docfile'])
> newdoc.save()
>
> # Redirect to the document list after POST
> return 
> HttpResponseRedirect(reverse('myproject.myapp.views.list'))
> else:
> form = DocumentForm() # A empty, unbound form
>
> # Load documents for the list page
> documents = Document.objects.all()
>
> # Render list page with the documents and the form
> return render_to_response(
> 'myapp/list.html',
> {'documents': documents, 'form': form},
> context_instance=RequestContext(request)
> )
>
> models.py:
> from django.db import models
>
> class Document(models.Model):
> docfile = models.FileField(upload_to='documents/%Y/%m/%d')
>
> this section works fine - ie files yesterday were uploaded to 
> c:\\\\myproject\\media\\documents\\2013\\06\\20\\file.csv. 
> I need now to be able to access them.  This error suggests I need to 
> convert  documents/%Y/%m/%d' to documents\\2013\\06\\20\\ to be able to do 
> so.  Is that correct? 
>
> Regards,
> Nigel Legg
> 07914 740972
> http://twitter.com/nigellegg
> http://uk.linkedin.com/in/nigellegg
>
>
>
> On 21 June 2013 16:25, Jacky Tian > wrote:
>
>> What does your project directory tree look like? I suspect the error has 
>> to do with where your documents/ directory is located in relation to the 
>> working directory. Try loading the document using a path relative to your 
>> project root.
>>
>> -Jacky Tian
>>
>>
>>
>> On Friday, June 21, 2013 9:29:20 AM UTC-4, Nigel Legg wrote:
>>>
>>> New to Django(ish).  I'm not sure whether my error is coding or OS 
>>> related:
>>> I am getting the following error message:
>>>
>>> IOError at /myapp/file_view/4/ 
>>>
>>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv'
>>>
>>>  Request Method: GET  Request URL: http://127.0.0.1:8000/myapp/**
>>> file_view/4/   Django Version: 
>>> 1.5.1  Exception Type: IOError  Exception Value: 
>>>
>>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv'
>>>
>>>  Exception Location: 
>>> C:\stats_portal\myproject\**myproject\myapp\fileview.py 
>>> in filedata, line 5  Python Executable: c:\python27\python.exe  Python 
>>> Version: 2.7.5  Python Path: 
>>>
>>> ['C:\\stats_portal\\myproject'**,
>>>  'c:\\python27\\lib\\site-**packages\\python_dateutil-1.5-**py2.7.egg',
>>>  
>>> 'c:\\python27\\lib\\site-**packages\\django_directupload-**0.0.11-py2.7.egg',
>>>  'C:\\windows\\system32\\**python27.zip',
>>>  'c:\\python27\\DLLs',
>>>  'c:\\python27\\lib',
>>>  'c:\\python27\\lib\\plat-win',
>>>  'c:\\python27\\lib\\lib-tk',
>>>  'c:\\python27',
>>>  'c:\\python27\\lib\\site-**packages']
>>>
>>>  Server time: Fri, 21 Jun 2013 14:09:20 +0100
>>> Is the file not found problem because the upload has recorded it as 
>>> documents/2013/06/... even though I am working on Windows, so python / 
>>> django should have ... documents\\2013\\06\\... etc? I am developing on 
>>> Windows, but will deploy on Linux. 
>>> Or have I made an error elsewhere?  
>>>
>>>
>>> Regards,
>>> Nigel Legg
>>> 07914 740972
>>> http://twitter.com/nigellegg
>>> http://uk.linkedin.com/in/**nigellegg
>>>
>>>   -- 
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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

Re: How to divide my apps? Good practices?

2013-06-21 Thread Tim Chase
On 2013-06-21 09:29, galgal wrote:
> But I can see now that there will be a massive amount of models.
[snip]
> I will have at least 15 models in it and I think it will
> increase in some time

Just as an aside, having worked developing a lot of
business/"enterprise" applications, 15 models is a pretty simple
world.  I usually think of "massive amount of models" as at least a
hundred, often several hundred.

So the rule of thumb is to separate your logical/functional units
(registration, team/league management, game management, common
models, reporting, etc) rather than by models.

-tkc



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




CachedStaticFilesStorage with database cache backend - static file not found (404)

2013-06-21 Thread luke lukes
Hi everyone. I've enabled 
CachedStaticFileStorage
.
I'm using db as cache backend. I followed all the things said in the django 
docs, now my settings looks like this: 

# cache table settings  

  
STATICFILES_STORAGE="django.contrib.staticfiles.storage.CachedStaticFilesStorage"
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'my_cache_table',
}
 }
DEBUG=False


I've tried it in a template on single css link :

{% load static from staticfiles %}



Well It correctly generate the HTML, e.g:




but I have a 404 on that file.

Is there something missing?
I've also launched manage.py collectstatic, but I get some errors in an 
app. May be that the error?

My initial intention was to implement a custom templatetag to do that, but 
since I don't want to reinvent the wheel I'd like to solve it in an 
appropeiate way.

Thanks
LuKe

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




database error

2013-06-21 Thread Michael P. Soulier
Hi,

I have a Django UI with a daemon running in the background, both using the
Django models to update the postgres database. When the daemon in the
background gets very busy, I'm getting errors in the UI while trying to load
the page (simply reading the postgres db).

DatabaseError at /clients/minet/

current transaction is aborted, commands ignored until end of transaction
block

Request Method: GET
Request URL:
http://10.38.200.253/server-manager/django/teleworker/clients/minet/
Django Version: 1.4.3
Exception Type: DatabaseError
Exception Value:

current transaction is aborted, commands ignored until end of transaction
block

Exception Location:
/usr/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py
in execute, line 52
Python Executable:  /usr/bin/python

I found a thread online that suggested I should have the autocommit option
set, so I did that, but it doesn't seem to be helping. 

I don't see any errors in the postgres logs, and I see no detail on this
problem. Help appreciated.

Mike

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




TEMPLATE_CONTEXT_PROCESSORS missing in settings.py

2013-06-21 Thread asaxena
Hey everyone,

Currently a noob to Django--I'm using Django 1.5.1 installed with Python 
2.7 in a virtualenv. I'm learning about context processors and noticed that 
TEMPLATE_CONTEXT_PROCESSORS is completely missing from my settings.py. Is 
this normal? Am I supposed to add Django's default template context 
processors or are they supposed to be there in the first place? Here's what 
my settings.py looks like:


# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 
'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 
'/media/UD/Virtual_Environments/kolasite/mysite/sqlite.db', 
 
# Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '',  # Empty for localhost through 
domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '',  # Set to empty string for default.
}
}

# Hosts/domain names that are valid for this site; required if DEBUG is 
False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded 
files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/";, "http://media.example.com/";
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://example.com/static/";, "http://static.example.com/";
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '8c(j)m3dm!m3gd_n#vjjfqdeuq!ltsj3+xii617dos1i@_pc7*'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or 
"C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

# A sample lo

Re: TEMPLATE_CONTEXT_PROCESSORS missing in settings.py

2013-06-21 Thread Addy Yeow
TEMPLATE_CONTEXT_PROCESSORS is not there by default in your project's
settings.py. It's defined in the django/conf/global_settings.py, see
https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATE_CONTEXT_PROCESSORSfor
the default callables that are included.


On Sat, Jun 22, 2013 at 11:08 AM,  wrote:

> Hey everyone,
>
> Currently a noob to Django--I'm using Django 1.5.1 installed with Python
> 2.7 in a virtualenv. I'm learning about context processors and noticed that
> TEMPLATE_CONTEXT_PROCESSORS is completely missing from my settings.py. Is
> this normal? Am I supposed to add Django's default template context
> processors or are they supposed to be there in the first place? Here's what
> my settings.py looks like:
>
>
> # Django settings for mysite project.
>
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
>
> ADMINS = (
> # ('Your Name', 'your_em...@example.com'),
> )
>
> MANAGERS = ADMINS
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.sqlite3', # Add
> 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
> 'NAME':
> '/media/UD/Virtual_Environments/kolasite/mysite/sqlite.db',
> # Or path to database file if using sqlite3.
> # The following settings are not used with sqlite3:
> 'USER': '',
> 'PASSWORD': '',
> 'HOST': '',  # Empty for localhost through
> domain sockets or '127.0.0.1' for localhost through TCP.
> 'PORT': '',  # Set to empty string for default.
> }
> }
>
> # Hosts/domain names that are valid for this site; required if DEBUG is
> False
> # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
> ALLOWED_HOSTS = []
>
> # Local time zone for this installation. Choices can be found here:
> # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
> # although not all choices may be available on all operating systems.
> # In a Windows environment this must be set to your system time zone.
> TIME_ZONE = 'America/Chicago'
>
> # Language code for this installation. All choices can be found here:
> # http://www.i18nguy.com/unicode/language-identifiers.html
> LANGUAGE_CODE = 'en-us'
>
> SITE_ID = 1
>
> # If you set this to False, Django will make some optimizations so as not
> # to load the internationalization machinery.
> USE_I18N = True
>
> # If you set this to False, Django will not format dates, numbers and
> # calendars according to the current locale.
> USE_L10N = True
>
> # If you set this to False, Django will not use timezone-aware datetimes.
> USE_TZ = True
>
> # Absolute filesystem path to the directory that will hold user-uploaded
> files.
> # Example: "/var/www/example.com/media/"
> MEDIA_ROOT = ''
>
> # URL that handles the media served from MEDIA_ROOT. Make sure to use a
> # trailing slash.
> # Examples: "http://example.com/media/";, "http://media.example.com/";
> MEDIA_URL = ''
>
> # Absolute path to the directory static files should be collected to.
> # Don't put anything in this directory yourself; store your static files
> # in apps' "static/" subdirectories and in STATICFILES_DIRS.
> # Example: "/var/www/example.com/static/"
> STATIC_ROOT = ''
>
> # URL prefix for static files.
> # Example: "http://example.com/static/";, "http://static.example.com/";
> STATIC_URL = '/static/'
>
> # Additional locations of static files
> STATICFILES_DIRS = (
> # Put strings here, like "/home/html/static" or "C:/www/django/static".
> # Always use forward slashes, even on Windows.
> # Don't forget to use absolute paths, not relative paths.
> )
>
> # List of finder classes that know how to find static files in
> # various locations.
> STATICFILES_FINDERS = (
> 'django.contrib.staticfiles.finders.FileSystemFinder',
> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
> #'django.contrib.staticfiles.finders.DefaultStorageFinder',
> )
>
> # Make this unique, and don't share it with anybody.
> SECRET_KEY = '8c(j)m3dm!m3gd_n#vjjfqdeuq!ltsj3+xii617dos1i@_pc7*'
>
> # List of callables that know how to import templates from various sources.
> TEMPLATE_LOADERS = (
> 'django.template.loaders.filesystem.Loader',
> 'django.template.loaders.app_directories.Loader',
> # 'django.template.loaders.eggs.Loader',
> )
>
> MIDDLEWARE_CLASSES = (
> 'django.middleware.common.CommonMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> # Uncomment the next line for simple clickjacking protection:
> # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> )
>
> ROOT_URLCONF = 'mysite.urls'
>
> # Python dotted path to the WSGI application used by Django's runserver.
> WSGI_APPLICATION = 'mysite.wsgi.application'
>
> TEMPLATE_DIRS = (
> # Put strings here, like "/home/html/django_templates" or
> "C:/www/django/templates

Re: TEMPLATE_CONTEXT_PROCESSORS missing in settings.py

2013-06-21 Thread asaxena
Thank you! I'm always amazed at how quickly and accurately people respond 
in this group--much appreciated. 

Alok

On Friday, June 21, 2013 9:18:59 PM UTC-4, ayeowch wrote:
>
> TEMPLATE_CONTEXT_PROCESSORS is not there by default in your project's 
> settings.py. It's defined in the django/conf/global_settings.py, see 
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATE_CONTEXT_PROCESSORSfor
>  the default callables that are included.
>
>
> On Sat, Jun 22, 2013 at 11:08 AM, >wrote:
>
>> Hey everyone,
>>
>> Currently a noob to Django--I'm using Django 1.5.1 installed with Python 
>> 2.7 in a virtualenv. I'm learning about context processors and noticed that 
>> TEMPLATE_CONTEXT_PROCESSORS is completely missing from my settings.py. Is 
>> this normal? Am I supposed to add Django's default template context 
>> processors or are they supposed to be there in the first place? Here's what 
>> my settings.py looks like:
>>
>>
>> # Django settings for mysite project.
>>
>> DEBUG = True
>> TEMPLATE_DEBUG = DEBUG
>>
>> ADMINS = (
>> # ('Your Name', 'your_...@example.com '),
>> )
>>
>> MANAGERS = ADMINS
>>
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.sqlite3', # Add 
>> 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
>> 'NAME': 
>> '/media/UD/Virtual_Environments/kolasite/mysite/sqlite.db',  
>> 
>> # Or path to database file if using sqlite3.
>> # The following settings are not used with sqlite3:
>> 'USER': '',
>> 'PASSWORD': '',
>> 'HOST': '',  # Empty for localhost through 
>> domain sockets or '127.0.0.1' for localhost through TCP.
>> 'PORT': '',  # Set to empty string for 
>> default.
>> }
>> }
>>
>> # Hosts/domain names that are valid for this site; required if DEBUG is 
>> False
>> # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
>> ALLOWED_HOSTS = []
>>
>> # Local time zone for this installation. Choices can be found here:
>> # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
>> # although not all choices may be available on all operating systems.
>> # In a Windows environment this must be set to your system time zone.
>> TIME_ZONE = 'America/Chicago'
>>
>> # Language code for this installation. All choices can be found here:
>> # http://www.i18nguy.com/unicode/language-identifiers.html
>> LANGUAGE_CODE = 'en-us'
>>
>> SITE_ID = 1
>>
>> # If you set this to False, Django will make some optimizations so as not
>> # to load the internationalization machinery.
>> USE_I18N = True
>>
>> # If you set this to False, Django will not format dates, numbers and
>> # calendars according to the current locale.
>> USE_L10N = True
>>
>> # If you set this to False, Django will not use timezone-aware datetimes.
>> USE_TZ = True
>>
>> # Absolute filesystem path to the directory that will hold user-uploaded 
>> files.
>> # Example: "/var/www/example.com/media/"
>> MEDIA_ROOT = ''
>>
>> # URL that handles the media served from MEDIA_ROOT. Make sure to use a
>> # trailing slash.
>> # Examples: "http://example.com/media/";, "http://media.example.com/";
>> MEDIA_URL = ''
>>
>> # Absolute path to the directory static files should be collected to.
>> # Don't put anything in this directory yourself; store your static files
>> # in apps' "static/" subdirectories and in STATICFILES_DIRS.
>> # Example: "/var/www/example.com/static/"
>> STATIC_ROOT = ''
>>
>> # URL prefix for static files.
>> # Example: "http://example.com/static/";, "http://static.example.com/";
>> STATIC_URL = '/static/'
>>
>> # Additional locations of static files
>> STATICFILES_DIRS = (
>> # Put strings here, like "/home/html/static" or 
>> "C:/www/django/static".
>> # Always use forward slashes, even on Windows.
>> # Don't forget to use absolute paths, not relative paths.
>> )
>>
>> # List of finder classes that know how to find static files in
>> # various locations.
>> STATICFILES_FINDERS = (
>> 'django.contrib.staticfiles.finders.FileSystemFinder',
>> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
>> #'django.contrib.staticfiles.finders.DefaultStorageFinder',
>> )
>>
>> # Make this unique, and don't share it with anybody.
>> SECRET_KEY = '8c(j)m3dm!m3gd_n#vjjfqdeuq!ltsj3+xii617dos1i@_pc7*'
>>
>> # List of callables that know how to import templates from various 
>> sources.
>> TEMPLATE_LOADERS = (
>> 'django.template.loaders.filesystem.Loader',
>> 'django.template.loaders.app_directories.Loader',
>> # 'django.template.loaders.eggs.Loader',
>> )
>>
>> MIDDLEWARE_CLASSES = (
>> 'django.middleware.common.CommonMiddleware',
>> 'django.contrib.sessions.middleware.SessionMiddleware',
>> 'django.middleware.csrf.CsrfViewMiddleware',
>> 'django.contrib.auth.middleware.AuthenticationMiddleware',
>> 'django.contrib.messages.middleware.MessageMiddleware',
>> # Uncomment the next line for simple clickjac

Best practices for serving images?

2013-06-21 Thread Jacky Tian
I've got an app that serves galleries of user-uploaded photos, some of 
which can be quite large in size. I've been serving scaled thumbnails for 
most templates, but I need a higher resolutions for a detail page. These 
images will still be smaller than the size of original image, and I'm 
wondering if it's better practice to dynamically resize them server-side 
based on the width of the viewport, or to just serve the full-size images 
and scale with CSS?

Thanks
-Jacky Tian

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




Re: Best practices for serving images?

2013-06-21 Thread Some Developer

On 22/06/2013 03:33, Jacky Tian wrote:

I've got an app that serves galleries of user-uploaded photos, some of
which can be quite large in size. I've been serving scaled thumbnails
for most templates, but I need a higher resolutions for a detail page.
These images will still be smaller than the size of original image, and
I'm wondering if it's better practice to dynamically resize them
server-side based on the width of the viewport, or to just serve the
full-size images and scale with CSS?

Thanks
-Jacky Tian


Personally what I would do is the following:

When a user uploads an image create three copies of the image. A 
thumbnail, a normal sized version and a slightly larger version. This 
will leave you with 4 image files for every upload (thumbnail, normal, 
slightly larger and original) that way you can just serve the image 
files using a fast web server without having to do any server side 
processing on retrieval. Nginx is built for this sort of thing and is 
what I would recommend to serve all static content.


If you need to do any scaling on retrieval at a later date due to 
changes in how you want things to appear that you didn't necessarily 
consider when you implemented the system do it client side so that you 
don't waste server resources.


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