Example #1
0
def devderby_landing(request):
    """Dev Derby landing page"""

    sort_order = request.GET.get('sort', 'created')

    # Grab current arrangement of challenges from Constance settings
    current_challenge_tag_name = str(
            constance.config.DEMOS_DEVDERBY_CURRENT_CHALLENGE_TAG).strip()
    previous_winner_tag_name = str(
            constance.config.DEMOS_DEVDERBY_PREVIOUS_WINNER_TAG).strip()
    previous_challenge_tag_names = parse_tags(
            constance.config.DEMOS_DEVDERBY_PREVIOUS_CHALLENGE_TAGS,
            sorted=False)
    challenge_choices = parse_tags(
            constance.config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS,
            sorted=False)

    submissions_qs = (Submission.objects.all_sorted(sort_order)
        .filter(taggit_tags__name__in=[current_challenge_tag_name])
        .exclude(hidden=True))

    previous_winner_qs = (Submission.objects.all()
        .filter(taggit_tags__name__in=[previous_winner_tag_name])
        .exclude(hidden=True))

    # TODO: Use an object_list here, in case we need pagination?
    return render(request, 'demos/devderby_landing.html', dict(
        current_challenge_tag_name=current_challenge_tag_name,
        previous_winner_tag_name=previous_winner_tag_name,
        previous_challenge_tag_names=previous_challenge_tag_names,
        submissions_qs=submissions_qs,
        previous_winner_qs=previous_winner_qs,
        challenge_choices=challenge_choices,
    ))
Example #2
0
File: views.py Project: Osmose/kuma
def devderby_landing(request):
    """Dev Derby landing page"""

    sort_order = request.GET.get('sort', 'created')

    # Grab current arrangement of challenges from Constance settings
    current_challenge_tag_name = str(
        config.DEMOS_DEVDERBY_CURRENT_CHALLENGE_TAG).strip()
    previous_winner_tag_name = str(
        config.DEMOS_DEVDERBY_PREVIOUS_WINNER_TAG).strip()
    previous_challenge_tag_names = parse_tags(
        config.DEMOS_DEVDERBY_PREVIOUS_CHALLENGE_TAGS,
        sorted=False)
    challenge_choices = parse_tags(
        config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS,
        sorted=False)

    submissions_qs = (Submission.objects.all_sorted(sort_order)
                                .filter(taggit_tags__name__in=[current_challenge_tag_name])
                                .exclude(hidden=True))

    previous_winner_qs = (Submission.objects.all()
                                    .filter(taggit_tags__name__in=[previous_winner_tag_name])
                                    .exclude(hidden=True))

    # TODO: Use an object_list here, in case we need pagination?
    return render(request, 'demos/devderby_landing.html', dict(
        current_challenge_tag_name=current_challenge_tag_name,
        previous_winner_tag_name=previous_winner_tag_name,
        previous_challenge_tag_names=previous_challenge_tag_names,
        submissions_qs=submissions_qs,
        previous_winner_qs=previous_winner_qs,
        challenge_choices=challenge_choices,
    ))
Example #3
0
File: views.py Project: Osmose/kuma
def submit(request):
    """Accept submission of a demo"""
    if not request.user.is_authenticated():
        return render(request, 'demos/submit_noauth.html')

    if request.method != "POST":
        initial = {}
        if 'tags' in request.GET:
            initial['challenge_tags'] = parse_tags(request.GET['tags'])
        form = SubmissionNewForm(initial=initial, request_user=request.user)
    else:
        form = SubmissionNewForm(
            request.POST, request.FILES, request_user=request.user)
        if form.is_valid():
            new_sub = form.save(commit=False)
            new_sub.creator = request.user
            new_sub.save()
            form.save_m2m()

            # TODO: Process in a cronjob?
            new_sub.process_demo_package()
            _invalidate_submission_listing_helper_cache()

            return redirect(new_sub)

    return render(request, 'demos/submit.html', {'form': form})
Example #4
0
def submit(request):
    """Accept submission of a demo"""
    if not request.user.is_authenticated():
        return render(request, 'demos/submit_noauth.html')

    if request.method != "POST":
        initial = {}
        if 'tags' in request.GET:
            initial['challenge_tags'] = parse_tags(request.GET['tags'])
        form = SubmissionNewForm(initial=initial, request_user=request.user)
    else:
        form = SubmissionNewForm(
            request.POST, request.FILES, request_user=request.user)
        if form.is_valid():
            new_sub = form.save(commit=False)
            new_sub.creator = request.user
            new_sub.save()
            form.save_m2m()

            # TODO: Process in a cronjob?
            new_sub.process_demo_package()
            _invalidate_submission_listing_helper_cache()

            return HttpResponseRedirect(reverse(
                    'kuma.demos.views.detail', args=(new_sub.slug,)))

    return render(request, 'demos/submit.html', {'form': form})
