def edit_band(request, band_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission edit this band cause you are not a member of it.") if request.method == 'POST': form = BandEditForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] bio = form.cleaned_data['bio'] url = form.cleaned_data['url'] band = bands_manager.update_band(band_id, name, bio, url) #get the updated band context['success'] = True else: # request.method == 'GET' data = {'name': band.name, 'bio': band.bio, 'url': band.url,} form = BandEditForm(data) context['form'] = form context['band'] = band except Exception as exc: # 404 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/edit.html', context, context_instance=RequestContext(request))
def add_setlist_batch(request, band_id): context = {} batch = request.POST["batch"] try: band = bands_manager.get_band(band_id) context["band"] = band if not band.is_member(request.user): raise Exception( "You have no permission to add songs to this band's setlist cause you are not a member of it." ) for line in batch.splitlines(): try: artist, title = line.split(" - ") except: raise BatchParseError(line) if artist is None or title is None: raise BatchParseError(line) try: bands_manager.add_setlist_song(band_id, artist, title) except SongAlreadyOnSetlistError: continue return redirect("/band/%s/setlist" % band_id) except BatchParseError as exc: context["error_msg"] = "Parsing error. The following line is in a unknow format: %s" % exc.line except Exception as exc: context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))
def add_unavailability(request, band_id): context = {} band = bands_manager.get_band(band_id) context['band'] = band form = UnavailabilityEntryForm(request.POST or None) context['form'] = form if request.method == 'POST' and form.is_valid(): date_start = form.cleaned_data['date_start'] date_end = form.cleaned_data['date_end'] time_start = form.cleaned_data['time_start'] time_end = form.cleaned_data['time_end'] all_day = form.cleaned_data['all_day'] try: if not band.is_member(request.user): raise Exception("You have no permission to add songs to this band's setlist cause you are not a member of it.") bands_manager.add_unavailability_entry(band_id, date_start, date_end, time_start, time_end, all_day, request.user) request.flash['success'] = "Unavailability added successfully!" return redirect('/band/%d/events' % band.id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message # 500 return render_to_response('band/events/unavailability/create.html', context, context_instance=RequestContext(request))
def add_rehearsal(request, band_id): context = {} band = bands_manager.get_band(band_id) context['band'] = band if request.method == 'POST': form = RehearsalEntryForm(request.POST) context['form'] = form if form.is_valid(): date_start = form.cleaned_data['date_start'] time_start = form.cleaned_data['time_start'] time_end = form.cleaned_data['time_end'] place = form.cleaned_data['place'] costs = form.cleaned_data['costs'] try: if not band.is_member(request.user): raise Exception("You have no permission to add songs to this band's setlist cause you are not a member of it.") bands_manager.add_rehearsal_entry(band_id, date_start, time_start, time_end, place, costs, request.user) request.flash['success'] = "Rehearsal added successfully!" return redirect('/band/%d/events' % band.id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message # 500 else: context['form'] = RehearsalEntryForm() return render_to_response('band/events/rehearsal/create.html', context, context_instance=RequestContext(request))
def add_gig(request, band_id): context = {} band = bands_manager.get_band(band_id) context['band'] = band form = GigEntryForm(request.POST or None) context['form'] = form if request.method == 'POST' and form.is_valid(): date_start = form.cleaned_data['date_start'] date_end = form.cleaned_data['date_end'] time_start = form.cleaned_data['time_start'] time_end = form.cleaned_data['time_end'] place = form.cleaned_data['place'] costs = form.cleaned_data['costs'] ticket = form.cleaned_data['ticket'] try: if not band.is_member(request.user): raise Exception("You have no permission to add songs to this band's setlist cause you are not a member of it.") bands_manager.add_gig_entry(band_id, date_start, date_end, time_start, time_end, place, costs, ticket, request.user) if (bands_manager.has_unavailabilities(band_id, date_start, date_end)): request.flash['warning'] = "There is at least one unavailability of a member on this period." request.flash['success'] = "Gig added successfully!" return redirect('/band/%d/events' % band.id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message # 500 return render_to_response('band/events/gig/create.html', context, context_instance=RequestContext(request))
def show_gig(request, band_id, entry_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to view this band's events cause you are not a member of it.") gig = bands_manager.get_gig(entry_id) # calculates the band diff setlist (band setlist songs minus gig setlist songs) diff_setlist = [] for song in band.setlist.song_list: if not gig.setlist.contains(song): diff_setlist.append(song) context['diff_setlist'] = diff_setlist context['band'] = band context['gig'] = gig if gig.contract is None: view_url = reverse('project.views_gig.upload_contract', args=[band.id, gig.id]) upload_url, upload_data = prepare_upload(request, view_url) context["contract_form"] = UploadBandFileForm() context['contract_url'] = upload_url context['contract_data'] = upload_data context['form'] = True else: context["contract"] = gig.contract context['form'] = False except Exception as exc: # 500 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/events/gig/show.html', context, context_instance=RequestContext(request))
def invite_user(request, band_id): band = bands_manager.get_band(band_id) email = request.POST['email'] if band.is_member(request.user): users_manager.invite_user(email, request.user, band) response_data = {'result': True} else: response_data = {'result': False} return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
def remove_unavailability(request, band_id, entry_id): context = {} band = bands_manager.get_band(band_id) try: if not band.is_member(request.user): raise Exception("You have no permission to remove this band's event cause you are not a member of it.") bands_manager.remove_unavailability(band_id, entry_id, request.user) return HttpResponse() except Exception as exc: print exc
def show_events(request, band_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): # 403 raise Exception("You have no permission to view this band cause you are not a member of it.") context['band'] = band except Exception as exc: # 500 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/events.html', context, context_instance=RequestContext(request))
def search_unavailabilities(request, band_id): from datetime import datetime band = bands_manager.get_band(band_id) date_start = datetime.strptime(request.GET["date_start"], '%m/%d/%Y') date_end = datetime.strptime(request.GET["date_end"], '%m/%d/%Y') unavailabilities = bands_manager.get_unavailabilities(band_id, date_start, date_end) if not band.is_member(request.user): # 403 raise Exception("You have no permission to view this band cause you are not a member of it.") response = HttpResponse(mimetype='application/json') json_serializer.serialize(unavailabilities, ensure_ascii=False, stream=response) return response
def remove_contact(request, band_id, contact_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to remove songs from this band's setlist cause you are not a member of it.") bands_manager.remove_contact(band_id, contact_id) return redirect('/band/%s/contacts' % band_id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message context['contact_form'] = ContactBandForm() return render_to_response('band/contacts.html', context, context_instance=RequestContext(request))
def sort_gig_setlist(request, band_id, entry_id, song_id): try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to view this band cause you are not a member of it.") response_data = {} bands_manager.sort_gig_setlist(entry_id, song_id, request.POST['position']) response_data = { 'success' : "ok" } except Exception as exc: response_data= { 'success' : "fail: " + exc.message } return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
def get_calendar_entries(request, band_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): # 403 raise Exception("You have no permission to view this band cause you are not a member of it.") except Exception as exc: # 500 context['error_msg'] = "Error ocurred: %s" % exc.message response = HttpResponse(mimetype='application/json') serializers.serialize('json', band.calendar_entries, ensure_ascii=False, stream=response, relations={'added_by':{'fields':('first_name',)}}) return response
def remove_setlist_song(request, band_id, song_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception( "You have no permission to remove songs from this band's setlist cause you are not a member of it." ) bands_manager.remove_setlist_song(band_id, song_id) return redirect("/band/%s/setlist" % band_id) except Exception as exc: context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))
def show_song_details(request, band_id, song_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to view this band's events cause you are not a member of it.") song = bands_manager.get_song(song_id) context = __prepare_context(request, band, song) except Exception as exc: # 500 print exc.message context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/song.html", context, context_instance=RequestContext(request))
def remove_band_member(request, band_id, username): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to remove members from this band cause you are not a member of it.") bands_manager.remove_band_member(band_id, users_manager.get_user(username)) return redirect('/band/%s' % band_id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message context['band'] = band return render_to_response('band/show.html', context, context_instance=RequestContext(request))
def add_band_member(request, band_id): context = {} username = request.POST['username'] try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to add members to this band cause you are not a member of it.") bands_manager.add_band_member(band_id, username) response_data = {'result': True} except Exception as exc: response_data = {'result': False} return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
def show_setlist(request, band_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): # 403 raise Exception("You have no permission to view this band cause you are not a member of it.") context["band"] = band context["song_list"] = band.setlist.song_list context["song_list_size"] = len(band.setlist.song_list) context["query_string"] = "" except Exception as exc: # 500 context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))
def add_setlist_song(request, band_id): context = {} artist = request.POST["artist"] title = request.POST["title"] try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception( "You have no permission to add songs to this band's setlist cause you are not a member of it." ) bands_manager.add_setlist_song(band_id, artist, title) return redirect("/band/%s/setlist" % band_id) except Exception as exc: context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))
def voting_dashboard(request, band_id): context = {} try: band = bands_manager.get_band(band_id) context["band"] = band context["active_voting"] = False context["older_votings"] = False if not band.is_member(request.user): raise Exception("You have no permission to view this band's votings cause you are not a member of it.") except Exception as exc: context["error_msg"] = "Error ocurred: %s" % exc.message return render_to_response("band/voting/dashboard.html", context, context_instance=RequestContext(request))
def edit_gig(request, band_id, entry_id): context = {} try: band = bands_manager.get_band(band_id) context['band'] = band gig = bands_manager.get_gig(entry_id) if not band.is_member(request.user): raise Exception("You have no permission to edit this band's events cause you are not a member of it.") if request.method == 'POST': form = GigEntryForm(request.POST) context['form'] = form if form.is_valid(): date_start = form.cleaned_data['date_start'] time_start = form.cleaned_data['time_start'] time_end = form.cleaned_data['time_end'] place = form.cleaned_data['place'] costs = form.cleaned_data['costs'] ticket = form.cleaned_data['ticket'] gig = bands_manager.update_gig_entry(entry_id, date_start, time_start, time_end, place, costs, ticket) request.flash['success'] = "Gig updated successfully!" return redirect('/band/%d/events' % band.id) else: # GET if gig.band != band: raise Exception("There is no gig for this band with the given Id.") data = {'date_start' : gig.date_start, 'date_end' : gig.date_end, 'time_start' : gig.time_start, 'time_end' : gig.time_end, 'place' : gig.place, 'costs' : gig.costs, 'ticket' : gig.ticket } form = GigEntryForm(data) context['gig'] = gig context['form'] = form except Exception as exc: # 404 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/events/gig/edit.html', context, context_instance=RequestContext(request))
def download_file(request, band_id, bandfile_id): try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to download this file cause you are not a member of the band.") try: band_file = BandFile.objects.get(pk=bandfile_id) except BandFile.DoesNotExist: raise Exception("There is no file associated with id %s" % bandfile_id) return serve_file(request, band_file.file, save_as=True) except Exception as exc: context = {} context['error_msg'] = "Error: " + exc.message return render_to_response('error.html', context, context_instance=RequestContext(request))
def show_files(request, band_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): # 403 raise Exception("You have no permission to view this band cause you are not a member of it.") context['band'] = band view_url = reverse('upload-band-file', args=[band.id]) upload_url, upload_data = prepare_upload(request, view_url) context['upload_form'] = UploadBandFileForm() context['upload_url'] = upload_url context['upload_data'] = upload_data except Exception as exc: # 500 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/files.html', context, context_instance=RequestContext(request))
def rehearsal_setlist(request, band_id, entry_id): context = {} try: band = bands_manager.get_band(band_id) if not band.is_member(request.user): raise Exception("You have no permission to view this band's event cause you are not a member of it.") context['band'] = band rehearsal = bands_manager.get_rehearsal(entry_id) context['rehearsal'] = rehearsal # calculates the band diff setlist (band setlist songs minus rehearsal setlist songs) diff_setlist = [] for song in band.setlist.song_list: if not rehearsal.setlist.contains(song): diff_setlist.append(song) context['diff_setlist'] = diff_setlist except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/events/rehearsal/setlist.html', context, context_instance=RequestContext(request))
def add_contact(request, band_id): context = {} band = bands_manager.get_band(band_id) form = ContactBandForm(request.POST) context['band'] = band context['form'] = form if form.is_valid(): name = form.cleaned_data['name'] phone = form.cleaned_data['phone'] service = form.cleaned_data['service'] cost = form.cleaned_data['cost'] added = datetime.now() try: if not band.is_member(request.user): raise Exception("You have no permission to add songs to this band's setlist cause you are not a member of it.") bands_manager.add_contact(band_id, name, phone, service, cost, added, added_by=request.user) return redirect('/band/%s/contacts' % band_id) except Exception as exc: context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('band/contacts.html', context, context_instance=RequestContext(request))