Skip to content

Commit

Permalink
Remove HunchUser through model.
Browse files Browse the repository at this point in the history
It contains a single extra field (status), which is showing no sign of
being implemented any time soon. This is simpler.
  • Loading branch information
adammck committed Nov 28, 2011
1 parent 2fb3341 commit feca9b0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 61 deletions.
1 change: 0 additions & 1 deletion hunchworks/fixtures/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def getparams(self):
description = 'markov %s' % pk
return locals()

#class HunchUserFactory(BaseFactory, DjangoMixin): pass
class GroupFactory(BaseFactory, DjangoMixin):
model = Group

Expand Down
41 changes: 2 additions & 39 deletions hunchworks/fixtures/sample_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,45 +598,8 @@
"time_modified": "2011-10-28 00:00:00",
"title": "There will be a serious cholera outbreak in the IDP camp in Gulu within a year",
"description": "There is a scarcity of basic sanitary facilities, shortage of water, poor drainage, poor sanitation habits, and contaminated boreholes. It is only a matter of time before disease breaks out.",
"location": 2
}
},


{
"pk": 1,
"model": "hunchworks.hunchuser",
"fields":
{
"hunch": 1,
"user_profile": 3
}
},
{
"pk": 2,
"model": "hunchworks.hunchuser",
"fields":
{
"hunch": 1,
"user_profile": 4
}
},
{
"pk": 3,
"model": "hunchworks.hunchuser",
"fields":
{
"hunch": 1,
"user_profile": 5
}
},
{
"pk": 4,
"model": "hunchworks.hunchuser",
"fields":
{
"hunch": 1,
"user_profile": 6
"location": 2,
"user_profiles": [1, 2, 3, 4]
}
},

Expand Down
8 changes: 1 addition & 7 deletions hunchworks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Hunch(models.Model):
location = models.ForeignKey('Location', null=True, blank=True)
evidences = models.ManyToManyField( 'Evidence', through='HunchEvidence', blank=True)
tags = models.ManyToManyField('Tag', blank=True)
user_profiles = models.ManyToManyField('UserProfile', through='HunchUser')
user_profiles = models.ManyToManyField("UserProfile")

class Meta:
verbose_name_plural = "hunches"
Expand Down Expand Up @@ -282,12 +282,6 @@ def evidence_count(self):
sender=Hunch)


class HunchUser(models.Model):
hunch = models.ForeignKey('Hunch')
user_profile = models.ForeignKey('UserProfile')
status = models.IntegerField(default=0)


class Evidence(models.Model):
title = models.CharField(verbose_name="Short description", max_length=100, blank=True,
help_text="This should be a short summary of the evidence or what it contains")
Expand Down
2 changes: 1 addition & 1 deletion hunchworks/tests/hunch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from hunchworks.models import Hunch, HunchUser, Evidence, HunchEvidence, Vote
from hunchworks.models import Hunch, Evidence, HunchEvidence, Vote
from hunchworks.tests.helpers import ViewTestHelpers, UnitTestHelpers
from django.test import TestCase

Expand Down
10 changes: 4 additions & 6 deletions hunchworks/views/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def show(req, group_id):
members = paginated(req, group.members.all(), 10)

group_members = group.members.values_list("id", flat=True)
hunch_users = models.HunchUser.objects.filter(user_profile__in=group_members).values_list("hunch_id", flat=True).distinct()
hunches = models.Hunch.objects.filter(id__in=hunch_users).order_by("-time_modified")[:3]

hunches = models.Hunch.objects.filter(user_profile__in=group_members).order_by("-time_modified")[:3]

if len(group.members.filter(pk=req.user.get_profile().pk)) > 0:
is_member = True
else:
Expand Down Expand Up @@ -107,10 +106,9 @@ def hunches(req, group_id):
group = get_object_or_404(models.Group, pk=group_id)

group_members = group.members.values_list("id", flat=True)
hunch_users = models.HunchUser.objects.filter(user_profile__in=group_members).values_list("hunch_id", flat=True).distinct()
hunches = models.Hunch.objects.filter(id__in=hunch_users).order_by("-time_modified")
all_hunches = models.Hunch.objects.filter(user_profile__in=group_members).order_by("-time_modified")[:3]

hunches = paginated(req, hunches, 10)
hunches = paginated(req, all_hunches, 10)

return _render(req, "hunches", {
"group": group,
Expand Down
10 changes: 3 additions & 7 deletions hunchworks/views/hunches.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,13 @@ def done(self, form_list, **kwargs):
location = form_list[2].cleaned_data["location"])

hunch.tags = form_list[2].cleaned_data["tags"]
hunch.user_profiles = form_list[3].cleaned_data["user_profiles"]

for evidence in form_list[1].cleaned_data["evidences"]:
models.HunchEvidence.objects.create(
evidence=evidence,
hunch=hunch)

for user_profile in form_list[3].cleaned_data["user_profiles"]:
models.HunchUser.objects.create(
user_profile=user_profile,
hunch=hunch)

hunch.save()

return redirect(hunch)
Expand All @@ -236,14 +232,14 @@ def done(self, form_list, **kwargs):
@login_required
def follow(req, hunch_id):
hunch = get_object_or_404(models.Hunch, pk=hunch_id)
hunch_user = models.HunchUser.objects.get_or_create(hunch=hunch, user_profile=req.user.get_profile())
hunch.userprofile_set.add(req.user.get_profile())
return redirect(index)


@login_required
def unfollow(req, hunch_id):
hunch = get_object_or_404(models.Hunch, pk=hunch_id)
hunch_user = get_object_or_404(models.HunchUser, hunch=hunch, user_profile=req.user.get_profile()).delete()
hunch.userprofile_set.remove(req.user.get_profile())
return redirect(index)


Expand Down

0 comments on commit feca9b0

Please sign in to comment.