string concat causing 'str' object has no attribute 'object' - django

I have a view like below:
I get the error: 'str' object has no attribute 'object'
it must have something to do with my string concat - what has gone wrong :)
thanks
def edit_skill_plan(request):
#t = skills.objects.get(skill_id='django_5158517')
skillid = request.POST.get('editbut')
user = request.user
t = skills.objects.get(creator=user, skill_id=skillid)
t.status = 'closed'
t.save() # this will update only
complete_date = datetime.today().strftime('%Y-%m-%d')
week_num = datetime.today().strftime('%V')
x = t.skill_name
user = request.user
points = t.points
cat = t.category
year = datetime.today().strftime('%Y')
status = str(request.user.username) +' completed the task: ' + str(x) + ' which was worth: ' + str(points) + ' points'
status.object.create(creator=user, status=status, status_date=complete_date)

Your last two line should be,
status_code = str(request.user.username) +' completed the task: ' + str(x) + ' which was worth: ' + str(points) + ' points'
status.object.create(creator=user, status=status_code, status_date=complete_date)

Related

Is there a way in Matlab where I can generate a list of folders that have a particular folder in them?

I'm working in Matlab and I have a directory of patients. Each patient has a folder with their ID("Patient ID"), and in that folder, there is a folder for the date("Date"). In the date folder, there are more folders that contain various information(for example CT_Image, PET_Image, MR_Image). The scheme is something like this:
Patients> Patient_ID> Date> MR_Image
Is there a way in Matlab where I can generate a list that tells me which "Patient ID" has a particular folder and which ones do not? So instead of manually checking all the patients in the "Patient" Folder for an "MR_Image" folder, I can just check the results of the list?
Here some code to scan you patients data.
Brahim
function ListPatientsData(strPatients, strDataType)
if(nargin == 0)
clc
clear
close all
strPatients = pwd;
strDataType = 'MR_Image';
end
disp(['root folder is ' strPatients])
hPatientIDs = dir(strPatients);
nNbPatientIDs = size(hPatientIDs, 1);
disp(['nNbPatientIDs = ' num2str(nNbPatientIDs)])
disp(' ')
for nPatient = 1:nNbPatientIDs
hPatientID = hPatientIDs(nPatient);
if(hPatientID.isdir)
strPatientID = hPatientID.name;
if(strcmp(strPatientID,'.'))
% Do nothing
elseif(strcmp(strPatientID,'..'))
% Do nothing
else
disp(['Patient_ID = ' strPatientID])
hDates = dir([strPatients '/' strPatientID]);
nNbDates = size(hDates, 1);
% Minus 2 coz '.' and '..'
disp(['nNbDates = ' num2str(nNbDates-2)])
for nDate = 1:nNbDates
hDate = hDates(nDate);
if(hDate.isdir)
strDate = hDate.name;
if(strcmp(strDate,'.'))
% Do nothing
elseif(strcmp(strDate,'..'))
% Do nothing
else
disp(['strDate = ' strDate])
hDataTypes = dir([strPatients '/' ...
strPatientID '/' ...
strDate]);
nNbDataTypes = size(hDataTypes, 1);
% Minus 2 coz '.' and '..'
disp(['nNbDataTypes = ' num2str(nNbDataTypes-2)])
for nDataType = 1:nNbDataTypes
hDataType = hDataTypes(nDataType);
if(hDataType.isdir)
strDataType = hDataType.name;
%
if(strcmp(strDataType,'.'))
% Do nothing
elseif(strcmp(strDataType,'..'))
% Do nothing
else
disp(['strDataType = ' strDataType])
hDataFiles = dir([strPatients '/' ...
strPatientID '/' ...
strDate '/' ...
strDataType '/*.*' ]);
nNbDataFiles = size(hDataFiles, 1);
% Minus 2 coz '.' and '..'
disp(['nNbDataFiles = ' num2str(nNbDataFiles-2)])
end
end
end
end
end
end
disp(' ')
end
end
end

IndexError: string index out of range in python2.7

