Thursday, June 30, 2011

Re: How to use the django-users mailing list properly and doing your homework..

What about including something about e.g. http://dpaste.com for snippets etc.
I know I hate to read more than 10 lines of code in my email reader,
without syntax highlighting or correct indentation.

--
With regards, Herman Schistad

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

Re: Global generic files? Best practice(s)?

Hello Andre! Thanks so much for your help, I really appreciate the pro
advice!!! :)

On Thu, Jun 30, 2011 at 6:01 AM, Andre Terra <andreterra@gmail.com> wrote:
> __init__.py
> app1/
> app2/
> appN/
>    __init__.py
>    models.py
>    views.py
>    urls.py
>    forms.py
>    templates/
>    utils.py
> project/
>    __init__.py
>    forms.py
>    settings.py
>    urls.py
>    utils.py
>    views.py
>    templates/
>    static/
>    (etc.)


Oooh, I really like the above setup!

That's similar to how I setup my very first Django project/app (sorry,
poorly packaged... er, not packaged at all!):

https://github.com/mhulse/code.hulse.me/tree/master/webapps

project/
__init__.py
manage.py
settings.py
urls.py
views.py
apps/
app1/
app2/
templates/
app1/
app2/

That layout seemed to work well for that particular project.

At work, we use a more out-of-the-box setup:

project/
__init__.py
manage.py
settings.py
urls.py
views.py
app1/
__init__.py
views.py
models.py
admin.py
helpers.py
managers.py
validators.py
widgets/
urls.py
forms.py
fields.py
utils.py
templates/
app1/
app2/
app3/
templates/
app1/
app2/
app2/

I really like your suggested setup though! Putting the apps at the
same level as the project seem to make a lot of sense.

Using the project as a container for utils.py is a great idea also. :)

> Which basically means my project is just another app. Nothing is
> preventing you from creating utils.py files in your apps, or even
> settings.py that get loaded from an import in your project's settings.

Yes! That sounds like an optimal setup! :)

When you talk about an app's settings.py file, do you just put
something like this:

from app import settings

... at the top of the project's settings.py file?

I had never considered doing that before... I will have to experiment.
Thanks for tip!

> I find this arrangement to be the best for my development workflow
> after many other attempts. This also helps newcomers avoid the often
> made mistake of referencing their apps in relation to the project like
> from project.app1 import views
> which would prevent the code from being reused in other projects.

Hehe, I can relate. Been there, done that. :)

> About your Place model, my recommendation/guess would be to abstract
> it one more time so that you could have a global BasePlace class which
> gets subclassed in an app-specific Place model.

That's an interesting idea!

I actually have several (abstract) models similar to "Place" that I
could use in my various apps/projects... I have found myself
duplicating the code for these various apps... It would be great to
put them at a higher level and import/sub-class as they are needed.

> Or at least that's what I thought last nignt before going to sleep. As
> I write this, I realize that a BasePlace would have no place (pun not
> intended) in your project, so maybe what you need is a package for
> your multiple apps which in turn gets imported into your project.

That's a great idea/tip!

You inspired me to create my first pip-installable package:

https://github.com/mhulse/django-goodies

Not much there at the moment, but I plan on adding more code at a later date.

The instructions found below were very helpful:

http://guide.python-distribute.org/creation.html

On my testing server, I was able to pip install django-goodies without
a hitch (I have yet to actually import and utilize the Place model in
a project/app though... It's getting late.) :(

> I'm pretty much guessing at this point, but in doing so, I have
> hopefully given you food for thought while also bumping the thread so
> that other developers will weigh in.

Definitely! Thanks so much!!!! I really appreciate it! :)

Have a great day.

Cheers,
Micky

--
Micky Hulse
Web Content Editor
The Register-Guard
3500 Chad Drive
Eugene, OR 97408
Phone: (541) 338-2621
Fax: (541) 683-7631
Web: <http://www.registerguard.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@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: JQuery .load() works in production but fails in development

Hi Folks:

I forgot to mention that FireBug tells me that development request has completed successfully (code 200) but there is no data which is what lead me to believe that it was a "same origin policy" problem possibly resulting from the use of the alternate port or from the fact that I just don't know how to tell runserver that /cgi is only for serving flat file executables.

Cheers,

Joe

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

Re: Implementing a User Search Feature

If you just want a simple user search (which seems to be what you are
asking for), it really depends on your models - but a basic approach I
usually use is to define a django form to use for the search, and
instead of defining a save method, make a method that returns a
queryset. As an off the top of my head example for a django auth user
(untested, I might have screwed something up):

class UserSearchForm(forms.Form):
first_name__istartswith=forms.CharField(label="First name",
required=False)
last_name__istartswith=forms.CharField(label="Last name",
required=False)

def queryset(self):
from django.contrib.auth.models import User
filters={}
for k,v in self.cleaned_data.items():
val=v.strip()
if val: filters[k]=val
return User.objects.filter(**filters)

Then use it in your view like any other form:

def user_search(request):
usf=UserSearchForm(request.GET or
request.POST,prefix='usersearch')
users=usf.queryset()
return render_to_response('sometemplate.html',{'users':users})

Now if you really do want to do text indexing and have full text
search capabilities then you should look at the other suggestions.
For many things those are either overkill or too generic.

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

Different urlpatterns for different subdomains

Is there any way of conditionally choosing an urlpatterns set in
urls.py depending on the subdomain requested?

I would like to configure different Django behaviors maintaining the
same url structure according only to the subdomain.
Please let me know if this is not a good approach to achieve this.

Thanks.
--
Vinicius Massuchetto
http://vinicius.soylocoporti.org.br

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

JQuery .load() works in production but fails in development

Hi Folks:

I have to say that I am completely enamored with Django. I have been using it for about a week and it is a really awesome framework!

