Skip to content

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 21, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from purna135 March 21, 2022 14:53
Comment on lines -39 to +46
MAX_LEN = 8
if pass1 and pass2:
if pass1 != pass2:
raise forms.ValidationError("Two passwords not same")
else:
if len(pass1) < MAX_LEN:
raise forms.ValidationError("Password should be %d characters" %MAX_LEN)
if pass1.isdigit():
raise forms.ValidationError("Password should not all numeric")
MAX_LEN = 8
if len(pass1) < MAX_LEN:
raise forms.ValidationError("Password should be %d characters" %MAX_LEN)
if pass1.isdigit():
raise forms.ValidationError("Password should not all numeric")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RegForm.clean_Confirm_Password refactored with the following changes:

form.save()
request.session['username'] = form.cleaned_data['Username']
system('mkdir media\{}'.format(request.session['username']))
system(f"mkdir media\\{request.session['username']}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function signupview refactored with the following changes:



def save_image ( request ):
def save_image( request ):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function save_image refactored with the following changes:

Comment on lines -4 to +12
def encryption( filename , encno ) :
fd = open( filename , 'rb')
data = fd . read()
fd . close()

def encryption( filename , encno ):
with open( filename , 'rb') as fd:
data = fd . read()
data = chr( int(encno)) + data [: : -1 ].decode ( 'latin-1')
data = data . encode ( 'latin-1', "ignore")
data = base64 . b64encode ( data )

fd = open( filename , 'wb')
fd . write( data )
fd . close()
with open( filename , 'wb') as fd:
fd . write( data )
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function encryption refactored with the following changes:

Comment on lines -20 to +25
fd = open(filename, 'rb')
data= fd. read()
fd . close()
with open(filename, 'rb') as fd:
data= fd. read()
data = base64.b64decode(data)
encno = data[0]
if chr(encno) == chr(int(decno)):
data = data.decode('latin-1')
data = data[:0:-1].encode('latin-1')
fd = open(filename, 'wb')
fd . write(data)
fd . close()
with open(filename, 'wb') as fd:
fd . write(data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decryption refactored with the following changes:

Comment on lines -44 to +58
if os.path.exists('media/{}/{}'.format(user, myfile.name)):
x = os.getcwd() +'\\media\\{}\\{}'.format(user, myfile.name)
if os.path.exists(f'media/{user}/{myfile.name}'):
x = os.getcwd() + f'\\media\\{user}\\{myfile.name}'
os.system('del "' + x + '"')
filename = fs.save("media/{}/{}".format(user, myfile.name), myfile)
filename = fs.save(f"media/{user}/{myfile.name}", myfile)
encdec.encryption( filename , request.POST ['enckey'])
rec = myuser.objects.filter( Username = user)

if rec[0].history == None or rec[0].history == [['None']]:
newhistory = myfile.name +' saved on' + str (time.ctime())
if rec[0].history is None or rec[0].history == [['None']]:
newhistory = f'{myfile.name} saved on{str(time.ctime())}'
else:
newhistory = myfile.name +' saved on' + str(time.ctime ()) + '\n' + rec[0].history
newhistory = (
f'{myfile.name} saved on{str(time.ctime ())}'
+ '\n'
+ rec[0].history
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function upload refactored with the following changes:

Comment on lines -70 to +74
file_path = 'media/{}/{}'.format(request.session['username'], filename)
file_path = f"media/{request.session['username']}/{filename}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download refactored with the following changes:

Comment on lines -90 to +107
if 'username' in request.session:
rec = myuser.objects.filter(Username = request.session['username'])
history = rec[0].history
if 'username' not in request.session:
return HttpResponseRedirect(reverse('indexview'))
rec = myuser.objects.filter(Username = request.session['username'])
history = rec[0].history

if history != None and history != '':
history = history.split('\n')
history = [ x.split ('saved on') for x in history ]
if history in [None, '']:
return render ( request, 'history.html')
history = history.split('\n')
history = [ x.split ('saved on') for x in history ]

for x in history :
x [ 0 ] = x[ 0 ]. replace ( request.session['username'] +'/', '')
for x in history :
x [ 0 ] = x[ 0 ]. replace ( request.session['username'] +'/', '')

return render (request , 'history.html', {'history': history})
else:
return render ( request, 'history.html')
else :
return HttpResponseRedirect(reverse('indexview'))
return render (request , 'history.html', {'history': history})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function history refactored with the following changes:

Comment on lines -133 to +148
if 'username' in request.session:
if request.method == 'POST':
to_mail = request.POST['tomail']
subject = request.POST['subject']
message = request.POST['mailbody']
email = EmailMessage(subject=subject,body=message,to=[to_mail])
try:
email.send()
except:
messages.error(request,"Mail can not send")
else:
messages.success(request, "The Email has successfully sent")
return HttpResponseRedirect(reverse('dashboard'))
else :
if 'username' not in request.session:
return HttpResponseRedirect(reverse('indexview'))
if request.method == 'POST':
to_mail = request.POST['tomail']
subject = request.POST['subject']
message = request.POST['mailbody']
email = EmailMessage(subject=subject,body=message,to=[to_mail])
try:
email.send()
except:
messages.error(request,"Mail can not send")
else:
messages.success(request, "The Email has successfully sent")
return HttpResponseRedirect(reverse('dashboard'))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sendmail refactored with the following changes:

Comment on lines -184 to +185
list = {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount}
return list
return {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function counter refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 21, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.45%.

Quality metrics Before After Change
Complexity 7.82 ⭐ 7.44 ⭐ -0.38 👍
Method Length 75.20 🙂 75.72 🙂 0.52 👎
Working memory 10.30 😞 10.22 😞 -0.08 👍
Quality 60.12% 🙂 60.57% 🙂 0.45% 👍
Other metrics Before After Change
Lines 365 359 -6
Changed files Quality Before Quality After Quality Change
home/forms.py 83.65% ⭐ 84.97% ⭐ 1.32% 👍
home/views.py 51.50% 🙂 51.31% 🙂 -0.19% 👎
user/encdec.py 75.88% ⭐ 76.63% ⭐ 0.75% 👍
user/views.py 59.70% 🙂 60.96% 🙂 1.26% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
home/views.py save_image 21 😞 360 ⛔ 13 😞 27.88% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
user/views.py upload 10 🙂 185 😞 17 ⛔ 39.91% 😞 Try splitting into smaller methods. Extract out complex expressions
user/views.py download 6 ⭐ 117 🙂 11 😞 58.93% 🙂 Extract out complex expressions
user/views.py counter 0 ⭐ 134 😞 13 😞 59.49% 🙂 Try splitting into smaller methods. Extract out complex expressions
user/views.py dashboard 5 ⭐ 126 😞 10 😞 60.68% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants