Initial data in 1.7

2014-07-21 Thread Tomas Ehrlich
Hi there,
as pointed in documentation [1], automatic loading of initial data from
initial_data.[xml/yaml/json] is deprecated since 1.7 in favor of data
migrations.

However, there are several drawbacks and differencies:

  1. Data migration is executed only once (unless migrations are
 rewinded to the beginning), while initial_data were loaded
 everytime with syncdb command.

 Former behavior ensures that the right data are present in table.
 Of course it can be used with data which doesn't change often
 (like sites).

  2. It's not straightforward to provide initial data to existing or
 third-party apps. One have to create custom app to store migrations
 (like 'initial_data') and then create *empty* models.py in app
 directory. Otherwise migrations won't be loaded, as already pointed
 in [2].

What's the correct way to provide initial data to apps which needs to be
present everytime, otherwise website won't work (like sites, auth
token, superadmins, etc.)?

Have anyone solved this issue recently in Django 1.7?


Thanks,
   Tom

[1] 
https://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures
[2] 
https://groups.google.com/d/msgid/django-users/20140715142108.GA10827%40rkade-thinkpad

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


Re: Creating a list off a model based on time delta

2014-07-20 Thread Tomas Ehrlich
Use __gte lookup:

latest_articles_list = Article.objects.filter(pub_date__gte=thirty_days_ago)

and take a look at other lookups:
https://docs.djangoproject.com/en/1.6/ref/models/querysets/#field-lookups

Cheers,
  Tom

Dne Sun, 20 Jul 2014 20:50:53 -0700 (PDT)
Conner DiPaolo  napsal(a):

> I've been thinking about it and I think this should work but it doesn't.
> 
> latest_articles_list = Article.objects.filter(pub_date>=thirty_days_ago)
> 
> Django is saying 'pub_date' is not defined, even though I used it to filter 
> a different list and it worked fine. What is wrong??
> Thanks
> 
> 
> On Sunday, July 20, 2014 8:16:21 PM UTC-7, Conner DiPaolo wrote:
> >
> > Hi!
> > I was wondering if anybody knew how to create a list based on that list 
> > having a DateTime attribute that is less than 30 days old. I already have a 
> > boolean in the model itself of 'published_recent_month' that can say if it 
> > is or is not published within a month, but how do I put into that a list to 
> > put into a template? I know how to do a list based on pub_date and have it 
> > be a certain length, but I would rather have the list be dynamic to usage.
> >
> > Thanks a lot!
> >
> >
> > abbreviated model to show the boolean definition I have:
> > class Model(models.Model):
> >...
> >def published_recent_month(self):
> > return self.pub_date >= timezone.localtime(timezone.now()) - 
> > datetime.timedelta(days=30)
> >
> > abbreviated  view using what I already know:
> > def index(request):
> >...
> >latest_25_list =Model.objects.order_by('-pub_date')[:25]
> >
> >
> >
> 

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


Re: Question about moving code to product from local or development server.

2014-06-10 Thread Tomas Ehrlich
Hi there,
since all have already mentioned Fabric, take a look at Ansible which
is a bit more sophisticated tool, but can be used efficiently even for
small setups.

Depends on your requirements, you can create simple "deployment"
playbook, which just takes your code, push it to the server, update
database, static files (and/or locales) and restarts wsgi. However,
if you need to setup whole server, Ansible is perfect tool for that.
But that would be beyond the scope of this question.


Cheers,
  Tom

Dne Sat, 7 Jun 2014 16:50:58 -0400
Chen Xu  napsal(a):

> I am building a django website, and wondering what is an easy way to move
> all of my code to production, is there a tool for doing that, or maybe
> write my own script?
> 
> 
> Thanks
> 


signature.asc
Description: PGP signature


Re: Programatically reverse an url to other language

2014-05-15 Thread Tomas Ehrlich
Hi,
use ugettext_lazy for translation of urls, models and other stuff which
is loaded before language is determined (it's usually done in
Middleware or later in view, otherwise all strings will be translated
into default language).

You can also write:

  url(_(r'^about$'), views.about, name='about'),

which is easier to read and you can see in your .po file, that you are
translating url.


Cheers,
  Tom


Dne Thu, 15 May 2014 11:24:41 -0700 (PDT)
Jorge Cardoso Leitão  napsal(a):

> Hi. 
> 
> I'm trying to reverse urls to other languages and I'm having some 
> difficulties:
> 
> Consider a new project in python 3.3 Django 1.6.4 with the adittional 
> settings
> 
>   LOCALE_PATHS = (BASE_DIR + '/locale',)
> 
> LANGUAGE_CODE = 'en-us'
> LANGUAGES = (
> ('en-us', 'English'),
> ('de', 'German'),
> )
> 
> 
> The following views.py:
> 
> def home(request):
> from django.utils import translation
> from django.utils.translation import ugettext as _
> 
>  
> 
> translation.activate('de')
> print(reverse("about"))
> print(_('search'))
> 
>   render(request, 'home.html') 
> 
>   def about(request):
>   render(request, 'about.html')
> 
> and the following urls.py:
> 
> urlpatterns = patterns('',
>url(r'^$', views.home, name='home'),
>url(r'^%s$' % _('about'), views.about, name='about'),
> 
> 
> After running make_messages, translate the strings in .po, compile_messages 
> and restart the server,
> going to / prints the following in the console:
> 
> >> /about
> 
> >> [translation of "search"]
> 
> 
> I.e. even though "about" is translatable, it is not being translated; my 
> objective is to have 
> it translated to a german url.
> 
> I tried going as far as using 
> 
> from django.conf import settings
> urlconf = settings.ROOT_URLCONF
> resolver = RegexURLResolver(r'^/', urlconf)
> 
> print(resolver._reverse_with_prefix(about, '/'))
> 
> or even
> 
> temp = __import__(urlconf, globals(), locals(), [], 0)
> print(getattr(temp.urls, "urlpatterns"))
> 
> but they are all giving me the untranslated url.
> 
> I digged into the core.urlresolvers.py, and it RegexURLPattern.regex is 
> always returning the en-us pattern, even when the language_code is 'de'.
> 
> I then went to see why, and it seems the urls.py are always being imported 
> in the en version, even after the translation.activate('de') call.
> 
> Does anyone know if this is the intended behavior, or if there a way to 
> change it?
> 
> Thanks a lot,
> Jorge
> 


signature.asc
Description: PGP signature


Deployment of django project using setuptools

2014-05-02 Thread Tomas Ehrlich
Hi there,
when I deploy my django projects I always run several commands after
pulling latest code from repository. I've started using setup.py few
weeks ago which adds manage.py script into $VENV/bin.

Basicaly, I always do:

source $VENV/bin/activate
export DJANGO_SETTINGS_MODULE=...

git pull
python setup.py install
manage.py syncdb --noinput
manage.py migrate
manage.py collectstatic --noinput
manage.py compilemessages


I wrote deployment scripts in fabric, salt, ansible, but now I'm
thinking that all these 'manage.py' actions should be part of setup
script. Anytime when would I run ``python setup.py install``
the setup script would run all defined management commands so my
environment, database and other stuff stays up to date.


I've found that install command can be extended:

http://www.niteoweb.com/blog/setuptools-run-custom-code-during-install

I haven't found any references that anyone have used this method to
deploy django project, so I'm looking for anyone who tried this
approach before.


Thanks in advance

Cheers,
   Tom


signature.asc
Description: PGP signature


Re: Streaming images with HttpResponse?

2013-11-15 Thread Tomas Ehrlich
Hi there,
I don't know if it's relevant, I've never used it, but the name sounds 
promising:

StreamingHttpResponse
https://docs.djangoproject.com/en/dev/ref/request-response/#streaminghttpresponse-objects

Cheers,
  Tom

Dne Fri, 15 Nov 2013 12:53:23 -0500
Javier Guerra Giraldez  napsal(a):

> On Fri, Nov 15, 2013 at 12:08 PM, Jorge Cardoso Leitão
>  wrote:
> > I believe that is not possible with Django views. Views are made for
> > request-response, i.e. the client sends a request, the view returns a
> > response, and that's it, end of connection.
> 
> 
> i think the WSGI standard does support it, by setting a generator
> instead of a string value as the response content.
> 
> the generator is a function that yield()s more content each time, so
> the HTTP response becomes a stream of data.
> 
> but i think you're right that Django doesn't support it.
> 


signature.asc
Description: PGP signature


Re: django debugger

2013-11-05 Thread Tomas Ehrlich
Hi Harjot,
try https://github.com/Kozea/wdb if you want debugger like pdb
or simple https://github.com/django-debug-toolbar/django-debug-toolbar
which provides lots of useful informations.

Unfortunately, I don't use pdb nor wdb, so I can't help you with any of them.


Cheers,
  Tom

Dne Tue, 5 Nov 2013 23:59:28 +0530
Harjot Mann  napsal(a):

> I want to know that how can we debug django applications?
> I got pdb but I think in this some commands are need to use and then I
> come to know about pycharm.
> Is it good?
> I successfully installed it but dont' know how to use it?
> Anyone please help me..


signature.asc
Description: PGP signature


Re: Django Templates: Using the "with" statement and "block.super" together

2013-09-24 Thread Tomas Ehrlich
I use it too.

Maybe it would be nice to document it somewhere.


Cheers,
  Tom


Dne Tue, 24 Sep 2013 10:59:27 -0700 (PDT)
Warren Smith  napsal(a):

> On occasion, I've used the following technique in my django templates:
> 
> # parent.html 
> 
> {% block someblock %}
> …stuff…
>   {% if cool_optional_feature_is_enabled %}
> …optional stuff...
>   {% endif %}
> …stuff...
> {% endblock %}
> 
> 
> # child.html
> {% extends "parent.html" %}
> 
> {% block someblock %}
>   {% with True as cool_optional_feature_is_enabled %}
> {{ block.super }}
>   {% endwith %}
> {% endblock %}
> 
> 
> The cool thing is that this technique allows a child template to 
> essentially enable a feature in the parent template. The same technique can 
> also be used to disable a feature in the parent template, or really 
> anything that can be driven from a context variable, since, as I understand 
> it, that is what the with statement is doing: temporarily injecting a 
> variable into the context within which the expressions in a chunk of 
> template code are evaluated against.
> 
> I was showing this to a colleague today and, though he thought it was neat, 
> he had never seen it before and was concerned that it was not a mainstream 
> use of the django template language. I did some cursory google searches and 
> couldn't find any overt references to this ability either.
> 
> My concern is that I may be relying on some undocumented side-effect of the 
> way that blocks or the with statement are implemented and that, at some 
> point in the future, this will be changed and all of my templates that use 
> this will break.
>  
> 


signature.asc
Description: PGP signature


Re: djangojobs.com

2013-09-20 Thread Tomas Ehrlich
I wonder if licence agreement applies for this case, since domain was
clearly bought before Django project finished it's trademark policy.


Dne Fri, 20 Sep 2013 08:23:27 -0400
Karen Tracey  napsal(a):

> Please note any use of djangojobs.com domain would need to conform to the
> Django trademark license agreement:
> 
> https://www.djangoproject.com/trademarks/
> 


signature.asc
Description: PGP signature


Re: db queries made twice

2013-08-31 Thread Tomas Ehrlich
Hi,
disable Template panel in debug_toolbar and try again.

Debug toolbar hits database when evaluating template context.


Cheers,
   Tom

Dne Sat, 31 Aug 2013 12:09:00 +0100
Marcin Szamotulski  napsal(a):

> Hello,
> 
> I am using django-1.6.b2 on a localserver (./manage.py runserver) and
> for every request I have the chain of db lookups made twice.  For
> example my log looks something like this (after enabling
> django.db.backands logger):
> 
> # HERE VIEW IS CALLED
> (0.001) SELECT "django_session"."session_key", 
> "django_session"."session_data", "django_session"."expire_date" FROM 
> "django_session" WHERE ("django_session"."session_key" = 
> '2dh8ly6cfqkyiauv8co5h1vossjg70ru'  AND "django_session"."expire_date" > 
> '2013-08-31 11:04:33.597734+00:00' ); 
> args=('2dh8ly6cfqkyiauv8co5h1vossjg70ru', u'2013-08-31 11:04:33.597734+00:00')
> (0.001) SELECT "auth_user"."id", "auth_user"."password", 
> "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", 
> "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", 
> "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" 
> FROM "auth_user" WHERE "auth_user"."id" = 1 ; args=(1,)
> 
> #... (AND SO ON)
> 
> # HERE VIEW CALL IS FINISHED
> [31/Aug/2013 12:04:33] "GET /coot/ HTTP/1.1" 200 220974
> [31/Aug/2013 12:04:34] "GET /site_media/static/css/style.css HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/js/jquery.js HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/js/jquery-ui.js HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/js/posts.js HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/js/confirm.js HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/css/posts.css HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET 
> /site_media/static/debug_toolbar/css/toolbar.min.css HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET 
> /site_media/static/debug_toolbar/js/toolbar.min.js HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/pics/django_logo.png HTTP/1.1" 
> 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/pics/python_logo.png HTTP/1.1" 
> 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/css/whitey.png HTTP/1.1" 304 0
> [31/Aug/2013 12:04:34] "GET /site_media/static/css/stressed_linen.png 
> HTTP/1.1" 304  
> 
> # DB LOOKUPS ONCE AGAIN:
> (0.001) SELECT "django_session"."session_key", 
> "django_session"."session_data", "django_session"."expire_date" FROM 
> "django_session" WHERE ("django_session"."session_key" = 
> '2dh8ly6cfqkyiauv8co5h1vossjg70ru'  AND "django_session"."expire_date" > 
> '2013-08-31 11:04:33.597734+00:00' ); 
> args=('2dh8ly6cfqkyiauv8co5h1vossjg70ru', u'2013-08-31 11:04:33.597734+00:00')
> (0.001) SELECT "auth_user"."id", "auth_user"."password", 
> "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", 
> "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", 
> "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" 
> FROM "auth_user" WHERE "auth_user"."id" = 1 ; args=(1,)
> 
> ... (AND SO ON)
> 
> 
> any ideas why?
> 
> The views (as it is not just one) returns using render().  This also
> happens when using DetailedView cbv.
> 
> I also setup looking on postgres (which I use) and indeed the queries
> are made twice.
> 
> Thanks for ideas,
> Marcin
> 


signature.asc
Description: PGP signature


Re: Does Model.save() write back all the field values?

2013-08-14 Thread Tomas Ehrlich
Hi,
I apologize for possible off-topic, but since Jacob already answered
your question, please allow me to add another hint:

Book.objects.filter(published=False).update(published=True)

would do the same in single query, updating "published" field only (even in 
<1.5).


Cheers,
  Tom


Dne Wed, 14 Aug 2013 10:17:04 -0500
Jacob Kaplan-Moss  napsal(a):

> It's not a bug; that is by design.
> 
> However, it's not perfect, so in 1.5 we added update_fields:
> https://docs.djangoproject.com/en/1.5/ref/models/instances/#specifying-which-fields-to-save
> 
> Jacob
> 
> 
> On Wed, Aug 14, 2013 at 7:01 AM, Dong Wang  wrote:
> 
> > Hi all,
> >
> > I'm using Django 1.4.2. Please let me start my question by an example:
> >
> > books = Book.objects.filter(published=False)
> > for book in books:
> >  book.published=True
> > book.save()
> >
> > I would think this small snippet of code will only update the "published"
> > field, but actually it write all the cached field values back to the
> > database.
> >
> > Is it a bug or designed to be this way?
> >
> > Thanks
> > --
> > Dong Wang
> >
> >  --
> > 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.
> >
> 


signature.asc
Description: PGP signature


Re: SESSION_COOKIE_DOMAIN on multiple domains.

2013-08-01 Thread Tomas Ehrlich
Ah, sorry, I understand now.

You can set up middleware, which modifies SESSION_COOKIE_DOMAIN based
on request.get_host() and put it before session middleware. I did
similar thing to set SITE_ID.

Only think you have to take care of is thread safety. You need to
override settings.SESSION_COOKIE_DOMAIN value with thread safe object,
and assign value to it.

Take a look at:
https://bitbucket.org/uysrc/django-dynamicsites/src/e3c6cad807f0328ed3020d28158b3d6ba0b67025/dynamicsites/middleware.py?at=default
https://bitbucket.org/uysrc/django-dynamicsites/src/e3c6cad807f0328ed3020d28158b3d6ba0b67025/dynamicsites/utils.py?at=default

I took that idea there.


Cheers,
  Tom

Dne Thu, 1 Aug 2013 08:40:18 -0700 (PDT)
"J. Cliff Dyer"  napsal(a):

> That doesn't make my use case impossible.  I'm not looking for a session 
> that works on both domains.  I'm looking for a site that can create 
> sessions for either domain.
> 
> On Thursday, August 1, 2013 11:10:59 AM UTC-4, Tomáš Ehrlich wrote:
> >
> > This isn't possible. The problem is with cookies: You have to bind them 
> > to certain domain ('example.com') or set of subdomains ('.example.com'). 
> >
> > About a month ago I've created app to bypass this limitation: 
> >
> > - There is one "master" domain, where new session keys are created. 
> > - When user access any of "slave" sites, his browser has to go through 
> >   several redirects: 
> > 
> >   1. First, it's redirected to "master" site. There he gets token 
> >  representing current session key. 
> >   2. Then it's redirected back to "slave" site, where django sets 
> >  appropriate cookie with session key (extracted from token). 
> >   3. After then, it's redirected back to original page (on slave site). 
> >  Session cookie is set so user can access the same session as on 
> >  master site. 
> >
> > - Cookie needs to be set only once. When session (on any site) is 
> >   invalid, the other sites will notice that and automatically generates 
> >   new session key. 
> >
> > Another solution I've seen was distributing session key through 
> > iframes, but when you have lot of domains, it's easier to do it this 
> > way. 
> >
> > I could share the code, if you were interested. It isn't published 
> > anywhere yet. 
> >
> >
> > Cheers, 
> >   Tom 
> >
> > Dne Thu, 1 Aug 2013 06:41:20 -0700 (PDT) 
> > "J. Cliff Dyer" > napsal(a): 
> >
> > > Is there a way to set the SESSION_COOKIE_DOMAIN for multiple domains, 
> > > possibly using the contrib.sites framework? 
> > > 
> > > We deploy on AWS, and when we roll out an update to one of our site, we 
> > > first create a new cloudformation stack, and attach a domain name to it 
> > > like prod-oursite-20130801.devstacks.net. 
> > > 
> > > When we decide it's ready for production, we point www.oursite.com to 
> > the 
> > > stack.  This causes problems with the SESSION_COOKIE_DOMAIN, as we need 
> > to 
> > > have the cookies domain set to .oursite.com if someone is visiting from 
> > > www.oursite.com (or fl.oursite.com, or wa.oursite.com, etc, etc.), but 
> > if 
> > > they are visiting from prod-oursite-20130801.devstacks.net, we want to 
> > > either set the SESSION_COOKIE_DOMAIN to 
> > > prod-oursite-20130801.devstacks.net, or unset it altogether, and just 
> > use 
> > > the default session domain. 
> > > 
> > > I would love if SESSION_COOKIE_DOMAIN could be set to a dictionary, like 
> > > this: 
> > > 
> > > SESSION_COOKIE_DOMAIN = { 
> > > 'www.oursite.com': '.oursite.com', 
> > > 'prod-oursite-20130801.devstacks.net': '.devstacks.net', 
> > > } 
> > > 
> > > but it doesn't seem like that's possible. 
> > > 
> > > 
> >
> 


signature.asc
Description: PGP signature


Re: SESSION_COOKIE_DOMAIN on multiple domains.

2013-08-01 Thread Tomas Ehrlich
This isn't possible. The problem is with cookies: You have to bind them
to certain domain ('example.com') or set of subdomains ('.example.com').

About a month ago I've created app to bypass this limitation:

- There is one "master" domain, where new session keys are created.
- When user access any of "slave" sites, his browser has to go through
  several redirects:
   
  1. First, it's redirected to "master" site. There he gets token
 representing current session key.
  2. Then it's redirected back to "slave" site, where django sets
 appropriate cookie with session key (extracted from token).
  3. After then, it's redirected back to original page (on slave site).
 Session cookie is set so user can access the same session as on
 master site.

- Cookie needs to be set only once. When session (on any site) is
  invalid, the other sites will notice that and automatically generates
  new session key.

Another solution I've seen was distributing session key through
iframes, but when you have lot of domains, it's easier to do it this
way.

I could share the code, if you were interested. It isn't published
anywhere yet.


Cheers,
  Tom

Dne Thu, 1 Aug 2013 06:41:20 -0700 (PDT)
"J. Cliff Dyer"  napsal(a):

> Is there a way to set the SESSION_COOKIE_DOMAIN for multiple domains, 
> possibly using the contrib.sites framework?
> 
> We deploy on AWS, and when we roll out an update to one of our site, we 
> first create a new cloudformation stack, and attach a domain name to it 
> like prod-oursite-20130801.devstacks.net.
> 
> When we decide it's ready for production, we point www.oursite.com to the 
> stack.  This causes problems with the SESSION_COOKIE_DOMAIN, as we need to 
> have the cookies domain set to .oursite.com if someone is visiting from 
> www.oursite.com (or fl.oursite.com, or wa.oursite.com, etc, etc.), but if 
> they are visiting from prod-oursite-20130801.devstacks.net, we want to 
> either set the SESSION_COOKIE_DOMAIN to 
> prod-oursite-20130801.devstacks.net, or unset it altogether, and just use 
> the default session domain.
> 
> I would love if SESSION_COOKIE_DOMAIN could be set to a dictionary, like 
> this:
> 
> SESSION_COOKIE_DOMAIN = {
> 'www.oursite.com': '.oursite.com',
> 'prod-oursite-20130801.devstacks.net': '.devstacks.net',
> }
> 
> but it doesn't seem like that's possible.
> 
> 


signature.asc
Description: PGP signature


Django/Python based webmail

2013-07-29 Thread Tomas Ehrlich
Hi there,
I'm looking for django (or python) based webmail, similar to RoundCube
and SquirrelMail.

I tried djangopackages.com and google search, but it doesn't seem to be
an alive project out there. How you ever wondered why? :) Seems to me
like useful app.

