Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seach is used postgres(SearchVector). Updated README #8

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ venv/
ENV/
env.bak/
venv.bak/
Pipfile
Pipfile.lock

# Spyder project settings #
.spyderproject
Expand All @@ -133,3 +135,6 @@ dmypy.json
cython_debug/

.vscode

Pipenv
Pipenv.lock
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,21 @@ Replace `<CONTAINER ID>` with the id of the postgres container and run the comma
```
cat dump.sql | docker exec -i <CONTAINER ID> psql --user admin djinni_sandbox
```
For search, the `PostgreSQL` module `pg_trgm` was used, which can be activated as follows:

```
docker-compose run web python app/manage.py dbshell
```
and then:

```
CREATE EXTENSION IF NOT EXISTS pg_trgm;
```
last step

```
docker-compose run web python app/manage.py migrate
```
Now open the http://0.0.0.0:8000 and you will see jobs list.

Good to go! 👍👍
Expand Down
34 changes: 31 additions & 3 deletions app/djinnitest/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,31 @@


# Application definition

INSTALLED_APPS = [
# Стандартні додатки Django
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

# Installed apps
THIRD_PARTY_APPS = [
"django_filters",
"crispy_forms",
"crispy_bootstrap5",
]

LOCAL_APPS = [
"jobs.apps.JobsConfig",
]


INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS


MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down Expand Up @@ -86,7 +100,13 @@
}
}


