How to use the tavern.models.TavernGroup 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 / views.py View on Github external
def index(request, template='tavern/home.html'):
    """ index page """
    all_groups = TavernGroup.objects.all()
    if request.user.is_authenticated():
        joined_groups = request.user.tavern_groups.all()
        unjoined_groups = list(set(all_groups) - set(joined_groups))
        upcoming_events = Event.visible_events.upcoming()
        events_rsvped = request.user.events_attending.all()

        context = {'joined_groups': joined_groups,
                   'unjoined_groups': unjoined_groups,
                   'upcoming_events': upcoming_events,
                   'events_rsvped': events_rsvped}
    else:
        context = {'groups': all_groups}
    return render(request, template, context)
github agiliq / opentavern / tavern / forms.py View on Github external
def clean(self):
        cleaned_data = super(RemoveOrganizerForm, self).clean()
        users = cleaned_data.get('users')
        group = TavernGroup.objects.get(pk=cleaned_data['group'])
        for user in users:
            try:
                group.organizers.get(username=user.username)
            except User.DoesNotExist:
                raise forms.ValidationError("%s is not an organizer of %s group" % (user.username, group.name))
        return cleaned_data
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 / signals.py View on Github external
for user in instance.organizers.all():
        remove_perm('change_taverngroup', user, instance)


def delete_event_permissions(sender, instance, **kwargs):
    remove_perm('change_event', instance.creator, instance)
    remove_perm('delete_event', instance.creator, instance)
    remove_perm('change_event', instance.group.creator, instance)
    remove_perm('delete_event', instance.group.creator, instance)


post_save.connect(create_event_permission, sender=Event)
post_save.connect(create_group_permission, sender=TavernGroup)
pre_save.connect(group_pre_save, sender=TavernGroup)
m2m_changed.connect(create_group_permission_for_organizers, sender=TavernGroup.organizers.through)
pre_delete.connect(delete_group_permissions, sender=TavernGroup)
pre_delete.connect(delete_event_permissions, sender=Event)
github agiliq / opentavern / tavern / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(EventDetail, self).get_context_data(**kwargs)
        event_name = self.kwargs['slug']
        group_name = self.kwargs['group']
        group = TavernGroup.objects.get(slug=group_name)
        event = group.event_set.get(slug=event_name)
        try:
            attendee = Attendee.objects.get(user_id=self.request.user.id,
                                            event=event)
            message = attendee.get_rsvp()
            context['attendee'] = attendee
        except Attendee.DoesNotExist:
            if timezone.now() <= event.ends_at:
                message = "You have not rsvped"
            else:
                message = "You did not rsvp"
        context['attendee_rsvp'] = message

        context['event_attendees'] = Attendee.objects.filter(event=event,
                                                             rsvp_status="yes")
        context['editable'] = event.starts_at > 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)
github agiliq / opentavern / tavern / views.py View on Github external
def index(request, template='tavern/home.html'):
    """ index page """
    all_groups = TavernGroup.objects.all()
    if request.user.is_authenticated():
        joined_groups = request.user.tavern_groups.all()
        unjoined_groups = list(set(all_groups) - set(joined_groups))
        upcoming_events = Event.visible_events.upcoming()
        events = Attendee.objects.filter(user=request.user)
        events_rsvped = [event.event for event in events]

        context = {'joined_groups': joined_groups,
                   'unjoined_groups': unjoined_groups,
                   'upcoming_events': upcoming_events,
                   'events_rsvped': events_rsvped}
    else:
        context = {'groups': all_groups}
    return render(request, template, 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 / models.py View on Github external
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()})

    def __unicode__(self):
        return "%s" % self.name


class Membership(models.Model):
    "People who are in a TavernGroup"
    user = models.ForeignKey(User,
                             related_name='tgroup_memberships')
    tavern_group = models.ForeignKey(TavernGroup,
                                     related_name='memberships')
    join_date = models.DateTimeField()

    class Meta:
        unique_together = ['user', 'tavern_group']

    def get_name(self):
        return self.user.get_full_name() or self.user.username

    def __unicode__(self):
        return "%s - %s" % (self.user.username, self.tavern_group.name)


class EventShowManager(models.Manager):

    def get_queryset(self):