Exemplo n.º 1
0
    def post(self, request, vacancy_id):
        user = request.user
        if user.is_anonymous:
            return redirect(reverse('login'))

        company = get_object_or_404(Company, owner=user)
        vacancy = Vacancy.objects.filter(id=vacancy_id).annotate(number_of_responses=Count('applications')).first()
        if vacancy is None:
            vacancy = Vacancy(company=company)
        applications = Application.objects.filter(vacancy=vacancy).all()
        form = VacancyEditForm(request.POST)
        context = {'form': form, 'company': company, 'vacancy': vacancy, 'applications': applications,
                   'title_left': 'Моя компания | Вакансия'}
        if form.is_valid():
            data = form.cleaned_data
            vacancy.title = data['title']
            specialty = Specialty.objects.filter(code=data['form_specialty']).first()
            if specialty is not None:
                vacancy.specialty = specialty
                vacancy.company = company
                vacancy.salary_min = data['salary_min']
                vacancy.salary_max = data['salary_max']
                vacancy.skills = data['skills']
                vacancy.description = data['description']
                vacancy.save()
                context['vacancy_specialty'] = data['specialty']
                context['info_updated'] = True
        return render(request, 'vacancies/vacancy-edit.html', context)
Exemplo n.º 2
0
    def test_saving_and_retrieving_vacancies(self):
        username1 = '*****@*****.**'
        password = '******'
        user1 = User.objects.create_user(username1, password)
        first_vacancy = Vacancy()
        first_vacancy.user = user1
        first_vacancy.employer = self.employer
        first_vacancy.title = 'Welder TIG'
        first_vacancy.salary_min = 50000
        first_vacancy.save()

        second_vacancy = Vacancy()
        username2 = '*****@*****.**'
        password = '******'
        user2 = User.objects.create_user(username2, password)
        second_vacancy.user = user2
        second_vacancy.employer = self.employer
        second_vacancy.title = "Welder MIG-MAG"
        second_vacancy.salary_min = 60000
        second_vacancy.save()

        saved_vacancies = Vacancy.objects.all()
        self.assertEqual(saved_vacancies.count(), 2)

        first_saved_vacancy = saved_vacancies[0]
        second_saved_vacancy = saved_vacancies[1]
        self.assertEqual(first_saved_vacancy.title, 'Welder TIG')
        self.assertEqual(second_saved_vacancy.title, 'Welder MIG-MAG')
Exemplo n.º 3
0
    def post(self, request, job_id=None):
        user = get_user(request)
        user_company = user.companies.first()
        vacancy = None

        if job_id:
            vacancy = self.get_vacancy(request, job_id)

        form = VacancyForm(request.POST)

        if not form.is_valid():
            return render(request, 'vacancies/user/vacancy_edit.html', {'form': form})

        if vacancy:
            vacancy.title = form.cleaned_data['title']
            vacancy.specialty = form.cleaned_data['specialty']
            vacancy.skills = form.cleaned_data['skills']
            vacancy.description = form.cleaned_data['description']
            vacancy.salary_min = form.cleaned_data['salary_min']
            vacancy.salary_max = form.cleaned_data['salary_max']
        else:
            vacancy = Vacancy(
                title=form.cleaned_data['title'],
                specialty=form.cleaned_data['specialty'],
                skills=form.cleaned_data['skills'],
                description=form.cleaned_data['description'],
                salary_min=form.cleaned_data['salary_min'],
                salary_max=form.cleaned_data['salary_max'],
                company=user_company,
            )
        vacancy.save()
        return redirect(reverse('my_vacancy_form', args=[vacancy.id]) + '?submitted=True')
Exemplo n.º 4
0
def _fill_vacancies():
    vacancy_titles: List[str] = [
        'Разработчик на Python',
        'Разработчик в проект на Django',
        'Разработчик на Swift в аутсорс компанию',
        'Мидл программист на Python',
        'Питонист в стартап',
    ]

    for company in Company.objects.all():
        specialty_list = Specialty.objects.all()
        number_of_specialties: int = len(specialty_list)

        number_of_vacancies: int = choice(range(1, 4))
        for index in range(number_of_vacancies):
            specialty: Specialty = specialty_list[choice(
                range(number_of_specialties))]
            salary_min = choice(range(10, 20)) * 10000

            vacancy_instance = Vacancy(
                title=choice(vacancy_titles),
                specialty=specialty,
                company=company,
                description=
                f'Описание вакансии №{index} для компании {company.name}',
                salary_min=salary_min,
                salary_max=salary_min + choice(range(1, 10)) * 10000,
                skills='Бэкенд, Старший (Senior), C#, ASP.NET MVC, MySQL, Git',
            )
            vacancy_instance.save()
