This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Integrate aldryn-categories into aldryn-jobs. #44
Open
chronossc
wants to merge
3
commits into
master
Choose a base branch
from
features/aldryn_categories
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 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 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,44 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
import aldryn_categories.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('aldryn_categories', '0003_auto_20150128_1359'), | ||
('aldryn_jobs', '0007_auto_20150330_0545'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='JobCategoryOpts', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('app_config', models.ForeignKey(verbose_name='app_config', to='aldryn_jobs.JobsConfig', null=True)), | ||
('category', aldryn_categories.fields.CategoryOneToOneField(related_name='jobs_opts', to='aldryn_categories.Category')), | ||
('supervisors', models.ManyToManyField(help_text='Those people will be notified via e-mail when new application arrives.', related_name='job_categories_opts', verbose_name='Supervisors', to=settings.AUTH_USER_MODEL, blank=True)), | ||
], | ||
options={ | ||
'verbose_name': 'Job category opts', | ||
'verbose_name_plural': 'Job categories opts', | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.AddField( | ||
model_name='joboffer', | ||
name='category_new', | ||
field=aldryn_categories.fields.CategoryForeignKey(related_name='job_offers', default=None, to='aldryn_categories.Category', null=True), | ||
preserve_default=True, | ||
), | ||
migrations.AlterField( | ||
model_name='joboffer', | ||
name='category', | ||
field=models.ForeignKey(related_name='jobs', default=None, verbose_name='Category', to='aldryn_jobs.JobCategory', null=True), | ||
preserve_default=True, | ||
), | ||
] |
This file contains 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,106 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from aldryn_categories.models import Category as NoFrozenCategory | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
"Write your forwards methods here." | ||
# Note: Don't use "from appname.models import ModelName". | ||
# Use orm.ModelName to refer to models in this application, | ||
# and orm['appname.ModelName'] for models in other applications. | ||
Category = apps.get_model('aldryn_categories.Category') | ||
JobCategory = apps.get_model('aldryn_jobs.JobCategory') | ||
JobCategoryOpts = apps.get_model('aldryn_jobs.JobCategoryOpts') | ||
for old_category in JobCategory.objects.all(): | ||
# This is maybe wrong but using the model out of 'orm' (not frozen) | ||
# we can access add_root. Copy all the treebeard category creation | ||
# into migration is a big overhead, but would be the perfect thing | ||
# to do. | ||
en_tr = old_category.translations.get(language_code='en') | ||
new_category = NoFrozenCategory.add_root( | ||
name=en_tr.name, | ||
slug=en_tr.slug, | ||
) | ||
new_category = Category.objects.get(pk=new_category.pk) | ||
|
||
# When creating default translation parler use as default 'en-us', | ||
# so we fix it here because we use only 'en'. | ||
en_tr = new_category.translations.get() | ||
en_tr.language_code = 'en' | ||
en_tr.save() | ||
|
||
# add other translations, we can't use create_translations | ||
# in migrations. | ||
for tr in old_category.translations.exclude(language_code='en'): | ||
new_category.translations.create( | ||
language_code=tr.language_code, | ||
name=tr.name, | ||
slug=tr.slug, | ||
) | ||
|
||
for job in old_category.jobs.all(): | ||
job.category_new = new_category | ||
job.category = None | ||
job.save() | ||
|
||
job_opts = JobCategoryOpts.objects.create( | ||
category_id=new_category.pk, | ||
app_config=old_category.app_config, | ||
# ordering isn't migrated since aldryn-categories provide a way | ||
# to order categories already | ||
) | ||
job_opts.supervisors = old_category.supervisors.all() | ||
job_opts.save() | ||
|
||
old_category.delete() | ||
|
||
|
||
def backwards(apps, schema_editor): | ||
"Write your backwards methods here." | ||
Category = apps.get_model('aldryn_categories.Category') | ||
JobCategory = apps.get_model('aldryn_jobs.JobCategory') | ||
JobCategoryOpts = apps.get_model('aldryn_jobs.JobCategoryOpts') | ||
|
||
for new_category in Category.objects.all(): | ||
job_opt = JobCategoryOpts.objects.get(category=new_category) | ||
# create the old category | ||
old_category = JobCategory.objects.create( | ||
app_config=job_opt.app_config | ||
) | ||
old_category.supervisors = job_opt.supervisors.all() | ||
|
||
# create default translation | ||
en_tr = new_category.translations.get(language_code='en') | ||
old_category.translations.create( | ||
language_code='en', | ||
name=en_tr.name, | ||
slug=en_tr.slug | ||
) | ||
for tr in new_category.translations.exclude(language_code='en'): | ||
# create another translations | ||
old_category.translations.create( | ||
language_code=tr.language_code, | ||
name=tr.name, | ||
slug=tr.slug, | ||
) | ||
|
||
for job in new_category.job_offers.all(): | ||
job.category = old_category | ||
job.category_new = None | ||
job.save() | ||
|
||
old_category.save() | ||
new_category.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('aldryn_jobs', '0008_auto_20150403_0611'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards, backwards) | ||
] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not relevant anymore