Graham Dumpleton | 1 Sep 01:02 2009
Picon

Re: Django and SSL Deployment using mod_wsgi


On Sep 1, 3:39 am, Francis <f.du... <at> gmail.com> wrote:
> We setup a Nginx proxy in front of Apache/WSGI and got Nginx to handle
> the SSL cert and simply pass on a flag to WSGI if the connection was
> coming through http or https.
>
> Next you'll want a SSL middleware, we use:http://www.djangosnippets.org/snippets/240/
>
> Now its a matter of configuring which views you want SSL (follow
> example in the middleware)

You don't need a SSL middleware. Just add to your Apache
configuration:

  SetEnvIf X-Forwarded-SSL on HTTPS=1

Apache/mod_wsgi will allow overriding of wsgi.url_scheme based on
HTTPS variable. The HTTPS variable can be set to 'On' or '1'. Case
ignored in comparison.

Thus, you can use mod_setenvif to check for header being set and what
value and then set HTTPS.

Graham

> On Aug 28, 11:04 pm, Vitaly Babiy <vbabi... <at> gmail.com> wrote:
>
>
>
> > Hey guys,
(Continue reading)

Gyanit | 1 Sep 02:18 2009
Picon

SQL query with complex WHERE clause


Hi All,

I don't seem to find good source to help me write a complex where condition
in the django.

The where condition is generic boolean clause built on top of literals. The
literal are just == or != check on a single field.
for example ((field1 == 2 and field2 != 5) or field3 == 6).
another example ((field1 > 1 or field1 < -3) and (field2 != "comment")) or
field3 == "django"

I think it should be writable in the django queryset but I can't seem to
formulate it in generic format.

Any pointers or guidance will be great.

thanks

--

-- 
View this message in context: http://www.nabble.com/SQL-query-with-complex-WHERE-clause-tp25232455p25232455.html
Sent from the django-users mailing list archive at Nabble.com.

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

(Continue reading)

weiwei | 1 Sep 02:35 2009
Picon

ImportError No module named myapp.views.hometest


backgroud information:
server: fedora11
web server : apache 2.2 + mod_wsgi2.5

my project location
'/usr/local/django/myproject'
'/usr/local/django/myproject/myapp'

in the django.wsgi i have

---------------
sys.path.append('/usr/local/django')
sys.path.append('/usr/local/django/myproject')
-------------

In the debug information i already saw python path '[/usr/local/
django]'

And i have everything under /usr/local/django readable an
executable .

i still got this error.  Something else i need to check?

Thanks for any help!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
(Continue reading)

weiwei | 1 Sep 02:35 2009
Picon

Re: ImportError No module named myapp.views.hometest


forgot to mention i am using django1.1

On Aug 31, 5:35 pm, weiwei <online.service.... <at> gmail.com> wrote:
> backgroud information:
> server: fedora11
> web server : apache 2.2 + mod_wsgi2.5
>
> my project location
> '/usr/local/django/myproject'
> '/usr/local/django/myproject/myapp'
>
> in the django.wsgi i have
>
> ---------------
> sys.path.append('/usr/local/django')
> sys.path.append('/usr/local/django/myproject')
> -------------
>
> In the debug information i already saw python path '[/usr/local/
> django]'
>
> And i have everything under /usr/local/django readable an
> executable .
>
> i still got this error.  Something else i need to check?
>
> Thanks for any help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
(Continue reading)

Joshua Partogi | 1 Sep 04:10 2009
Picon

Renaming displayed django application name in admin

Dear all,


How do we change the displayed application name in django admin? Let's say I have an application called foo, I wanted it to be displayed as bar instead of foo in the admin system.

I've searched the document but failed to get the answer for this. 

Thank you in advance for your help.

--
http://blog.scrum8.com
http://twitter.com/scrum8

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

Karen Tracey | 1 Sep 04:51 2009
Picon

Re: unique=True and IntegrityError

On Mon, Aug 31, 2009 at 6:27 PM, aa56280 <aa56280 <at> gmail.com> wrote:


I can't find an answer to this, so I'm hoping folks here can help: why
is it that Django catches IntegrityError for a field with unique=True
in the Admin tool but requires you to catch it yourself in your app?
That is, why isn't it handled like all other built-in validation
checks that come bundled with other options like, say, max_length?

