-
Notifications
You must be signed in to change notification settings - Fork 17
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
feature/55 first approach to campaigns #92
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2559d02
feature/55 first approach to campaigns
juan-ignacio-sanchez 763aa92
feature/55 fix flake8 style
juan-ignacio-sanchez 916cc9a
feature/55 add python3.5 compat
juan-ignacio-sanchez ce91776
remove previous migrations and refactor campaings/drip models
juan-ignacio-sanchez c3bb67d
refactor drip/campaign models
juan-ignacio-sanchez 92e39ff
fix campaign creation tests
juan-ignacio-sanchez aa97de5
remove unused variable
juan-ignacio-sanchez eb30453
allow the user to control wheter to remove or not the drips attached …
juan-ignacio-sanchez eac182c
add unittest and missing migration
juan-ignacio-sanchez 43f507d
add DripInline to CampaignAdmin
juan-ignacio-sanchez 1e24198
fix style to match pep8
juan-ignacio-sanchez e4768e9
bump second digit according to CONTRIBUTING as this is a non-breaking…
juan-ignacio-sanchez 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
Empty file.
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,16 @@ | ||
from django.contrib import admin | ||
from campaigns.models import Campaign | ||
from drip.models import Drip | ||
|
||
|
||
class DripInline(admin.TabularInline): | ||
model = Drip | ||
|
||
|
||
class CampaignAdmin(admin.ModelAdmin): | ||
inlines = [ | ||
DripInline, | ||
] | ||
|
||
|
||
admin.site.register(Campaign, CampaignAdmin) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CampaignsConfig(AppConfig): | ||
name = 'campaigns' |
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,22 @@ | ||
# Generated by Django 3.0.7 on 2020-12-30 21:11 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Campaign', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(default='Unnamed Campaign', max_length=256)), | ||
('delete_drips', models.BooleanField(default=True)), | ||
], | ||
), | ||
] |
Empty file.
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,11 @@ | ||
from django.db import models | ||
|
||
|
||
class Campaign(models.Model): | ||
name = models.CharField(max_length=256, default='Unnamed Campaign') | ||
delete_drips = models.BooleanField(default=True) | ||
|
||
def delete(self, using=None, keep_parents=False): | ||
if self.delete_drips: | ||
self.drip_set.all().delete() | ||
super().delete(using, keep_parents) |
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,65 @@ | ||
from django.test import TestCase | ||
from drip.models import Drip | ||
from campaigns.models import Campaign | ||
|
||
DRIP_AMOUNT = 10 | ||
|
||
|
||
def _drips_generator(amount, **drip_extra_args): | ||
for i in range(amount): | ||
yield Drip( | ||
name='{}th drip'.format(i), | ||
**drip_extra_args | ||
) | ||
|
||
|
||
class DripsTestCase(TestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please test also using a class different from Drip, to test the |
||
|
||
def test_campaings_creation(self): | ||
campaign = Campaign() | ||
campaign.save() | ||
|
||
Drip.objects.bulk_create( | ||
_drips_generator( | ||
DRIP_AMOUNT, | ||
campaign=campaign | ||
) | ||
) | ||
|
||
assert len(campaign.drip_set.all()) == DRIP_AMOUNT | ||
|
||
def test_remove_campaings(self): | ||
campaign_delete_drips = Campaign(name='remove me!', delete_drips=True) | ||
campaign_delete_drips.save() | ||
|
||
Drip.objects.bulk_create( | ||
_drips_generator( | ||
DRIP_AMOUNT, | ||
campaign=campaign_delete_drips | ||
) | ||
) | ||
|
||
drips_before_delete = Drip.objects.count() | ||
|
||
campaign_delete_drips.delete() | ||
|
||
assert drips_before_delete > Drip.objects.count() | ||
|
||
campaign_do_not_delete_drips = Campaign( | ||
name='remove me, but keep my drips alive!', | ||
delete_drips=False, | ||
) | ||
campaign_do_not_delete_drips.save() | ||
|
||
Drip.objects.bulk_create( | ||
_drips_generator( | ||
DRIP_AMOUNT, | ||
campaign=campaign_do_not_delete_drips | ||
) | ||
) | ||
|
||
drips_before_delete = Drip.objects.count() | ||
|
||
campaign_do_not_delete_drips.delete() | ||
|
||
assert drips_before_delete == Drip.objects.count() |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.9.3' | ||
__version__ = '1.10.3' |
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,20 @@ | ||
# Generated by Django 3.0.7 on 2020-12-30 22:10 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('campaigns', '0001_initial'), | ||
('drip', '0002_querysetrule_rule_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='drip', | ||
name='campaign', | ||
field=models.ForeignKey(blank=True, help_text='If set, this is the campaign to which this Drip belongs to.', null=True, on_delete=django.db.models.deletion.CASCADE, to='campaigns.Campaign'), | ||
), | ||
] |
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,20 @@ | ||
# Generated by Django 3.0.7 on 2020-12-30 22:23 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('campaigns', '0001_initial'), | ||
('drip', '0003_drip_campaign'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='drip', | ||
name='campaign', | ||
field=models.ForeignKey(blank=True, default=None, help_text='If set, this is the campaign to which this Drip belongs to.', null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='campaigns.Campaign'), | ||
), | ||
] |
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
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.
I would use
random.randint
. Just a suggestion