def revert(): """ Revert all settings to default values. """ from setman import settings if not auth_permitted(request): output = render_template('setman/edit.html', auth_forbidden=True) return Response(output, status=403) settings.revert() flash('Settings have been reverted to default values.', 'success') return redirect('%s?%d' % (url_for('setman.edit'), randint(1000, 9999)))
def edit(request, template='setman/edit.html', title=None): """ Edit Settings page. By default only logged in superusers can have access to this page. But you can customize things, by setup ``SETMAN_AUTH_PERMITTED`` option. For example, if you need to permit staff users to edit settings too, you need to specify:: SETMAN_AUTH_PERMITTED = lambda request: request.user.is_staff in your project settings module. Also, you can check necessary profile role there as well as:: SETMAN_AUTH_PERMITTED = \ lambda request: request.user.profile.role == 'project_manager' But also, don't forget that only **logged** in users can access this page. Not guest users able to edit custom project settings in any way. """ if not auth_permitted(request): return render(request, 'setman/edit.html', {'auth_forbidden': True}, status=403) if request.method == 'POST': form = SettingsForm(request.POST) if form.is_valid(): form.save() messages.success( request, _('Settings have been succesfully updated.') ) return redirect('%s?%d' % (request.path, randint(1000, 9999))) else: form = SettingsForm() return render(request, template, {'form': form, 'title': title})
def revert(request): """ Revert settings to default values. This view uses same permission rules as "Edit Settings" view. """ redirect_to = request.GET.get('next') if not redirect_to: redirect_to = reverse('setman_edit') if not auth_permitted(request): return render(request, 'setman/edit.html', {'auth_forbidden': True}, status=403) settings.revert() messages.success(request, _('Settings have been reverted to default values.')) return redirect('%s?%d' % (redirect_to, randint(1000, 9999)))
def edit(request, template='setman/edit.html', title=None): """ Edit Settings page. By default only logged in superusers can have access to this page. But you can customize things, by setup ``SETMAN_AUTH_PERMITTED`` option. For example, if you need to permit staff users to edit settings too, you need to specify:: SETMAN_AUTH_PERMITTED = lambda request: request.user.is_staff in your project settings module. Also, you can check necessary profile role there as well as:: SETMAN_AUTH_PERMITTED = \ lambda request: request.user.profile.role == 'project_manager' But also, don't forget that only **logged** in users can access this page. Not guest users able to edit custom project settings in any way. """ if not auth_permitted(request): return render(request, 'setman/edit.html', {'auth_forbidden': True}, status=403) if request.method == 'POST': form = SettingsForm(request.POST) if form.is_valid(): form.save() messages.success(request, _('Settings have been succesfully updated.')) return redirect('%s?%d' % (request.path, randint(1000, 9999))) else: form = SettingsForm() return render(request, template, {'form': form, 'title': title})
def edit(): """ Edit all available settings. """ if not auth_permitted(request): output = render_template('setman/edit.html', auth_forbidden=True) return Response(output, status=403) settings_form = settings_form_factory() if request.method == 'POST': form = settings_form(request.form) if form.validate(): form.save() flash('Settings have been succesfully updated.', 'success') return redirect('%s?%d' % (url_for('setman.edit'), randint(1000, 9999))) else: form = settings_form() return render_template('setman/edit.html', form=update_form_fields(form))
def revert(request): """ Revert settings to default values. This view uses same permission rules as "Edit Settings" view. """ redirect_to = request.GET.get('next') if not redirect_to: redirect_to = reverse('setman_edit') if not auth_permitted(request): return render(request, 'setman/edit.html', {'auth_forbidden': True}, status=403) settings.revert() messages.success( request, _('Settings have been reverted to default values.') ) return redirect('%s?%d' % (redirect_to, randint(1000, 9999)))
def has_delete_permission(self, request): """ Do not show "Delete" link in admin panel for "Settings" models. """ return auth_permitted(request)
def has_change_permission(self, request): """ Do not show "Change" link in admin panel for "Settings" line in "Settings Manager" app. """ return auth_permitted(request)