Пример #1
0
    def run(self):
        counter = 0
        for job in self.jobs:
            new_job = Job(
                title=job.title,
                description=job.description,
                employer=self.profile,
                availability=job.availability,
                experience=job.experience,
                education=job.education,
                employment_type=job.employment_type,
                overtime=job.overtime,
                latitude=job.latitude,
                longitude=job.longitude,
            )
            new_job.save()
            new_job.workday = job.workday.all()
            new_job.industry = job.industry.all()
            new_job.save()

            new_location = JobLocation(
                business_name=job.location.business_name,
                business_address1=job.location.business_address1,
                business_address2=job.location.business_address2,
                city=job.location.city,
                zip_code=job.location.zip_code,
                latitude=job.location.latitude,
                longitude=job.location.longitude,
                job=new_job,
            )
            new_location.save()

            for existing_profile in self.profiles:
                rec = JobRecommendation(
                    job=new_job,
                    applicant=existing_profile,
                    state=(JobRecommendation.NEW_REC_SENT if counter > 2 else JobRecommendation.APPLIED_REC),
                )
                rec.save()

                if counter <= 2:
                    application = ApplicantJob(job=new_job, applicant=existing_profile, send_email=False)
                    application.save()

                if existing_profile.id == 24 and job.id == 12:
                    application = ApplicantJob(job=new_job, applicant=existing_profile, send_email=False)
                    application.save()

                counter = counter + 1

            counter = 0