Remove OldJobAd model

This commit is contained in:
Aarni Halinen
2022-07-26 22:52:33 +03:00
parent 1eb5e7e10c
commit ae136aebae
6 changed files with 24 additions and 62 deletions
@@ -0,0 +1,16 @@
# Generated by Django 2.2.28 on 2022-07-26 19:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("webapp", "0089_auto_20220726_2229"),
]
operations = [
migrations.DeleteModel(
name="RemoveJobAd",
),
]
-45
View File
@@ -218,50 +218,6 @@ class JobAd(BaseFeed):
verbose_name_plural = _("JobAds")
class RemoveJobAd(models.Model):
"""Job advertisements shown on Corporate relations page"""
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=255)
visible = models.BooleanField(default=True)
deleted = models.BooleanField(default=False)
autohide_at = models.DateTimeField(default=month_from_now)
autohide_enabled = models.BooleanField(default=False)
description = models.CharField(max_length=255)
content = models.TextField()
created_at = models.DateTimeField(default=timezone.now)
class Meta:
verbose_name = _("JobAd")
verbose_name_plural = _("JobAds")
def __str__(self):
delete_str = _("Deleted: ") if self.deleted else ""
return f"{delete_str}{self.title}"
__previousVisible = False
def __init__(self, *args, **kwargs):
super(RemoveJobAd, self).__init__(*args, **kwargs)
self.__previousVisible = self.visible
def save(self, force_insert=False, force_update=False, *args, **kwargs):
created = self.pk is None
super(RemoveJobAd, self).save(force_insert, force_update, *args, **kwargs)
if self.visible and (created or not self.__previousVisible):
self.refresh_from_db() # Fetch so we can use primary key
url = f"https://{FRONTEND_URL}/jobads/{self.pk}"
processHooks(
message=generateMessage(
"Uusi työpaikkailmoitus", self.title, self.description, url
),
eventType="jobad",
)
self.__previousVisible = self.visible
def generateMessage(heading: str, title: str, description: str, url: str):
return render_to_string(
"webapp/tg_message.tpl",
@@ -347,6 +303,5 @@ auditlog.register(Event)
auditlog.register(SignupForm)
auditlog.register(Signup)
auditlog.register(JobAd)
auditlog.register(RemoveJobAd)
auditlog.register(GenericWebhook)
auditlog.register(TelegramHook)
+1 -1
View File
@@ -184,7 +184,7 @@ class FeedSerializer(serializers.ModelSerializer):
class JobAdSerializer(serializers.ModelSerializer):
class Meta:
model = RemoveJobAd
model = JobAd
fields = (
"id",
"title_fi",
+4 -4
View File
@@ -2,7 +2,7 @@ from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase, APIRequestFactory
from webapp.models import RemoveJobAd
from webapp.models import JobAd
from webapp.serializers import JobAdSerializer
API = "/api/jobads/"
@@ -10,7 +10,7 @@ API = "/api/jobads/"
class JobAdTestCase(APITestCase):
def setUp(self):
self.prefilled_jobad = RemoveJobAd.objects.create(
self.prefilled_jobad = JobAd.objects.create(
title_fi="ABB Test",
title_en="ABB Test",
visible=True,
@@ -46,10 +46,10 @@ class JobAdTestCase(APITestCase):
# Try post without authentication
response = self.client.post(API, data, format="json")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(RemoveJobAd.objects.count(), 1)
self.assertEqual(JobAd.objects.count(), 1)
# Authenticate
self.client.force_authenticate(user=self.authClient)
response = self.client.post(API, data, format="json")
# Return success and check object was created
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(RemoveJobAd.objects.count(), 2)
self.assertEqual(JobAd.objects.count(), 2)
-9
View File
@@ -39,15 +39,6 @@ class SignupTranslationOptions(TranslationOptions):
fields = ()
@register(RemoveJobAd)
class JobAdTranslationOptions(TranslationOptions):
fields = (
"title",
"description",
"content",
)
@register(JobAd)
class JobAdTranslationOptions(TranslationOptions):
fields = ()
+3 -3
View File
@@ -325,14 +325,14 @@ class TagsViewSet(ReadOnlyModelViewSet):
class JobAdViewSet(ModelViewSet):
queryset = RemoveJobAd.objects.filter(deleted=False)
queryset = JobAd.objects.filter(deleted=False)
serializer_class = JobAdSerializer
permission_classes = [IsAuthenticatedOrReadOnly]
def get_queryset(self):
if self.request.user.is_authenticated:
return RemoveJobAd.objects.filter(deleted=False)
return RemoveJobAd.objects.filter(
return JobAd.objects.filter(deleted=False)
return JobAd.objects.filter(
deleted=False, visible=True, autohide_at__gt=timezone.now()
)