Allow None values for max downvotes

This commit is contained in:
Sonny Bakker 2020-12-19 13:52:35 +01:00
parent 83ee1b2f8d
commit aafbf8a68d
4 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-12-19 12:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("collection", "0012_auto_20201219_1331")]
operations = [
migrations.AlterField(
model_name="collectionrule",
name="reddit_downvotes_max",
field=models.PositiveIntegerField(
blank=True, null=True, verbose_name="Maximum amount of downvotes"
),
)
]

View file

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-12-19 12:46
from django.db import migrations
def reset_default_downvotes(apps, schema_editor):
CollectionRule = apps.get_model("collection", "CollectionRule")
for rule in CollectionRule.objects.all():
rule.reddit_downvotes_max = None
rule.save()
class Migration(migrations.Migration):
dependencies = [("collection", "0013_auto_20201219_1345")]
operations = [migrations.RunPython(reset_default_downvotes)]

View file

@ -66,7 +66,7 @@ class CollectionRule(TimeStampedModel):
_("Minimum amount of upvotes"), default=0 _("Minimum amount of upvotes"), default=0
) )
reddit_downvotes_max = models.PositiveIntegerField( reddit_downvotes_max = models.PositiveIntegerField(
_("Maximum amount of downvotes"), default=0 _("Maximum amount of downvotes"), blank=True, null=True
) )
reddit_comments_min = models.PositiveIntegerField( reddit_comments_min = models.PositiveIntegerField(
_("Minimum amount of comments"), default=0 _("Minimum amount of comments"), default=0

View file

@ -194,7 +194,10 @@ class RedditBuilder(PostBuilder):
raise BuilderSkippedException( raise BuilderSkippedException(
"Post does not meet minimum amount of upvotes" "Post does not meet minimum amount of upvotes"
) )
elif downvotes >= rule.reddit_downvotes_max: elif (
rule.reddit_downvotes_max is not None
and downvotes > rule.reddit_downvotes_max
):
raise BuilderSkippedException("Post has more downvotes than allowed") raise BuilderSkippedException("Post has more downvotes than allowed")
elif not comments >= rule.reddit_comments_min: elif not comments >= rule.reddit_comments_min:
raise BuilderSkippedException("Post does not have enough comments") raise BuilderSkippedException("Post does not have enough comments")