def get(self, request) -> HttpResponseRedirect: if not Path.exists(settings.ADMIN_SERIALIZE): Path.mkdir(settings.ADMIN_SERIALIZE) if checkWiFi(): try: with FTP(settings.FTP, settings.FTP_USER, settings.FTP_LOGIN) as myFTP: myFTP.cwd(settings.FTP_SERIALIZE) files = (name for name, facts in myFTP.mlsd() if facts['type'] == 'file') for file in files: myFTP.retrbinary( f'RETR {file}', open(f'{settings.ADMIN_SERIALIZE}/{file}', 'wb').write) myFTP.delete(file) # messages.info(request, f'\nThe file <<{file}>> has been copied into<<{settings.ADMIN_SERIALIZE}>>') except: messages.info( request, f'There aren\'t files in {settings.FTP_SERIALIZE}') else: messages.info(request, r'Occurred problem with FTP connection...') readfixture(request, settings.ADMIN_SERIALIZE) messages.info(request, f'\nAll database have been deserializing....') return HttpResponseRedirect(reverse_lazy('account:dashboard'))
def get(self, request, company_id:int) -> HttpResponseRedirect: if checkWiFi(): company = get_object_or_404(Company, pk=company_id) month, year = now().month, now().year month, year = previous_month_year(month, year) html = cashregisterhtml2pdf(company_id, month, year) if html: # create pdf file and save on templates/pdf/cashregister_{company}_{month}_{year}.pdf options = {'page-size': 'A4', 'margin-top': '0.4in', 'margin-right': '0.2in', 'margin-bottom': '0.4in', 'margin-left': '0.6in', 'encoding': "UTF-8", 'orientation': 'portrait', 'no-outline': None, 'quiet': ''} pdfile = f'templates/pdf/cashregister_{company}_{month}_{year}.pdf' pdfkit.from_string(html, pdfile, options=options, css=settings.CSS_FILE) # send e-mail with attached cash register as file in pdf format mail = {'subject': f'cash register for {month}/{year} r.', 'message': f'Cash Register for {company} on {month}/{year} in attachment ...', 'sender': settings.EMAIL_HOST_USER, 'recipient': [settings.ACCOUNTANT_MAIL], 'attachments': [pdfile]} sendemail(**mail) messages.info(request, f'Cash register for {company} on {month}/{year} was sending....') else: messages.warning(request, r'Nothing to send...') else: messages.error(request, 'Occurred problem with internet connection...') return HttpResponseRedirect(reverse('cashregister:cash_register', args=[company_id]))
def get(self, request) -> HttpResponseRedirect: if checkWiFi() and cmp_fixtures(): root = Path(settings.FTP_SERIALIZE) try: with FTP(settings.FTP, settings.FTP_USER, settings.FTP_LOGIN) as myFTP: dirs = (item[0] for item in myFTP.mlsd(path=root.parent)) if root.name not in dirs: myFTP.mkd(settings.FTP_SERIALIZE) myFTP.cwd(settings.FTP_SERIALIZE) for file in list(Path.iterdir(settings.TEMP_SERIALIZE)): with file.open('rb') as fixture: myFTP.storbinary(f'STOR {file.name}', fixture) messages.info( request, f'\nFile <<{file.name}>> was sent on the FTP server' ) file.unlink() Path.rmdir(settings.TEMP_SERIALIZE) messages.info(request, r'All fixtures have been serializing...') except: msg = f'Occurred problem with FTP connection. Directory: {settings.FTP_SERIALIZE}' messages.error(request, msg) else: messages.info(request, r'All files are up to date...') return HttpResponseRedirect(reverse_lazy('account:dashboard'))
def get(self, request, month:int, year:int) -> HttpResponseRedirect: # convert html file (evidence/monthly_payroll_pdf.html) to pdf file if checkWiFi(): if request.GET['spRadio'] == 'simple': multipdfile = payrollhtml2pdf(month, year, option='send') subject = f'Simplified payroll for {month}/{year}' message = f'Simplified payroll for {month}/{year} in attachment...' elif request.GET['spRadio'] == 'detailed': multipdfile = dphtmpd(month, year) subject = f'Detailed multi-page payroll for {month}/{year}' message = f'Detailed multi-page payroll for {month}/{year} in attachment...' else: messages.warning(request, r'Nothing to send...') # send e-mail with attached payroll as file in pdf format mail = {'subject': subject, 'message': message, 'sender': settings.EMAIL_HOST_USER, 'recipient': [settings.ACCOUNTANT_MAIL], 'attachments': [multipdfile]} try: sendemail(**mail) messages.info(request, f'The file <<{multipdfile}>> was sending....') except: messages.warning(request, r'Payroll isn\'t sending...') else: messages.error(request, 'FTP connection failure...') return HttpResponseRedirect(reverse('evidence:monthly_payroll_view', args=[month, year]))
def get(self, request, employee_id:int) -> HttpResponseRedirect: # convert html file (evidence/leave_data_{}.html.format(employee_id) to pdf file html = leavehtml2pdf(employee_id, now().year) # create pdf file and save on templates/pdf/leves_data_{}.pdf'.format(employee_id) options = {'page-size': 'A4', 'margin-top': '1.0in', 'margin-right': '0.1in', 'margin-bottom': '0.1in', 'margin-left': '0.1in', 'encoding': "UTF-8", 'orientation': 'landscape','no-outline': None, 'quiet': '', } pdfile = f'templates/pdf/leaves_data_{employee_id}.pdf' if checkWiFi(): pdf = pdfkit.from_string(html, pdfile, options=options, css=settings.CSS_FILE) if pdf: # send e-mail with attached leaves_data in pdf format worker = get_object_or_404(Employee, pk=employee_id) mail = {'subject': f'list of leave for {worker} ({date.today().year})r.', 'message': f'List of leave in attachment {worker} za {date.today().year}r.', 'sender': settings.EMAIL_HOST_USER, 'recipient': [settings.ACCOUNTANT_MAIL], 'attachments': [pdfile]} sendemail(**mail) messages.info(request, f'The file <<{pdfile}>> was sending....') else: messages.warning(request, r'Nothing to send...') else: messages.error(request, 'FTP connection failure...') return HttpResponseRedirect(reverse('evidence:leave_time_recorder_add', args=[employee_id]))
def exit(request) -> HttpResponseRedirect: '''backups features and exit from the application''' if platform.system() == 'Darwin': paths = (Path('/Users/jurgen/Downloads'), Path('/private/var/tmp'), Path('templates/pdf')) else: paths = (Path('templates/pdf'), Path('~/Downloads').expanduser()) # remove unused files remgarbage(*paths) args = (settings.ARCHIVE_FILE, settings.FTP_DIR, settings.FTP, settings.FTP_USER, settings.FTP_LOGIN) if socket.gethostname() in settings.OFFICE_HOSTS: backup() mkfixture(settings.ADMIN_SERIALIZE, backup_models=backup_models) make_archives(settings.ARCHIVE_NAME, settings.ADMIN_SERIALIZE, settings.ARCHIVE_FILE) try: if checkWiFi(): uploadFileFTP(*args) except: pass finally: if request.user.is_authenticated: logout(request) elif socket.gethostname() in settings.HOME_HOSTS: if backup_models: backup() else: print(r'All fixtures are up to date...') if request.user.is_authenticated: logout(request) if platform.system() == 'Darwin': exec_script() return HttpResponseRedirect(r'https://www.google.pl/')
def get(self, request) -> HttpResponseRedirect: if request.user.is_superuser or request.user.is_staff: user = request.user.username context = {'user': user, 'usage': spaceusage()} employee = Employee.objects.all() if request.session.get('check_update', True): if socket.gethostname() in settings.HOME_HOSTS: args = (settings.FTP, settings.FTP_USER, settings.FTP_LOGIN, settings.ARCHIVE_FILE, settings.ROOT_BACKUP) getArchiveFilefromFTP(request, *args) else: msg = f'User: {user}, Host name: {socket.gethostname()}, Host addres: {socket.gethostbyname("localhost")}' messages.info(request, msg) request.session['check_update'] = False if employee.exists(): if employee.filter(status=True): employee_id = employee.filter(status=True).first().id else: employee_id = employee.first().id # update context context |= ({'employee_id': employee_id, 'nodata': False}) else: backup = settings.ARCHIVE_ROOT created = datetime.fromtimestamp(backup.stat().st_mtime) # update context context |= ({ 'nodata': True, 'backup': str(backup), 'created': created }) return render(request, '500.html', context) if socket.gethostname() in settings.SERIALIZE_HOST: context.__setitem__('serialize', True) if checkWiFi(): try: with FTP(settings.FTP, settings.FTP_USER, settings.FTP_LOGIN) as myFTP: try: files = [ name for name, facts in myFTP.mlsd( settings.FTP_SERIALIZE) if facts['type'] == 'file' ] if files: context.__setitem__('ftp_files', True) except: context.__setitem__('ftp_files', False) except: messages.error( request, f'Occurred problem with FTP connection... Directory: {settings.FTP_SERIALIZE}' ) else: messages.error(request, r'Occurred problem with FTP connection...') return render(request, 'account/admin.html', context) return HttpResponseRedirect(reverse_lazy('login'))