예제 #1
0
def create_project(request, band_id_str):
    band = get_object_or_404(Band, id=int(band_id_str))
    err_msg = ''

    permission = band.permission_to_work(request.user)
    if not permission:
        err_msg = design.only_band_members_can_create_projects

    if request.method == 'POST':
        form = NewProjectForm(request.POST, request.FILES)
        if form.is_valid() and permission:
            mp3_file = request.FILES.get('file_mp3')
            source_file = request.FILES.get('file_source')

            # upload the song
            result = upload_song(request.user,
                file_mp3_handle=mp3_file,
                file_source_handle=source_file, 
                band=band,
                song_title=form.cleaned_data.get('title'),
                song_comments=form.cleaned_data.get('comments', ''),
                filename_appendix="_1")
            if not result['success']:
                err_msg = result['reason']
            else:
                # fill in the rest of the fields
                song = result['song']
                song.save()

                # create the project
                project = Project()
                project.band = band
                project.save()

                # create the first version
                version = ProjectVersion()
                version.project = project
                version.song = song
                version.version = 1
                version.saveNewVersion()

                # subscribe the creator
                project.subscribers.add(request.user)
                project.save()

                # email band members saying that a new project is posted.
                for member in BandMember.objects.filter(band=band).exclude(user=request.user):
                    if member.user.get_profile().email_notifications:
                        context = Context({
                            'project': project,
                            'version': version,
                            'member': member,
                            'host': request.get_host(),
                        })
                        message_txt = get_template('workbench/email/new_project.txt').render(context)
                        message_html = get_template('workbench/email/new_project.html').render(context)
                        subject = design.x_uploaded_new_project_to_y.format(version.owner.username, band.title)
                        send_html_mail(subject, message_txt, message_html, [member.user.email])

                return HttpResponseRedirect(reverse("workbench.project", args=[band.id, project.id]))
    else:
        form = NewProjectForm()
    return render_to_response('workbench/band/new_project.html', {
            'form': form,
            'err_msg': err_msg,
            'band': band,
            'permission': permission,
        }, context_instance=RequestContext(request))
