小编Ben*_*lah的帖子

Angularjs 1.3 $ http拦截器

我目前在我的应用程序中有以下内容,每当有$ http请求运行时显示加载动画,然后隐藏在最后;

app.config(['$httpProvider', function ($httpProvider) {
    var $http,
        interceptor = ['$q', '$injector', function ($q, $injector) {
            var error;

            function response(response) {
                // get $http via $injector because of circular dependency problem
                $http = $http || $injector.get('$http');
                if ($http.pendingRequests.length < 1) {
                    $('#loadingWidget').hide();
                }
                return response;
            }

            function responseError(response) {
                if (response.status == 401) {
                    alert("You have been logged out or have tried to access a restricted area, redirecting to the login screen...");
                    window.location = globals.siteUrl + 'login';
                } else { …
Run Code Online (Sandbox Code Playgroud)

angularjs

6
推荐指数
1
解决办法
4570
查看次数

选择字段的Django初始值

我遇到了一个奇怪的问题,我似乎无法在 django 的表单中设置其中一个字段的初始值。

我的模型字段是:

section = models.CharField(max_length=255, choices=(('Application', 'Application'),('Properly Made', 'Properly Made'), ('Changes Application', 'Changes Application'), ('Changes Approval', 'Changes Approval'), ('Changes Withdrawal', 'Changes Withdrawal'), ('Changes Extension', 'Changes Extension')))
Run Code Online (Sandbox Code Playgroud)

我的表单代码是:

class FeeChargeForm(forms.ModelForm):
    class Meta:
        model = FeeCharge
        # exclude = [] # uncomment this line and specify any field to exclude it from the form

    def __init__(self, *args, **kwargs):
        super(FeeChargeForm, self).__init__(*args, **kwargs)
        self.fields['received_date'] = forms.DateField(('%d/%m/%Y',), widget=forms.DateTimeInput(format='%d/%m/%Y', attrs={'class': 'date'}))
        self.fields['comments'].widget.attrs['class']='html'
        self.fields['infrastructure_comments'].widget.attrs['class']='html'
Run Code Online (Sandbox Code Playgroud)

我的视图代码是:

form = FeeChargeForm(request.POST or None)
form.fields['section'].initial = section
Run Code Online (Sandbox Code Playgroud)

其中 section …

python django

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

Python SUDS错误 - SAXParseException

"<unknown>:1:0: syntax error"当响应看起来像这样时,有谁知道为什么我会从python suds调用得到一个?

<?xml version='1.0' encoding='UTF-8'?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Body>
    <external.bz1:reply xmlns:abn.types="uri:abn.types.asic.gov.au" xmlns:bn.types="uri:bn.types.asic.gov.au" xmlns:business.document.header.types="uri:business.document.header.types.asic.gov.au" xmlns:external.bz1="uri:external.bz1.asic.gov.au" xmlns:fss.types="uri:fss.types.asic.gov.au" xmlns:types="uri:types.asic.gov.au">
      <business.document.header.types:businessDocumentHeader>
        <business.document.header.types:messageType>bnLodgeApplication</business.document.header.types:messageType>
        <business.document.header.types:messageReferenceNumber>1</business.document.header.types:messageReferenceNumber>
        <business.document.header.types:messageVersion>1</business.document.header.types:messageVersion>
        <business.document.header.types:senderId>ASIC</business.document.header.types:senderId>
        <business.document.header.types:senderType>GOVT</business.document.header.types:senderType>
        <business.document.header.types:messageEvents>
          <business.document.header.types:messageEvent>
            <business.document.header.types:errorCode>00007</business.document.header.types:errorCode>
            <business.document.header.types:serverityCode>Error</business.document.header.types:serverityCode>
            <business.document.header.types:description>Message previously processed but no valid reponse is available</business.document.header.types:description>
          </business.document.header.types:messageEvent>
        </business.document.header.types:messageEvents>
      </business.document.header.types:businessDocumentHeader>
    </external.bz1:reply>
  </env:Body>
</env:Envelope>
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪:

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/django_projects/ecr/businessNames/views.py" in externalBz1
  19.     result = doExternalBz1(test)
File "/django_projects/ecr/businessNames/models.py" in doExternalBz1
  75.     result = client.service.externalBz1(header, body)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py" in __call__
  542.             return client.invoke(args, kwargs) …
Run Code Online (Sandbox Code Playgroud)

python soap

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

Django @staticmethod两个字段的总和

我有一个快速的问题.我正在尝试将字段添加到模型中,该模型是2个字段的总和.

例如:

class MyModel(models.Model)
      fee = models.DecimalField()
      fee_gst = models.DecimalField()
Run Code Online (Sandbox Code Playgroud)

我想我可以在模型中添加@staticmethod:

@staticmethod
def fee_total(self):
     return self.fee + self.fee_gst
Run Code Online (Sandbox Code Playgroud)

但我似乎无法使用以下方法访问模型的"fee_total"字段:

model = MyModel.objects.get(pk=1)
total = model.fee_total
Run Code Online (Sandbox Code Playgroud)

我有什么想法我做错了吗?

干杯

python django

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

SQLAlchemy克隆表行与关系

继这个问题SQLAlchemy:修改分离对象.

这使得对象的副本很好,但它丢失了原始对象具有的任何多对多关系.有没有办法复制对象和任何多对多关系?

干杯!

sqlalchemy

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

SQLAlchemy MySQL IF声明

我正在将旧的遗留PHP系统转换为Flask + SQLAlchemy,并想知道如何构建以下内容:

我有一个模特:

class Invoice(db.Model):
   paidtodate = db.Column(DECIMAL(10,2))
   fullinvoiceamount = db.Column(DECIMAL(10,2))
   invoiceamount = db.Column(DECIMAL(10,2))
   invoicetype = db.Column(db.String(10))
   acis_cost = db.Column(DECIMAL(10,2))
Run Code Online (Sandbox Code Playgroud)

我需要运行的查询是:

SELECT COUNT(*) AS the_count, sum(if(paidtodate>0,paidtodate,if(invoicetype='CPCN' or invoicetype='CPON' or invoicetype='CBCN' or invoicetype='CBON' or invoicetype='CPUB' or invoicetype='CPGU' or invoicetype='CPSO',invoiceamount,
fullinvoiceamount))) AS amount,
SUM(acis_cost) AS cost, (SUM(if(paidtodate>0,paidtodate,invoiceamount))-SUM(acis_cost)) AS profit FROM tblclientinvoices
Run Code Online (Sandbox Code Playgroud)

是否有SQLAlchemyish方法来构造此查询? - 我尝试使用SQlAlchemy谷歌搜索Mysql IF的声明,但画了空白.

非常感谢!

sqlalchemy flask-sqlalchemy

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

django模板中的表单字段值

快问,

我可以使用输出表单字段的值

{{ form.field.value }}
Run Code Online (Sandbox Code Playgroud)

但我似乎无法在if语句中检查该值.

{% if form.field.value == 'whatever' %}
Run Code Online (Sandbox Code Playgroud)

总是失败..任何想法?

该字段是布尔类型字段.

编辑 - 下面给出的答案适用于某些领域..这是我想要做的;

表单字段是模型中的boolen字段,在表单中使用此代码;

self.fields['information_request'] = forms.TypedChoiceField(choices=((True, 'Yes'), (False, 'No')), widget=forms.RadioSelect, coerce=lambda x: x and (x.lower() != 'false'))
Run Code Online (Sandbox Code Playgroud)

使用{{form.information_request.value}}时输出是正确的(例如,True或False) - 但是当我在模板中的IF语句中使用它时 - 它永远不会起作用..

python django

2
推荐指数
1
解决办法
4166
查看次数

AngularJs承诺承诺

嘿家伙我正在将一些数据发布到服务器然后基于几个变量再次发布到循环内的不同URL.

到目前为止我用的是一个例子:

    $scope.items = [{'name':'Test1','hasd':1,'hase':1},{'name':'Test2','hasd':0,'hase':1}];
    var promises = [];

    angular.forEach($scope.items,function(obj) {
    promises.push($http({
        type:'post',
        url:'test',
        data:obj
      }).then(function(response) { 
          if(response.status==201) {
             //do another http call
             if(obj.hasd==1) {
                $http({}).then(function() { 
                    var something=1; 
                });
             }
          }
        }));

   $q.all(promises).then(function(){
      alert('done');
   });
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,它只是查看最初的$ http呼叫的承诺,而不是任何内部呼叫.有没有办法将所有$ http调用添加到循环内的promise中?

干杯,本

angularjs angular-promise

2
推荐指数
1
解决办法
3271
查看次数

Jquery最近不起作用

我已经尝试了一段时间才弄清楚为什么我永远无法从jquery获得"最接近"的功能.

说我有这个代码;

<form>
<input type='text' name='q'>
<a href='javascript:void(0);' id='search_items'>Search</a>
</form>
Run Code Online (Sandbox Code Playgroud)

为什么以下始终警告"未定义"?

$("#search_items").bind('click', function () {
    var q = $(this).closest("input[name=q]").val();
    alert(q);
});
Run Code Online (Sandbox Code Playgroud)

提前致谢!干杯,本

jquery

0
推荐指数
1
解决办法
3491
查看次数