The problem I have is that JQuery .load() does not work correctly in my development environment on port 8001 (manage.py runserver 0.0.0.0:8001).

It works just fine in my production environment (port 80) which leads me to believe that the the problem is related to the "same origin" policy or some sort of Apache configuration problem but I don't know how to fix it.

I have a very simple example that illustrates what is going on. It is a page that dynamically call /cgi/getstatus.py script each time the "loadit" link is clicked.

How can I make it work in the development environment? Is there some way to allow apache to handle the CGI calls on port 8001 while Django runserver manages the rest? Is there a better way to do this?

Thank you,

Joe

Details follow.

Setup:
  O/S:      Linux (CentOS 5.5)
  Apache:   2.2.3
  Django:   1.3
  JQuery:   1.6.1
  mod_wsgi: 3.3.3
  Python:   2.7.2

CGI script:
  #!/opt/python2.7/bin/python2.7
  import cgitb
  import datetime
 
  cgitb.enable()
  now = datetime.datetime.now()
  print "Content-Type: text/plain;charset=utf-8"
  print
  print 'Timestamp %s' % (now.strftime("%Y-%m-%d %H:%M:%S"))

template (sync.html):
  {% extends "base.html" %}
  {% block head_title %}{{ title }}{% endblock %}
  {% block content %}
  <script type="text/javascript">
  $(document).ready(function() {
      getStatus();
  });
  function getStatus() {
      $('#status').load('/cgi/getstatus.py');
  }
  </script>
  <div id="status"></div>
  <a href="javascript:getStatus();"> loadit </a>
  {% endblock %}

views.py:
  from django.shortcuts import render_to_response
  from django.template import RequestContext
 
  def sync(request):
      return render_to_response('sync.html',
                                {'title':'JQuery .load() Test'},
                                context_instance=RequestContext(request))

httpd.conf:
  <VirtualHost *:80>
    ServerAdmin  me@example.com
    ServerName   mysite-server.example.com
    DocumentRoot /opt/mysite/2.0/mysite
    ErrorLog     logs/mysite-server_error.log
    AddHandler   cgi-script .cgi .py
 
    ScriptAlias /cgi /opt/mysite/2.0/cgi
    <Directory /opt/mysite/2.0/cgi>
      Options Indexes FollowSymLinks
      Order allow,deny
      Allow from all
    </Directory>
 
    Alias /media /opt/mysite/2.0/media
    <Directory /opt/mysite/2.0/media>
      Options Indexes FollowSymLinks
      Order allow,deny
      Allow from all
    </Directory>
   
    Alias /static/admin /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media
    <Directory /opt/python2.7/lib/python2.7/site-packages/django/contri/admin/media>
      Options Indexes
      Order allow,deny
      Allow from all
    </Directory>
 
    WSGIScriptAlias / /opt/mysite/2.0/mysite/apache/django.wsi
  </VirtualHost>


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

Stay on a step in a form wizard until the user is ready to move on.

I'm working on a site that uses a form wizard as the main user interface. I've got one step however that I'd like to have a user be able to complete it several times if needed, storing the data bound to the user's session. Is there a way to do this using the FormWizard class, or am I asking too much? Thank you for your consideration and have a good day.

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

Re: can i control select column order in a queryset?

Hi Karen:

Thank you for your response. The reason that I care about about column order is so that I can use the same template for different queries with arbitrary column orders using a single variable. I would like to be able to extract the field key name and use them directly in the column header. Perhaps something like this:

01 {% extends "base.html" %}
02
03 {% block head %}{{title}}{% endblock %}
04
05 {% block content %}
06   {% if rows %}
07     <table class="cls1 cls2">
08        {% for row in rows %}
09          {% if forloop.first %}
10
11             <tr class="cls3">
12               <!-- The headers -->
13               {% for key,val in row %}
14                  <th class="cls4">key</th>
15               {% endfor %}
16             </tr>
17
18             {% cycle even odd as rc %}
19             <tr class="cls5 {{rc}}">
20               {% for key,val in row %}
21                 <td class="cls6">val<td>
22               {% endfor %}
23             </tr>
24          {% endfor %}
25        {% endfor %}
26     </table>
27   { %endif }
28 {% endblock %}

Instead, what I am doing now is I am manually adding the column titles as a separate template variable.

Regards,

Joe

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

Re: OperationalError: no connection to the server using Django and gunicorn

Hi Adrian,

Have you solved this weird issue?

if yes, please tell me how.

Best regards,
Andrey Makhnach

On May 27, 12:53 pm, Adrián Ribao <ari...@gmail.com> wrote:
> I'm doing it manually because I'm just testing:
>
> ./manage.py run_gunicorn -c gunicorn.conf.py
>
> where gunicorn.conf.py
>
> # -*- coding: utf-8 -*-
> import multiprocessing
>
> bind = "127.0.0.1:8000"
> workers = multiprocessing.cpu_count() * 2 + 1
> worker_class = 'gevent'
>
> On 27 mayo, 02:23, Shawn Milochik <sh...@milochik.com> wrote:
>
>
>
>
>
>
>
> > What's the command you're using to run it?
>
> > Are you in screen? Are you using supervisor or anything like that?

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

Re: Weird join conditions