예제 #2
0
def ajax_submit_entry(request):
    compo = get_obj_from_request(request.POST, 'compo', Competition)
    if compo is None:
        return json_failure(design.competition_not_found)

    # make sure it's still submission time
    now = datetime.now()
    if now >= compo.submit_deadline:
        return json_failure(design.past_submission_deadline)

    if now <= compo.start_date:
        return json_failure(design.competition_not_started)

    title = request.POST.get('entry-title','')
    comments = request.POST.get('entry-comments', '')
    mp3_file = request.FILES.get('entry-file-mp3')
    source_file = request.FILES.get('entry-file-source')
    is_open_source = request.POST.get('entry-open-source', False)

    entries = Entry.objects.filter(owner=request.user, competition=compo)
    resubmitting = entries.count() > 0

    # make sure files are small enough
    if not resubmitting and mp3_file is None:
        return json_failure(design.mp3_required)

    if mp3_file is not None and mp3_file.size > settings.FILE_UPLOAD_SIZE_CAP:
        return json_failure(design.mp3_too_big)

    if source_file is not None:
        if source_file.size > settings.FILE_UPLOAD_SIZE_CAP:
            return json_failure(design.source_file_too_big)

    if title == '':
        return json_failure(design.entry_title_required)

    if mp3_file is not None:
        band = request.user.get_profile().solo_band

        if resubmitting:
            entry = entries[0]
            project = Project.objects.get(latest_version__song=entry.song)
            new_version_number = project.latest_version.version + 1
            filename_appendix = "_" + str(new_version_number)
        else:
            filename_appendix = ""

        result = upload_song(request.user,
            file_mp3_handle=mp3_file,
            file_source_handle=source_file, 
            max_song_len=settings.COMPO_ENTRY_MAX_LEN,
            band=band,
            song_title=title,
            song_album=compo.title,
            song_comments=comments,
            filename_appendix=filename_appendix)

        if not result['success']:
            return json_failure(result['reason'])

        song = result['song']
        song.is_open_source = is_open_source
        song.is_open_for_comments = True
        song.save()

        # make a new version and attach that to the entry
        if resubmitting:

            # create new version
            version = ProjectVersion()
            version.project = project
            version.song = song
            version.version = new_version_number
            version.saveNewVersion()

            old_length = entry.song.length
            buffer_time = 0
        else:
            # create the project
            project = Project()
            project.band = band
            project.save()

            # create the first version
            version = ProjectVersion()
            version.project = project
            version.song = song
            version.version = 1
            version.saveNewVersion()

            # subscribe the creator
            project.subscribers.add(request.user)
            project.save()

            # create new entry
            entry = Entry()
            entry.competition = compo
            entry.owner = request.user

            old_length = 0
            buffer_time = settings.LISTENING_PARTY_BUFFER_TIME

        entry.song = song
        entry.save()

        # update competition dates based on this newfound length 
        vote_period_delta = timedelta(seconds=compo.vote_period_length)
        if compo.have_listening_party:
            compo.listening_party_end_date += timedelta(seconds=(song.length-old_length+buffer_time))
            compo.vote_deadline = compo.listening_party_end_date + vote_period_delta
        else:
            compo.vote_deadline = compo.submit_deadline + vote_period_delta
        compo.save()

        chatroom = compo.chat_room
        chatroom.end_date = compo.listening_party_end_date + timedelta(hours=1)
        chatroom.save()
    else:
        # only providing source and possibly renaming.
        entry = entries[0]
        song = entry.song

        if source_file is not None:
            handle_project_upload(source_file, request.user, song)

        song.title = title
        song.is_open_source = is_open_source
        song.comments = comments
        song.save()

    return json_response({'success': True})
예제 #3
0
def ajax_submit_entry(request):
    compo = get_obj_from_request(request.POST, 'compo', Competition)
    if compo is None:
        return json_failure(design.competition_not_found)

    # make sure it's still submission time
    now = datetime.now()
    if now >= compo.submit_deadline:
        return json_failure(design.past_submission_deadline)

    if now <= compo.start_date:
        return json_failure(design.competition_not_started)

    title = request.POST.get('entry-title', '')
    comments = request.POST.get('entry-comments', '')
    mp3_file = request.FILES.get('entry-file-mp3')
    source_file = request.FILES.get('entry-file-source')
    is_open_source = request.POST.get('entry-open-source', False)

    entries = Entry.objects.filter(owner=request.user, competition=compo)
    resubmitting = entries.count() > 0

    # make sure files are small enough
    if not resubmitting and mp3_file is None:
        return json_failure(design.mp3_required)

    if mp3_file is not None and mp3_file.size > settings.FILE_UPLOAD_SIZE_CAP:
        return json_failure(design.mp3_too_big)

    if source_file is not None:
        if source_file.size > settings.FILE_UPLOAD_SIZE_CAP:
            return json_failure(design.source_file_too_big)

    if title == '':
        return json_failure(design.entry_title_required)

    if mp3_file is not None:
        band = request.user.get_profile().solo_band

        if resubmitting:
            entry = entries[0]
            project = Project.objects.get(latest_version__song=entry.song)
            new_version_number = project.latest_version.version + 1
            filename_appendix = "_" + str(new_version_number)
        else:
            filename_appendix = ""

        result = upload_song(request.user,
                             file_mp3_handle=mp3_file,
                             file_source_handle=source_file,
                             max_song_len=settings.COMPO_ENTRY_MAX_LEN,
                             band=band,
                             song_title=title,
                             song_album=compo.title,
                             song_comments=comments,
                             filename_appendix=filename_appendix)

        if not result['success']:
            return json_failure(result['reason'])

        song = result['song']
        song.is_open_source = is_open_source
        song.is_open_for_comments = True
        song.save()

        # make a new version and attach that to the entry
        if resubmitting:

            # create new version
            version = ProjectVersion()
            version.project = project
            version.song = song
            version.version = new_version_number
            version.saveNewVersion()

            old_length = entry.song.length
            buffer_time = 0
        else:
            # create the project
            project = Project()
            project.band = band
            project.save()

            # create the first version
            version = ProjectVersion()
            version.project = project
            version.song = song
            version.version = 1
            version.saveNewVersion()

            # subscribe the creator
            project.subscribers.add(request.user)
            project.save()

            # create new entry
            entry = Entry()
            entry.competition = compo
            entry.owner = request.user

            old_length = 0
            buffer_time = settings.LISTENING_PARTY_BUFFER_TIME

        entry.song = song
        entry.save()

        # update competition dates based on this newfound length
        vote_period_delta = timedelta(seconds=compo.vote_period_length)
        if compo.have_listening_party:
            compo.listening_party_end_date += timedelta(
                seconds=(song.length - old_length + buffer_time))
            compo.vote_deadline = compo.listening_party_end_date + vote_period_delta
        else:
            compo.vote_deadline = compo.submit_deadline + vote_period_delta
        compo.save()

        chatroom = compo.chat_room
        chatroom.end_date = compo.listening_party_end_date + timedelta(hours=1)
        chatroom.save()
    else:
        # only providing source and possibly renaming.
        entry = entries[0]
        song = entry.song

        if source_file is not None:
            handle_project_upload(source_file, request.user, song)

        song.title = title
        song.is_open_source = is_open_source
        song.comments = comments
        song.save()

    return json_response({'success': True})
