def ajax_checkout(request): project = get_obj_from_request(request.POST, 'project', Project) if project is None: return json_failure(design.bad_project_id) # make sure user can work on this band if not project.band.permission_to_work(request.user): return json_failure(design.you_dont_have_permission_to_work_on_this_band) if project.band.is_read_only(): return json_failure(design.band_in_readonly_mode) # make sure project is available if project.checked_out_to is not None: return json_failure(design.this_project_already_checked_out) project.checked_out_to = request.user project.date_checked_out = datetime.now() project.save() # create log entry entry = LogEntry() entry.entry_type = LogEntry.SONG_CHECKED_OUT entry.band = project.band entry.project = project entry.catalyst = request.user entry.save() return json_success()
def ajax_checkout(request): project = get_obj_from_request(request.POST, 'project', Project) if project is None: return json_failure(design.bad_project_id) # make sure user can work on this band if not project.band.permission_to_work(request.user): return json_failure( design.you_dont_have_permission_to_work_on_this_band) if project.band.is_read_only(): return json_failure(design.band_in_readonly_mode) # make sure project is available if project.checked_out_to is not None: return json_failure(design.this_project_already_checked_out) project.checked_out_to = request.user project.date_checked_out = datetime.now() project.save() # create log entry entry = LogEntry() entry.entry_type = LogEntry.SONG_CHECKED_OUT entry.band = project.band entry.project = project entry.catalyst = request.user entry.save() return json_success()
def account_plan(request): """The page that shows the user what plan they're on and wants them to click to the upgrade plans page.""" user = request.user profile = user.get_profile() err_msg = "" if request.method == 'POST': changes = [] space_total = 0 for key, val in request.POST.iteritems(): # format: member-X-amt=Y # X = member id, Y = amount donated member_str, member_id, amt_str = key.split('-') if member_str == 'member' and amt_str == 'amt': try: member_id = int(member_id) member = BandMember.objects.get(pk=member_id) except ValueError, BandMember.DoesNotExist: err_msg = design.bad_band_member_id break # make sure the user is the band member if member.user != user: err_msg = design.can_only_edit_your_own_amount_donated break try: val = int(val) except ValueError: err_msg = design.invalid_amount break changes.append((member, val,)) space_total += val if err_msg == "": if space_total <= profile.purchased_bytes: # everything is good. apply the change. # also create log entries for affected bands for member, new_space in changes: old_space = member.space_donated if old_space != new_space: # save new space into member member.space_donated = new_space member.save() # add or take away space from the band band = member.band band.total_space += new_space - old_space band.save() # make log entry entry = LogEntry() entry.entry_type = LogEntry.SPACE_ALLOCATED_CHANGE entry.band = member.band entry.catalyst = user entry.old_amount = old_space entry.new_amount = new_space entry.save() return HttpResponseRedirect(reverse('account.plan')) else: err_msg = design.you_dont_have_enough_space_to_do_that
def ajax_checkin(request): project = get_obj_from_request(request.POST, 'project', Project) if project is None: return json_failure(design.bad_project_id) # make sure project is checked out to request user if project.checked_out_to is None or project.checked_out_to.id != request.user.id: return json_failure(design.not_checked_out_to_you) if project.band.is_read_only(): return json_failure(design.band_in_readonly_mode) project_file = request.FILES.get('project_file') mp3_preview = request.FILES.get('mp3_preview') comments = request.POST.get('comments', '') if project_file is None and mp3_preview is None: # just check in project.checked_out_to = None project.save() # create log entry entry = LogEntry() entry.entry_type = LogEntry.SONG_JUST_CHECK_IN entry.band = project.band entry.catalyst = request.user entry.project = project entry.save() return json_success() # must supply a project file if project_file is None: return json_failure(design.must_submit_project_file) new_version_number = project.latest_version.version + 1 filename_appendix = "_" + str(new_version_number) # upload the song and make a new project version result = upload_song(request.user, file_mp3_handle=mp3_preview, file_source_handle=project_file, band=project.band, song_title=project.title, song_comments=comments, filename_appendix=filename_appendix) if not result['success']: return json_failure(result['reason']) song = result['song'] song.save() # make a new version version = ProjectVersion() version.project = project version.song = song version.version = new_version_number version.saveNewVersion() # update project info project.checked_out_to = None project.latest_version = version project.title = song.title project.save() return json_success()
def createNewBandMemberLogEntry(member): entry = LogEntry() entry.entry_type = LogEntry.BAND_MEMBER_JOIN entry.band = member.band entry.catalyst = member.user entry.save()
def account_plan(request): """The page that shows the user what plan they're on and wants them to click to the upgrade plans page.""" user = request.user profile = user.get_profile() err_msg = "" if request.method == 'POST': changes = [] space_total = 0 for key, val in request.POST.iteritems(): # format: member-X-amt=Y # X = member id, Y = amount donated member_str, member_id, amt_str = key.split('-') if member_str == 'member' and amt_str == 'amt': try: member_id = int(member_id) member = BandMember.objects.get(pk=member_id) except ValueError, BandMember.DoesNotExist: err_msg = design.bad_band_member_id break # make sure the user is the band member if member.user != user: err_msg = design.can_only_edit_your_own_amount_donated break try: val = int(val) except ValueError: err_msg = design.invalid_amount break changes.append(( member, val, )) space_total += val if err_msg == "": if space_total <= profile.purchased_bytes: # everything is good. apply the change. # also create log entries for affected bands for member, new_space in changes: old_space = member.space_donated if old_space != new_space: # save new space into member member.space_donated = new_space member.save() # add or take away space from the band band = member.band band.total_space += new_space - old_space band.save() # make log entry entry = LogEntry() entry.entry_type = LogEntry.SPACE_ALLOCATED_CHANGE entry.band = member.band entry.catalyst = user entry.old_amount = old_space entry.new_amount = new_space entry.save() return HttpResponseRedirect(reverse('account.plan')) else: err_msg = design.you_dont_have_enough_space_to_do_that