> Hmm, could you please provide an example? (-: Don't know whether it's
> the late night combined with lack of caffeine or something else but I
> can't figure out the difference at the mo> It seems you know pretty much about Django ORM if you work on

One example will be an outer join. Adding same condition to where
will force it to an

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

Re: Weird join conditions

On Thu, Jun 30, 2011 at 02:13:05PM -0700, peroksid wrote:
> Thank you, Michal,
>
> Unfortunately, I need join condition, not a WHERE clause, which can be
> easily extended with extra() method arguments.
> It is not my bad mood, simply the same condition in WHERE and ON
> produces different effect.

Hmm, could you please provide an example? (-: Don't know whether it's
the late night combined with lack of caffeine or something else but I
can't figure out the difference at the moment...

> I think rather about some method which gets together whole SQL query.
> Currently I call join() on queryset's query to join my table with part
> of target join condition.
> I could take the query assembled by "assembler" method and replace the
> part of condition with an entire one.
>
> It seems you know pretty much about Django ORM if you work on
> composite keys (great respect).
> Could you please hint me about this "assembler" method I babble about?

Well, basically, the models.sql.query.Query.join method and friends
manage a list of joins which is then processed in
models.sql.compiler.SQLCompiler.get_from_clause.

Anyway, in some cases it might be more reasonable to just write your
own query instead of fighting with the ORM to make it do what you
wanti at all cost. (-; Bear in mind that if you try to override these
deeply hidden mechanisms in your code, you'll have to keep in sync
with any internal changes and refactors. And I can assure you these
will happen in the foreseeable future. (-;

Michal

Re: Drop down box in django getting populated from a database table column

Thanks a lot...I understood...and its working
provided me a complete different angle of looking at it :)

On Jun 30, 2:17 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> Op donderdag 30 juni 2011 22:10:08 UTC+1 schreef sony het volgende:
>
>
>
> > Ok...this might work for the second option .
> > How about getting a drop down box from a data base table column
>
> For the third time: that is what automatically happens when you use a
> ForeignKey field in a form. No programming required.
> --
> DR.

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

Re: Open source Django websites

On Monday 20 June 2011 13:42:52 benregn wrote:
> Thank you very much. I was not aware of that site.
>
> On Jun 20, 12:48 pm, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> > On Mon, 2011-06-20 at 00:11 -0700, benregn wrote:
> > > I was wondering if there are any complete websites using Django that
> > > are open source, i.e. it's possible to browse all its files, structure
> > > and code.

Hi,

Did you actually manage to get any of those sites to work? (and if yes,which
one?)

As far as I can tell they are for
- older versions of django
- miss basic files (settings.py?) of instructions how to get things to work
- or generate bundles of errors often due to being an old version of missing
all kinds of undocumented dependancies.

Al in all after trying to get some 15 sites running I can only conclude that
the site isuseless for finding a site to learn from. As a promotional site
it's fine of course although it could use a repeating recheck of the sites
mentioned as many seemed to have disappeared of use other CMS'es or
frameworks.


Anyhow, I'm still searching for the sourcecode for a simple basic site with a
few static pages, maybe a small app. Not to many obscure external dependancies
and using the default django 1.3 environment (eg. the default settings.py
etc.)

I just need something to start hacking around in and the tutorial on the
django site doesn't offer that. The webmonkey tutorial is outdated as are the
other tutorials I've found.

Anyone?

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

Re: Deferred fields

Use a property in combination with an ordinary null=True field. Always
access it (from python or template code) via the property.

On Thu, Jun 30, 2011 at 4:13 PM, Ori <ori.livneh@gmail.com> wrote:
> Hi,
>
> I'd like to defer calculating a value for a particular field until the
> value is required.
>
> Suppose I have these models:
>
> class Fruit(models.Model):
>    # various fields
>
> class FruitBasket(models.Model):
>    fruit = models.ManyToManyField(Fruit)
>
> I'd like to add a "most_nutritious" field to FruitBasket that is a
> ForeignKey to a fruit object, which will represent the most nutritious
> fruit in the basket. But determining which fruit is the most
> nutritious is expensive, so I'd like to only set a value for this if
> it's required. But if I do compute a value, I want to store it in the
> database so that I don't have to re-compute every time.
>
> Ideally, I'd like to do something like this:
>
> most_nutritious = models.LazyField(default=None,
> compute=some_callable)
>
> Whenever a FruitBasket is loaded, if the raw value of
> "most_nutritious" is None, some validator computes the identity of the
> most nutritious fruit, saves it, and pretends the value was always
> there. If it's not None, the validator just returns the value
> unmodified.
>
> I think I'd know how to implement this if calculating the final value
> did not depend on the value of other columns. My problem is that
> to_python methods & co. are not (to my knowledge) given access to the
> model instance being loaded/saved -- just the column value.)
>
> Any thoughts?
>
> Thanks!
> Ori
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

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

Re: Implementing a User Search Feature

On Jun 30, 8:23 pm, raj <nano.ri...@gmail.com> wrote:
> Tried googling but couldn't come up with much.
> How do I implement a User Search feature?

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#filter

Anything else ?

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

Django AJAX polling: Best practice?

Hello everyone,

We have a game-application where several players should interact in
realtime (i.e. change attributes of a "game"-object, which is a django
model instance). To my knowledge, best / easiest method for this
problem would be AJAX-polling several times per second, to check
whether the game has changed or not since the last poll. To avoid
waste of bandwidth, we want of course only send the data that has
changed since the last poll, not the whole object over and over again.
We decided to use dajaxice and jquery.

However, I'm not really sure how to approach that task:
- One possiblity would be using the db, writing every change in there
and querying it for every poll. Maybe that game-instance will then get
cached if we use cache-middleware, but since I've never worked with
caching I'm not sure about this and don't feel confident with this
approach.
- The other possibility would be a global dict (or instance of an own
class), let's call it GAMES_ACTIVE, where each active game is stored
by its id. Then I could save the 'state' and the 'changes' of the game
there. So if player X changes game attributes that others would need
to poll, I could update the state and additionally append the new data
to a list of changes for each player that yet wasn't polled:
GAMES_ACTIVE[game.id]['state'] = game-instance, always up to date
GAMES_ACTIVE[game.id]['changes'][player_Y] = [list of not yet
polled changes for player Y]
As soon as Player Y polls the changes, they are sent to the client,
and the 'changes' for player Y is reset to an empty list []

Is this a good way to solve the problem? Any other suggestions?

Regards,
Andreas

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

Deferred fields

Hi,

I'd like to defer calculating a value for a particular field until the
value is required.

Suppose I have these models:

class Fruit(models.Model):
# various fields

class FruitBasket(models.Model):
fruit = models.ManyToManyField(Fruit)

I'd like to add a "most_nutritious" field to FruitBasket that is a
ForeignKey to a fruit object, which will represent the most nutritious
fruit in the basket. But determining which fruit is the most
nutritious is expensive, so I'd like to only set a value for this if
it's required. But if I do compute a value, I want to store it in the
database so that I don't have to re-compute every time.

Ideally, I'd like to do something like this:

most_nutritious = models.LazyField(default=None,
compute=some_callable)

Whenever a FruitBasket is loaded, if the raw value of
"most_nutritious" is None, some validator computes the identity of the
most nutritious fruit, saves it, and pretends the value was always
there. If it's not None, the validator just returns the value
unmodified.

I think I'd know how to implement this if calculating the final value
did not depend on the value of other columns. My problem is that
to_python methods & co. are not (to my knowledge) given access to the
model instance being loaded/saved -- just the column value.)

Any thoughts?

Thanks!
Ori

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

Re: forms and form processing

Hello,

thanks for the reply

I dont have email settings in my settings.py file? is that straightforward, like an import statement or
something more complex?

I am using django version (1, 1, 1, 'final', 0) - that's what i got after typing import django django.VERSION on the python shell

Jay k

On Thu, Jun 30, 2011 at 3:36 AM, urukay <radovan.bella@gmail.com> wrote:
Hi,
have you got email settings set in your settings.py?
What version of Django are you using?

Radovan
http://www.yau.sk

On 29. Jún, 00:23 h., "jay K." <jay.developer2...@gmail.com> wrote:
> Hello,
>
> I need to add a form on my django website
>
> so far this is what i have:
>
> in my models.py:
>
> .... import statements not shown here
>
> CONTACT_OPTIONS = (
>                                  ('skype video anruf','Skype Video-
> Anruf'),
>                                  ('skype anruf ','Skype Anruf'),
>                                  ('telefon','Telefon')
>                                 )
>
> class ContactForm(forms.Form):
>
>     #wann
>     date_input = forms.CharField(max_length=30, required=True) #,
> initial="MO-FR"
>     time_input = forms.CharField(max_length=30, required=True) # 14:00
> - 22:00
>
>     #wie
>     choice_options = forms.ChoiceField(widget=RadioSelect,
> choices=CONTACT_OPTIONS, required=True)
>
>     #contact
>     email = forms.EmailField(max_length=30, required=True)
>     telephone = forms.CharField(max_length=30, required=False)
>     skype = forms.CharField(max_length=30, required=False)
>
>     #comment
>     comment_text = forms.CharField(widget=forms.Textarea,
> required=False)
>
> my views.py
>
> from website.contact.models import ContactForm
> from django.shortcuts import render_to_response
> from django.template.context import RequestContext
> from django.http import HttpResponseRedirect, HttpResponse
> from django.core.mail import send_mail
>
> def contact(request):
>
>     if request.method == 'POST': # If the form has been submitted...
>         form = ContactForm(request.POST) # A form bound to the POST
> data
>
>         if form.is_valid(): # All validation rules pass
>             # Process the data in form.cleaned_data
>
>             subject = form.cleaned_data['subject']
>             message = form.cleaned_data['message']
>             sender = form.cleaned_data['sender']
>             cc_myself = form.cleaned_data['cc']
>
>             date_input = form.cleaned_data['date input']
>             time_input = form.cleaned_data['time input']
>             choice_options = form.cleaned_data['contact options']
>
>             telephone = form.cleaned_data['telefone']
>             email = form.cleaned_data['email'] # this is the sender's
> email
>             skype = form.cleaned_data['skype']
>
>             comment_text = form.cleaned_data['comment text']
>
>             """
>             recipients = ['joung.k...@lingua-group.org']
>             if cc_myself:
>                 recipients.append(sender)
>             """
>            #subject
>             send_mail('subject', 'message', 'myem...@myemail.com',
> ['myem...@myemail.com', email], fail_silently=False)
>
>             return HttpResponseRedirect('/danke/')
>
>     else:
>         form = ContactForm() # An unbound form
>
>     return render_to_response('beratungstermin.html', {'form': form},
> context_instance=RequestContext(request))
>
> And on the website I have all the fields inside the form tag
> <form action="/mythankyoupage" method="post">
> {{ forms.as_p }}
> </form>
>
> What I want to do basically is to add the fields for name, email, tel,
> some of them being compulsory, so the form should not be processed if
> there is some info. missing.
>
> I also want to receive a confirmation email whenever a user sends
> information through the page, to my "myem...@myemail.com" (this is not
> working on my code either), and a "CC" button if the user wants a copy
> of his/her own message.
>
> Thanks
>
> Let me know if you need any details
>
> PS: i copied most of the code from the official django tutorial athttps://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs, but
> somehow I do not receive any emails after hitting the submit button.
> Also, even if I declared in my views.py that some fields are
> "required=True", I can still hit the send button with no error
> messages for those unfilled textfields.

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


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

Re: Implementing a User Search Feature

The canonical answer for search in django is probably solr,
http://lucene.apache.org/solr/ This probably covers all your search needs.

haystack, http://haystacksearch.org/ should provide an easy to use API

Stuart Mackay
Lisbon, Portugal

> Tried googling but couldn't come up with much.
> How do I implement a User Search feature? Where an individual can type
> in the first and/or last name of user and come up with results? I saw
> some things about how to search through a site, but I think this is a
> little different.
> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Drop down box in django getting populated from a database table column

On Thursday, 30 June 2011 18:51:54 UTC+1, sony wrote:
I searched the same thing on net and got many answers but some how
dint get working with any of them. Table: 1. Report :
reportType(foreign key from ReportCategory), name, description 2.
Report Category: name,description forms.py

class ReportForm_insert(forms.ModelForm):

class Meta:
    model=Report
    invent = ReportCategory.objects.all()
    print invent
    reportType_id = forms.ModelMultipleChoiceField(queryset = invent)

    fields =('name','description',)

model.py

class ReportCategory(models.Model):

name = models.CharField(max_length=20)

description =  models.CharField(max_length=20)

def __unicode__(self):
    return self.name

class Report(models.Model):

reportType = models.CharField(max_length=200)

name = models.CharField(max_length=200)

description = models.CharField(max_length=300)

def __unicode__(self):
    return self.name

I want the ReportType to be shown as a drop down box which would
contain values from the name column of the Report Category table. I am
surely going wrong big way but I am not understanding what to do... So
I am not understanding whether there is a problem with not able to
handle the foreign key or the drop down box.


It's not so much "going about it the wrong way" as "posting completely nonsensical code". You certainly didn't see anywhere "on the net" anything that told you to write logic in the Meta inner class.

You don't have a ForeignKey in your model. If you want the reportType field to be populated with elements from the ReportCategory model, you should make it a ForeignKey.
--
DR.

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

Re: Implementing a User Search Feature

On 06/30/2011 02:23 PM, raj wrote:
> Tried googling but couldn't come up with much.
> How do I implement a User Search feature? Where an individual can type
> in the first and/or last name of user and come up with results? I saw
> some things about how to search through a site, but I think this is a
> little different.
> Thank you.
>
What search terms did you use in Google?

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

Implementing a User Search Feature

Tried googling but couldn't come up with much.
How do I implement a User Search feature? Where an individual can type
in the first and/or last name of user and come up with results? I saw
some things about how to search through a site, but I think this is a
little different.
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Drop down box in django getting populated from a database table column

I searched the same thing on net and got many answers but some how
dint get working with any of them. Table: 1. Report :
reportType(foreign key from ReportCategory), name, description 2.
Report Category: name,description forms.py

class ReportForm_insert(forms.ModelForm):

class Meta:
model=Report
invent = ReportCategory.objects.all()
print invent
reportType_id = forms.ModelMultipleChoiceField(queryset = invent)

fields =('name','description',)

model.py

class ReportCategory(models.Model):

name = models.CharField(max_length=20)

description = models.CharField(max_length=20)

def __unicode__(self):
return self.name

class Report(models.Model):

reportType = models.CharField(max_length=200)

name = models.CharField(max_length=200)

description = models.CharField(max_length=300)

def __unicode__(self):
return self.name

I want the ReportType to be shown as a drop down box which would
contain values from the name column of the Report Category table. I am
surely going wrong big way but I am not understanding what to do... So
I am not understanding whether there is a problem with not able to
handle the foreign key or the drop down box.

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

django.contrib.admin - custom css class in result_headers

Hi there,
as I want to add custom css class to table header in admin, I was
looking for template, which I should edit.

I found that method result_headers in django/contrib/admin/
templatetags/admin_list.py sets whole 'class="xxx"' string. Why is
there 'class=' thing ? It's quiet complicated to alter template with
this hardcoded string. (This part of question is more for developers,
maybe)

My question is, how can I override templatetag ( result_headers in
this case ) ?

Thank you!

Ps: My original idea was add css class according to field name and
type, eg: class="id integer", etc. I want to specify column width
according it's content. Is there any better solution than overriding
template tag?

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

Re: More than one project using the same database

OP: in a nutshell, unless you fully understand the risks, you should avoid doing this on a site which is in production. However, this would be a great opportunity to learn about this subject in a dev environment. After all, thats how i learnt (except i made the mistake of doing it in production and now i have to support and maintain that bad code for 5 years) lol.

On 30 Jun 2011 16:46, "Cal Leeming [Simplicity Media Ltd]" <cal.leeming@simplicitymedialtd.co.uk> wrote:
> On Thu, Jun 30, 2011 at 4:36 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
>
>> On Thu, Jun 30, 2011 at 4:24 PM, Cal Leeming [Simplicity Media Ltd]
>> <cal.leeming@simplicitymedialtd.co.uk> wrote:
>> >
>> > I agree the principle is *almost* the same, but the risks are higher,
>> > because OP said that the two applications are not the same, and that the
>> > external app performs db writes, thus increasing the risk even further.
>> > Andres said, that because the database has transactions, then the OP
>> should
>> > be fine. This is a huge overstatement, and could have left OP under the
>> > impression that race conditions wouldn't happen. The reason I've jumped
>> on
>> > this pretty hard, is simply because of a lack of respect for
>> > handling/understanding race conditions by some developers, and because
>> > Andres answered an issue which he clearly did not understand
>> properly. (of
>> > which the OP accepted that answer as correct). Could have lead to the OP
>> > having a very bad day a few days/weeks/months later lol.
>> >
>>
>> The applications have different purposes, it doesn't mean the data
>> structures aren't the same. You keep banging on about race conditions,
>> but I see no races here - unless you do something 'racy', but you can
>> do that easily enough with a single website.
>>
>
> I agree that the same could happen with any other single website. This is
> more about making sure the OP realises that race conditions do (and will)
> happen, despite if transactions are enabled or not.
>
>
>>
>> I have a site that is in a similar situation to this. The frontend
>> website is served from two different DCs, with multi master
>> replication between the sites, with read mirrors in each DC. There is
>> then a backend website, which runs from one of the DCs, and connects
>> to one of the master/slave to do live analysis of data. This works
>> perfectly.
>>
>> OP: Keep your model definitions the same between the sites, and you
>> will have no issues whatsoever, 100% guaranteed*.
>>
>> Cheers
>>
>> Tom
>>
>> * This is not a guarantee ;)
>>
>
> lol ;p
>
>
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>

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

Re: giving download links

Actually, to serve the media you'll want to use any normal web server
such as Apache or Lighttpd.

In other words, Django has nothing to do with serving up those files.
The Django application only provides a means for users to upload to
the media folder. The media folder has to be configured outside of
Django to be served up by the HTTP server.


On Jun 28, 4:00 am, Herman Schistad <herman.schis...@gmail.com> wrote:
> On Tue, Jun 28, 2011 at 05:20, raj <nano.ri...@gmail.com> wrote:
> > I allow a user to upload a file, how do I now allow them to download
> > this file? I looked at the "serving static files" thing in the
> > djangoproject, but they said it causes security flaws or something.
> > Can someone help me? I couldn't find good information on google. Thank
> > you.
>
> What do you mean, you just give them the link to the file they just uploaded.
> <a href="{{ MEDIA_URL }}/images/image_to_download.jpg">Download here</a>
> Here you can use whatever template tools you have available.
>
> Serving static files are just for debugging and to be used with
> manage.py runserver, due to, as you said, security and scaling.
> You should look into mod_python, mod_wsgi, fastcgi or some other
> application, in order to serve your media files.
>
> Take a look at the documentation or the djangobook:https://docs.djangoproject.com/en/dev/howto/deployment/http://www.djangobook.com/en/beta/chapter21/
>
> Or am I missing something?
>
> --
> With regards, Herman Schistad

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

Re: More than one project using the same database



On Thu, Jun 30, 2011 at 4:36 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Thu, Jun 30, 2011 at 4:24 PM, Cal Leeming [Simplicity Media Ltd]
> I agree the principle is *almost* the same, but the risks are higher,
> because OP said that the two applications are not the same, and that the
> external app performs db writes, thus increasing the risk even further.
> Andres said, that because the database has transactions, then the OP should
> be fine. This is a huge overstatement, and could have left OP under the
> impression that race conditions wouldn't happen. The reason I've jumped on
> this pretty hard, is simply because of a lack of respect for
> handling/understanding race conditions by some developers, and because
> Andres answered an issue which he clearly did not understand properly. (of
> which the OP accepted that answer as correct). Could have lead to the OP
> having a very bad day a few days/weeks/months later lol.
>

The applications have different purposes, it doesn't mean the data
structures aren't the same. You keep banging on about race conditions,
but I see no races here - unless you do something 'racy', but you can
do that easily enough with a single website.

I agree that the same could happen with any other single website. This is more about making sure the OP realises that race conditions do (and will) happen, despite if transactions are enabled or not.
 

I have a site that is in a similar situation to this. The frontend
website is served from two different DCs, with multi master
replication between the sites, with read mirrors in each DC. There is
then a backend website, which runs from one of the DCs, and connects
to one of the master/slave to do live analysis of data. This works
perfectly.

OP: Keep your model definitions the same between the sites, and you
will have no issues whatsoever, 100% guaranteed*.

Cheers

Tom

* This is not a guarantee ;)