예제 #4
0
def create_project(request, band_id_str):
    band = get_object_or_404(Band, id=int(band_id_str))
    err_msg = ''

    permission = band.permission_to_work(request.user)
    if not permission:
        err_msg = design.only_band_members_can_create_projects

    if request.method == 'POST':
        form = NewProjectForm(request.POST, request.FILES)
        if form.is_valid() and permission:
            mp3_file = request.FILES.get('file_mp3')
            source_file = request.FILES.get('file_source')

            # upload the song
            result = upload_song(request.user,
                                 file_mp3_handle=mp3_file,
                                 file_source_handle=source_file,
                                 band=band,
                                 song_title=form.cleaned_data.get('title'),
                                 song_comments=form.cleaned_data.get(
                                     'comments', ''),
                                 filename_appendix="_1")
            if not result['success']:
                err_msg = result['reason']
            else:
                # fill in the rest of the fields
                song = result['song']
                song.save()

                # create the project
                project = Project()
                project.band = band
                project.save()

                # create the first version
                version = ProjectVersion()
                version.project = project
                version.song = song
                version.version = 1
                version.saveNewVersion()

                # subscribe the creator
                project.subscribers.add(request.user)
                project.save()

                # email band members saying that a new project is posted.
                for member in BandMember.objects.filter(band=band).exclude(
                        user=request.user):
                    if member.user.get_profile().email_notifications:
                        context = Context({
                            'project': project,
                            'version': version,
                            'member': member,
                            'host': request.get_host(),
                        })
                        message_txt = get_template(
                            'workbench/email/new_project.txt').render(context)
                        message_html = get_template(
                            'workbench/email/new_project.html').render(context)
                        subject = design.x_uploaded_new_project_to_y.format(
                            version.owner.username, band.title)
                        send_html_mail(subject, message_txt, message_html,
                                       [member.user.email])

                return HttpResponseRedirect(
                    reverse("workbench.project", args=[band.id, project.id]))
    else:
        form = NewProjectForm()
    return render_to_response('workbench/band/new_project.html', {
        'form': form,
        'err_msg': err_msg,
        'band': band,
        'permission': permission,
    },
                              context_instance=RequestContext(request))