예제 #1
0
파일: views.py 프로젝트: Faldrian/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(
            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,
    ))
예제 #2
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,
        ))
예제 #3
0
파일: views.py 프로젝트: Faldrian/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 HttpResponseRedirect(reverse(
                    'kuma.demos.views.detail', args=(new_sub.slug,)))

    return render(request, 'demos/submit.html', {'form': form})
예제 #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('demos.views.detail', args=(new_sub.slug, )))

    return render(request, 'demos/submit.html', {'form': form})
예제 #5
0
파일: test_views.py 프로젝트: trinaldi/kuma
 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)
예제 #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)
예제 #7
0
    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)
                    ]
예제 #8
0
파일: forms.py 프로젝트: Arveti/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)]
예제 #9
0
파일: forms.py 프로젝트: tantek/kuma
class SubmissionEditForm(MyModelForm):
    """Form accepting demo submissions"""

    class Meta:
        model = Submission
        widgets = {
            'navbar_optout': forms.Select
        }
        fields = (
            'title', 'summary', 'description', 'hidden',
            'tech_tags', 'challenge_tags',
            'screenshot_1', 'screenshot_2', 'screenshot_3', 
            'screenshot_4', 'screenshot_5', 
            'video_url', 'navbar_optout',
            'demo_package', 'source_code_url', 'license_name',
        )

    # Assemble tech tag choices from TAG_DESCRIPTIONS
    tech_tags = forms.MultipleChoiceField(
        label = "Tech tags",
        widget = CheckboxSelectMultiple,
        required = False,
        choices = ( 
            (x['tag_name'], x['title']) 
            for x in TAG_DESCRIPTIONS.values() 
            if x['tag_name'].startswith('tech:')
        )
    )

    challenge_tags = forms.MultipleChoiceField(
        label = "Dev Derby Challenge tags",
        widget = CheckboxSelectMultiple,
        required = False,
        choices = (
            (TAG_DESCRIPTIONS[x]['tag_name'], TAG_DESCRIPTIONS[x]['title'])
            for x in parse_tags(
                constance.config.DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS, 
                sorted=False)
        )
    )

    def __init__(self, *args, **kwargs):

        # Set the request user, for tag namespace permissions
        self.request_user = kwargs.get('request_user', AnonymousUser)
        del kwargs['request_user']

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

        # Initialize form with namespaced tags.
        instance = kwargs.get('instance', None)
        if instance:
            for ns in ('tech', 'challenge'):
                self.initial['%s_tags' % ns] = [t.name 
                    for t in instance.taggit_tags.all_ns('%s:' % ns)]

    def clean(self):
        cleaned_data = super(SubmissionEditForm, self).clean()

        # If we have a demo_package, try validating it.
        if 'demo_package' in self.files:
            try:
                demo_package = self.files['demo_package']
                Submission.validate_demo_zipfile(demo_package)
            except ValidationError, e:
                self._errors['demo_package'] = self.error_class(e.messages)

        return cleaned_data
예제 #10
0
class SubmissionEditForm(MyModelForm):
    """Form accepting demo submissions"""
    class Meta:
        model = Submission
        widgets = {'navbar_optout': forms.Select}
        fields = (
            'title',
            'summary',
            'description',
            'hidden',
            'tech_tags',
            'challenge_tags',
            'screenshot_1',
            'screenshot_2',
            'screenshot_3',
            'screenshot_4',
            'screenshot_5',
            'video_url',
            'navbar_optout',
            'demo_package',
            'source_code_url',
            'license_name',
        )

    # Assemble tech tag choices from TAG_DESCRIPTIONS
    tech_tags = forms.MultipleChoiceField(
        label="Tech tags",
        widget=CheckboxSelectMultiple,
        required=False,
        choices=((x['tag_name'], x['title'])
                 for x in TAG_DESCRIPTIONS.values()
                 if x['tag_name'].startswith('tech:')))

    challenge_tags = forms.ChoiceField(
        label="Dev Derby Challenge tag",
        widget=RadioSelect,
        required=False,
        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))

    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)

        # 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)
                    ]

    def clean(self):
        cleaned_data = super(SubmissionEditForm, self).clean()

        # If we have a demo_package, try validating it.
        if 'demo_package' in self.files:
            try:
                demo_package = self.files['demo_package']
                Submission.validate_demo_zipfile(demo_package)
            except ValidationError, e:
                self._errors['demo_package'] = self.error_class(e.messages)

        return cleaned_data