lol ;p
 

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


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

Re: More than one project using the same database

On Thu, Jun 30, 2011 at 4:24 PM, Cal Leeming [Simplicity Media Ltd]
<cal.leeming@simplicitymedialtd.co.uk> wrote:
>
> I agree the principle is *almost* the same, but the risks are higher,
> because OP said that the two applications are not the same, and that the
> external app performs db writes, thus increasing the risk even further.
> Andres said, that because the database has transactions, then the OP should
> be fine. This is a huge overstatement, and could have left OP under the
> impression that race conditions wouldn't happen. The reason I've jumped on
> this pretty hard, is simply because of a lack of respect for
> handling/understanding race conditions by some developers, and because
> Andres answered an issue which he clearly did not understand properly. (of
> which the OP accepted that answer as correct). Could have lead to the OP
> having a very bad day a few days/weeks/months later lol.
>

The applications have different purposes, it doesn't mean the data
structures aren't the same. You keep banging on about race conditions,
but I see no races here - unless you do something 'racy', but you can
do that easily enough with a single website.

I have a site that is in a similar situation to this. The frontend
website is served from two different DCs, with multi master
replication between the sites, with read mirrors in each DC. There is
then a backend website, which runs from one of the DCs, and connects
to one of the master/slave to do live analysis of data. This works
perfectly.