Exemplo n.º 5
0
def run():

    cache = {
        'companies': {},
        'specialties': {},
    }

    for _specialty in specialties:
        picture = _specialty.get('logo', '')

        if picture:
            picture = f'{settings.MEDIA_SPECIALITY_IMAGE_DIR}/{picture}'
        else:
            picture = f'{settings.MEDIA_SPECIALITY_IMAGE_DIR}/{settings.NO_LOGO_PIC}'

        specialty = Specialty.objects.create(code=_specialty['code'],
                                             title=_specialty['title'],
                                             picture=picture)
        cache['specialties'][specialty.code] = specialty

    for company_no, _company in enumerate(companies):
        logo = _company.get('logo', '')

        if logo:
            logo = f'{settings.MEDIA_COMPANY_IMAGE_DIR}/{logo}'
        else:
            logo = f'{settings.MEDIA_COMPANY_IMAGE_DIR}/no_logo.png'

        company = Company.objects.create(name=_company['title'],
                                         location=_company['location'],
                                         employee_count=randint(1, 10),
                                         logo=logo,
                                         description=_company.get(
                                             'description', ''),
                                         owner=create_user(company_no))
        cache['companies'][company.name] = company

    for job in jobs:
        vacancy = Vacancy(
            title=job['title'],
            published_at=job['posted'],
            salary_min=job.get('salary_from'),
            salary_max=job.get('salary_to'),
            description=job['desc'],
            specialty=cache['specialties'][job['cat']],
            company=cache['companies'][job['company']],
            is_remote=job.get('is_remote', False),
        )
        vacancy.save()

        for _skill in job.get('skills', []):
            skill, _ = Skill.objects.get_or_create(title=_skill)
            vacancy.skills.add(skill)
            vacancy.save()
Exemplo n.º 6
0
def main():

    # companies
    Company.objects.all().delete()
    for company in data.companies:
        new_company = Company(
            id=company['id'],
            name=company['title'],
            location=company['location'],
            logo=company['logo'],
            description=company['description'],
            employee_count=company['employee_count'],
        )
        new_company.save()

    # specialties
    Specialty.objects.all().delete()
    for specialty in data.specialties:
        new_specialty = Specialty(
            code=specialty['code'],
            title=specialty['title'],
            picture='specty_' + specialty['code'] + '.png',
        )
        new_specialty.save()

    # vacancies
    Vacancy.objects.all().delete()
    for job in data.jobs:
        new_vacancy = Vacancy(
            id=job['id'],
            title=job['title'],
            specialty=Specialty.objects.get(code=job['specialty']),
            company=Company.objects.get(id=job['company']),
            skills=job['skills'],
            description=job['description'],
            salary_min=job['salary_from'],
            salary_max=job['salary_to'],
            published_at=job['posted'],
        )
        new_vacancy.save()

    # settings
    Settings.objects.all().delete()
    new_setting = Settings(name='site_title', setval='Джуманджи')
    new_setting.save()
    new_setting = Settings(name='site_description',
                           setval='Вакансии для <br>Junior-разработчиков')
    new_setting.save()
Exemplo n.º 7
0
def post_job(request):
  success = False
  ctx = None
  logged_user_id = request.session.get('logged_user', False)
  if request.method == 'POST':
    companyObj = Companies.objects.get(auth_id_id=logged_user_id)
    job_form = JobPostingForm(request.POST)
    if job_form.is_valid():
      success = True
      title = job_form.cleaned_data['title']
      description = job_form.cleaned_data['description']
      district = job_form.cleaned_data['district']
      experience = job_form.cleaned_data['experience']
      personality = job_form.cleaned_data['personality']
      vacancy_type = job_form.cleaned_data['vacancy_type']
      salary_ranges = job_form.cleaned_data['salary_ranges']

      new_job = Vacancy(
        company_id=companyObj, 
        name=title, description=description, 
        district=district,
        experience=experience,        
        vacancy_type=vacancy_type,
        salary_ranges=salary_ranges,
        updated=timezone.now(),
        created=timezone.now(),
      )
      new_job.save()

      personality = request.POST.getlist('personality')
      for item in personality:
        Vacancy_personality(vacancy_id_id=new_job.pk, personality_id=item.encode('utf8')).save()

      skills = request.POST.getlist('skills')
      for skill in skills:
        Vacancy_skills(vacancy_id_id=new_job.pk, skill_id_id=skill.encode('utf8')).save()

      new_job_form = JobPostingForm()
      ctx = {'success':success, 'job_form':new_job_form}
    return render_to_response('post_job.html', ctx , context_instance=RequestContext(request))
  else:
    job_form = JobPostingForm()
    ctx = {'job_form':job_form}
    return render_to_response('post_job.html', ctx, context_instance=RequestContext(request))
