我创建了一个作为deamon运行的linux服务(并从/etc/init.d/X开始).我需要设置一些可以被应用程序访问的环境变量.
这是场景.该应用程序是一组Perl AGI脚本,依赖于(因此需要以asstisk用户身份运行)asterisk用户,但asterisk没有shell.理想情况下,我只需在/home/asterisk/.bashrc中设置它,但星号不存在.
如何在星号用户的运行环境中为我的应用设置环境变量,以便我的应用可以使用它们?
我正在尝试执行验证,以便在他是管理员时无法删除用户.因此,如果用户是管理员并且已被标记为删除,我想检查并引发错误.
这是我的内联 ModelForm
class UserGroupsForm(forms.ModelForm):
class Meta:
model = UserGroups
def clean(self):
delete_checked = self.fields['DELETE'].widget.value_from_datadict(
self.data, self.files, self.add_prefix('DELETE'))
if bool(delete_checked):
#if user is admin of group x
raise forms.ValidationError('You cannot delete a user that is the group administrator')
return self.cleaned_data
Run Code Online (Sandbox Code Playgroud)
该if bool(delete_checked):条件返回true,里面的东西if块被执行,但由于某种原因从来没有提出这个验证错误.有人可以向我解释原因吗?
更好的是,如果还有另一种更好的方法,请告诉我
假设您正在为异步运行的对象编写库.要通知调用者异步对象的状态,调用者必须实现侦听器接口.
现在,当使用侦听器时,侦听器可能会做错,这将导致在库对象中抛出异常.
例
public interface SomeListener {
public void progressNotification(int status);
}
public class SomeClass {
SomeListener listener = null;
…
public void setListener(SomeListener listener) {
this.listener = listener;
}
…
public void someRandomMethod() {
int progressStatus = 0;
//Do some stuff here that updates progressStatus
//then notify the caller
if (listener != null) {
listener.progressNotification(progressStatus);
}
}
}
public class CallerClass implements SomeListener{
public void progressNotification(int status) {
//do something that will throw an exception
//e.g assume status is …Run Code Online (Sandbox Code Playgroud) asterisk ×1
bash ×1
django ×1
django-admin ×1
django-forms ×1
init.d ×1
java ×1
linux ×1
perl ×1
validation ×1