Could someone help me out with what is going wrong and what I can do to fix it?
File "C:/Users/rawaa/raw/untitled2.py", line 246, in disp_message
str02= str02 + str01[single]
IndexError: string index out of range
def disp_message(val01, file_name):
f = open(file_name,'r')
data = f.readlines()
f.close()
str01 = str(data[0])
str02 = ' '
for each in val01:
#print each
for single in each:
#print single
str02= str02 + str01[single]
str02 = str02 + ' '
print("the hidden message in the data is:")
print(str02)
print("\n\npress 1. to see hidden data visualisation or ctrl+c to terminate")
cho = raw_input()
if cho == '1':
print(show_data(str01,1,val01))
you didn't specify the range of length of each, you should do maybe :
for each in val01:
#print each
for single in range (len(each)):
#print single
str02= str02 + str01[single]
str02 = str02 + ' '

how to do lowercase of 'xl cell value + some content/somethng '?

here my function . I have to do lower what ever coming in newfilename..i.e newfilename.lower()
def my_function(start, end):
sheetname = 'my-sheet'
filepath = "/myxl.xlsx"
try:
work_book=xlrd.open_workbook(filepath)
except:
print 'error'
try:
worksheet = work_book.sheet_by_name(sheetname)
except:
print 'error'
rows=worksheet.nrows
cols=worksheet.ncols
success = []
fail = []
for row in xrange(start,end):
print "row no. : ",row
state = '/home/myfolder/'
if os.path.exists(state):
print "state folder exits"
else:
os.makedirs(state)
district = state + worksheet.cell_value(row,0) + '/'
if os.path.exists(district):
print "district folder exits"
else:
os.makedirs(district)
city = district + worksheet.cell_value(row,2) + '/'
if os.path.exists(city):
print "city folder exits"
else:
os.makedirs(city)
newfilename = city + worksheet.cell_value(row,4).replace (" ", "-") + '.png'
if worksheet.cell_value(row,5) !="":
oldfilename = worksheet.cell_value(row,5)
else:
oldfilename="no-image"
newfullpath = newfilename
oldfullpath = '/home/old/folder/' + oldfilename
try:
os.rename(oldfullpath,newfullpath)
success.append(row)
except Exception as e:
fail.append(row)
print "Error",e
print 'renaming done for row #' ,row , ' file ', oldfilename , ' to ', newfilename
print 'SUCCESS ', success
print 'FAIL ', fail
newfilename.lower() not working
here when I am going to use unicode error coming...
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 72: ordinal not in range(128)

ValueError: invalid literal for int() with base 10: '12,652'

I am trying to get no of reviews count of a particular product
The code is:
total_reviews = soup.find("div", {"class": "feature"}).findNext(
"span", {"id": "acrCustomerReviewText"}).string
x = ''
for number in total_reviews:
if number == ' ':
break
else:
x = x + number
num_reviews =int(x)
Replace the comma with an empty string using str.replace():
num_reviews = int(x.replace(",", ""))

django make log that works for all models

I am trying to make my own log that makes a string of changed data between object (my old object and my new object) However i keep getting back empty string,
My code:
def log_fields(old_obj, new_obj):
fields = new_obj.__class__._meta.fields
changed_fields = ""
old_data = ""
new_data = ""
# get all changed data
for field in fields:
old_field_data = old_obj.__getattribute__(field.name)
new_field_data = new_obj.__getattribute__(field.name)
if old_field_data != new_field_data:
count =+ 1
# convert changed data to strings
# number + space + data + 5 spaces for next string
changed_fields.join(str(count)).join(" ").join(str(field)).join(" ")
old_data.join(str(count)).join(" ").join(str(old_field_data)).join(" ")
new_data.join(str(count)).join(" ").join(str(new_field_data)).join(" ")
print changed_fields
print old_data
print new_data
I got a feeling something with the string .join combination something is going wrong, cause trying this manually in shell seems to work up to the comparison. Not sure tho hos i should change the string
changed_fields = changed_fields + str(count) + "." + str(field.name) + " "
old_data = old_data + str(count) + "." + str(old_field_data) + " "
new_data = new_data + str(count) + "." + str(new_field_data) + " "
Seems to do the job, so for now, ill keep it at this