OP: Keep your model definitions the same between the sites, and you
will have no issues whatsoever, 100% guaranteed*.

Cheers

Tom

* This is not a guarantee ;)

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

Re: Problem with Tutorial 1 - Django Version = 1.3

Hi OP,

Just as a side note, it's probably worth learning about how Python works before jumping straight into Django. (I'm assuming this based on __unicode__ did not have proper indentation). 

My apologies if I am wrong though!

Cal

On Thu, Jun 30, 2011 at 3:19 PM, Jarilyn Hernandez <jary.hernandez@gmail.com> wrote:
Thanks for your responses. The problem was solved.

Best Regards,

Eiram


On Thu, Jun 30, 2011 at 10:06 AM, Jirka Vejrazka <jirka.vejrazka@gmail.com> wrote:
> class Poll(models.Model):
>    question = models.CharField(max_length=200)
>    pub_date = models.DateTimeField('date published')
> def __unicode__(self):
>        return self.question
>
> class Choice(models.Model):
>    poll = models.ForeignKey(Poll)
>    choice = models.CharField(max_length=200)
>    votes = models.IntegerField()
> def __unicode__(self):
>        return self.choice
>
> When I execute the command Poll(objetcs.all): I get as result the
> following: class [<Poll: Poll object>, <Poll: Poll object>] when I;m
> supposed to get as result [<Poll: What's up?>]
>
> I don't know what is missing. If someone can help me I would
> appreciate it. Thanks!!

 Apart from the problem Kenneth pointed out, you seem to have the
indentation wrong. The "def __unicode__" belongs to the class, not on
the same level as the "class" word.

 Cheers

   Jirka

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




--
Jarilyn M. Hernández
MS Computer Science
Polytechnic University of Puerto Rico
Tel: (787) 408-6637

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

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

Re: Installing requirements in a virtualenv works when installed manually, fails when installed automatically

On Thu, Jun 30, 2011 at 3:59 PM, Benedict Verheyen
<benedict.verheyen@gmail.com> wrote:
> Hi,
>
>
> i've encountered a strange problem. When I install packages on the server in a virtualenv
> with pip manually, my page loads correctly.
> If I install the requirements via "pip install -r requirements", then i get the following error in apache:
>

Did you forget to tell pip to install to a virtualenv? Activate the
virtualenv, or pass "-E /path/to/venv/base" to pip.

If that doesn't work, we'd probably need to see the pip installation log.

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

Re: More than one project using the same database



On Thu, Jun 30, 2011 at 4:13 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Thu, Jun 30, 2011 at 4:03 PM, Cal Leeming [Simplicity Media Ltd]
<cal.leeming@simplicitymedialtd.co.uk> wrote:
> The advice given to you by Andres is absolutely wrong.
> By doing this, you are opening yourself up to all sorts of race conditions.
> If you absolutely must allow this, you may want to consider implementing an
> object locking server (we have used memcache to do this before), but you'd
> need to handle this within the code logic, and you can open yourself up to
> more issues if it's not done correctly.
> Personally, I would strongly advice against doing this.
> Cal

Woah, thats a bit harsh. I can't see anything wrong with this
approach, provided that both applications use precisely the same model
definitions (preferably by sharing the app between the two projects).

In effect, it is no different from two load balanced backends talking
to the same DB server, which is *well tested*.

I agree the principle is *almost* the same, but the risks are higher, because OP said that the two applications are not the same, and that the external app performs db writes, thus increasing the risk even further.

Andres said, that because the database has transactions, then the OP should be fine. This is a huge overstatement, and could have left OP under the impression that race conditions wouldn't happen. The reason I've jumped on this pretty hard, is simply because of a lack of respect for handling/understanding race conditions by some developers, and because Andres answered an issue which he clearly did not understand properly. (of which the OP accepted that answer as correct). Could have lead to the OP having a very bad day a few days/weeks/months later lol.
 

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


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

Weird join conditions

Hi.

Queryset attribute query has method join() which allows to explicitly
make JOINs. First argument passed to this method is a tuple of left
table, right table, left column and right column, and rest of
arguments define if we have LEFT OUTER or INNER join. Arguments from
the tuple are used to create an "ON" expression like
left_table.left_column=right_table.right_column.

I need to have for the "ON" expression slighlty more complex
expression, something like
"left_table.left_column=right_table.right_column AND
right_table.another_column=42". Method join() obviously can not be
used for this purpose because it tuple defining join connection
consists off 4 elements.
I suspect there is no way to create such a double join condition at
all, event without constant involved instead of column.

Tinkering with query does not promise anything here.
I could be happy with replacing a part of resulting SQL query before
it is sent to the database.
Is there a way to filter text of SQL query somewhere before it is
executed?

Best regards,
Alexander Pugachev.

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

Re: More than one project using the same database

On Thu, Jun 30, 2011 at 4:03 PM, Cal Leeming [Simplicity Media Ltd]
<cal.leeming@simplicitymedialtd.co.uk> wrote:
> The advice given to you by Andres is absolutely wrong.
> By doing this, you are opening yourself up to all sorts of race conditions.
> If you absolutely must allow this, you may want to consider implementing an
> object locking server (we have used memcache to do this before), but you'd
> need to handle this within the code logic, and you can open yourself up to
> more issues if it's not done correctly.
> Personally, I would strongly advice against doing this.
> Cal

Woah, thats a bit harsh. I can't see anything wrong with this
approach, provided that both applications use precisely the same model
definitions (preferably by sharing the app between the two projects).

In effect, it is no different from two load balanced backends talking
to the same DB server, which is *well tested*.

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

Re: More than one project using the same database

The advice given to you by Andres is absolutely wrong.

By doing this, you are opening yourself up to all sorts of race conditions.

If you absolutely must allow this, you may want to consider implementing an object locking server (we have used memcache to do this before), but you'd need to handle this within the code logic, and you can open yourself up to more issues if it's not done correctly.

Personally, I would strongly advice against doing this.

Cal

On Thu, Jun 30, 2011 at 12:53 PM, <andres.osinski@gmail.com> wrote:
In theory, unless you've disabled transactions, the database should be able to manage all contention issues.
Enviado desde mi BlackBerry de Movistar (http://www.movistar.com.ar)

-----Original Message-----
From: ALJ <astley.lejasper@gmail.com>
Sender: django-users@googlegroups.com
Date: Thu, 30 Jun 2011 04:46:15
To: Django users<django-users@googlegroups.com>
Reply-To: django-users@googlegroups.com
Subject: More than one project using the same database

I have an extranet type project that has been running for a year. It
only has a maximum user base of about 50 people of which probably only
a few are using it at any one time. The users can add, edit and delete
items within the application

However, we need to expose the data in that extranet application to a
another group of users but through another domain. Anonymous users
will be able to register requests to be contacted, and another group
of known users  will be able to log in with read only access to see
the status of those requests.

My question is, what are the issues that I need to think about (are
race issues one?), is it possible to detect if these issues could
occur in my particular situation, and how do you mitigate against
these.

ALJ

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

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


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

Installing requirements in a virtualenv works when installed manually, fails when installed automatically

Hi,


i've encountered a strange problem. When I install packages on the server in a virtualenv
with pip manually, my page loads correctly.
If I install the requirements via "pip install -r requirements", then i get the following error in apache:

Internal Server Error

Apaches error.log:
[Thu Jun 30 15:04:27 2011] [info] [client 172.16.50.2] mod_wsgi (pid=5416, process='', application='inventory|'): Loading WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi'.
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] mod_wsgi (pid=5416): Target WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi' cannot be loaded as Python module.
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] mod_wsgi (pid=5416): Exception occurred processing WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi'.
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] Traceback (most recent call last):
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] File "/home/ict/websites/inventory/inventory/apache/inventory.wsgi", line 27, in
<module>
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] import django.core.handlers.wsgi
[Thu Jun 30 15:04:27 2011] [error] [client 172.16.50.2] ImportError: No module named django.core.handlers.wsgi
[Thu Jun 30 15:04:27 2011] [debug] mod_deflate.c(615): [client 172.16.50.2] Zlib: Compressed 605 to 372 : URL /
[Thu Jun 30 15:04:30 2011] [info] [client 172.16.50.2] mod_wsgi (pid=5417, process='', application='inventory|'): Loading WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi'.
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] mod_wsgi (pid=5417): Target WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi' cannot be loaded as Python module.
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] mod_wsgi (pid=5417): Exception occurred processing WSGI script
'/home/ict/websites/inventory/inventory/apache/inventory.wsgi'.
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] Traceback (most recent call last):
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] File "/home/ict/websites/inventory/inventory/apache/inventory.wsgi", line 27, in
<module>
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] import django.core.handlers.wsgi
[Thu Jun 30 15:04:30 2011] [error] [client 172.16.50.2] ImportError: No module named django.core.handlers.wsgi
[Thu Jun 30 15:04:30 2011] [debug] mod_deflate.c(615): [client 172.16.50.2] Zlib: Compressed 605 to 372 : URL /

