def xml_config_settings_edit_user(request, userid): """The settings view for editing a user Keyword arguments: userid -- The id of the user """ # get form if request.method == 'POST': user = get_object_or_404(XMLAPIUser, id=userid) user_form = XMLAPIUserEditForm(request.POST, instance=user) if user_form.is_valid(): user_form.save() return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'user_form': user_form, 'config_user': user } return csrf_render(request, 'config/xml_settings_edit_user.html', ctx) else: user = get_object_or_404(XMLAPIUser, id=userid) user_form = XMLAPIUserEditForm(instance=user) ctx = { 'user_form': user_form, 'config_user': user } return csrf_render(request, 'config/xml_settings_edit_user.html', ctx)
def config_settings_new_user(request): """The settings view for creating a new user """ # get form if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() profile = profile_form.save(commit=False) profile.user = user profile.save() return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'user_form': user_form, 'profile_form': profile_form } return csrf_render(request, 'config/settings_new_user.html', ctx) else: user_form = UserForm() profile_form = UserProfileForm() ctx = { 'user_form': user_form, 'profile_form': profile_form } return csrf_render(request, 'config/settings_new_user.html', ctx)
def config_profile(request): """The profile view """ # get form if request.method == 'POST': user = request.user user_profile = request.user.get_profile() user_form = UserEditForm(request.POST, instance=user) profile_form = UserEditProfileForm(request.POST, instance=user_profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() set_language(request) return HttpResponseRedirect(reverse('player:config_profile')) ctx = { 'user_form': user_form, 'profile_form': profile_form } return csrf_render(request, 'config/profile.html', ctx) else: user = request.user user_profile = request.user.get_profile() user_form = UserEditForm(instance=user) profile_form = UserEditProfileForm(instance=user_profile) ctx = { 'user_form': user_form, 'profile_form': profile_form } return csrf_render(request, 'config/profile.html', ctx)
def config_settings(request): """The settings view """ # get all files in the themepath that are folders themes = [] themepath = os.path.join(settings.MEDIA_ROOT, 'themes/') for entry in os.listdir( themepath ): path = os.path.join(themepath, entry) if os.path.isdir( path ): themes.append(entry) users = User.objects.all() xml_users = XMLAPIUser.objects.all() warnings = ResourceChecker().get_warnings() # get form if request.method == 'POST': settings_form = SettingsForm(request.POST) if settings_form.is_valid(): settings_form.save() return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'settings_form': settings_form, 'users': users, 'xml_users': xml_users, 'themes': themes, 'warnings': warnings } return csrf_render(request, 'config/settings.html', ctx) else: config = LaudioConfig(settings.LAUDIO_CFG) initial = { 'transcoding': config.transcoding, 'collection_path': config.collectionPath, 'debug': config.debug, 'require_login': config.requireLogin, 'collection_startup': config.collectionStartup, 'xml_auth': config.xmlAuth, 'token_lifespan': config.tokenLifespan } settings_form = SettingsForm(initial=initial) ctx = { 'settings_form': settings_form, 'users': users, 'xml_users': xml_users, 'themes': themes, 'warnings': warnings } return csrf_render(request, 'config/settings.html', ctx)
def setup(request): """Setup view """ su_exists = len(User.objects.filter(is_superuser=True)) if not su_exists: form = SetupForm() # get form if request.method == 'POST': form = SetupForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_active = True user.is_superuser = True user.is_staff = True user.save() # create a profile profile = UserProfile() profile.user = user profile.save() return HttpResponseRedirect(reverse('player:index')) ctx = { 'form': form, } return csrf_render(request, 'install/index.html', ctx) else: raise Http404
def xml_config_settings_new_user(request): """The settings view for creating a new xml api user """ # get form if request.method == 'POST': user_form = XMLAPIUserForm(request.POST) if user_form.is_valid(): user_form.save() return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'user_form': user_form } return csrf_render(request, 'config/xml_settings_new_user.html', ctx) else: user_form = XMLAPIUserForm() ctx = { 'user_form': user_form } return csrf_render(request, 'config/xml_settings_new_user.html', ctx)
def player(request): """Shows the player if there are superusers """ artists = Artist.objects.all().order_by('name') albums = Album.objects.all().order_by('name') genres = Genre.objects.all().order_by('name') ctx = { 'artists': artists, 'albums': albums, 'genres': genres } return csrf_render(request, 'player/index.html', ctx)
def xml_config_settings_delete_user(request, userid): """The settings view for deleting a user Keyword arguments: userid -- The id of the user """ user = get_object_or_404(XMLAPIUser, id=userid) if request.method == 'POST': user.delete() return HttpResponseRedirect(reverse('player:config_settings')) else: ctx = { 'change_user': user } return csrf_render(request, 'config/xml_settings_delete_user.html', ctx)
def config_settings_new_theme(request): """The settings view for creating a new xml api user """ # get form debug = LaudioDebugger() if request.method == 'POST': theme_form = ThemeForm(request.POST, request.FILES) if theme_form.is_valid(): try: theme_form.install_theme(request.FILES['theme']) except (tarfile.CompressionError, tarfile.ReadError, TypeError), msg: debug.log('Theme Upload', msg) return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'theme_form': theme_form } return csrf_render(request, 'config/settings_new_theme.html', ctx)
def config_settings_delete_theme(request, themename): """The settings view for deleting a user Keyword arguments: userid -- The id of the user """ if request.method == 'POST': # todo unlink theme if themename != 'default': themes_dir = os.path.join(settings.MEDIA_ROOT, 'themes/') theme_path = os.path.join(themes_dir, themename) shutil.rmtree(theme_path) else: debug = LaudioDebugger() debug.log('Theme Deletion', 'Can not delete default theme') return HttpResponseRedirect(reverse('player:config_settings')) else: ctx = { 'themename': themename } return csrf_render(request, 'config/settings_delete_theme.html', ctx)
if theme_form.is_valid(): try: theme_form.install_theme(request.FILES['theme']) except (tarfile.CompressionError, tarfile.ReadError, TypeError), msg: debug.log('Theme Upload', msg) return HttpResponseRedirect(reverse('player:config_settings')) ctx = { 'theme_form': theme_form } return csrf_render(request, 'config/settings_new_theme.html', ctx) else: theme_form = ThemeForm() ctx = { 'theme_form': theme_form } return csrf_render(request, 'config/settings_new_theme.html', ctx) @check_login('admin') def config_settings_delete_theme(request, themename): """The settings view for deleting a user Keyword arguments: userid -- The id of the user """ if request.method == 'POST': # todo unlink theme if themename != 'default': themes_dir = os.path.join(settings.MEDIA_ROOT, 'themes/') theme_path = os.path.join(themes_dir, themename) shutil.rmtree(theme_path)