Esempio n. 1
0
def _event_process(request, form, event):
    """Generate and clean associated event data for an event request
       or event edit:  timezone application, approvals update and
       notifications, creator and modifier."""
    if not event.creator:
        event.creator = request.user
    event.modified_user = request.user

    if event.location:
        tz = pytz.timezone(event.location.timezone)
        event.start_time = tz_apply(event.start_time, tz)

    if 'approvals' in form.cleaned_data:
        event.save()
        approvals_old = [app.group for app in event.approval_set.all()]
        approvals_new = form.cleaned_data['approvals']
        approvals_add = set(approvals_new).difference(approvals_old)
        for approval in approvals_add:
            group = Group.objects.get(name=approval)
            app = Approval.objects.create(group=group, event=event)
            sending.email_about_approval_requested(
                event,
                group,
                request
            )
        # Note! we currently do not allow approvals
        # to be "un-requested". That's because the email has already
        # gone out and it's too late now.

        if 'curated_groups' in form.cleaned_data:
            # because this form field acts like "tags",
            # we split them by ,
            names = [
                x.strip() for x in
                form.cleaned_data['curated_groups'].split(',')
                if x.strip()
            ]
            if names:
                all = mozillians.get_all_groups_cached()
            for name in names:
                group, __ = CuratedGroup.objects.get_or_create(
                    event=event,
                    name=name
                )
                found = [x for x in all if x['name'] == name]
                if found and found[0]['url'] != group.url:
                    group.url = found[0]['url']
                    group.save()

            # delete any we had before that aren't submitted any more
            (
                CuratedGroup.objects
                .filter(event=event)
                .exclude(name__in=names)
                .delete()
            )
Esempio n. 2
0
    def test_get_all_groups_cached(self, rget, rlogging):
        cache.clear()
        calls = []

        def mocked_get(url, **options):
            calls.append(url)
            if 'offset=0' in url:
                return Response(GROUPS1)
            if 'offset=500' in url:
                return Response(GROUPS2)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        all = mozillians.get_all_groups_cached()
        eq_(len(all), 750)
        eq_(len(calls), 2)

        # a second time
        all = mozillians.get_all_groups_cached()
        eq_(len(all), 750)
        eq_(len(calls), 2)
Esempio n. 3
0
    def test_get_all_groups_cached(self, rget):
        cache.clear()
        calls = []

        def mocked_get(url, **options):
            calls.append(url)
            if '/v2/groups/' in url and 'page=2' in url:
                return Response(GROUPS2)
            if '/v2/groups/' in url:
                return Response(GROUPS1)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        all = mozillians.get_all_groups_cached()
        eq_(len(all), 3)
        eq_(len(calls), 2)

        # a second time
        all = mozillians.get_all_groups_cached()
        eq_(len(all), 3)
        eq_(len(calls), 2)
Esempio n. 4
0
    def test_get_all_groups_cached(self, rget):
        cache.clear()
        calls = []

        def mocked_get(url, **options):
            calls.append(url)
            if '/v2/groups/' in url and 'page=2' in url:
                return Response(GROUPS2)
            if '/v2/groups/' in url:
                return Response(GROUPS1)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        all = mozillians.get_all_groups_cached()
        eq_(len(all), 3)
        eq_(len(calls), 2)

        # a second time
        all = mozillians.get_all_groups_cached()
        eq_(len(all), 3)
        eq_(len(calls), 2)
Esempio n. 5
0
    def test_get_all_groups_cached(self, rget, rlogging):
        cache.clear()
        calls = []

        def mocked_get(url, **options):
            calls.append(url)
            if 'offset=0' in url:
                return Response(GROUPS1)
            if 'offset=500' in url:
                return Response(GROUPS2)
            raise NotImplementedError(url)

        rget.side_effect = mocked_get

        all = mozillians.get_all_groups_cached()
        eq_(len(all), 750)
        eq_(len(calls), 2)

        # a second time
        all = mozillians.get_all_groups_cached()
        eq_(len(all), 750)
        eq_(len(calls), 2)
Esempio n. 6
0
def curated_groups_autocomplete(request):
    q = request.GET.get('q', '').strip()
    if not q:
        return {'groups': []}

    all = mozillians.get_all_groups_cached()

    def describe_group(group):
        if group['number_of_members'] == 1:
            return '%s (1 member)' % (group['name'], )
        else:
            return ('%s (%s members)' %
                    (group['name'], group['number_of_members']))

    groups = [(x['name'], describe_group(x)) for x in all
              if q.lower() in x['name'].lower()]
    return {'groups': groups}
Esempio n. 7
0
def curated_groups_autocomplete(request):
    q = request.GET.get('q', '').strip()
    if not q:
        return {'groups': []}

    all = mozillians.get_all_groups_cached()

    def describe_group(group):
        if group['number_of_members'] == 1:
            return '%s (1 member)' % (group['name'],)
        else:
            return (
                '%s (%s members)' % (group['name'], group['number_of_members'])
            )

    groups = [
        (x['name'], describe_group(x))
        for x in all
        if q.lower() in x['name'].lower()
    ]
    return {'groups': groups}
Esempio n. 8
0
def curated_groups_autocomplete(request):
    q = request.GET.get('q', '').strip()
    if not q:
        return {'groups': []}

    all = mozillians.get_all_groups_cached()

    def describe_group(group):
        if group['member_count'] == 1:
            return '%s (1 member)' % (group['name'],)
        else:
            return (
                '%s (%s members)' % (group['name'], group['member_count'])
            )

    groups = [
        (x['name'], describe_group(x))
        for x in all
        if q.lower() in x['name'].lower()
    ]
    # naively sort by how good the match is
    groups.sort(key=lambda x: x[0].lower().find(q.lower()))
    return {'groups': groups}