(self, request, *args, **kwargs)
View's dispatch method automatically calls this
View's dispatch method automatically calls this
View s dispatch method automatically calls this
def post(self, request, *args, **kwargs):
        """View's dispatch method automatically calls this"""
        try:
            self.workbook = get_workbook(request.FILES.get('bulk_upload_file'))
        except WorkbookJSONError as e:
            messages.error(request, str(e))
            return self.get(request, *args, **kwargs)

        try:
            self.user_specs = self.workbook.get_worksheet(title='users')
        except WorksheetNotFound:
            try:
                self.user_specs = self.workbook.get_worksheet()
            except WorksheetNotFound:
                return HttpResponseBadRequest("Workbook has no worksheets")

        try:
            self.group_specs = self.workbook.get_worksheet(title='groups')
        except WorksheetNotFound:
            self.group_specs = []
        try:
            from corehq.apps.user_importer.importer import check_headers
            check_headers(self.user_specs, self.domain, is_web_upload=self.is_web_upload)
        except UserUploadError as e:
            messages.error(request, _(str(e)))
            return HttpResponseRedirect(reverse(self.urlname, args=[self.domain]))

        task_ref = expose_cached_download(payload=None, expiry=1 * 60 * 60, file_extension=None)
        if PARALLEL_USER_IMPORTS.enabled(self.domain) and not self.is_web_upload:
            if list(self.group_specs):
                messages.error(
                    request,
                    _("Groups are not allowed with parallel user import. Please upload them separately")
                )
                return HttpResponseRedirect(reverse(self.urlname, args=[self.domain]))

            task = parallel_user_import.delay(
                self.domain,
                list(self.user_specs),
                request.couch_user
            )
        else:
            upload_record = UserUploadRecord(
                domain=self.domain,
                user_id=request.couch_user.user_id
            )
            upload_record.save()
            task = import_users_and_groups.delay(
                self.domain,
                list(self.user_specs),
                list(self.group_specs),
                request.couch_user,
                upload_record.pk,
                self.is_web_upload
            )
        task_ref.set_task(task)
        if self.is_web_upload:
            return HttpResponseRedirect(
                reverse(
                    WebUserUploadStatusView.urlname,
                    args=[self.domain, task_ref.download_id]
                )
            )
        else:
            from corehq.apps.users.views.mobile import UserUploadStatusView
            return HttpResponseRedirect(
                reverse(
                    UserUploadStatusView.urlname,
                    args=[self.domain, task_ref.download_id]
                )
            )
def post ( self , request , * args , * * kwargs ) : try : self . workbook = get_workbook ( request . FILES . get ( 'bulk_upload_file' ) ) except WorkbookJSONError as e : messages . error ( request , str ( e ) ) return self . get ( request , * args , * * kwargs ) try : self . user_specs = self . workbook . get_worksheet ( title = 'users' ) except WorksheetNotFound : try : self . user_specs = self . workbook . get_worksheet ( ) except WorksheetNotFound : return HttpResponseBadRequest ( "Workbook has no worksheets" ) try : self . group_specs = self . workbook . get_worksheet ( title = 'groups' ) except WorksheetNotFound : self . group_specs = [ ] try : from corehq . apps . user_importer . importer import check_headers check_headers ( self . user_specs , self . domain , is_web_upload = self . is_web_upload ) except UserUploadError as e : messages . error ( request , _ ( str ( e ) ) ) return HttpResponseRedirect ( reverse ( self . urlname , args = [ self . domain ] ) ) task_ref = expose_cached_download ( payload = None , expiry = 1 * 60 * 60 , file_extension = None ) if PARALLEL_USER_IMPORTS . enabled ( self . domain ) and not self . is_web_upload : if list ( self . group_specs ) : messages . error ( request , _ ( "Groups are not allowed with parallel user import. Please upload them separately" ) ) return HttpResponseRedirect ( reverse ( self . urlname , args = [ self . domain ] ) ) task = parallel_user_import . delay ( self . domain , list ( self . user_specs ) , request . couch_user ) else : upload_record = UserUploadRecord ( domain = self . domain , user_id = request . couch_user . user_id ) upload_record . save ( ) task = import_users_and_groups . delay ( self . domain , list ( self . user_specs ) , list ( self . group_specs ) , request . couch_user , upload_record . pk , self . is_web_upload ) task_ref . set_task ( task ) if self . is_web_upload : return HttpResponseRedirect ( reverse ( WebUserUploadStatusView . urlname , args = [ self . domain , task_ref . download_id ] ) ) else : from corehq . apps . users . views . mobile import UserUploadStatusView return HttpResponseRedirect ( reverse ( UserUploadStatusView . urlname , args = [ self . domain , task_ref . download_id ] ) )