Esempio n. 1
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()
Esempio n. 2
0
def _fill_specialties() -> None:
    class SpecialtyChoices(Enum):
        frontend = 'Фронтенд'
        backend = 'Бэкенд'
        gamedev = 'Геймдев'
        devops = 'Девопс'
        design = 'Дизайн'
        products = 'Продукты'
        management = 'Менеджмент'
        testing = 'Тестирование'

    specialty_logos_directory = Path('specialty_logos')
    for specialty_item in SpecialtyChoices:
        specialty_instance = Specialty(
            code=specialty_item.name,
            title=specialty_item.value,
            picture=str(specialty_logos_directory /
                        f'specty_{specialty_item.name}.png'))
        specialty_instance.save()
Esempio n. 3
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()
Esempio n. 4
0
    def handle(self, *args, **kwargs):
        for direction in specialties:
            item = DotMap(direction)
            new_item = Specialty(
                code=item.code,
                title=item.title,
                picture=item.picture
            )
            new_item.save()

        for company in companies:
            item = DotMap(company)
            new_item = Company(
                id=item.id,
                title=item.title,
                location=item.location,
                logo=item.logo,
                description=item.description,
                employee_count=item.employee_count
            )
            new_item.save()

        for job in jobs:
            item = DotMap(job)
            direction = Specialty.objects.filter(code=item.specialty).first()
            company = Company.objects.get(id=item.company)
            new_item = Vacancy(
                id=item.id,
                title=item.title,
                specialty=direction,
                company=company,
                skills=item.skills,
                description=item.description,
                salary_min=item.salary_from,
                salary_max=item.salary_to,
                posted=item.posted
            )
            new_item.save()
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'conf.settings')
django.setup()

from vacancies.models import Vacancy, Specialty, Company
from conf import settings
import random
import data

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'])
Esempio n. 6
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()
Esempio n. 7
0
specialties = [
    {"code": "frontend", "title": "Фронтенд"},
    {"code": "backend", "title": "Бэкенд"},
    {"code": "gamedev", "title": "Геймдев"},
    {"code": "devops", "title": "Девопс"},
    {"code": "design", "title": "Дизайн"},
    {"code": "products", "title": "Продукты"},
    {"code": "management", "title": "Менеджмент"},
    {"code": "testing", "title": "Тестирование"}

]

# Добавление данных в базу

""" Категории """
for specialty in specialties:
    new_specialty = Specialty(code=specialty["code"], title=specialty["title"], picture="https://place-hold.it/100x60")
    # new_specialty.save()

""" Компании """
for company in companies:
    new_company = Company(name=company["title"], logo="https://place-hold.it/100x60")
    # new_company.save()

""" Вакансии """
for job in jobs:
    new_job = Vacancy(title=job["title"], specialty=Specialty.objects.get(code=job["cat"]),
                      salary_min=job["salary_from"], company=Company.objects.get(name=job["company"]),
                      salary_max=job["salary_to"], published_at=job["posted"], description=job["desc"])
    # new_job.save()