def show_user(request, username): context = {} context_instance = RequestContext(request) try: user = users_manager.get_user(username) context['profile_user'] = user except Exception as exc: # 500 context['error_msg'] = "Error ocurred: %s" % exc.message return render_to_response('user/show.html', context, context_instance=context_instance)
def add_band_member(band_id, username): try: band = get_band(band_id) user = users_manager.get_user(username) if band.is_member(user): raise Exception(username + " is already rocking in this band!") band.members.add(user) band.save() return band except Exception as exc: raise Exception("Error adding member: %s" % exc.message)
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 remove_band_member(band_id, username): try: band = get_band(band_id) user = users_manager.get_user(username) if not band.is_member(user): raise Exception(username.username + " is not a member of this band.") if len(band.members.all()) <= 1: raise Exception(username.username + " is the unique representant of this band. Please delete the band to get out.") band.members.remove(user) band.save() return band except Exception as exc: raise Exception("Error removing member: %s" % exc.message)