Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!
At the moment I'm using Django as part of a small project I'm doing for shits and giggles. So far I've got a project, 'imageupload', and an app, 'image', that seems to be working well enough. What it does is offer up an upload screen to the user and allows them to, obviously, upload an image. All of this works but now I need to move onto the next part and I'm lost with how to proceed.

I have a Pythong script, separate from Django, that does a bunch of stuff to the image the user uploads. The specifics of what the script does isn't important. What I'd like to be able to do is have Django pass the file to my other script and have it kick off from there. The results are returned as 'results.xml' which are then formatted and displayed on the next webpage.

Ideas?

Adbot
ADBOT LOVES YOU

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!

ashgromnies posted:

and put it in my /usr/lib/python2.5/ directory(and added it to source control).

I understood everything but this :)

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!

Bonus posted:

Kind of that ashgrommies said, only I wouldn't try to shoehorn it into a class if it doesn't need to be a class. If it's just a script that does something when execute it, I'd wrap that functionality into a function call inside the script and then in Django you can just do
code:
form your_script import the_function
and use that function in your views

All the functions in my script are required.. And they're in class form already.

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!

Bonus posted:

Oh, well then yeah, just import the stuff you need from the script and that's it. Unless I'm misunderstanding your problem somehow.

Using views.py?

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!
Can somebody post an example of how to use the validators mentioned at the bottom of http://www.djangoproject.com/documentation/forms/

The one provided isn't to clear, for a newb like me, on the proper usage.

Specifically I have three fields that are only required if the user selects 'Yes' on a BooleanField with the RadioSelect widget. If the user selects or No or selects nothing the fields aren't required.

I'm thinking RequiredIfOtherFieldGiven but prove me wrong :)

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!

king_kilr posted:

Don't use that, you should be using newforms.

And also, for everyone using pretty much any version of django there is a security update to fix an XSS issue in the Admin, more info on the django blog.

I am using newforms :( I'm just a bit to new to this to realise what's deprecated and what's not.

Wulfeh posted:

http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validation

Yea the old forms and manipulators are on the way out I believe. To do it in newforms, you would put something like this in your form class:

code:
def clean(self):
	if 'bool_field' in self.cleaned_data:
		if self.cleaned_data['bool_field']:
			if not 'field1' in self.cleaned_data:
				raise forms.ValidationError('field1 is required')
			if not 'field2' in self.cleaned_Data:
				raise forms.ValidationError('field2 is required')
			if not 'field3' in self.cleaned_data:
				raise forms.ValidationError('field3 is required')
	return self.cleaned_data
Just make sure that you loop through the errors in the template, since they aren't field specific errors, they are thrown into a list form.non_field_errors

I'll give this a try and post a trip report. Thanks!

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!
Can anybody help me out with creating an Object outside of the Django Admin console and the Python shell. I'd like to be able to run a script like this:

'createobject.py'
code:
from News.models import ChoiceArticle as CA
NewCA = CA()
NewCA.Title = "News Story title"
NewCA.URL = "http://www.genericnewssite.com"
NCA.Summary = "A summary of what the story is about"
NCA.save()
But, as possibly expected, I keep getting an ImportError:

code:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Any idea how to get around this?

Adbot
ADBOT LOVES YOU

FrontLine
Sep 17, 2003
I gave Mr. Adequate hot, steamy man love and all he bought me was a custom title!

The Real Ambassador posted:

Put this in your codes at the top:

import sys
import os
sys.path.append('..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

I haven't tested this yet but I'll trust that it works... although to be honest it looks weird. In any case if no one posts a better solution I'll run with it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply