小编an0*_*nym的帖子

如何更新 Celery Task ETA?

我正在使用 Celery 4.1.0 在 Django 1.10.3 中构建简单的等待列表应用程序。

我有以下基本任务:

@shared_task
def start_user_counter():
    logging.info('Task executed @ {}'.format(datetime.datetime.utcnow()))
    # This task is executed when user reaches the Top of the queue.
    # Send email, perform other stuff in here ...

@shared_task
def update_queue():
    curr_time = datetime.datetime.utcnow()
    logging.info('Task called @ {}'.format(curr_time))
    time_to_exec = curr_time + datetime.timedelta(seconds=10)
    # Here, perform checks if task already exists in Redis
    # if it does not exist - create a new one and store it to Redis
    # if …
Run Code Online (Sandbox Code Playgroud)

python django celery python-3.x

5
推荐指数
1
解决办法
3405
查看次数

角度应用程序中的共享接口/数据类型

我有一个HeaderComponent将表单对象{title: string, short_desc: string}作为其输入属性的对象。

@Component({
  selector: 'header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
  @Input() data: { title: string, short_desc: string };

  constructor() { }

  ngOnInit() { }
}
Run Code Online (Sandbox Code Playgroud)

这是我定义将传递给的数据的方式HeaderComponent

@Component({
  templateUrl: './my-custom.component.html',
  styleUrls: ['./my-custom.component.scss']
})
export class MyCustomComponent implements OnInit {
    public headerData: {title: string, short_desc: string};

    constructor() {
        this.headerData = {
            title: 'Settings Page',
            short_desc: 'Update your settings',
        }
    }

  ngOnInit() { }
}
Run Code Online (Sandbox Code Playgroud)

现在,我需要HeaderComponent在相当多的组件中使用。所以我创建了一个header-data.ts …

typescript angular

5
推荐指数
1
解决办法
2622
查看次数

Python3中的子类型与对象的子类化

我一直在阅读有关元类的内容,type而且在object课堂上我迷路了.

我知道它们位于层次结构的顶层,并且它们是用C代码实现的.我也明白,type继承自objectobject是一个实例type.

在我发现的其中一个答案中,有人说 - 在object-type关系中 - 说:

这种相互继承通常是不可能的,但这就是Python中这些基本类型的方式:它们违反了规则.

我的问题是为什么以这种方式实现,这种实现的目的是什么?它解决了什么问题/这个设计有什么好处?难道不是只是type或只是object在每个类继承的层次结构顶部的类?

最后,子类化object与子类化之间是否有任何区别type,何时我想使用另一个?

class Foo(object):
    pass
Run Code Online (Sandbox Code Playgroud)

VS

class Foo(type):
    pass
Run Code Online (Sandbox Code Playgroud)

python inheritance metaclass

3
推荐指数
1
解决办法
577
查看次数

Django modelform 字段如何禁用和防止篡改?

有这个禁用属性。但我无法将其应用于模型表单字段。我不知道该怎么做。我可以轻松地将它添加到 forms.Form 中。但是因为我使用的是小部件,所以我不知道在哪里插入它。

https://docs.djangoproject.com/en/2.0/ref/forms/fields/#disabled

class TestForm(forms.ModelForm):
    class Meta:
        model = Test
        fields = ['date']
        widgets = {'date': forms.TextInput(attrs={'readonly': 'readonly'})}
Run Code Online (Sandbox Code Playgroud)

django django-forms

3
推荐指数
2
解决办法
7258
查看次数