Any ideas? On Jun 1, 8:17 am, strelok31 <[EMAIL PROTECTED]> wrote: > I inherited an application written in Python and I need to make a > change to it. The guy who created it is gone and I am not an expert in > Python. I was able to get one thing to work but I am having difficulty > with another part. I need to add a drop down selection list to the > HTML page and the save the value selected to the MySQL database. > Currently application reads the uploaded file, decrypts the info and > stores the results in MySQL database. The structure is already in > place I just need to add the drop down selection list. Any help would > be greatly appreciated. I have already added a field to the table. > > This is the code for the HTML page. Keyfile is the name of the file. > -------------------------------------------------------------------------------- > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> > > <title>AccuRateS</title> > > </head> > > <body> > <h1>AccuRateS - Upload License Key File</h1> > <form action="/upload_key/" method="post" enctype="multipart/form- > data"> > <p><label for="keyfile">Select file: </label> <input type="file" > name="keyfile"/></p> > <p> Sales Person: > <select name="salespeople_dropdown"> > <option value="Angelo">Angelo</option> > <option value="Debbie">Debbie</option> > <option value="James">James</option> > <option value="Gabe">Gabe</option> > <option value="Mark H">Mark H</option> > <option value="Mike">Mike</option> > <option value="Rob">Rob</option> > <option value="Ron W">Ron W</option> > <option value="Yeciel">Yieciel</option> > </select> > </p> > <input type="submit" name="Submit"/> > </form> > </body> > </html> > -------------------------------------------------------------------------- > -------------------------------------------------------------------------- > this is the python utility file that decrypts the info in the uploaded > file and generates a field dictionary for database insertion > ---------------------------------------------------------------------------- > def load_file(fname): > '''Loads the AccuraRates license file, reads the first line and splits > the contents by colon''' > f = open(fname,'r') > line = f.readline() > line = line.replace('\r\n','') > return line.split(':') > > def load_string(s): > '''Loads the AccuraRates license file content passed as a string, > reads the first line and splits the contents by colon''' > s = s.replace('\r\n','') > return s.split(':') > > def parse_fields(l): > '''Takes a list of the data values in the AccuRateS and generates a > field dictionary for database insertion''' > import time, datetime > d = {'rio':'', > 'days_licensed':'', > 'volume_id':'', > 'keygen_date':'', > 'accu_id':'' > > } > > d['days_licensed'] = int(l[0]) # days_licensed > d['volume_id'] = l[1] # volume id > d['accu_id'] = l[(len(l)-1)] # accuid > d['rio'] = d['accu_id'][:-12] # rio code is accuid minus 12 digit > timestamp appendix > > # format keygen date > epochsecs = time.mktime( time.strptime(l[2], '%m/%d/%Y') ) > kgd = datetime.datetime.fromtimestamp(epochsecs).date() > d['keygen_date'] = kgd > > return d > > def parse_content(c): > # scrub the input string and split > l = load_string(c) > cleartext = decrypt_string(l[0],l[1]) > return parse_fields( cleartext.split(':') ) > > if __name__ == '__main__': > pass > > ----------------------------------------------------------------------------- > this is a python file where database insertion is done. But it does > not work after my changes > ------------------------------------------------------------------------------ > # Create your views here. > from django.utils.httpwrappers import HttpResponse, > HttpResponseRedirect > from django.core.extensions import render_to_response > from django.core.extensions import DjangoContext > from django.core.exceptions import Http404 > from django.core.template import loader > from accurates.apps.accukeys import util > from django.models.accukeys import acculicenses > from django.views.decorators.auth import login_required > > def index(request): > t = loader.get_template("accukeys/index") > c = DjangoContext(request, {'foo':'yeah'}) > return HttpResponse(t.render(c)) > #return render_to_response("accukeys/index", {'foo':'yeah'}) > > def upload_key(request): > if not request.FILES.has_key('keyfile'): > raise Http404 > # get the file info > fileinfo = request.FILES['keyfile'] > try: > field_dict = util.parse_content(fileinfo['content']) > > # make a new accu_license object > al = acculicenses.AccuLicense( > rio=field_dict['rio'], > days_licensed=field_dict['days_licensed'], > volume_id=field_dict['volume_id'], > keygen_date=field_dict['keygen_date'], > accu_id=field_dict['accu_id'], > sales_person = document.Submit.salespeople_dropdown.value # I added > this line > ) > # commit to database > al.save() > > # store in session > request.session['license']=al > > return HttpResponseRedirect("/confirmation/") > except: > raise Http404 > > def confirmation(request): > if 'license' in request.session: > license = request.session['license'] > else: > license = None > > return render_to_response("accukeys/confirmation", {'license':license})
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