Thanks in advance


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: django statics

2013-07-15 Thread Tomas Ehrlich
Hi there,
first, there's a difference between MEDIA files and STATIC files (since
1.3, I think). Media files are files uploaded by users, while static
files are usually persistent files on the server from the beginning,
eg. stylesheets, images, javascripts, robots.txt, etc.

It's good to keep these files separated, since static files are usualy
in VCS, while media files not.


As others said, it's convinient to use {{ MEDIA_URL }} and
{{ STATIC_URL }} variables in your templates. Just don't forget to use
RequestContext with proper context processor while rendering template:
https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-static


Django should't server static/media files in production. They should be
served using your http server (nginx, apache, ...). In development,
however, you can add static files handler to your urls:

# your_project/urls.py
from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
... # your url patterns
)

# Serve static and media files in development
from django.conf import settings
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
media = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = (media + staticfiles_urlpatterns() + urlpatterns)


Cheers,
  Tom


Dne Mon, 15 Jul 2013 17:54:24 +0800
Phang Mulianto  napsal(a):

> Hi,
> 
> Better not use hard coded url path for static, use {{ STATIC_URL }} in your
> link ;
> eg : 
> 
> 
> 
> 
> On Mon, Jul 15, 2013 at 7:28 AM, Sébastien Billion <
> sebastien.bill...@gmail.com> wrote:
> 
> > Hi,
> >
> > In your project folder, you can create a folder media zith a subfolder
> > css, an other img, js, whatever.
> > In your settings.py, you can use this line to get the absolute path
> > dynamically:
> >
> > from os import path
> > PROJECT_ROOT = path.dirname(path.abspath(__file__))
> >
> > After, you need to specify your MEDIA_ROOT and MEDIA_URL
> >
> >
> > MEDIA_ROOT = path.join(PROJECT_ROOT,'media')
> >
> > MEDIA_URL = '/media/'
> >
> > In your template, if you want to get your css or your js, img, etc... you
> > just need to do
> > 
> >
> > Regards,
> > Seb
> >
> >
> > 2013/7/15 Kakar Arunachal Service 
> >
> >> Hello,
> >> I read the django docs, but my still confused. How do i use the static
> >> files, for css?
> >> Thank you.
> >>
> >> --
> >> 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: redirct page

2013-07-06 Thread Tomas Ehrlich
Hi there,
you're certaily missing {% csfr_token %} in your form.

If it doesn't solve the problem, you need to provide more info and be more 
specific about your "trouble".

Dne Sat, 6 Jul 2013 17:44:04 +0530
Kakar Arunachal Service  napsal(a):

> Hi,
> I am having trouble with redirecting the login page to index page. Please
> guide me.
> 
> Here's the html snippet:
> 
> User Login
> {% if form.errors %}
> Your username and password didn't match.
> Please try again.
> {% endif %}
> 
> Username:{{ form.username
> }}
> Password:{{ form.password
> }}
> 
> 
> 
> 
> 
> Thanks.
> 

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




Namespace URLs in TestCase

2013-07-04 Thread Tomas Ehrlich
Hi there,
it's probably silly bug, but I can't figure it out:


I have one test:
###
# app/tests_functional/test_app.py
from django.core.urlresolvers import reverse
from django.test import TestCase

class TestApp(TestCase):
urls = 'app.tests_functional.urls'

def test_app(self):
print(reverse('app:get'), reverse('app:retrieve'))
self.fail()


where urls are defined:
###
# apps/tests_functional/urls.py
from django.conf.urls import patterns, url, include

# I use class-based views, which are tested and works.
def view(request): pass  

app_patterns = patterns('',
url(r'^get/$', view, name='get'),
url(r'^retrieve/$', view, name='retrieve'))

urlpatterns = patterns('',
url(r'^sso/$', include(app_patterns, 'app', 'app')))


Now, when I run tests, I got Exception:
NoReverseMatch: Reverse for 'get' with arguments '()' and keyword
arguments '{}' not found.


I tried to rename app_patterns to urlpatterns and reverse('get'). It
works, but my app uses namespaced urls, so I can't change code of view
to test it that way.

I believe it's really silly think. Can you see it?


Thank you :)

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: Form validation vs. DRY

2013-07-03 Thread Tomas Ehrlich
Hi Roman,
you can use model validation
https://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects

It works similar to form validation. After, when you create ModelForm,
it will take validation rules from model.

All these validations should be called outside save()


Cheers,
  Tom

Dne Wed, 3 Jul 2013 10:21:51 +0200
Roman Klesel  napsal(a):

> Hello,
> 
> I'm programming a database front end. In many cases I want to
> constrain the data written to the database. Therefore I implement some
> checks either through real database constraints or trough some logic
> in the model, so it will throw an exception when the constraints are
> not met.
> 
> e.g.: unique constraint on a database column.
> 
> Now, when I write my form validation, I have to implement the same
> logic again, since form validation takes place before a save() is even
> considered. Like this:
> 
> >>> if form.is_valid():
> >>>form.save()
> 
> Is there a better way to do it? Is there a good way to avoid this
> duplicate logic?
> 
> Regards
>   Roman
> 

-- 
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: Customize the admin look and feel

2013-06-27 Thread Tomas Ehrlich
Hi there,
please try:

TEMPLATE_DIRS = (
"C:/xampp/htdocs/mytemplates/"
)

After all, it's TEMPLATE_DIRS not TEMPLATE_FILES. It should contain
directories with templates.

Cheers,
  Tom


Dne Thu, 27 Jun 2013 09:46:40 -0700 (PDT)
krazyXplorer <1.kc.d...@gmail.com> napsal(a):

> I am new to Django and got stuck at 
> Tutorial 2 - Customize the admin look and feel
> 
> 
> When I directly went into *
> C:\Python27\Lib\site-packages\django\contrib\admin\templates\admin\base_site.html
> * and made changes in *base_site.html* there was no problem and I didn't 
> even had to edit the *TEMPLATE_DIRS (...)*
> 
> 
> But When I copy the *base_site.html* into *C:\xampp\htdocs\mytemplates\admin
> * and edit *TEMPLATE_DIRS (...)*  to
> 
> TEMPLATE_DIRS = (
> "C:/xampp/htdocs/mytemplates/admin/base_site.html"
> # Always use forward slashes, even on Windows.
> # Don't forget to use absolute paths, not relative paths.
> )*
> *
> 
> *There was no Change in admin look 
> *
> 
> *Please help ..what am I doing wrong ??
> *
> 

-- 
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: Sharing session among multiple domains (generic web development question)

2013-06-12 Thread Tomas Ehrlich
Hi Tom,
that's interesting approach. I'm going to use it and publish code later.


Thank you!

Cheers, 
  Tom


PS: The key is the name of problem:) SSO

https://github.com/ojii/django-simple-sso
https://github.com/bltravis/django-token-sso

Dne Wed, 12 Jun 2013 10:30:43 +0100
Tom Evans  napsal(a):

> 
> You could do poor man's SSO, which would be similar to your
> /sess/ idea.
> 
> Basically, only one of your websites can create a new empty session -
> we'll call this the master. If you get a client visit one of your
> websites, and they do not have a session on that website, you redirect
> them to the master website, with a parameter indicating the source
> website.
> 
> If they already have a session on the master website, you simply
> redirect them to the source website with a token indicating their
> (existing) session id.
> Otherwise, you create a new session on the master website, and
> redirect them back to the source website, again with a token.
> 
> When the user returns to the source website, extract the session id
> from the token, and set the appropriate cookies so that they are using
> that as their session.
> 
> Because the session id is hidden behind an opaque token during
> transfer, there can be no fixation attacks. Delete the token
> immediately after consumption, and you minimise replay attacks.
> 
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Model inheritance, implicit OneToOneField and stray inherited reverse relations

2013-06-12 Thread Tomas Ehrlich
Hi Benjamin,
you can create explicit OneToOne field with parent_link=True
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.OneToOneField.parent_link

Then you can set different related_name for each model.


Cheers,
  Tom


Dne Wed, 12 Jun 2013 01:10:40 -0700 (PDT)
Benjamin  Wohlwend  napsal(a):

> Hi,
> 
> I have a bit of a problem with inherited reverse relations and django model 
> inheritance. Consider these models:
> 
> 
> class Content(models.Model):
> display = models.BooleanField()
> 
> 
> class Link(Content):
> url = models.URLField()
> 
> 
> class Teaser(Content):
> text = models.TextField()
> link = models.URLField()
> 
> 
> As we all know, Django uses an implicit OneToOneField for model 
> inheritance. This OneToOneField generates accessors for the reverse 
> relation, which in this case means that objects of the type Content will 
> have a "link" and a "teaser" attribute to access the other side of the 
> one-to-one relation. These attributes are, of course, inherited to the 
> Content subclasses, meaning that Link and Teaser also will have those 
> accessors. But wait, Teaser already defines a link attribute! We got 
> ourselves a nice little name clash.
> 
> While it's perfectly according to the rules of inheritance for Link and 
> Teaser to inherit the "link" and "teaser" reverse relations accessors, it 
> is also a bit nonsensical in this case. As far as I can tell, it's not 
> possible to suppress the creation of these accessors when defining the 
> model inheritance. Any ideas how to get around this (other than "just 
> rename the link attribute in Teaser, silly!")?
> 
> Benjamin
> 
> P.S.: the real use case here is django CMS, with its content plugins all 
> inheriting from a CMSPlugin base class. Since there are e.g. subclasses 
> called Text, Link, and Picture, it's not possible to use field names called 
> "text", "link", or "picture" in a CMSPlugin subclass, which is frustrating 
> and hard to explain to our users.
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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




Re: Sharing session among multiple domains (generic web development question)

2013-06-11 Thread Tomas Ehrlich
Hi Marcin,
unfortunately it doesn't solve the problem. As it's said in document:

Just like the secret keys, the SESSION_COOKIE_DOMAIN setting from
OldWebsite.com  and NewWebsite.com must match if you want 
to share sessions.

... but that's possible only when you share sessions in subdomains (eg.
SESSION_COOKIE_DOMAIN = '.domain.td' and your sites are
at sub1.domain.td, sub2.domain.td, etc.)


Database routing is interesting, but I have one database, one website,
which is accessed from multiple domains. The problem isn't tied to
Django nor Python, it's simply limitation of cookies.


Thanky your anyway


Cheers,
  Tom



Dne Tue, 11 Jun 2013 14:03:13 +
Marcin Szamotulski  napsal(a):

> Hi,
> 
> If you use db backend for sessions you could save the session in both
> databases.  Check this:
> http://dustinfarris.com/2012/2/sharing-django-users-and-sessions-across-projects/
> I hope this helps.
> 
> Best regards,
> Marcin
> 
> On 14:22 Tue 11 Jun , Tomas Ehrlich wrote:
> > Hi Avraham,
> > I know that cookies can be shared among subdomains, but my customer wants to
> > have separate domains.
> > 
> > The iframe solution is already implemented. It simply opens
> > http:///sess/ url for each domain in hidden iframes.
> > The view only saves session_id to cookie "sessionid" (by default).
> > https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name
> > 
> > It could be probably handled at nginx/apache level, but I don't have
> > sources or server access to that site.
> > 
> > The drawback is that lots of requests are called on every page refresh ->
> > that's why we are looking for another solution. Fallback to subdomains
> > is the only solution which is on the table right now.
> > 
> > 
> > Cheers,
> >   Tom
> > 
> > Dne Tue, 11 Jun 2013 12:40:12 +0300
> > Avraham Serour  napsal(a):
> > 
> > > interesting problem!
> > > I googled for "Sharing session among multiple domains"
> > > 
> > > take a look here for example:
> > > http://stackoverflow.com/questions/6080017/how-to-share-session-among-multiple-domains-on-single-asp-net-website
> > > 
> > > it looks like you can do it across subdomains, so one solution is to split
> > > your websites on subdomains
> > > one interesting suggestion is the iframe one, if you implement that please
> > > share how
> > > 
> > > 
> > > On Tue, Jun 11, 2013 at 10:04 AM, Tomas Ehrlich 
> > > wrote:
> > > 
> > > > Hi there,
> > > > this question isn't bound to Django Web Framework as the major
> > > > limitation are cookies:
> > > >
> > > > I have single instance Django site running on multiple domains. Each
> > > > domain simply filters specific categories. There's an eshop and I need
> > > > to share sessions among all domains so user can log in on one site and
> > > > stay logged while browsing other domains.
> > > >
> > > > As I said before, the major limitation is how cookies work -- they're
> > > > bound to single domain or many subdomains.
> > > >
> > > >
> > > > I saw one solution -- on every page request send many GET requests to 
> > > > all
> > > > domains, giving them session_id, eg:
> > > >
> > > > http://domain/sess/
> > > >
> > > > Each domain then receives session_id and save it to cookie. When user
> > > > browse through site and switches to other domains, he remains logged in
> > > > as the session_id is the same.
> > > >
> > > > This works but I'm concerned with security issues. Also I don't like
> > > > 30+ requests on every refresh (it could be probably limitet only to
> > > > login/logout views).
> > > >
> > > >
> > > > What's you opinion? Have you ever dealt with problem like this? How
> > > > have you solved it?
> > > >
> > > >
> > > >
> > > > S pozdravem
> > > >   Tomáš Ehrlich
> > > >
> > > > Email:  tomas.ehrl...@gmail.com
> > > > Tel:+420 608 219 889
> > > > Jabber: elv...@jabber.cz
> > > >
> > > > "Půjdu kamkoliv, pokud je to kupředu." - D. Livingstone
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Djang

