Victor Hooi | 1 Feb 01:01 2011
Picon

Configuration for Nginx and staticfiles

Hi,


I'm using Django 1.3 and the included staticfiles app to handle my static media, and Nginx as the webserver.

It's currently working, but I have a feeling my paths are more complex than they need to be. I was wondering if anybody could perhaps point out a better way to config this, or any improvements to the following.

My settings.py:

# Absolute path to the directory that holds static files.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/sites/example.com/static_media/static' 
# URL that handles the static files served from STATIC_ROOT.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/' 
# URL prefix for admin media -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/' 
# A list of locations of additional static files
STATICFILES_DIRS = ()
My /etc/nginx/sites-available/example.com file:
server {
  listen 80;
  server_name www.example.com;
  rewrite ^/(.*) http://example.com/$1 permanent;
}
server {
  listen 80;
  server_name example.com;
  access_log /sites/example.com/logs/access.log;
  error_log /sites/example.com/logs/error.log;
  location /static {
    root /sites/example.com/static_media;
  }
  location / {
    proxy_pass http://127.0.0.1:8000;
  }
}
My static media is collected inside of /sites/example.com/static_media/static - I'm not sure why I need two layers of static directories, but I couldn't see a way around this (although I'm undoubtedly missing something obvious here).

Also, any recommended changes to Nginx config?

Cheers,
Victor

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Karen McNeil | 1 Feb 02:22 2011
Picon

Storing *big* texts in db fields

I've created an application to manage texts, storing the content in a
TextField, along with metadata in other fields. Now that I've
completed the model and started actually adding the texts, the admin
is getting verrrry slow. The app is just for the use of me and my
team, so the slowness is not a deal-breaker, but it's annoying to work
with and I still have a lot of texts to add to the corpus.

Although I may be adding a large amount of smaller texts in the
future, the texts that I have now are large, mostly in the tens of
thousands of words, with the largest currently at 101,399 words.
(Which I know because I added a method to the model to calculate the
wordcount, and have it displayed in the admin list. Which gives me no
end of pleasure.)

So, is it a bad idea to be storing texts this large in a database
field? I really hope not, because when I first started this project
(granted, before I started using Django), I was reading the data from
files and running into constant encoding/decoding problems. (These
texts I'm collecting are in Arabic.)

If it's not a totally horrible idea to do this like I'm doing, is
there anything I can do to improve performance?  I tried implementing
caching and it didn't make any difference.

Thanks,
Karen

--

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

Scot Hacker | 1 Feb 02:23 2011
Picon

Styling help_text

This ticket

http://code.djangoproject.com/ticket/8426

says that, as of six months ago, model field help_text rendered in
forms by {{form.as_p}} gets wrapped in a style-able span. But in
Django 1.2.4, {{form.as_p}} still generates unspanned help_text. It
also doesn't show up spanned in the docs:

http://docs.djangoproject.com/en/dev/ref/forms/fields/#help-text

I'm not sure what I'm missing here. I'd really like to stop manually
creating every field in form templates just to get style-able help
text.

Any pointers? Thanks.

./s

--

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

Andre Terra | 1 Feb 02:55 2011
Picon

Re: Storing *big* texts in db fields

I'm not really experienced, but my approach would be to reference files in some open format in the DB and use python to edit open/edit/save them. Sounds leaner, cleaner, faster, imho.



Sincerely,

André Terra

On Mon, Jan 31, 2011 at 23:22, Karen McNeil <karenlmcneil <at> gmail.com> wrote:
I've created an application to manage texts, storing the content in a
TextField, along with metadata in other fields. Now that I've
completed the model and started actually adding the texts, the admin
is getting verrrry slow. The app is just for the use of me and my
team, so the slowness is not a deal-breaker, but it's annoying to work
with and I still have a lot of texts to add to the corpus.

Although I may be adding a large amount of smaller texts in the
future, the texts that I have now are large, mostly in the tens of
thousands of words, with the largest currently at 101,399 words.
(Which I know because I added a method to the model to calculate the
wordcount, and have it displayed in the admin list. Which gives me no
end of pleasure.)

So, is it a bad idea to be storing texts this large in a database
field? I really hope not, because when I first started this project
(granted, before I started using Django), I was reading the data from
files and running into constant encoding/decoding problems. (These
texts I'm collecting are in Arabic.)

If it's not a totally horrible idea to do this like I'm doing, is
there anything I can do to improve performance?  I tried implementing
caching and it didn't make any difference.

Thanks,
Karen

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Eric Chamberlain | 1 Feb 04:39 2011

Re: Storing *big* texts in db fields

Karen,

In your use case, large text fields shouldn't be a problem.  I would install the django-toolbar and use the
reporting to determine if a particular query or template is causing the slowdown.  

Are you displaying the large text field in the admin list view?  If you are and the view template is using a
table, the browser won't display the table until all the data is rendered, that could be the cause of your slowness.

On Jan 31, 2011, at 5:22 PM, Karen McNeil wrote:

> I've created an application to manage texts, storing the content in a
> TextField, along with metadata in other fields. Now that I've
> completed the model and started actually adding the texts, the admin
> is getting verrrry slow. The app is just for the use of me and my
> team, so the slowness is not a deal-breaker, but it's annoying to work
> with and I still have a lot of texts to add to the corpus.
> 
> Although I may be adding a large amount of smaller texts in the
> future, the texts that I have now are large, mostly in the tens of
> thousands of words, with the largest currently at 101,399 words.
> (Which I know because I added a method to the model to calculate the
> wordcount, and have it displayed in the admin list. Which gives me no
> end of pleasure.)
> 
> So, is it a bad idea to be storing texts this large in a database
> field? I really hope not, because when I first started this project
> (granted, before I started using Django), I was reading the data from
> files and running into constant encoding/decoding problems. (These
> texts I'm collecting are in Arabic.)
> 
> If it's not a totally horrible idea to do this like I'm doing, is
> there anything I can do to improve performance?  I tried implementing
> caching and it didn't make any difference.
> 
> Thanks,
> Karen

--
Eric Chamberlain, Founder
RF.com - http://RF.com/

--

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

Jani Tiainen | 1 Feb 06:43 2011
Picon

Re: working django with existing database

On Monday 31 January 2011 18:21:40 Ian wrote:
> On Jan 31, 3:29 am, arief nur andono <ariefnurand... <at> gmail.com> wrote:
> > oh please...
> > 
> > i need only to query the table, have no access to modified the table
> > 
> > why there is no way query the database and then make the output as
> > object??
> 
> You don't need to modify the table.  That was just a recommendation.
> I also suggested changing the precision (max_digits) and scale
> (decimal_places) in your models file to match what is actually used in
> your data.  If you have no idea what to use, then
> DecimalField(max_digits=38, decimal_places=19) is *probably* safe.
> 
> If updating the models is going to be too laborious, then you should
> probably look at a different ORM.  I don't know whether SQLAlchemy
> will do a better job introspecting your database, but it's worth a
> shot and can be used in conjunction with TurboGears or Pylons.
> 
> Cheers,
> Ian

In the past I used MyGeneration 
<http://sourceforge.net/projects/mygeneration/> to generate models for me.

It's pretty neat ORM template mapper (Not bound to any particular ORM).

I'm not sure does it run under Mono or Linux but. But it did very good job to 
produce output like I wanted with a little effort.

-- 

Jani Tiainen

--

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

Orgil | 1 Feb 06:52 2011
Picon

Re: pyodbc & FreeTDS: Can I work with NVARCHAR column on MSSQL2008

> Hi,
> I have expirience with pymssql and mssql server, and that works fine
> (utf-8).
> Did You try utf-8?

I think that I have tried pymssql using charsets including utf-8,
utf-16, iso-****.
But I have no luck there. I can not get unicode datas. Also, I have
read that pymssql does not support unicode. This news made me find
other libraries and I found pyodbc. But still I have no luck. Unicode
turns ? sign always.
Now I am at a corner, I'm stuck!!!!

If you succeeded with pymssql and unicode data, please suggest me how
to do so!
Please help me to get out from this terrible corner!

My code which uses pymssql is here:
        import _mssql
        conn = _mssql.connect(server='10.0.0.61\mssql2008',
user='erp', password='123', database='eoffice_clone',
charset='utf-16')
        conn.execute_query('SELECT cc_Name FROM tblHR_CodeClass')
        for line in conn:
            print 'cc_Name: %s' % (line['cc_Name'])
            break
        conn.close()

regards,
Orgil

--

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

Ivo Brodien | 1 Feb 07:34 2011
Picon

Re: ImportError importing forms.py into models.py

if you have circular imports, you can try to put the name of the model. This at least works for Foreign Keys

http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

On 01.02.2011, at 00:34, Jeffrey Stiles wrote:

> I would really like to make a form instance a model attribute so that
> i have access to the form from the template through an object that I
> have handy.
> 
> When I try to import import any form into models.py, I get an
> ImportError on each of the import statements in the forms.py file
> which reference a model in models.py. I'm assuming this is due to
> circular imports.
> 
> I can't seem to find any information on importing forms into models.
> Is this possible? If so, how?
> 
> -- 
> 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 <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Jani Tiainen | 1 Feb 08:01 2011
Picon

Re: mis-named setting? SESSION_EXPIRE_AT_BROWSER_CLOSE

On Monday 31 January 2011 18:38:20 Tim Sawyer wrote:
> > You can't stop the user from closing the browser, or switching to another
> > tab, with JS. And you shouldn't try to stop them navigating away - this
> > sort of thing is only likely to annoy them intensely.
> 
> Taking this to the extreme - what do you want to happen if a person using
> your site has a powercut?  Or pulls out their network connection?  This
> will not run any site-close javascript.
> 
> We had a designer request similar functionality in a Struts app years ago
> - it's really annoying and goes wrong often and we vowed never to do it
> again.
> 
> How about looking at RabbitMQ or XMPP for presence?
> 
> Tim.

This is known as hartbeat pattern. Sending small message from a client to a 
server stating "i'm alive".

That way you can have rather small window (still it's a window, not exact 
time) to determine is someone logged in or not. Note that you still need 
something to determine if heartbeats stopped to come in. So it's you need 
additional tests is time between two heartbeats too much, and then do forced 
logout.

Now you can have feature that can tell "active users within last X minutes" 
quite easily.

-- 

Jani Tiainen

--

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

Adnan Sadzak | 1 Feb 08:23 2011
Picon

Re: pyodbc & FreeTDS: Can I work with NVARCHAR column on MSSQL2008

This is how Your FreeTDS config should look like:
;----------------------
[mssql2008]
    host = 10.0.0.61
    port = 1433
    tds version = 7.0
;----------------------


Here is the code with pymssql:
#----------------------
import pymssql
conn = pymssql.connect(host='mssql2008', user='erp', password='123', database='eoffice_clone', charset = "utf8")
cur = conn.cursor()
cur.execute('SELECT cc_Name FROM tblHR_CodeClass')
for row in cur:
    print 'cc_Name: %s' % (row[0])
conn.close()
#----------------------

Also if You print this to linux console check terminal character encoding (sould be UTF-8 too)!

Cheers,
Adnan

On Tue, Feb 1, 2011 at 6:52 AM, Orgil <orgilhp <at> gmail.com> wrote:
> Hi,
> I have expirience with pymssql and mssql server, and that works fine
> (utf-8).
> Did You try utf-8?

I think that I have tried pymssql using charsets including utf-8,
utf-16, iso-****.
But I have no luck there. I can not get unicode datas. Also, I have
read that pymssql does not support unicode. This news made me find
other libraries and I found pyodbc. But still I have no luck. Unicode
turns ? sign always.
Now I am at a corner, I'm stuck!!!!

If you succeeded with pymssql and unicode data, please suggest me how
to do so!
Please help me to get out from this terrible corner!

My code which uses pymssql is here:
       import _mssql
       conn = _mssql.connect(server='10.0.0.61\mssql2008',
user='erp', password='123', database='eoffice_clone',
charset='utf-16')
       conn.execute_query('SELECT cc_Name FROM tblHR_CodeClass')
       for line in conn:
           print 'cc_Name: %s' % (line['cc_Name'])
           break
       conn.close()

regards,
Orgil

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

Gmane