Exemplo n.º 8
0
    def test_get_vacancy_count(self):
        username1 = '*****@*****.**'
        password = '******'
        user1 = User.objects.create_user(username1, password)
        first_vacancy = Vacancy()
        first_vacancy.user = user1
        first_vacancy.employer = self.employer_1
        first_vacancy.title = 'Welder TIG'
        first_vacancy.salary_min = 50000
        first_vacancy.save()

        second_vacancy = Vacancy()
        username2 = '*****@*****.**'
        password = '******'
        user2 = User.objects.create_user(username2, password)
        second_vacancy.user = user2
        second_vacancy.employer = self.employer_1
        second_vacancy.title = "Welder MIG-MAG"
        second_vacancy.salary_min = 60000
        second_vacancy.save()

        self.assertEqual(2, self.employer_1.get_vacancy_count())
Exemplo n.º 9
0
    def handle(self, *args, **options):
        for specialty in specialties:
            sp = Specialty(code=specialty['code'],
                           title=specialty['title'],
                           picture='https://place-hold.it/100x60')
            sp.save()

        for company in companies:
            cm = Company(name=company['title'],
                         logo='https://place-hold.it/100x60')
            cm.save()

        for job in jobs:
            vc = Vacancy(
                title=job['title'],
                specialty=Specialty.objects.filter(code=job['cat']).first(),
                company=Company.objects.filter(name=job['company']).first(),
                salary_min=job['salary_from'],
                salary_max=job['salary_to'],
                published_at=job['posted'],
                description=job['desc'])
            vc.save()
Exemplo n.º 10
0
if __name__ == '__main__':
    for spec in data.specialties:
        specialty = Specialty(code=spec['code'],
                              title=spec['title'],
                              picture=f'{settings.MEDIA_SPECIALITY_IMAGE_DIR}/specty_{spec["code"]}.png')
        specialty.save()

    loc = ['Москва', 'Калуга', 'п. Марс', 'Брянск', 'Прага', 'Лос-Анджелес', 'Сухиничи']
    for index, company in enumerate(data.companies, start=1):
        company = Company(name=company['title'],
                          location=random.choice(loc),
                          logo=f'{settings.MEDIA_COMPANY_IMAGE_DIR}/logo{index}.png',
                          description='',
                          employee_count=random.randint(1, 1000))
        company.save()

    skills = ['Python', 'Django', 'Git', 'Linux', 'CSS', 'Excel', 'Photoshop', 'ICQ', 'C++', 'Java', 'C#']
    for vacancy in data.jobs:
        specialty = Specialty.objects.get(code=vacancy['cat'])
        company = Company.objects.get(name=vacancy['company'])
        _vacancy = Vacancy(title=vacancy['title'],
                           specialty=specialty,
                           company=company,
                           skills=', '.join(random.sample(skills, 4)),
                           description=vacancy['desc'],
                           salary_min=int(vacancy['salary_from']),
                           salary_max=int(vacancy['salary_to']),
                           published_at=vacancy['posted'])
        _vacancy.save()
Exemplo n.º 11
0
def main():

    # users
    if not User.objects.all().count():
        last_login = '******'
        User.objects.create_superuser(username='******',
                                      email='admin@stepik_vacancies.com',
                                      password='******',
                                      last_login=last_login,
                                      first_name='Иван',
                                      last_name='Петров')
        User.objects.create_user(username='******',
                                 email='user1@stepik_vacancies.com',
                                 password='******',
                                 last_login=last_login,
                                 first_name='Петр',
                                 last_name='Сергеев')
        User.objects.create_user(username='******',
                                 email='user2@stepik_vacancies.com',
                                 password='******',
                                 last_login=last_login,
                                 first_name='Сергей',
                                 last_name='Иванов')

    # companies
    users = User.objects.all()
    Company.objects.all().delete()
    for company in data.companies:
        user = users[randint(0, 2)]
        new_company = Company(
            id=company['id'],
            name=company['title'],
            location=company['location'],
            description=company['description'],
            employee_count=company['employee_count'],
            owner=user,
        )
        new_company.save()

    # specialties
    Specialty.objects.all().delete()
    for specialty in data.specialties:
        new_specialty = Specialty(
            code=specialty['code'],
            title=specialty['title'],
        )
        new_specialty.save()

    # vacancies
    Vacancy.objects.all().delete()
    for job in data.jobs:
        new_vacancy = Vacancy(
            id=job['id'],
            title=job['title'],
            specialty=Specialty.objects.get(code=job['specialty']),
            company=Company.objects.get(id=job['company']),
            skills=job['skills'],
            description=job['description'],
            salary_min=job['salary_from'],
            salary_max=job['salary_to'],
            published_at=job['posted'],
        )
        new_vacancy.save()