It is handled like other built-in validation checks.  Within admin both max_length, unique, etc. are checked/validated through use of a ModelForm for the model.  If your code uses ModelForms you will get the same validation checks.  If you don't use forms you won't (as presently there is no model validation).  Depending on the database you can get an exception raised as easily for violating max_length as you can for violating uniqueness.  For example, given this model:

class Foo(models.Model):
    name = models.CharField(max_length=2, unique=True)

and using a MySQL db with DEBUG on, attempting to create a model that violates the max_length constraint will raise an exception:

>>> from ttt.models import Foo
>>> Foo.objects.all()
[]
>>> Foo.objects.create(name='Yeppers')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
[snip]
  File "/usr/lib/python2.5/warnings.py", line 102, in warn_explicit
    raise message
Warning: Data truncated for column 'name' at row 1
>>>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
MySQL considers that just a warning (though there may well be a configuration option to tell it whether to treat this is a warning or error situation, I haven't checked) so you need to have DEBUG True for that to raise an exception, and MySQL has saved the model anyway with the truncated data.  Sqlite won't enforce the max_length check at all, I don't believe.  Not sure off the top of my head how others behave.

If you then try to add another object that violates the unique constraint again you get an exception if you do it directly by attempting to create the model:

>>> Foo.objects.create(name='Ye')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
[snip]
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry 'Ye' for key 2")
>>>

However if you use a ModelForm to validate the data prior to attempting to save the model you get these problems reported as validation errors:

>>> from django import forms
>>> class FooForm(forms.ModelForm):
...      class Meta:
...         model = Foo
...
>>> ff = FooForm(data={'name': 'Yeppers'})
>>> ff.is_valid()
False
>>> ff.errors
{'name': [u'Ensure this value has at most 2 characters (it has 7).']}
>>> ff = FooForm(data={'name': 'Ye'})
>>> ff.is_valid()
False
>>> ff.errors
{'name': [u'Foo with this Name already exists.']}
>>>

Since admin uses ModelForms, you see form validation errors when using it instead of exceptions.

Karen

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

aaron smith | 1 Sep 06:16 2009
Picon

Re: subprocess.Popen in django production - are file descriptors closed?


it ended up being an incorrect working directory. I had to give the
runfcgi parameter the "workdir" parameter so that it would run from
the right place. arg!. By default if you don't specify workdir it puts
the working dir as "/"

On Mon, Aug 31, 2009 at 7:16 AM, Bill Freeman<ke1g.nh <at> gmail.com> wrote:
> Are you saying that it works in the development server environment?  If so,
> it could be permission
> issues.  Have the ruby script append a time stamp to a world writable log
> file to confirm that it gets
> run.
>
> Bill
>
> On Fri, Aug 28, 2009 at 9:07 PM, aaron smith
> <beingthexemplarylists <at> gmail.com> wrote:
>>
>> Hey All, quick question.
>>
>> I have a small snippet of code that runs a ruby script, which I read
>> the stdout when it's done. But, I'm not getting the stdout when it's
>> in django production.
>>
>> Here's my python snippet:
>>
>> def generate_license(paymentForm,dsaPrivFile):
>>        name = paymentForm.cleaned_data['firstname'] + " " +
>> paymentForm.cleaned_data['lastname']
>>        product = paymentForm.cleaned_data['product_code']
>>        command = "/usr/bin/ruby licensing/genlicense.rb " + "'" +
>> dsaPrivFile + "'" + " " + product + " '"+name+"'"
>>        process =
>> subprocess.Popen(command,stdout=subprocess.PIPE,shell=True)
>>        stdout_value = process.communicate()[0]
>>        print process.stdout.read()
>>        print stdout_value
>>        return stdout_value
>>
>> I have a couple prints in there just for testing in debug. My question
>> is how to get this to behave normally in django production
>> environment. I've tried a couple different things with opening tmp
>> files and using that for stdout for subprocess. But no luck. Any help
>> is much appreciated.
>>
>> 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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

aa56280 | 1 Sep 07:20 2009
Picon

Re: unique=True and IntegrityError


On Aug 31, 9:51 pm, Karen Tracey <kmtra... <at> gmail.com> wrote:

> However if you use a ModelForm to validate the data prior to attempting to
> save the model you get these problems reported as validation errors:

Karen,

Thanks for the thorough explanation. I really appreciate it. What I
took from it is that if I'm using a ModelForm, Django should return a
validation error for a duplicate value. However, for my scenario, I
*am* using a ModelForm. Here's a snippet:

### Model ###
class School(models.Model):
    url = models.SlugField(max_length=50, unique=True)
    name = models.CharField(max_length=255)
    ...

### Form ###
class SchoolForm(ModelForm):

    class Meta:
        model = School
        fields = ('url', 'name')

### View ###
def new_school(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            form.save()

new_school craps out with an IntegrityError exception any time I have
a duplicate value. Any additional thoughts?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Joost Cassee | 1 Sep 08:17 2009
Picon

Re: django-tinymce problem on server


Hi Sonal,

On 27 aug, 14:13, Sonal Breed <sonal.br... <at> gmail.com> wrote:

> I have django-tinymce spellchecker working perfectly on my local
> machine which is Ububtu.
> But as soon as, I deploy it on a web host (CentOS), it gives me
> problems. Specifically, when I click the specllchecker button,
> following errors are logged:
>
> [...]
>
>  File "/home/mygoplanner/webapps/mygostaging/mygo/tinymce/views.py",
> line 69, in spell_check
>    return HttpResponse(simplejson.dumps(output),
>
> UnboundLocalError: local variable 'output' referenced before
> assignment

Looking at the code, I don't see how the spell_check function could
throw that Error. I have just one idea: can you move the last return
statement:

    return HttpResponse(simplejson.dumps(output),
        content_type='application/json')

into the try block, just after the assignment of the output variable:

        output = {
            'id': id,
            'result': result,
            'error': None,
        }
        return HttpResponse(simplejson.dumps(output),
            content_type='application/json')

Regards,

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

nbv4 | 1 Sep 08:52 2009

user disappearing when saved


(Pdb) f0
<django.forms.models.FlightForm object at 0x2303c10>
(Pdb) f0.cleaned_data
{'ipc': False, 'xc': 0, 'app': 0, 'pic': 0, 'cfi_checkride': False,
'dual_r': 0, 'date': datetime.date(2009, 9, 5), 'dual_g': 0, 'total':
5.5999999999999996, 'id': None, 'sic': 0, 'night_l': 0, 'holding':
False, 'act_inst': 0, 'pilot_checkride': False, 'solo': 0,
'flight_review': False, 'sim_inst': 0, 'plane': <Plane: UNKNOWN>,
'user': <User: chris>, 'remarks': u'', 'tracking': False, 'day_l': 0,
'route': <Route: SD-ER>, 'person': u'', 'night': 0}
(Pdb) f=f0.save(commit=False)
(Pdb) f
<Flight: 2009-09-05 -- >
(Pdb) f.user
*** DoesNotExist:
(Pdb)

What on earth could be causing this? According to cleaned_data, the
user field is valid. Why the heck is the flight being created not
having a valid user?

The form in question is coming from a heavily customized modelformset
where the queryset parameter is set to
Flight.objects.get_empty_query_set(), and extra parameter is set to
20. So it's essentially 20 blank fields. When I use this same
modelformset with a full queryset and extra set to 0, the formset
saves just fine.

The Flight form looks like this:

###
class FlightForm(ModelForm):
    user =     forms.ModelChoiceField(queryset=User.objects.all(),
widget=HiddenInput)
    [...]
###

and in the view I have this:

###
    if request.POST.get('submit'):
        post = request.POST.copy()
        for pk in range(0, profile.per_page):
            if post["form-" + str(pk) + "-date"]:
                post.update({"form-" + str(pk) + "-user": str
(request.user.pk)})
            else:
                post.update({"form-" + str(pk) + "-user": u''})

        formset = NewFlightFormset(post,
queryset=Flight.objects.get_empty_query_set())

        if formset.is_valid():
            import pdb; pdb.set_trace()
            formset.save()
###

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


Gmane