Posts

Showing posts from January, 2021

Celery vs Channel

  Celery channel Celery is an asynchronous task queue/job queue based on distributed message passing. It does this by taking the core of Django and adding a fully asynchronous layer underneath, running Django itself in a synchronous mode but handling connections and sockets asynchronously, and giving you the choice to write in either style. https://en.wikipedia.org/wiki/Asynchronous_Layered_Coding Django Channels  is detailed as " It extends Django's abilities beyond HTTP - to handle WebSockets, chat protocols, IoT protocols ". not use protocol Celery can be classified as a tool in the  "Message Queue"  category Django Channels is grouped under  "Frameworks (Full Stack)" . both open source both open source

send error message from view to ajax

  class DataInputInsightPage ( View ): def post ( self , request ): try : // code except Exception as ex: return JsonResponse({ 'success' : False , 'message' : 'CSV file not found' }, status = 404 ) return JsonResponse(context)

Delete all file in a directory using python

  files_path=os.path.join(settings.MEDIA_ROOT , 'intermediate' , str (request.user)) for root, dirs, files in os.walk(files_path): for filename in files: os.remove(os.path.join(root, filename))

Create a dataframe by reading a csv and show this in template

 https://avkashchauhan.medium.com/full-stack-development-tutorial-sending-pandas-dataframe-as-json-to-coreui-react-template-bf8c6d970548    views.py: class ReportView ( View ): def get ( self , request ): if not request.user.is_authenticated: return HttpResponseRedirect( '/login/' ) output_predictions_filepath = settings.MEDIA_ROOT+ '/pred_result_data/' # if the directory doesn't exist before, create a new directory if os.path.isfile(output_predictions_filepath + 'output.csv' ): logger.info( "dir" ) report_df=pd.read_csv(output_predictions_filepath + 'output.csv' ) logger.info(report_df) else : report_df= None logger.info( "I am in report page" ) row_count = report_df.shape[ 0 ] column_count = report_df.shape[ 1 ] column_names = report_df.columns.tolist() final_row_da...

javascripts popup for images popup

 base.html: < script src = "https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity = "sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin = "anonymous" ></ script >  this is plugin  style.js: $ ( document ). ready ( function () { // required elements var imgPopup = $ ( '.img-popup' ); var imgCont = $ ( '.container__img-holder' ); var popupImage = $ ( '.img-popup img' ); var closeBtn = $ ( '.close-btn' ); // handle events imgCont . on ( 'click' , function () { var img_src = $ ( this ). children ( 'img' ). attr ( 'src' ); imgPopup . children ( 'img' ). attr ( 'src' , img_src ); imgPopup . addClass ( 'opened' ); }); $ ( imgPopup , closeBtn ). on ( 'click' , function () { imgPopup . removeClass ( 'opened' ); imgPopup . children ( 'img' )....

Download file using ajax and django

  class downloadPredictionReport ( LoginRequiredMixin , View ): def post ( self , request ): logger.info( "I am in downloadPredictionReport view" ) pred_dir=settings.MEDIA_ROOT+ '/pred_result_data/' + 'predictions.csv' if os.path.isfile(pred_dir): with open (pred_dir, 'rb' ) as file : context = file .read() response = HttpResponse(context, content_type = 'application/vnd.ms-excel' ) response[ 'Content-Disposition' ] = 'attachment; filename="predictions.csv"' return response else : raise Http404( "File does not exist" )     $ ( '#download_prediction_report_btn' ). click ( function ( e ){ e . preventDefault (); var this_context = $ ( this ); var csrftoken = getCookie ( 'csrftoken' ); // var formData = new...