Re: Sharing session among multiple domains (generic web development question)

2013-06-11 Thread Tomas Ehrlich
Hi Avraham,
I know that cookies can be shared among subdomains, but my customer wants to
have separate domains.

The iframe solution is already implemented. It simply opens
http:///sess/ url for each domain in hidden iframes.
The view only saves session_id to cookie "sessionid" (by default).
https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name

It could be probably handled at nginx/apache level, but I don't have
sources or server access to that site.

The drawback is that lots of requests are called on every page refresh ->
that's why we are looking for another solution. Fallback to subdomains
is the only solution which is on the table right now.


Cheers,
  Tom

Dne Tue, 11 Jun 2013 12:40:12 +0300
Avraham Serour  napsal(a):

> interesting problem!
> I googled for "Sharing session among multiple domains"
> 
> take a look here for example:
> http://stackoverflow.com/questions/6080017/how-to-share-session-among-multiple-domains-on-single-asp-net-website
> 
> it looks like you can do it across subdomains, so one solution is to split
> your websites on subdomains
> one interesting suggestion is the iframe one, if you implement that please
> share how
> 
> 
> On Tue, Jun 11, 2013 at 10:04 AM, Tomas Ehrlich 
> wrote:
> 
> > Hi there,
> > this question isn't bound to Django Web Framework as the major
> > limitation are cookies:
> >
> > I have single instance Django site running on multiple domains. Each
> > domain simply filters specific categories. There's an eshop and I need
> > to share sessions among all domains so user can log in on one site and
> > stay logged while browsing other domains.
> >
> > As I said before, the major limitation is how cookies work -- they're
> > bound to single domain or many subdomains.
> >
> >
> > I saw one solution -- on every page request send many GET requests to all
> > domains, giving them session_id, eg:
> >
> > http://domain/sess/
> >
> > Each domain then receives session_id and save it to cookie. When user
> > browse through site and switches to other domains, he remains logged in
> > as the session_id is the same.
> >
> > This works but I'm concerned with security issues. Also I don't like
> > 30+ requests on every refresh (it could be probably limitet only to
> > login/logout views).
> >
> >
> > What's you opinion? Have you ever dealt with problem like this? How
> > have you solved it?
> >
> >
> >
> > S pozdravem
> >   Tomáš Ehrlich
> >
> > Email:  tomas.ehrl...@gmail.com
> > Tel:+420 608 219 889
> > Jabber: elv...@jabber.cz
> >
> > "Půjdu kamkoliv, pokud je to kupředu." - D. Livingstone
> >
> > --
> > 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?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> >
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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




Sharing session among multiple domains (generic web development question)

2013-06-11 Thread Tomas Ehrlich
Hi there,
this question isn't bound to Django Web Framework as the major
limitation are cookies:

I have single instance Django site running on multiple domains. Each
domain simply filters specific categories. There's an eshop and I need
to share sessions among all domains so user can log in on one site and
stay logged while browsing other domains.

As I said before, the major limitation is how cookies work -- they're
bound to single domain or many subdomains.


I saw one solution -- on every page request send many GET requests to all
domains, giving them session_id, eg:

http://domain/sess/

Each domain then receives session_id and save it to cookie. When user
browse through site and switches to other domains, he remains logged in
as the session_id is the same.

This works but I'm concerned with security issues. Also I don't like
30+ requests on every refresh (it could be probably limitet only to
login/logout views).


What's you opinion? Have you ever dealt with problem like this? How
have you solved it?



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - D. Livingstone

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




Re: request.FILES empty, I think I am doing everything correctly

2013-04-04 Thread Tomas Ehrlich
Hi John
{% csrf_token %} must be definitely inside the  tag. It renders .

Please try it and tell if it works.


Cheers,
  Tom

Dne Thu, 4 Apr 2013 14:38:58 -0700 (PDT)
John  napsal(a):

> This is Django 1.5
> Python 2.7.3
> MYSQL Database
> 
> Here is the model that I am using:
> 
> class SupportingDocument(models.Model):
> 
> """Defines an archived attachment."""
> 
> provision = models.ForeignKey(Provision, null = False, blank = False)
> 
> submitted_by = models.CharField(max_length = 64, null = False, blank = 
> True, default = "")
> 
> source_file_name = models.CharField(max_length = 256, null = False, 
> blank = False)
> 
> content_type = models.CharField(max_length = 64, null = True, blank = 
> True, default = "")
> 
> submission_time = models.DateTimeField()
> 
> version = models.CharField(max_length = 32, null = True, blank = True, 
> default = "")
> 
> comment = models.TextField(null = True, blank = True, default = "")
> 
> saved_file = models.FileField(upload_to = "supporting_documents", null 
> = True, blank = True)
> 
> 
> 
> def __init__(self, *args, **kwargs):
> 
> super(SupportingDocument, self).__init__(*args, **kwargs)
> 
> self.submission_time = datetime.today()
> 
> 
> 
> def __unicode__(self):
> 
> return self.source_file_name + ':' + unicode(self.submission_time)
> 
> 
> and the form definition
> 
> class SupportingDocumentForm(ModelForm):
> 
> def __init__(self, *args, **kwargs):
> 
> try:
> 
> provision = None
> 
> if 'provision' in kwargs:
> 
> self.provision = kwargs.pop('provision')
> 
> if 'user' in kwargs:
> 
> self.submitted_by = kwargs.pop('user')
> 
> except Exception, e:
> 
> pass
> 
> return super(SupportingDocumentForm, self).__init__(*args, **kwargs)
> 
> 
> 
> class Meta:
> 
> model = SupportingDocument
> 
> exclude = ('provision', 'submitted_by', 'source_file_name', 
> 'content_type', 'submission_time')
> 
> 
> def save(self, request=None, commit=True):
> 
> try:
> 
> supporting_document = super(SupportingDocumentForm, 
> self).save(commit=False)
> 
> supporting_document.source_file = self.source_file
> 
> supporting_document.provision = self.provision
> 
> supporting_document.submitted_by = self.submitted_by
> 
> supporting_document.save()
> 
> except Exception, e:
> 
> provisionLogger.error('Failure:%s when supplementing group 
> details' %(repr(e)))
> 
> 
> 
> def as_table(self):
> 
> try:
> 
> response = super(SupportingDocumentForm, self).as_table()
> 
> except Exception, e:
> 
> pass
> 
> return response
> 
> and the code to handle the request
> 
> def supporting_document_new(request):
> 
> current_tab = "Data"
> 
> current_section = "SUPDOCS"
> 
> action_url = urlresolvers.reverse('provision-supporting-document-new')
> 
> if request.POST:
> 
> try:
> 
> form = SupportingDocumentForm(request.POST,
> 
>   request.FILES,
> 
>   provision=request.provision,
> 
>   user=request.user)
> 
> if form.is_valid():
> 
> supporting_document = form.save()
> 
> return redirect_to_url("provision-supporting-document-list")
> 
> except Exception, e:
> 
> modal_error_message = "Fatal error:" + repr(e)
> 
> provisionLogger.error("Error saving Supporting Document %s" % 
> (supporting_document.source_file))
> 
> else:
> 
> try:
> 
> form = SupportingDocumentForm(provision=request.provision, 
> user=request.user)
> 
> except Exception, e:
> 
> pass
> 
> return render_to_response("provision/suppdocform.html", locals(), 
> context_instance=RequestContext(request))
> 
> and the html for the form
> 
> Supporting Document {{ sourcefile }}
> 
>  id="supporting_document_form" class="provision_modal_form" name=
> "supporting_document_form">
> 
> 
> 
> {{ form.as_table }}
> 
>  
> 
> 
> 
> 
> 
>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> {% if modal_error_message %}
> 
> {{ modal_error_message }}
> 
> {% else %}
> 
>    
> 
> {% endif %}
> 
> 
> 
> 
> 
>  
> 
> 
> 
> {% csrf_token %}
> 
> I am sure that there must be a problem with the html but this is driving me 
> crazy.  Probably some stupid typo.
> 
> When I set a breakpoint following the if request.POST the request.FILES is 
> an empty dictionary.
> 

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

Re: What are the steps to build a website?

2013-03-25 Thread Tomas Ehrlich
> You can't do it perfectly the first time. The only way to do it well
> is experience. The only way to get experience is to make mistakes.

I disagree. When you make mistake, you know what's wrong, but you still
don't know, what's right. You need to learn, how to make things right.


To Benjamin:
Question is: Do you have any experiences with building websites? Other
languages, frameworks? If your answer is "yes" and you've just start
learning Django/Python as a new way to build websites, try following:

 1) Take your time to finish tutorial and at least skim through
documentation. It can be overwhelming for the first time, but even
after couple of years developing in Django I always find something in
documentation which makes my life easier (I'm probably lousy reader.)
Most of your questions could be answered by simply pointing you to
the right page in documentation. Also there  are other good books to read:
 eg http://www.djangobook.com/en/2.0/index.html

 2) Write something. Any thing. What about your own blog app? :)

 3) Look at http://www.djangosites.org/ Some of those sites have public
