def ajax_provide_project(request): version = get_obj_from_request(request.POST, 'version', ProjectVersion) if version is None: return json_failure(design.bad_version_id) band = version.project.band if not band.permission_to_work(request.user): return json_failure(design.you_dont_have_permission_to_work_on_this_band) if band.is_read_only(): return json_failure(design.band_in_readonly_mode) project_handle = request.FILES.get('file') handle_project_upload(project_handle, request.user, version.song) return json_success()
def ajax_provide_project(request): version = get_obj_from_request(request.POST, 'version', ProjectVersion) if version is None: return json_failure(design.bad_version_id) band = version.project.band if not band.permission_to_work(request.user): return json_failure( design.you_dont_have_permission_to_work_on_this_band) if band.is_read_only(): return json_failure(design.band_in_readonly_mode) project_handle = request.FILES.get('file') handle_project_upload(project_handle, request.user, version.song) return json_success()
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})
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})