The inventory.wsgi file:
=====================================
import sys
import os

apache_dir = os.path.dirname(os.path.abspath(__file__))
project_dir = os.path.normpath(os.path.join(apache_dir + '/../..'))
app_dir = os.path.normpath(os.path.join(apache_dir + '/..'))

sys.path = [
os.path.join(project_dir, 'lib/python2.7/site-packages'),
project_dir,
app_dir
] + sys.path

os.environ['DJANGO_SETTINGS_MODULE'] = 'inventory.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
=====================================

There is nothing wrong with apache/nginx/memcached as other projects run correctly.

Although I have a solution, I'm puzzled as to what causes this.
My requirements file:

-e svn+http://code.djangoproject.com/svn/django/trunk#egg=django
Werkzeug==0.6.2
-e
git+git://kwebvs02/projects/common_utils#egg=common_utils
distribute==0.6.14
django-extensions==0.6
psycopg2==2.4.2
python-memcached==1.47
wsgiref==0.1.2

I use Django from trunk, common_utils is a local lib I developed .
So using above requirements, installation with pip -r fails, installing them manually works, for instance
pip install psycopg2

Any idea?

Cheers,
Benedict

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

Re: "attempt to write a readonly database" with write permissions in database file and folder

Hi

> Seems selinux permissions are causing trouble. Try shutting it off and try
> again.