# CACHE
CACHES = {
'default': {
'BACKEND': "django.core.cache.backends.memcached.PyMemcacheCache",
'LOCATION': "cache:11211", # The "cache" hostname matches the service name in your docker-compose.yml
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -123,7 +143,15 @@

STATIC_URL = "static/"

STATICFILES_DIRS = [
BASE_DIR / "static",
]

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# CRISPY FORMS SETTINGS
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
10 changes: 9 additions & 1 deletion app/jobs/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from django.contrib import admin

# Register your models here.
from jobs.models import JobPosting

class JobPostingAdmin(admin.ModelAdmin):
list_display = ('position', 'company', 'created')
list_filter = ('position', 'company', 'created')
search_fields = ('position',)


admin.site.register(JobPosting, JobPostingAdmin)
76 changes: 76 additions & 0 deletions app/jobs/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import django_filters
from django import forms

from jobs.utils import get_unique_choices, get_choices
from jobs.models import (
JobPosting,
JobDomain,
CompanyType,
EnglishLevel,
AcceptRegion,
RemoteType
)

class JobPostingFilter(django_filters.FilterSet):
""" Filters for job postings. """
position = django_filters.ChoiceFilter(choices=get_unique_choices('position', JobPosting))
domain = django_filters.MultipleChoiceFilter(
choices=JobDomain.choices,
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
company_type = django_filters.MultipleChoiceFilter(
choices=CompanyType.choices,
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
experience_years = django_filters.MultipleChoiceFilter(
choices=get_unique_choices('experience_years', JobPosting),
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
english_level = django_filters.MultipleChoiceFilter(
choices=EnglishLevel.choices,
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
accept_region = django_filters.MultipleChoiceFilter(
choices=AcceptRegion.choices,
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
remote_type = django_filters.MultipleChoiceFilter(
choices=RemoteType.choices,
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
salary_min = django_filters.NumberFilter(
field_name='salary_min', lookup_expr='gte', label='Payment from'
)
location = django_filters.MultipleChoiceFilter(
choices=lambda: get_choices('location'),
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
country = django_filters.MultipleChoiceFilter(
choices=lambda: get_choices('country'),
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)
# company = django_filters.ChoiceFilter(choices=lambda: JobPostingFilter.get_choices('company'))
sort_by = django_filters.ChoiceFilter(
choices=[('created', 'Oldest to Newest'), ('-created', 'Newest to Oldest')],
method='filter_by_sort', label='Sort by'
)

class Meta:
model = JobPosting
fields = [
'domain',
'company_type',
'experience_years',
'english_level',
'accept_region',
'remote_type',
'salary_min',
'country',
'location',
# 'company',

]


def filter_by_sort(self, queryset, name, value):
return queryset.order_by(value)
24 changes: 24 additions & 0 deletions app/jobs/migrations/0002_jobposting_search_vector_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.4 on 2024-08-09 14:14

import django.contrib.postgres.indexes
import django.contrib.postgres.search
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('jobs', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='jobposting',
name='search_vector',
field=django.contrib.postgres.search.SearchVectorField(null=True),
),
migrations.AddIndex(
model_name='jobposting',
index=django.contrib.postgres.indexes.GinIndex(fields=['search_vector'], name='jobs_jobpos_search__a9892e_gin'),
),
]
19 changes: 19 additions & 0 deletions app/jobs/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVectorField


class Experience(models.TextChoices):
ZERO = "no_exp", _("No experience")
Expand All @@ -8,17 +11,20 @@ class Experience(models.TextChoices):
THREE = "3y", _("3 years")
FIVE = "5y", _("5 years")


class RemoteType(models.TextChoices):
OFFICE = "office", _("Office Work")
PARTLY_REMOTE = "partly_remote", _("Hybrid Remote")
FULL_REMOTE = "full_remote", _("Full Remote")
CANDIDATE_CHOICE = "candidate_choice", _("Office/Remote of your choice")


class RelocateType(models.TextChoices):
NO_RELOCATE = "no_relocate", _("No relocation")
CANDIDATE_PAID = "candidate_paid", _("Covered by candidate")
COMPANY_PAID = "company_paid", _("Covered by company")


class AcceptRegion(models.TextChoices):
OFFICE_LOCATIONS = "office_locations", _("Office locations")
WORLDWIDE = "", _("Worldwide")
Expand All @@ -27,6 +33,7 @@ class AcceptRegion(models.TextChoices):
EUROPE = "europe", _("Ukraine + Europe")
CUSTOM_SELECTION = "custom_selection", _("Custom selection")


class EnglishLevel(models.TextChoices):
NONE = ("no_english", "No English")
BASIC = ("basic", "Beginner/Elementary")
Expand All @@ -35,6 +42,7 @@ class EnglishLevel(models.TextChoices):
UPPER = ("upper", "Upper-Intermediate")
FLUENT = ("fluent", "Advanced/Fluent")


class JobDomain(models.TextChoices):
ADULT = "adult", "Adult"
ADTECH = "advertising", "Advertising / Marketing"
Expand All @@ -59,19 +67,22 @@ class JobDomain(models.TextChoices):
TRAVEL = "travel", "Travel / Tourism"
OTHER = "other", "Other"


class CompanyType(models.TextChoices):
AGENCY = "agency", _("Agency")
OUTSOURCE = "outsource", _("Outsource")
OUTSTAFF = "outstaff", _("Outstaff")
PRODUCT = "product", _("Product")
STARTUP = "startup", _("Startup")


class RemoteType(models.TextChoices):
OFFICE = "office", _("Office Work")
PARTLY_REMOTE = "partly_remote", _("Hybrid Remote")
FULL_REMOTE = "full_remote", _("Full Remote")
CANDIDATE_CHOICE = "candidate_choice", _("Office/Remote of your choice")


class CompanyType(models.TextChoices):
AGENCY = ("agency/freelance", "agency/freelance")
PRODUCT = ("product", "product")
Expand Down Expand Up @@ -172,14 +183,22 @@ class Status(models.TextChoices):
last_modified = models.DateTimeField(blank=True, null=True, auto_now=True, db_index=True)
published = models.DateTimeField(blank=True, null=True, db_index=True)
created = models.DateTimeField(auto_now_add=True, db_index=True)
search_vector = SearchVectorField(null=True)

class Meta:
indexes = [
GinIndex(fields=['search_vector']),
]
ordering = ["-published"]


class Recruiter(models.Model):
email = models.EmailField(blank=False, db_index=True, unique=True)
name = models.CharField(max_length=250, blank=False, default="")
company_id = models.IntegerField(blank=True, null=True)
slug = models.SlugField()


class Company(models.Model):
name = models.CharField(max_length=250, blank=False, default="")
company_type = models.CharField(
Expand Down
Loading