sources. However, some of them may be confusing. Try to find some
simple ones.

If your answer is "no", then don't expect that you won't make design
mistakes and simply dive into.


To your questions:
 1) Yes, that's usual approach. However, Django has it's own user
management, so you can use it or extend it. Templates for login page
are usualy in some "global" directory (I use /templates).
Location of other basic pages depends on what they are. Are the static?
Then you can leave them in global dir. Are they dynamic? Then you need
an view, to render them, which belongs to one of your apps.

 2) Both are probably good idea. I usualy draw on paper few pages to
get the idea about whole website settled. But today with
twitter-bootstrap and similar frameworks, you can as easily create
sketches of your pages directly as html and use it later as skeleton
for your templates.
  Populate test DB isn't good idea, rather try to create fixtures and
load them, because then you can use them in your tests.
https://docs.djangoproject.com/en/1.5/howto/initial-data/

 3) It depends. How generic is your code? Do you want to reuse it in
other projects? Then create app. Is this code specific for this project
only and you are 100% sure you won't need it anymore in future? Then
you can store it in project app.
  You example, however, is a bad idea. Django has template engine which
allows you to extend templates. You don't need to glue together header,
body and footer templates. You just create base template with header,
body, footer blocks (for example) and define it's content later.
https://docs.djangoproject.com/en/1.5/topics/templates/#template-inheritance


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




Re: [ANN] Introducing Brillixy - Django admin skin & customization kit

2013-03-12 Thread Tomas Ehrlich
Hi Alex,
congratulation to alpha release of your app.

I was about to suggest you django-bootstrap-admin, django-admin-tools
and django-fluent-dashboard, but since you already know Admin tools,
could you please provide more details about your app? I took a quick
look at demo page and read Readme file at github, but it seems to me
like lightweight version of django-bootstrap-admin.


Anyway, I wish you good luck in future development.

Cheers,
  Tom


Dne Tue, 12 Mar 2013 19:58:22 +0400
Alexey Kinyov  napsal(a):

> Hello everyone!
> 
> Today we've released alpha of Brillixy https://github.com/05bit/brillixy.
> 
> This is a Django admin skin with some extras. Actually it's an
> alternative to Grapelli, Admin Tools and other apps that changes
> standard Django admin look and user experience. It's simple and
> minimal at the moment and we're going to keep it the way like that.
> 
> I'm working on it with Vasily Sadovnikov and Pavel Yakovlev - they
> helped me with vision and are working on design improvevents. Thank
> you guys!
> 
> Core features:
> 
> - skin powered by basic Twitter Bootstrap with responsive layout +
> Awesome Font
> - easy header customization: logo & title
> - lighter nav breadcrumbs: no application index
> - custom dashboard panels
> 
> It seems that most of standard admin functions are working. There're
> some issues with Django 1.4.x inlines, as I used Django 1.5 templates
> and scrips as basis. And I see we're not perfect with design and
> navigation, so we're working on that :)
> 
> You're welcome to make a test-drive, and I would really appreciate any
> feedback. Please, let me know if it does fit your real projects! :)
> 
> Alex K. rudyryk
> ///
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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




Re: Template inheritance

2013-03-11 Thread Tomas Ehrlich
This approach is more flexible. It's easier to override template than
override view. You can still put your "context variable" logic there,
if you want.

Take Django admin as example. You can customize it quiet easily when
you override/subclass templates. If you want to customize view, you
have to sublass ModelAdmin or whole AdminSite. It's overkill when you
need tune some details like this.

Cheers,
 Tom


Dne Mon, 11 Mar 2013 11:51:47 +
Tom Evans  napsal(a):

> On Sat, Mar 9, 2013 at 10:28 AM, Tomas Ehrlich  
> wrote:
> > Hi Nenad,
> > you can wrap your meta-refresh line in another block and then delete
> > it's content in templates which shouldn't be refreshed.
> >
> > # base_site.html
> > {% block extrahead %}
> > {% block extrahead-refresh %}
> > 
> > {% endblock %}
> > {% endblock %}
> >
> > # change_form.html -- deletes content of block extrahead-refresh
> > {% block extrahead-refresh %}{% endblock %}
> 
> 
> This approach is exactly what the docs are warning about. This is
> putting all of the logic of whether to display something into the
> template, and not the view.
> 
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Template inheritance

2013-03-09 Thread Tomas Ehrlich
Hi Nenad,
you can wrap your meta-refresh line in another block and then delete
it's content in templates which shouldn't be refreshed.

# base_site.html
{% block extrahead %}
{% block extrahead-refresh %}

{% endblock %}
{% endblock %}

# change_form.html -- deletes content of block extrahead-refresh
{% block extrahead-refresh %}{% endblock %}


Quote from django docs:
* More {% block %} tags in your base templates are better. Remember,
child templates don’t have to define all parent blocks, so you can fill
in reasonable defaults in a number of blocks, then only define the ones
you need later. It’s better to have more hooks than fewer hooks.


Cheers,
 Tom

Dne Sat, 9 Mar 2013 01:41:35 -0800 (PST)
Nenad Cikic  napsal(a):

> Hello,
> I am using django admin for my project so I am not writing much templates 
> by myself, therefore I am not very skilled with them, so excuse me if I ask 
> dumb question.
> I have extended base_site.html to add browser refresh in block extrahead.
> I do not want however to do refresh while I am inserting data.
> In my change_form.html I have something as
> {% block extrahead %}{{ block.super }}
> 
> What I would need is the possiblity to have some template variable that is 
> True for base_site.html and that I set to False only in change_form.html, 
> and then I could use that in base_site.html something as
> 
> base_site.html
> {% block extrahead %}
> {% if do_refresh %}
> 
> {% endif %}
> {% endblock %}
> 
> I understand that the template is only for presentation and not logic, as 
> found in docs, but this I do see as logic of presentation:)
> I am looking in docs but can not see anythign useful for my scenario, which 
> should not be so uncommon.
> 
> What's the proper way to solve this.
> Thanks
> Nenad
>

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




Re: How to customize Django Admin interface with custom urls and views?

2013-03-06 Thread Tomas Ehrlich
Hello John,
welcome in Django, hope you'll find it useful as I did.

Extend Django admin is a little bit tricky, but not impossible.

You can add your own views to admin simply by extending your ModelAdmin
subclass.
See
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
for more info.

It's good practice to name your url pattern according to django
standard, otherwise it can get messy.
See
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#reversing-admin-urls
where you can find how to reverse admin urls and get the idea about
naming conventions. It's not mandatory, though.

Basicaly, you always need to have *view* and define *url*. There's no
*generic* pattern, like /module/controller/action/, you have to define
everything by yourself.

You can also create your own Admin site, subclass it, replace it,
whatever you want. You can have more than one admin site running along,
both for different tasks. There's more info at
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf

Final note: Django *is* MVC framework, but instead of controllers,
there are view and insted of views, there are templates. It works the same 
though.
See
https://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names
 
for more info.


Hope I answered your questions. If you need more information, feel free to ask.

Cheers,
  Tom


Dne Wed, 6 Mar 2013 08:36:06 -0800 (PST) John James
 napsal(a):

> Hi to all!
> 
> I'm completely new in Django. All I done is read one Introduction Book by 
> Adrian Holovaty. 
> When I finished I thought I knew enough to build even something simple, 
> because the book is real good and clear.
> 
> Maybe I could create something simple, but I wanna create my own 
> Administration interface with bunch of widgets, a lot of JS/AJAX nevermind.
> 
> Anyway, when I tried to create one link by click on which an AJAX request 
> should be sent to specific url. For example /admin/page/untouchData
> 
> I have the *Page* model, and I need to perform some action named 
> *untouchData. 
> *But I dont know where should I define untouchData method, neither
> how could I make the Django know about my specific URL *untouchData*, 
> because it's not the standard action, neither CRUD. 
> 
> For now I can't realize the concept of Django architecture, I mean MTV 
> seems. I came from Yii  PHP framework, it has MVC concept, so there I could
> create specific action in a Controller and all staff is done. Of course URL 
> routing exists there too, but it's quite simple.
> 
> I'm sure for Django it's not enough to create only one rule:
> *url(r'^admin/', include(admin.site.urls)),*
> 
> So guys, could you please tell me where to read about this? Because I can't 
> find an answer in three books and in Django Official Documentation too =(
> 
> Thanks for advice anyway.
> 

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




Re: What used @models.permalink and get_absolute_url? Please an example to better understand this. An example of the documentation is not clear to me

2012-11-17 Thread Tomas Ehrlich
Hi there,
the key idea is: *Let's have URLs defined at one and only one place.*

So, when you have urls.py like this:

urlpatterns = patterns('',
'^blog/(?P\w+)', BlogDetail.as_view(), name='blog-detail',
'^articles/(?P\w+)', ArticleDetail.as_view(),
name='article-detail'
'^$', HomepageView.as_view(), name='homepage')

Your urls are defined:

/ -- Homepage
/blog/ -- Blog detail (eg. one entry)
/artices/ -- Article detail (eg. one article)


Imagine you want to point some link to one of these pages. Hard-coded
links, like:


Homepage
{{ blog.title }}
{{ article.title }}

are bad. Because now are your urls defined at two places -- urls.py and
navigation.html. When you change urls.py, you have to update
navigation.html also. Right now, it's not such a problem, just two
files. Imagine that your project contains lot of templates, lot of
views and you have to change everything everytime when you change
urls.py. That's 1) boring and 2) very fragile. You'll probably spend a
huge amount of time with fixing bugs.

So, there's a solution:

Reverse url from urls.py for given parameters. Let's say you want link
to blog entry and you know the slug:

url = reverse('blog-detail', [], {'slug': slug})

So, our template could look like this:


{% load url from future %}

{{ blog.title }}
{{ article.title }}

Now all links are "reversed" from urls.py. That's good, but again: When
you change urls.py, let's say you change blog url to:

/blog///

you'll have to change all your templates again! And that's boring.

So, another improvement: Every model instance should have it's own url
(every model instance should be identified somehow). Therefore it's
convenient to define get_absolute_url method:

def get_absolute_url(self):  # return url which points to this instance
return reverse('blog-detail', [], {'slug': slug})

But usually we use 'reverse' function every time, so it's probably
easier to use method decorator:


@models.permalink
def get_absolute_url(self):
return ('blog-detail', [], {'slug': slug})

and return only arguments for 'reverse' function.


Now, in you template, you can use:


{% load url from future %}

{{ blog.title }}
{{ article.title }}

and be happy ever after :)


