def viewProfile(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/') if not request.get_full_path().__contains__('id') and request.user.is_superuser: return HttpResponseRedirect('/') if request.get_full_path().__contains__('id') and not request.user.is_superuser: inputCusId = int(request.get_full_path().split('id=')[-1]) if inputCusId != dbaccess.getCustIdByUserId(request.user.id): return HttpResponseRedirect('/') else: custRow = dbaccess.getCustInfoById(int(request.get_full_path().split('id=')[-1])) else: if request.get_full_path().__contains__('id'): custRow = dbaccess.getCustInfoById(int(request.get_full_path().split('id=')[-1])) else: cusId = dbaccess.getCustIdByUserId(request.user.id) custRow = dbaccess.getCustInfoById(cusId) custInfo = SortedDict([ ('Email', custRow[3]), ('First Name', custRow[1]), ('Last Name', custRow[2]), ('Street Name', custRow[6]), ('Postal Code', custRow[5]), ('Contact Number', custRow[4]), ]) custCredit = SortedDict([ ('Serial Number', custRow[8]), ('Expiry Date', custRow[7]) ]) return render_to_response('userprofile/viewProfile.html', { 'custInfo': custInfo.iteritems(), 'custCredit': custCredit.iteritems(), }, context_instance=RequestContext(request))
def editProfile(request): if not request.user.is_authenticated() or request.user.is_superuser: return HttpResponseRedirect('/') cusId = dbaccess.getCustIdByUserId(request.user.id) custRow = dbaccess.getCustInfoById(cusId) if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): params = [ request.POST['firstName'], request.POST['lastName'], request.POST['contactNo'], request.POST['zipcode'], request.POST['streetName'], request.POST['cExpDate'], request.POST['cSerialNo'], cusId ] dbaccess.updateCustomer(params) return HttpResponseRedirect('/user') else: form = ProfileForm(initial={ 'firstName': custRow[1], 'lastName': custRow[2], 'contactNo': custRow[4], 'streetName': custRow[6], 'zipcode': custRow[5], 'cSerialNo': custRow[8], 'cExpDate': custRow[7], }) return render_to_response('userprofile/editProfile.html', { 'form': form, }, context_instance=RequestContext(request))