How to use the tavern.models.Membership function in tavern

To help you get started, we’ve selected a few tavern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agiliq / opentavern / tavern / tests.py View on Github external
def test_tavern_group_save(self):
        """When a TavernGroup is saved, we want to make sure
        an instance of Membership which associates the creator
        with group is created"""

        creator = create_and_get_user()
        tavern_group = create_and_get_tavern_group(creator=creator)
        self.assertEqual(TavernGroup.objects.count(), 1)
        self.assertEqual(Membership.objects.count(), 1)
        # Change an attribute of tavern_group
        tavern_group.description = 'Changed description'
        tavern_group.save()
        self.assertEqual(TavernGroup.objects.count(), 1)
        self.assertEqual(Membership.objects.count(), 1)

        member = Membership.objects.all()[0]
        self.assertEqual(member.__unicode__(), u'test - TestGroup')
github agiliq / opentavern / tavern / tests.py View on Github external
def test_tavern_group_save(self):
        """When a TavernGroup is saved, we want to make sure
        an instance of Membership which associates the creator
        with group is created"""

        creator = create_and_get_user()
        tavern_group = create_and_get_tavern_group(creator=creator)
        self.assertEqual(TavernGroup.objects.count(), 1)
        self.assertEqual(Membership.objects.count(), 1)
        # Change an attribute of tavern_group
        tavern_group.description = 'Changed description'
        tavern_group.save()
        self.assertEqual(TavernGroup.objects.count(), 1)
        self.assertEqual(Membership.objects.count(), 1)

        member = Membership.objects.all()[0]
        self.assertEqual(member.__unicode__(), u'test - TestGroup')
github agiliq / opentavern / tavern / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(GroupDetail, self).get_context_data(**kwargs)
        context['past_events'] = Event.visible_events.past()

        tavern_group = context['group']
        try:
            Membership.objects.get(tavern_group=tavern_group,
                                   user=self.request.user.id)
            user_is_member = True
        except Membership.DoesNotExist:
            user_is_member = False
        context['user_is_member'] = user_is_member

        recent_group_members = get_list_or_404(Membership, tavern_group=tavern_group)[:5]
        context["recent_group_members"] = recent_group_members

        return context
github agiliq / opentavern / tavern / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(GroupDetail, self).get_context_data(**kwargs)
        context['past_events'] = Event.visible_events.past()

        tavern_group = context['group']
        try:
            Membership.objects.get(tavern_group=tavern_group,
                                   user=self.request.user.id)
            user_is_member = True
        except Membership.DoesNotExist:
            user_is_member = False
        context['user_is_member'] = user_is_member

        recent_group_members = get_list_or_404(Membership, tavern_group=tavern_group)[:5]
        context["recent_group_members"] = recent_group_members

        return context
github agiliq / opentavern / tavern / views.py View on Github external
def tavern_toggle_member(request):
    """
    Adds a member to the group if he's not in the group, or
    deletes a member if he's already a member
    """

    user = get_object_or_404(User, id=request.POST.get('user_id'))
    group = get_object_or_404(TavernGroup, slug=request.POST.get('slug'))
    try:
        member = Membership.objects.get(user=user, tavern_group=group)
        response = "Join Group"
        member.delete()
    except Membership.DoesNotExist:
        member = Membership.objects.create(
            user=user,
            tavern_group=group,
            join_date=today_date())
        response = "Unjoin Group"
    return HttpResponse(response)
github agiliq / opentavern / tavern / forms.py View on Github external
def clean(self):
        cleaned_data = super(CreateEventForm, self).clean()
        group = cleaned_data.get('group')
        try:
            Membership.objects.get(user=self.user, tavern_group=group)
        except Membership.DoesNotExist:
            raise forms.ValidationError("You are not a member of this group")
        return cleaned_data
github agiliq / opentavern / tavern / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(GroupDetail, self).get_context_data(**kwargs)
        context['past_events'] = Event.visible_events.past()

        tavern_group = context['group']
        try:
            Membership.objects.get(tavern_group=tavern_group,
                                   user=self.request.user.id)
            user_is_member = True
        except Membership.DoesNotExist:
            user_is_member = False
        context['user_is_member'] = user_is_member

        recent_group_members = get_list_or_404(Membership, tavern_group=tavern_group)[:5]
        context["recent_group_members"] = recent_group_members

        return context
github agiliq / opentavern / tavern / models.py View on Github external
def save(self, *args, **kwargs):
        unique_slugify(self, self.name)
        super(TavernGroup, self).save(*args, **kwargs)
        Membership.objects.get_or_create(
            user=self.creator,
            tavern_group=self,
            defaults={'join_date': timezone.now()})
github agiliq / opentavern / tavern / models.py View on Github external
def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(TavernGroup, self).save(*args, **kwargs)
        Membership.objects.get_or_create(
            user=self.creator,
            tavern_group=self,
            defaults={'join_date': timezone.now()})
github agiliq / opentavern / tavern / views.py View on Github external
def tavern_toggle_member(request):
    """
    Adds a member to the group if he's not in the group, or
    deletes a member if he's already a member
    """

    user = get_object_or_404(User, id=request.POST.get('user_id'))
    group = get_object_or_404(TavernGroup, slug=request.POST.get('slug'))
    try:
        member = Membership.objects.get(user=user, tavern_group=group)
        response = "Join Group"
        member.delete()
    except Membership.DoesNotExist:
        member = Membership.objects.create(
            user=user,
            tavern_group=group,
            join_date=today_date())
        response = "Unjoin Group"
    return HttpResponse(response)