我的应用程序中有以下服务:
uaInProgressApp.factory('uaProgressService',
function(uaApiInterface, $timeout, $rootScope){
var factory = {};
factory.taskResource = uaApiInterface.taskResource()
factory.taskList = [];
factory.cron = undefined;
factory.updateTaskList = function() {
factory.taskResource.query(function(data){
factory.taskList = data;
$rootScope.$digest
console.log(factory.taskList);
});
factory.cron = $timeout(factory.updateTaskList, 5000);
}
factory.startCron = function () {
factory.cron = $timeout(factory.updateTaskList, 5000);
}
factory.stopCron = function (){
$timeout.cancel(factory.cron);
}
return factory;
});
Run Code Online (Sandbox Code Playgroud)
然后我在这样的控制器中使用它:
uaInProgressApp.controller('ua.InProgressController',
function ($scope, $rootScope, $routeParams, uaContext, uaProgressService) {
uaContext.getSession().then(function(){
uaContext.appName.set('Testing house');
uaContext.subAppName.set('In progress');
uaProgressService.startCron();
$scope.taskList = uaProgressService.taskList;
});
}
);
Run Code Online (Sandbox Code Playgroud)
所以基本上我的服务factory.taskList
每5秒更新一次,我将其链接factory.taskList
到$scope.taskList …
我对Ansible有一个令人不安的问题.我使用当前主机的ssh键在我的环境中设置了一个git克隆:
- name: Add user Public Key
copy:
src: "/Users/alexgrs/.ssh/id_rsa.pub"
dest: "/home/vagrant/.ssh/id_rsa.pub"
mode: 0644
- name: Add user Private Key
copy:
src: "/Users/alexgrs/.ssh/id_rsa"
dest: "/home/vagrant/.ssh/id_rsa"
mode: 0600
- name: Clone Repository
git:
repo: repo.git
dest: /home/vagrant/workspace/
update: true
accept_hostkey: true
key_file: "/home/vagrant/.ssh/id_rsa.pub"
Run Code Online (Sandbox Code Playgroud)
如果我vagrant ssh
在Vagrant并执行git pull repo
它工作.但是当我这样做时,vagrant provision
我收到以下错误消息:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我很确定我的公钥不被vangrant规定使用,但我无法检测到原因.
你有没有看到这种问题?
谢谢. …
我正在尝试用Ansible编写部署规则.一些步骤是:
我想将存储库作为harry
用户在其主目录中克隆(这就是我复制它的公钥和私钥的原因).问题是无法指定用户必须执行git clone.所以Ansible尝试以root身份克隆存储库并失败,因为他没有访问存储库的权限.
你是如何解决这个问题的?
我有一个带有DateTimeField的模型:
class MyShell(models):
created = models.DateTimeField(auto_now=true)
Run Code Online (Sandbox Code Playgroud)
我使用Django Rest Framework将api链接到它:
class ShellMessageFilter(django_filters.FilterSet):
created = django_filters.DateTimeFilter(name="created",lookup_type="gte")
class Meta:
model = ShellMessage
fields = ['created']
class ShellListViewSet(viewsets.ModelViewSet):
"""
List all ShellMessages
"""
serializer_class = ShellMessageSerializer
queryset = ShellMessage.objects.all()
filter_class = ShellMessageFilter
Run Code Online (Sandbox Code Playgroud)
当我使用以下URL点击我的API时,它完美地运行:
http://127.0.0.1:8000/api/shell/?created=2014-07-17
# It returns all shell with a date greater than the one provided in URL
Run Code Online (Sandbox Code Playgroud)
但是,我希望通过根据日期和时间进行过滤来做更多的事情.我尝试了以下网址但没有成功:
http://127.0.0.1:8000/api/shell/?created=2014-07-17T10:36:34.960Z
# It returns an empty array whereas there are items with a created field greater than 2014-07-17T10:36:34.960Z
Run Code Online (Sandbox Code Playgroud)
如果你们知道如何继续......我在django-filters文档中找不到任何好的信息或示例......
我有多个API,历史上id
用作查找字段:
/api/organization/10
Run Code Online (Sandbox Code Playgroud)
我有一个消耗这些api的前端.
我正在构建一个新的界面,出于某些原因,我想使用slug而不是id:
/api/organization/my-orga
Run Code Online (Sandbox Code Playgroud)
API是使用Django Rest Framework构建的.除了查找字段的更改外,api行为应该保持不变.
有没有一个解决方案允许我的API同时使用a slug
和a pk
?这两条路径应该给他们相同的结果:
/api/organization/10
/api/organization/my-orga
Run Code Online (Sandbox Code Playgroud)
这是我的API定义:
# urls.py
router = DefaultRouter()
router.register(r'organization', Organization)
urlpatterns = router.urls
#view.py
class Organization(viewsets.ModelViewSet):
queryset = OrganisationGroup.objects.all()
serializer_class = OrganizationSerializer
# serializer.py
class OrganizationSerializer(PermissionsSerializer):
class Meta:
model = Organization
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我想执行一个简单的查询:
Pizza.object.filter(topping__contains='PEPERONI')
Run Code Online (Sandbox Code Playgroud)
像这样,它就像一个魅力.但是,如果我尝试:
Pizza.object.filter(topping__contains='peperoni')
Run Code Online (Sandbox Code Playgroud)
它不起作用.
你知道为什么它区分大小写吗?有没有从django取消此功能的选项?
我只想将以下JSONobjects发送到我的API后端:
{
"username":"alex",
"password":"password"
}
Run Code Online (Sandbox Code Playgroud)
所以我使用Angular $ http编写了以下函数:
$http(
{
method: 'POST',
url: '/api/user/auth/',
data: '{"username":"alex", "password":"alex"}',
})
.success(function(data, status, headers, config) {
// Do Stuff
})
.error(function(data, status, headers, config) {
// Do Stuff
});
Run Code Online (Sandbox Code Playgroud)
我在POST文档的文档中读到Content-Type标题将自动设置为"application/json".
但我意识到我在后端(Django + Tastypie)api上收到的内容类型是"text/plain".
这导致我的API无法正确响应此请求.我该如何管理这种内容类型?
我想在导航器中使用带有cookie的资源.
使用$ http非常简单,因为我只需将withCredential设置为true:
$http({
method: 'POST',
url: url,
data: user,
withCredentials: true
});
Run Code Online (Sandbox Code Playgroud)
但是对于$ resource,我没有找到解决方案来点同样的...我在github上看到了关于这一点的讨论,但我认为对于所有请求,对于true的设置为true是不正常的.你知道怎么做吗?
所以我对MongoDB和文档存储设备都很陌生.我很难找到最优雅,最有效的解决方案来做到以下几点:
我有一个叫做测试的集合.在每个测试中,都有一个字段所有者的操作.见下文:
{
"_id" : ObjectId("528c731a810761651c00000f"),
"actions" : [
{
"action" : "6784",
"owner" : "MERCHAND_1",
"_id" : ObjectId("528c7292810761651c00000e")
},
{
"action" : "1",
"owner" : "MERCHAND_1",
"_id" : ObjectId("528c7292810761651c00000d")
},
{
"action" : "1358",
"owner" : "MERCHAND_2",
"_id" : ObjectId("528c7292810761651c00000c")
}
],
"name" : "Test 1",
"product" : ObjectId("528bc4b3a0f5430812000010")
Run Code Online (Sandbox Code Playgroud)
}
如何使用Node.js和MongoDB(我使用的是mongoose驱动程序)获得每个不同所有者值的列表(数组).在mongoside或node.js方面做得更好吗?例如,如果我在上一个表上运行该函数,它应该返回:
[
{
"owner":"MERCHAND_1"
},
{
"owner":"MERCHAND_2"
}
]
Run Code Online (Sandbox Code Playgroud) 我有以下API:
{
"meta": {
"total_item": 1,
"number_of_pages": 1,
"page_number": 1,
"status": "Success"
},
"data": [
{
"name": "Operator 1",
"short_name": "OP1",
"_id": "534d69bba758b3b7839ba7b9",
"__v": 0,
"users": [
"532ef6e28b42970ab797444f"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我使用Angular $资源使用以下代码查询API:
var apiDataTransformer = function ($http) {
return $http.defaults.transformResponse.concat([
function (data, headersGetter) {
var result = data.data;
result.meta = data.meta;
console.log(result);
return result;
}
])
};
angular.module('ua.common').factory('uaApi', function($resource, $http){
var factory = {};
factory.operator_ressource = $resource(
'/operators/:operatorId',
{},
{'query': {method: 'GET', isArray: true, transformResponse: apiDataTransformer($http) } } …
Run Code Online (Sandbox Code Playgroud)