Note: For me the documentation was clear. Could you please suggest any
improvement?

Link:
https://docs.djangoproject.com/en/1.5/ref/models/instances/#get-absolute-url


Cheers,
 Tom

http://www.tomas-ehrlich.cz/en/

"Půjdu kamkoliv, pokud je to kupředu." - J. London


Dne Fri, 16 Nov 2012 07:03:08 -0800 (PST)
enemytet  napsal(a):

>  
> 
> How (and why) to use @models.permalink and get_absolute_url? 
> 
> Please an example to better understand this. An example of the 
> documentation is not clear to me
> 

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



Re: Queries to multiple tables

2012-11-10 Thread Tomas Ehrlich
Hi Kristofer,
I usualy put methods like this one into Model, although Manager is also
possible. Definitely not View or sth else.

Why I like Model more than Manager is this difference (suppose your
method is called make_payment):

Account.make_payment  # via Model
Account.objects.make_payment  # via Manager

and because this method is "creating" object instead of "retrieving"
objects, it seems to me more apropriate. I know, there are methods like
create or get_or_create in Manager, so propably someone would have a
better arguments on this. Or maybe it's just matter of taste. In fact,
in one application of mine I have method Node.create which do some
fancy stuff (creating other related objects, consistency checks, etc.)
and then call Node.objects.create.


Cheers,
 Tom

Dne Sat, 10 Nov 2012 01:23:44 -0600 (CST)
Kristofer  napsal(a):

> Hello, 
> 
> I'm new to Django and trying to learn it by making a simple budget/checkbook 
> application. 
> 
> I apologize for my ignorance, but I couldn't seem to find an answer to this 
> on Google or the Django docs from my searches. 
> 
> I want to create a function that will take a bank account as an id number 
> (assumed to already exist), and the payee/amount. From there, the function 
> will do a typical bank transaction: 1) add the entry to the "Ledger" table, 
> and subtract the amount from the "balance" field of the "Account" table for 
> the account referenced in the id number passed to the function. 
> 
> Where is the appropriate/intended place to put that type of function? Model, 
> Manager, View, or somewhere completely different? 
> 
> My best guess is that it belongs in a Manager, but all of the examples I can 
> find seem to indicate that Managers are intended for queries. 
> 
> Thanks in advance, 
> 
> Kris 
> 
> 
> 
<

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



Re: Status of bug #11580 ?

2012-11-07 Thread Tomas Ehrlich
Hi Michał,
actually, you *do have* such a privilege. Simply clone development
version of django, fix the file with bug, test it, and post patch to
ticket you've mentioned.

If you include test which check, that your patch really fix the bug,
core developers will pull in into repository soon.

It's really that easy and for you it would be dead easy, since you
already know the solution.

Take a look at
https://docs.djangoproject.com/en/dev/internals/contributing/


Cheers,
 Tom

Dne Wed, 7 Nov 2012 09:13:33 +
Michał Nowotka  napsal(a):

> OK, so first of all I'm new to both lists. I already asked some questions
> here and usually I get email with my question 5 minutes after post (I mean
> my original question not the answer). I was waiting long and I though my
> question didn't pass moderation so maybe it would be better to ask it on
> probably less strict django-users group. So my apologies for my impatience.
> 
> Now about  the bug itself. Although there is not any patch attached to this
> bug report you can find it in the text.  The filed_cast_sql function should
> be changed from:
> 
> def field_cast_sql(self, db_type):
> if db_type and db_type.endswith('LOB'):
> return "DBMS_LOB.SUBSTR(%s)"
> else:
> return "%s"
> 
>  to:
> 
> def field_cast_sql(self, db_type):
> return "%s"
> 
> or even completely removed. Since this is trivial it's only a matter of
> including this small change in core. I don't have such privileges that's
> why I'm asking you to do it.
> 
> Kind regards,
> Michal Nowotka
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Re: urls.py and default values...

2012-10-21 Thread Tomas Ehrlich
Hello,
you need to make 'year' argument optional:

def student_reports(request, year=None):
year = year or datetime.date.today().year
...

Another option could be passing extra option to you view function:
https://docs.djangoproject.com/en/1.4/topics/http/urls/#passing-extra-options-to-view-functions


Cheers,
 Tom

Dne Mon, 22 Oct 2012 15:24:51 +1200
Lachlan Musicman  napsal(a):

