Commit 07a59352 authored by Anna Kostenko's avatar Anna Kostenko

Add demo django application.

parents
from django.contrib import admin
from testimonials.models import Author
from testimonials.models import Testimonial
from testimonials.models import TestimonialShare
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ('__str__', 'first_name', 'last_name')
@admin.register(Testimonial)
class TestimonialAdmin(admin.ModelAdmin):
list_filter = ('agency', 'testimonial_type', 'is_verified')
list_select_related = ('agency', 'consultant')
list_display = ('consultant', 'testimonial_type', 'is_verified', 'rating', 'agency')
search_fields = (
'consultant__email', 'consultant__first_name', 'consultant__last_name')
raw_id_fields = ('consultant', 'author', 'application')
@admin.register(TestimonialShare)
class TestimonialShareAdmin(admin.ModelAdmin):
raw_id_fields = ['image_own', 'image_colleague']
from django.apps import AppConfig
class TestimonialsConfig(AppConfig):
name = 'testimonials'
def ready(self):
super().ready()
from testimonials import signals # pylint:disable=unused-variable
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django_filters import rest_framework as filters
from accounts.models import AgencyUser
from testimonials.models import Testimonial
class TestimonialFilter(filters.FilterSet):
author_type = filters.CharFilter(
name='author__author_type', help_text='Author type. One of [candidate, contact]')
consultant_id = filters.ModelChoiceFilter(
name='consultant_id', to_field_name='id',
help_text=_('Filter by consultant_id'),
queryset=AgencyUser.objects.all())
specialities = filters.CharFilter(
method='filter_specialities',
help_text=_('Filter by consultant\'s specialities(tags). '
'if consultant has any tag from the list. Value should be separated by | '
'Example: \'one\' or \'one|two\' '))
class Meta:
model = Testimonial
fields = ['author_type', 'consultant_id', 'specialities']
def filter_specialities(self, queryset, name, value):
values = value.split('|')
q = Q()
for tag in values:
q |= Q(consultant__specialities__icontains=tag)
qs = queryset.filter(q)
return qs
from django.db import models
class TestimonialQueryset(models.QuerySet):
def public(self):
qs = self\
.filter(status=self.model.STATUS.public)\
.exclude(text='')
return qs
def private(self):
return self.exclude(status=self.model.STATUS.public)
def placed(self):
qs = self.filter(testimonial_type=self.model.TYPES.app_placed)
return qs
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-11-27 08:21
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
class Migration(migrations.Migration):
initial = True
dependencies = [
('agencies', '0061_add_testimonials_flag'),
('applications', '0023_auto_20190924_0709'),
('accounts', '0036_can_delete_crm'),
]
operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='Email address')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='First Name')),
('last_name', models.CharField(blank=True, max_length=30, verbose_name='Last Name')),
('occupation', models.CharField(blank=True, max_length=30, verbose_name='Occupation')),
('author_type', models.CharField(choices=[('candidate', 'Candidate'), ('client', 'Client'), ('consultant', 'Consultant')], max_length=20, verbose_name='Type')),
],
),
migrations.CreateModel(
name='Testimonial',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('rating', models.PositiveSmallIntegerField(help_text='Rating value [1 to 5].', validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(1)], verbose_name='Rating')),
('testimonial_type', models.CharField(choices=[('app_viewed', 'App was viewed'), ('app_interviewed', 'App was interviewed'), ('app_offered', 'App was offered'), ('app_placed', 'App was placed')], db_index=True, max_length=20, verbose_name='Type')),
('comment', models.TextField(blank=True, verbose_name='Comment')),
('date', models.DateTimeField(verbose_name='Custom date of create')),
('agency', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='agencies.Agency', verbose_name='Agency')),
('application', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='applications.Application', verbose_name='Application')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='testimonials.Author', verbose_name='Author')),
('consultant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='accounts.AgencyUser', verbose_name='Consultant')),
],
options={
'ordering': ('-created',),
},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-11-29 09:04
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='author',
options={'ordering': ('-id',)},
),
migrations.AlterField(
model_name='author',
name='email',
field=models.EmailField(max_length=254, verbose_name='Email address'),
),
migrations.AlterUniqueTogether(
name='author',
unique_together=set([('email', 'author_type')]),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-12-02 08:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0002_update_author_constraint'),
]
operations = [
migrations.AddField(
model_name='testimonial',
name='text',
field=models.TextField(blank=True, verbose_name='Main testimonial'),
),
migrations.AlterField(
model_name='author',
name='author_type',
field=models.CharField(
choices=[('candidate', 'Candidate'), ('contact', 'Contact client'), ('consultant', 'Consultant')],
max_length=20, verbose_name='Type'),
),
migrations.AlterField(
model_name='author',
name='occupation',
field=models.CharField(blank=True, max_length=100, verbose_name='Occupation'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-12-05 14:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0003_add_main_text'),
]
operations = [
migrations.AlterField(
model_name='testimonial',
name='comment',
field=models.TextField(blank=True, max_length=100, verbose_name='Comment'),
),
migrations.AlterField(
model_name='testimonial',
name='text',
field=models.TextField(blank=True, max_length=1000, verbose_name='Main testimonial'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-12-06 08:13
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0004_add_limit'),
]
operations = [
migrations.AlterField(
model_name='author',
name='email',
field=models.EmailField(blank=True, max_length=254, verbose_name='Email address'),
),
migrations.AlterField(
model_name='testimonial',
name='agency',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='agencies.Agency', verbose_name='Agency'),
),
migrations.AlterField(
model_name='testimonial',
name='rating',
field=models.PositiveSmallIntegerField(help_text='Rating value [1 to 5].', null=True, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(1)], verbose_name='Rating'),
),
migrations.AlterField(
model_name='testimonial',
name='testimonial_type',
field=models.CharField(choices=[('default', 'Default'), ('app_interviewed', 'App was interviewed'), ('app_placed', 'App was placed')], db_index=True, max_length=20, verbose_name='Type'),
),
migrations.AlterUniqueTogether(
name='author',
unique_together=set([]),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-12-09 07:49
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0005_blank_values_internal_testimonials'),
]
operations = [
migrations.AddField(
model_name='testimonial',
name='status',
field=model_utils.fields.StatusField(choices=[('new', 'New'), ('public', 'Public')], default='new', max_length=100, no_check_for_status=True, verbose_name='status'),
),
migrations.AddField(
model_name='testimonial',
name='status_changed',
field=model_utils.fields.MonitorField(default=django.utils.timezone.now, monitor='status', verbose_name='status changed'),
),
migrations.AlterField(
model_name='testimonial',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='testimonials.Author', verbose_name='Author'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-12-10 09:22
from __future__ import unicode_literals
from django.db import migrations, models
def sync_old_interviewed(apps, schema_editor):
Testimonial = apps.get_model("testimonials", "Testimonial")
Testimonial.objects.filter(testimonial_type='app_interviewed').update(testimonial_type='app_interviewed_internal')
def reverse_old_interviewed(apps, schema_editor):
Testimonial = apps.get_model("testimonials", "Testimonial")
Testimonial.objects.filter(testimonial_type='app_interviewed_internal').update(testimonial_type='app_interviewed')
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0006_add_public_status'),
]
operations = [
migrations.AlterField(
model_name='testimonial',
name='testimonial_type',
field=models.CharField(choices=[('default', 'Default'), ('app_interviewed_internal', 'Candidate has internal interview'), ('app_interviewed_external', 'Candidate has external interview'), ('app_placed', 'Candidate has been placed')], db_index=True, max_length=40, verbose_name='Type'),
),
migrations.RunPython(sync_old_interviewed, reverse_old_interviewed),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-02-13 08:28
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0007_separate_status_interviewed'),
]
operations = [
migrations.AlterModelOptions(
name='testimonial',
options={'ordering': ('-date', '-created')},
),
migrations.AddField(
model_name='testimonial',
name='is_verified',
field=models.BooleanField(default=True, verbose_name='Is verified?'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-02-13 08:30
from __future__ import unicode_literals
from django.db import migrations
def remove_consultant_author_type(apps, schema_editor):
Testimonial = apps.get_model("testimonials", "Testimonial")
Testimonial.objects.filter(author__author_type='consultant').update(is_verified=False)
for t in Testimonial.objects.filter(is_verified=False):
t.author.author_type = 'candidate'
t.author.save()
def revert_consultant_author_type(apps, schema_editor):
Testimonial = apps.get_model("testimonials", "Testimonial")
for t in Testimonial.objects.filter(is_verified=False):
t.author.author_type = 'consultant'
t.author.save()
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0008_add_is_verified'),
]
operations = [
migrations.RunPython(remove_consultant_author_type, revert_consultant_author_type),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-02-13 09:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0009_migrate_author_type'),
]
operations = [
migrations.AlterField(
model_name='author',
name='author_type',
field=models.CharField(choices=[('candidate', 'Candidate'), ('contact', 'Contact client')], max_length=20, verbose_name='Type'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-03-11 14:09
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0010_remove_consultant_author_type'),
]
operations = [
migrations.AlterField(
model_name='testimonial',
name='agency',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='agencies.Agency', verbose_name='Company'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-03-11 15:17
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0011_rename-agency'),
]
operations = [
migrations.AlterField(
model_name='testimonial',
name='consultant',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='testimonials', to='accounts.AgencyUser', verbose_name='Recruiter'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-04-09 13:32
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
class Migration(migrations.Migration):
dependencies = [
('files', '0008_add_testimonial_share'),
('testimonials', '0012_rename-consultant'),
]
operations = [
migrations.CreateModel(
name='TestimonialShare',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('image_colleague', models.ForeignKey(help_text='Image about someone', on_delete=django.db.models.deletion.CASCADE, related_name='colleagues', to='files.TestimonialImage', verbose_name='Colleague image')),
('image_own', models.ForeignKey(help_text='Image about me', on_delete=django.db.models.deletion.CASCADE, related_name='own', to='files.TestimonialImage', verbose_name='Own image')),
('testimonial', models.OneToOneField(help_text='Testimonial.', on_delete=django.db.models.deletion.CASCADE, to='testimonials.Testimonial', verbose_name='Testimonial')),
],
options={
'abstract': False,
},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-04-09 14:43
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('testimonials', '0013_add_testimonial_share'),
]
operations = [
migrations.AlterModelOptions(
name='testimonialshare',
options={'ordering': ('-created',)},
),
migrations.AlterField(
model_name='testimonialshare',
name='testimonial',
field=models.OneToOneField(help_text='Testimonial.', on_delete=django.db.models.deletion.CASCADE, related_name='share', to='testimonials.Testimonial', verbose_name='Testimonial'),
),
]
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from model_utils.models import StatusModel
from model_utils.models import TimeStampedModel
from testimonials.managers import TestimonialQueryset
class Author(models.Model):
"""
User who left review
"""
TYPES = Choices(
('candidate', _('Candidate')),
('contact', _('Contact client')))
VERIFIED = [TYPES.candidate, TYPES.contact]
email = models.EmailField(_('Email address'), blank=True)
first_name = models.CharField(_('First Name'), max_length=30, blank=True)
last_name = models.CharField(_('Last Name'), max_length=30, blank=True)
occupation = models.CharField(_('Occupation'), max_length=100, blank=True)
author_type = models.CharField(_('Type'), choices=TYPES, max_length=20)
class Meta:
ordering = ('-id', )
def __str__(self):
return self.email or 'Unknown'
def get_full_name(self):
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip() or str(self)
class Testimonial(StatusModel, TimeStampedModel):
TYPES = Choices(
('default', _('Default')),
('app_interviewed_internal', _('Candidate has internal interview')),
('app_interviewed_external', _('Candidate has external interview')),
('app_placed', _('Candidate has been placed')))
STATUS = Choices(
('new', _('New')),
('public', _('Public')))
agency = models.ForeignKey(
'agencies.Agency', on_delete=models.CASCADE, related_name='testimonials',
verbose_name=_('Company'), blank=True, null=True)
consultant = models.ForeignKey(
'accounts.AgencyUser', on_delete=models.CASCADE,
verbose_name=_('Recruiter'), related_name='testimonials')
author = models.ForeignKey(
Author, on_delete=models.CASCADE, verbose_name=_('Author'),
related_name='testimonials')
application = models.ForeignKey(
'applications.Application', on_delete=models.CASCADE,
verbose_name=_('Application'), blank=True, null=True)
rating = models.PositiveSmallIntegerField(
_('Rating'), help_text=_('Rating value [1 to 5].'),
validators=[MaxValueValidator(5), MinValueValidator(1)], null=True)
testimonial_type = models.CharField(
_('Type'), choices=TYPES, max_length=40, db_index=True)
comment = models.TextField(_('Comment'), blank=True, max_length=100)
text = models.TextField(_('Main testimonial'), blank=True, max_length=1000)
date = models.DateTimeField(_('Custom date of create'))
is_verified = models.BooleanField(_('Is verified?'), default=True)
objects = TestimonialQueryset.as_manager()
class Meta:
ordering = ('-date', '-created', )
def __str__(self):
return f'Testimonials {self.testimonial_type} agency={self.agency_id}'