-
Notifications
You must be signed in to change notification settings - Fork 0
fixed bug. also slightly optimized other signal #318
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b000d3c
fixed bug. also slightly optimized other signal
sh1nkey 3004c56
refactored signals code
sh1nkey 83f14c1
devscript added new
sh1nkey 321242c
corrected projects/signals, deleted useless variables
sh1nkey c2d64bd
deleted useless variables x2
sh1nkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from projects.models import Project | ||
| from vacancy.models import Vacancy | ||
|
|
||
| SIGNALS_MODELS = Vacancy | Project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from django.contrib.contenttypes.models import ContentType | ||
|
|
||
| from feed.constants import SIGNALS_MODELS | ||
| from news.models import News | ||
|
|
||
|
|
||
| def delete_news_for_model(instance: SIGNALS_MODELS): | ||
| content_type = ContentType.objects.get_for_model(instance) | ||
| obj = News.objects.filter(content_type=content_type, object_id=instance.id).first() | ||
| if obj: | ||
| obj.delete() | ||
|
|
||
|
|
||
| def create_news_for_model(instance: SIGNALS_MODELS): | ||
| content_type = ContentType.objects.get_for_model(instance) | ||
| News.objects.get_or_create(content_type=content_type, object_id=instance.id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,33 @@ | ||
| from django.contrib.contenttypes.models import ContentType | ||
| from django.db.models.signals import post_save | ||
| from django.db.models.signals import post_save, post_delete | ||
| from django.dispatch import receiver | ||
|
|
||
| from news.models import News | ||
|
|
||
| from feed.services import create_news_for_model, delete_news_for_model | ||
| from projects.models import Project | ||
|
|
||
| from vacancy.models import Vacancy | ||
|
|
||
|
|
||
| @receiver(post_save, sender=Vacancy) | ||
| def create_news_on_save(sender, instance, created, **kwargs): | ||
| if created: | ||
| content_type = ContentType.objects.filter(model="vacancy").first() | ||
| news_instance, created = News.objects.get_or_create( | ||
| content_type=content_type, object_id=instance.id | ||
| ) | ||
| if instance.is_active: | ||
| create_news_for_model(instance) | ||
| else: | ||
| delete_news_for_model(instance) | ||
|
|
||
|
|
||
| @receiver(post_delete, sender=Vacancy) | ||
| def delete_news_vacancy(sender, instance, **kwargs): | ||
| delete_news_for_model(instance) | ||
|
|
||
|
|
||
| @receiver(post_save, sender=Project) | ||
| def create_news_on_created_project(sender, instance, created, **kwargs): | ||
| if not instance.draft: | ||
| create_news_for_model(instance) | ||
| else: | ||
| delete_news_for_model(instance) | ||
|
|
||
|
|
||
| @receiver(post_delete, sender=Project) | ||
| def delete_news_project(sender, instance, **kwargs): | ||
| delete_news_for_model(instance) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.