> Hola,
> 
> I have data across multiple years.
> 
> I want to run reports on a per year basis, so I have in my urls:
> url(r'^students/reports/(?P\d{4})/$', student_reports,
> name='student_reports'),
> 
> etc.
> 
> What I want to know though, is how to have this in the urls:
> url(r'^students/reports/$', student_reports, name='student_reports'),
> 
> defaulting to the year it's run. (ie, year = datetime.date.today().year)
> 
> I thought about passing extra options, but it feels like overkill?
> 
> I have in my views.py:
> 
> def student_reports(request, year):
>if not year:
> year = datetime.date.today().year
>yada yada
> 
> 
> but this is failing on not enough arguments...
> 
> 
> Cheers
> L.
> 
> 
z`


S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Re: ImportError: Could not import settings

2012-10-20 Thread Tomas Ehrlich
Hello,
there's a little hint at the end of exception:

> No module named unipath

Seems like you import module unipath in your settings.py, which is not
on your sys.path.

I never set PYTHONPATH for development and everything works fine.
Python adds current directory to sys.path, so when you run ./manage.py,
you don't need to set PYTHONPATH pointing to current working directory.

Check content of you sys.path.


Cheers,
 Tom

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



Re: Stop executing template tag

2012-10-19 Thread Tomas Ehrlich
Hi Nikhil,
you can't do that with django template system without additional "raw" tag.

Here's a relevant article:
http://www.holovaty.com/writing/django-two-phased-rendering/

Cheers,
 Tom

Dne Fri, 19 Oct 2012 15:51:39 +0530
Nikhil Verma  napsal(a):

> Hello people
> 
> I need some suggestion in a problem.
> 
> How can i stop django template engine  not executing {{name}}. Meaning I do
> not want that {{}}, the value should be printed it should somehow pass into
> the browser as it is.
> If i writing {{name}} it should print {{name}} in html file/browser
> 
> How can i achieve this ?
> 

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



Re: Question in document "How to use Django with Apache and mod_wsgi"

2012-10-18 Thread Tomas Ehrlich
Hello,
sometimes I have similar problem. Usually helps clear cache or reload page 
(using F5). I'm still not sure why that happens, since both develop and 
production versions run on different domains (localhost:8000 and mysite.com).

If admin site have proper css style and only images are missing, I don't have a 
clue what cause it.


Cheers,
 Tom


Dne Fri, 19 Oct 2012 10:02:25 +0800
"Dae James"  napsal(a):

> Thank you. Yes, I didn't set "Alias /static/ /path/to/mysite.com/static/" in 
> my site config. 
> However, when I set that alias, I met another problem as the following 
> picture. As the picture, my models don't have "Add" and "Change" button, 
> which they have when I run this site on development server or when I just set 
> DEBUG in settings.py to True.
>  
> 
> 
> 
> 
> Dae James
> 
> From: Tomas Ehrlich
> Date: 2012-10-19 00:48
> To: django-users
> Subject: Re: Question in document "How to use Django with Apache and mod_wsgi"
> Hello,
> have you set proper aliases in apache site config?
> 
> Alias /robots.txt /path/to/mysite.com/static/robots.txt
> Alias /favicon.ico /path/to/mysite.com/static/favicon.ico
> 
> AliasMatch ^/([^/]*\.css) /path/to/mysite.com/static/styles/$1
> 
> Alias /media/ /path/to/mysite.com/media/
> Alias /static/ /path/to/mysite.com/static/
> 
> 
> Order deny,allow
> Allow from all
> 
> 
> 
> Order deny,allow
> Allow from all
> 
> 
> or similar. Check that apache can read
> directories /path/to/mysite.com/{static,media} ...
> 
> You should have appropriate settings in your settings.py, eg.
> 
> MEDIA_URL = '/media/'
> STATIC_URL = '/static/'
> 
> MEDIA_ROOT and STATIC_ROOT aren't important in this case.
> 
> Then, take a look at you access.log, if there is something relevant.
> 
> Does it works now? If no, please send your settings.py and apache site
> config file. (Don't forget to delete sensitive data from settings.py
> before posting here).
> 
> Cheers,
>  Tom
> 
> 
> Dne Thu, 18 Oct 2012 06:39:13 -0700 (PDT)
> Dae_James  napsal(a):
> 
> > The url of the document is: 
> > https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/
> > I can't succeed at the last part, "Serving the admin files".  My admin page 
> > is as follows.
> > 
> > <https://lh3.googleusercontent.com/-JvizcFwx52s/UIADfuCY-UI/AAM/59oDrVVuHzA/s1600/Untitled20121018212559.png>
> > I have tried two ways. However both can't succeed.
> > First means is as the following steps:
> > 1, Activate the admin site following 
> > https://docs.djangoproject.com/en/1.4/intro/tutorial02/
> > 2, Execute "manage.py collectstatic" in console.
> > 3, Start mob_wsgi.
> > 
> > Second means is as the following steps:
> > 1, Activate the admin site following 
> > https://docs.djangoproject.com/en/1.4/intro/tutorial02/
> > 2, Copy the admin files live in (django/contrib/admin/static/admin) into my 
> > Apache document root(C:\Program Files\Apache Software 
> > Foundation\Apache2.2\htdocs)
> > 3, Start mob_wsgi
> > 
> > Help, please! Thank you~~
> > 
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Re: Question in document "How to use Django with Apache and mod_wsgi"

2012-10-18 Thread Tomas Ehrlich
Hello,
have you set proper aliases in apache site config?

Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

AliasMatch ^/([^/]*\.css) /path/to/mysite.com/static/styles/$1

Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/


Order deny,allow
Allow from all



Order deny,allow
Allow from all


or similar. Check that apache can read
directories /path/to/mysite.com/{static,media} ...

You should have appropriate settings in your settings.py, eg.

MEDIA_URL = '/media/'
STATIC_URL = '/static/'

MEDIA_ROOT and STATIC_ROOT aren't important in this case.

Then, take a look at you access.log, if there is something relevant.

Does it works now? If no, please send your settings.py and apache site
config file. (Don't forget to delete sensitive data from settings.py
before posting here).

Cheers,
 Tom


Dne Thu, 18 Oct 2012 06:39:13 -0700 (PDT)
Dae_James  napsal(a):

> The url of the document is: 
> https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/
> I can't succeed at the last part, "Serving the admin files".  My admin page 
> is as follows.
> 
> 
> I have tried two ways. However both can't succeed.
> First means is as the following steps:
> 1, Activate the admin site following 
> https://docs.djangoproject.com/en/1.4/intro/tutorial02/
> 2, Execute "manage.py collectstatic" in console.
> 3, Start mob_wsgi.
> 
> Second means is as the following steps:
> 1, Activate the admin site following 
> https://docs.djangoproject.com/en/1.4/intro/tutorial02/
> 2, Copy the admin files live in (django/contrib/admin/static/admin) into my 
> Apache document root(C:\Program Files\Apache Software 
> Foundation\Apache2.2\htdocs)
> 3, Start mob_wsgi
> 
> Help, please! Thank you~~
> 

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



Re: django multi db routing doesnt work wich multiple schemas

2012-10-12 Thread Tomas Ehrlich
Hi Michał,
is "schema" the same as thing as "tablespace"? If so, you should define them 
using
db_tablespace meta keyword.
https://docs.djangoproject.com/en/1.4/topics/db/tablespaces/

DATABASES creates new database connection and it's really not
possible to make relations between databases.

Cheers,
 Tom

Dne Fri, 12 Oct 2012 17:19:42 +0100
Michał Nowotka  napsal(a):

> First of all the error is not from django but from database.
> Secondly I'm not using different databases but different schemas so
> relations are possible.
> The error has nothing to do with foreign key or any relation.
> It just looks like django is ignoring router suggestion and directs
> sql query to wrong DB.
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Re: Unhandled exception during validation

2012-10-12 Thread Tomas Ehrlich
Well, in this case, I don't see problem in erroritself  (that happens).
I see problem in missing trackback (that's not usual). My assuption was
that "something" suppress it (don't know if it's possible, but I
assume it is).

Cheers,
 Tom

Dne Fri, 12 Oct 2012 17:00:01 +0100
Tom Evans  napsal(a):

> On Fri, Oct 12, 2012 at 4:45 PM, Tomáš Ehrlich  
> wrote:
> > Hello Oyvind,
> > that's weird, Django (or Python  in general) usually provide very long and
> > descriptive trackback.
> >
> > Could you please provide more information? What version of Python do you
> > have? Does it fail when you run ./manage.py runserver? You've mentioned, the
> > error is in local app, does that app load any thirdparty modules?
> >
> > I've never came across unhandled exception which doesn't show trackback, so
> > my guess is some c/c++ python extension (PIL, psycopg2, …). But that's just
> > guess…
> >
> > Cheers,
> >  Tom
> 
> I think you've misunderstood the OP, the error occurs in Django's
> AppCache, which is populated when you start django in any manner (even
> going to the shell). The error occurs when AppCache tries to load one
> of his custom apps, and the issue is that the error message does not
> indicate the error that occurred, provide a proper traceback or even
> indicate which app it failed to load.
> 
> (Sorry OP, haven't a clue)
> 
> Cheers
> 
> Tom
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Re: A very basic question with Django

2012-10-10 Thread Tomas Ehrlich
Common guys, this thread isn't about me and CGI :) I really don't care
what it is and know, when you've just told me what it is I don't care
even more :)

If you know what's CGI, feel free to answer the original question:
"Could Django be deployed using CGI?"

Cheers,
 Tom :)

Dne Wed, 10 Oct 2012 14:11:39 -0400
Dennis Lee Bieber  napsal(a):

> On Tue, 9 Oct 2012 23:09:07 -0700 (PDT), Tomáš Ehrlich
>  declaimed the following in
> gmane.comp.python.django.user:
> 
> > Hello,
> > I wouldn't say that Django is not suitable for web development. Even when 
> > someone says it's not, it's just an opinion, but in general, Django is 
> > framework for web development.
> > 
>   In a way, Django is not useful for anything except web development
> 
> 
>   It's probably not the most suited for a site with 90% of the pages
> static information, being optimized to link pages through to
> live/dynamic database information.
> 
> > 
> > A2: I admit that I don't know exactly what CGI means, but you actually can 
> 
>   Common Gateway Interface: Typically it meant running a whole
> program/script for each request. The start-up time for the Python
> interpreter itself makes pure CGI costly.
> 
> > deploy Django using FastCGI. I'm using WSGI, which is recommended method 
> > right now. Please checkout documentation for more 
> > details https://docs.djangoproject.com/en/1.4/howto/deployment/fastcgi/
> 
>   FastCGI, mod_python, and WSGI all, as I understand them, attempt to
> keep the interpreter and script loaded in a form that allows the server
> to "call" into the application script, rather than start a process from
> scratch.
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



Providing custom settings with default values

2012-07-22 Thread Tomas Ehrlich
Hello there,
until now I (and many others) used to define default custom settings
in /settings.py in this way:

from django.conf import settings

default = lambda k, v: getattr(settings, k, v)

PREFIX_KEY = default('PREFIX_KEY', 'value')
...

and in other modules I used django-settings along my own settings like
this:

from django.conf import settings
from  import settings as _settings

That's easy-enough solution, but has several problems:

1. ./manage.py diffsettings doesn't work with this approach
2. /settings.py is a little bit messy
3. You have to REPEAT one line of code (with lambda) and thus violate
DRY principle. Well, this is not problem at all, I'm just trying to
get your attention ;)


I've found two years old article by Thomas Sutton's about different
approach 
http://passingcuriosity.com/2010/default-settings-for-django-applications/
and after reading through his repository I decided to create fork,
update his work and publish it. It's nothing special, just one
function, the reason why I packed it and posted to pypi (http://
pypi.python.org/pypi/django-application-settings/0.1a) is that now I
can easilly install it into virtualenv and share it within different
projects/apps.

The usage is simple:
1. Add these two lines somewhere to __init__.py in your application
directory:

from application_settings import provide_default_settings
provide_default_settings(__name__)

2. Create settings.py in your application directory and write your own
settings as you would write in project/settings.py


I would appreciate any feedback or suggestions about different
approaches. Thanks!

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