Thank you! After switching selinux to permissive mode I was able to
access the admin pages.
(Now I need to learn how to config selinux to let django do its thing
without the need to disable selinux completely .... pointers are
welcome)

Hector

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

Re: ImportError: No module named site

On Thu, Jun 30, 2011 at 4:54 AM, bruno desthuilliers
<bruno.desthuilliers@gmail.com> wrote:
> On Jun 29, 7:32 pm, Kyle Latham <kly.lat...@gmail.com> wrote:
> (snip)
>> I have no idea what is going wrong, but here is all my code thus far
>> (I'm following the tutorial to create my own app that will display
>> various material measurements)
>>
>> -----------------------------------------------
>> models.py
>> -----------------------------------------------
>> from django.db import models
>>
>> # Create your models here.
>> class adhesive(models.Model):
>>     measurement_id = models.CharField(max_length = 200)
>>     material_id = models.CharField(max_length = 200)
>>     program_name = models.CharField(max_length = 200)
>>     date = models.DateField()
>>     measurement_method = models.CharField(max_length = 30)
>>     frequency_low = models.IntegerField()
>>     frequency_high = models.IntegerField()
>>
>> class ceramic(models.Model):
>>     measurement_id = models.CharField(max_length = 200)
>>     material_id = models.CharField(max_length = 200)
>>     program_name = models.CharField(max_length = 200)
>>     date = models.DateField()
>>     measurement_method = models.CharField(max_length = 30)
>>     frequency_low = models.IntegerField()
>>     frequency_high = models.IntegerField()
>>
>> class composite(models.Model):
>>     measurement_id = models.CharField(max_length = 200)
>>     material_id = models.CharField(max_length = 200)
>>     program_name = models.CharField(max_length = 200)
>>     date = models.DateField()
>>     measurement_method = models.CharField(max_length = 30)
>>     frequency_low = models.IntegerField()
>>     frequency_high = models.IntegerField()
>>
>
> Totally unrelated to your question, but: why on earth are you creating
> 3 distincs models with the exact same fields ??? You just need one
> single model, and add a "material_type" field (eventually passing in a
> choices list of "Composite", "Ceramic" and "Adhesive").

Another possibility is to make a Material abstract base class, and
have Adhesive, Ceramic, and Composite inherit from it. Or, have a
non-abstract Material base class. Doing either of these things really
only makes sense if you have extra fields to add to the subclasses. I
tend to think doing what Bruno suggests (adding a material type field)
will work better.

Reference; https://docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance

--
Question the answers

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