Repository: ciudadanointeligente/votainteligente-portal-electoral

Issue:
Reportar una propuesta
Se pueden reportar por :
- [ ] Faltas a los T&C
- [ ] Repetida


Discussion:

Resolving patch:
diff --git a/popular_proposal/admin.py b/popular_proposal/admin.py
--- a/popular_proposal/admin.py
+++ b/popular_proposal/admin.py
@@ -10,10 +10,13 @@ class PopularProposalAdmin(admin.ModelAdmin):
                     'area',
                     'title',
                     'data',
-                    'proposer'
+                    'proposer',
                     )
     exclude = ('organization',)
 
+    def get_queryset(self, *args, **kwargs):
+        return PopularProposal.all_objects.all()
+
 
 fieldset = []
 for key in ProposalTemporaryDataModelForm.base_fields:
diff --git a/popular_proposal/migrations/0024_auto_20170720_2052.py b/popular_proposal/migrations/0024_auto_20170720_2052.py
new file mode 100644
--- /dev/null
+++ b/popular_proposal/migrations/0024_auto_20170720_2052.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2017-07-20 20:52
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('popular_proposal', '0023_auto_20170711_1805'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='popularproposal',
+            options={'ordering': ['for_all_areas', '-created'], 'verbose_name': 'Propuesta Ciudadana', 'verbose_name_plural': 'Propuestas Ciudadanas'},
+        ),
+        migrations.AddField(
+            model_name='popularproposal',
+            name='is_reported',
+            field=models.BooleanField(default=False),
+        ),
+        migrations.AlterField(
+            model_name='proposallike',
+            name='user',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes', to=settings.AUTH_USER_MODEL),
+        ),
+    ]
diff --git a/popular_proposal/models.py b/popular_proposal/models.py
--- a/popular_proposal/models.py
+++ b/popular_proposal/models.py
@@ -79,6 +79,7 @@ class Statuses(DjangoChoices):
     needing_moderation = NeedingModerationManager()
     objects = models.Manager()
 
+
     def save(self, *args, **kwargs):
         if not self.comments:
             self.comments = {}
@@ -146,20 +147,24 @@ def get_title(self):
     def __str__(self):
         return self.get_title()
 
+class ProposalsManager(models.Manager):
+    def get_queryset(self):
+        qs = super(ProposalsManager, self).get_queryset()
+        qs = qs.exclude(is_reported=True)
+        return qs
 
 class ProposalQuerySet(models.QuerySet):
     def by_likers(self, *args, **kwargs):
         return self.order_by('-num_likers', 'proposer__profile__is_organization')
 
 
-class ProposalsOrderedManager(models.Manager):
+class ProposalsOrderedManager(ProposalsManager):
     def get_queryset(self):
-        qs = ProposalQuerySet(self.model, using=self._db)
+        qs = ProposalQuerySet(self.model, using=self._db).exclude(is_reported=True)
         qs = qs.annotate(num_likers=Count('likers'))
         return qs
 
 
-
 @python_2_unicode_compatible
 class PopularProposal(models.Model, OGPMixin):
     title = models.CharField(max_length=255, default='')
@@ -198,11 +203,13 @@ class PopularProposal(models.Model, OGPMixin):
                                      null=True,
                                      blank=True)
     is_local_meeting = models.BooleanField(default=False)
+    is_reported = models.BooleanField(default=False)
 
     ogp_enabled = True
 
     ordered = ProposalsOrderedManager.from_queryset(ProposalQuerySet)()
-    objects = models.Manager()
+    objects = ProposalsManager()
+    all_objects = models.Manager()
 
     class Meta:
         ordering = ['for_all_areas', '-created']


Test patch:
diff --git a/popular_proposal/tests/popular_proposal_model_tests.py b/popular_proposal/tests/popular_proposal_model_tests.py
--- a/popular_proposal/tests/popular_proposal_model_tests.py
+++ b/popular_proposal/tests/popular_proposal_model_tests.py
@@ -40,6 +40,7 @@ def test_instantiate_one(self):
         self.assertEquals(popular_proposal.clasification, u'education')
         self.assertFalse(popular_proposal.for_all_areas)
         self.assertFalse(popular_proposal.is_local_meeting)
+        self.assertFalse(popular_proposal.is_reported)
 
     def test_popular_proposal_card_as_property(self):
         popular_proposal = PopularProposal.objects.create(proposer=self.fiera,
@@ -54,6 +55,29 @@ def test_popular_proposal_card_as_property(self):
 
         self.assertEquals(popular_proposal.card, expected_card_html)
 
+    def test_reportedproposals_are_not_in_default_manager(self):
+        p1 = PopularProposal.objects.create(proposer=self.fiera,
+                                            area=self.arica,
+                                            data=self.data,
+                                            title=u'This is a title',
+                                            clasification=u'education'
+                                            )
+        p2 = PopularProposal.objects.create(proposer=self.fiera,
+                                            area=self.arica,
+                                            data=self.data,
+                                            title=u'This is a title',
+                                            clasification=u'education',
+                                            is_reported=True
+                                            )
+        self.assertIn(p1, PopularProposal.objects.all())
+        self.assertNotIn(p2, PopularProposal.objects.all())
+        # now ordered
+        self.assertIn(p1, PopularProposal.ordered.all())
+        self.assertNotIn(p2, PopularProposal.ordered.all())
+        #but they appear in the all Manager
+        self.assertIn(p1, PopularProposal.all_objects.all())
+        self.assertIn(p2, PopularProposal.all_objects.all())
+
     def test_proposal_ogp(self):
         site = Site.objects.get_current()
         popular_proposal = PopularProposal.objects.create(proposer=self.fiera,