Example #5
0
 def test_edit_with_challenge_tag(self):
     s = save_valid_submission('hello world')
     edit_url = reverse('demos_edit', args=[s.slug])
     r = self.client.post(edit_url, data=dict(
         title=s.title,
         summary='This is a test edit',
         description='Some description goes here',
         tech_tags=('tech:audio',),
         challenge_tags=parse_tags(
             constance.config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS)[0],
         license_name='gpl',
         accept_terms='1',
     ))
     eq_(r.status_code, 302)
     r = self.client.get(edit_url)
     eq_(r.status_code, 200)
Example #6
0
 def test_edit_with_challenge_tag(self):
     s = save_valid_submission('hello world')
     edit_url = reverse('demos_edit', args=[s.slug])
     r = self.client.post(edit_url, data=dict(
         title=s.title,
         summary='This is a test edit',
         description='Some description goes here',
         tech_tags=('tech:audio',),
         challenge_tags=parse_tags(
             constance.config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS)[0],
         license_name='gpl',
         accept_terms='1',
     ))
     eq_(r.status_code, 302)
     r = self.client.get(edit_url)
     eq_(r.status_code, 200)
Example #7
0
File: forms.py Project: samucc/kuma
    def __init__(self, *args, **kwargs):

        # Set the request user, for tag namespace permissions
        self.request_user = kwargs.pop('request_user', AnonymousUser)

        # Hit up the super class for init
        super(SubmissionEditForm, self).__init__(*args, **kwargs)

        self.fields['challenge_tags'].choices = (
            (TAG_DESCRIPTIONS[x]['tag_name'], TAG_DESCRIPTIONS[x]['title'])
            for x in parse_tags(
                'challenge:none %s' %
                constance.config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS,
                sorted=False) if x in TAG_DESCRIPTIONS)

        # If this is being used to edit a submission, we need to do
        # the following:
        #
        # 1. Populate the tech tags.
        #
        # 2. If the deadline has passed for the challenge this is
        #    entered in, remove the 'demo_package' field since they
        #    can't upload a new package past the deadline.
        #
        # 3. If the deadline has passed, remove the field for choosing
        #    which derby they're entered in. Otherwise, populate it so
        #    they can choose to change it.
        #
        # 4. Make sure we stash away the existing challenge tags, and
        #    ensure they're preserved across the edit.
        instance = kwargs.get('instance', None)
        if instance:
            if instance.is_derby_submission():
                if instance.challenge_closed():
                    for fieldname in ('demo_package', 'challenge_tags'):
                        del self.fields[fieldname]
                    self._old_challenge_tags = [
                        unicode(tag)
                        for tag in instance.taggit_tags.all_ns('challenge:')
                    ]
            for ns in ('tech', 'challenge'):
                if '%s_tags' % ns in self.fields:
                    self.initial['%s_tags' % ns] = [
                        t.name for t in instance.taggit_tags.all_ns('%s:' % ns)
                    ]
Example #8
0
File: forms.py Project: Osmose/kuma
    def __init__(self, *args, **kwargs):

        # Set the request user, for tag namespace permissions
        self.request_user = kwargs.pop('request_user', AnonymousUser)

        # Hit up the super class for init
        super(SubmissionEditForm, self).__init__(*args, **kwargs)

        self.fields['challenge_tags'].choices = (
            (TAG_DESCRIPTIONS[x]['tag_name'], TAG_DESCRIPTIONS[x]['title'])
            for x in parse_tags(
                'challenge:none %s' %
                config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS,
                sorted=False)
            if x in TAG_DESCRIPTIONS
        )

        # If this is being used to edit a submission, we need to do
        # the following:
        #
        # 1. Populate the tech tags.
        #
        # 2. If the deadline has passed for the challenge this is
        #    entered in, remove the 'demo_package' field since they
        #    can't upload a new package past the deadline.
        #
        # 3. If the deadline has passed, remove the field for choosing
        #    which derby they're entered in. Otherwise, populate it so
        #    they can choose to change it.
        #
        # 4. Make sure we stash away the existing challenge tags, and
        #    ensure they're preserved across the edit.
        instance = kwargs.get('instance', None)
        if instance:
            if instance.is_derby_submission():
                if instance.challenge_closed():
                    for fieldname in ('demo_package', 'challenge_tags'):
                        del self.fields[fieldname]
                    self._old_challenge_tags = [unicode(tag) for tag in instance.taggit_tags.all_ns('challenge:')]
            for ns in ('tech', 'challenge'):
                if '%s_tags' % ns in self.fields:
                    self.initial['%s_tags' % ns] = [
                        t.name
                        for t in instance.taggit_tags.all_ns('%s:' % ns)]