Conversation
| 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") |
There was a problem hiding this comment.
Function RegForm.clean_Confirm_Password refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| form.save() | ||
| request.session['username'] = form.cleaned_data['Username'] | ||
| system('mkdir media\{}'.format(request.session['username'])) | ||
| system(f"mkdir media\\{request.session['username']}") |
There was a problem hiding this comment.
Function signupview refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
|
|
||
|
|
||
| def save_image ( request ): | ||
| def save_image( request ): |
There was a problem hiding this comment.
Function save_image refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| 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 ) |
There was a problem hiding this comment.
Function encryption refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| 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) |
There was a problem hiding this comment.
Function decryption refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| 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 | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function upload refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Use x is None rather than x == None (
none-compare) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| file_path = 'media/{}/{}'.format(request.session['username'], filename) | ||
| file_path = f"media/{request.session['username']}/{filename}" |
There was a problem hiding this comment.
Function download refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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}) |
There was a problem hiding this comment.
Function history refactored with the following changes:
- Add guard clause (
last-if-guard) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| 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')) |
There was a problem hiding this comment.
Function sendmail refactored with the following changes:
- Add guard clause (
last-if-guard)
| list = {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount} | ||
| return list | ||
| return {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount} |
There was a problem hiding this comment.
Function counter refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.45%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!