小编Mar*_*ruz的帖子

在django中缓存查询结果

我正在尝试找到一种方法来缓存不会随频率变化的查询结果.例如,来自电子商务(手机,电视等)的产品类别.我正在考虑使用模板片段缓存,但在这个片段中,我将迭代这些类别的列表.此列表可在网站的任何部分使用,因此它位于我的base.html文件中.在渲染模板时,我是否始终发送类别列表?或者是否有更动态的方法来执行此操作,使列表始终在模板中可用?

django caching

43
推荐指数
2
解决办法
4万
查看次数

AngularJS和django tastypie返回的复杂JSON

我在AngularJS上编写了很少的资源来访问Tastypie API.一切都运行正常,除了细节:tastypie总是将实际结果封装在objectsJSON 的属性中,例如:

/api/v1/reminder/:

{
    meta: {
        limit: 20,
        next: null,
        offset: 0,
        previous: null,
        total_count: 3
    },
    objects: [{
        category: {
            color: "#999999",
            id: 1,
            name: "Groceries",
            resource_uri: "/api/v1/category/1"
        },
        description: "",
        due_date: "2010-10-16",
        id: 1,
        repeat: "weekly",
        resource_uri: "/api/v1/reminder/1",
        value: "-50"
    }, {
        category: {
            color: "#999999",
            id: 1,
            name: "Groceries",
            resource_uri: "/api/v1/category/1"
        },
        description: "",
        due_date: "2010-10-17",
        id: 2,
        repeat: "weekly",
        resource_uri: "/api/v1/reminder/2",
        value: "-50"
    }
}
Run Code Online (Sandbox Code Playgroud)

使用回调get()调用修复是很糟糕的:

Reminder.get().$then(function (result) {
    $scope.reminders …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-resource

10
推荐指数
1
解决办法
3785
查看次数

Google Analytics:自定义指标/维度与事件

自定义指标/维度和事件之间有什么区别?

据我所知,基本的区别是:

  • 度量标准在设置时不会立即发送,而是在随后的点击中发送;
  • 由于事件动作是针对事件类别,因此消息不与指标相关联;
  • 事件可用于实现目标;
  • 维度和指标具有使用限制.

我学会了先使用事件.我的代码中有以下事件(类别/操作):

Account / create

Transaction / create / <transaction type>

Transaction / create-first (the first time the user interacts with the app)

Transaction / remove
Run Code Online (Sandbox Code Playgroud)

以下针对这些事件的目标:

Create account -> Account/create
Create the first transaction (Transaction/create-first)
Run Code Online (Sandbox Code Playgroud)

我可以使用配置为显示Total events,按事件操作和类别过滤的度量窗口小部件或直接显示目标来查看报告中的这些数据,因为它们是度量标准.

但后来我发现了自定义指标,现在我不知道应该使用哪一个跟踪这些数据.虽然事件似乎更灵活,但我可以用两者获得相同的结果.使用自定义指标和维度,我可以进行以下配置:

度量

Total transactions
Created accounts
Removed transactions
Run Code Online (Sandbox Code Playgroud)

外形尺寸

Transaction type
Run Code Online (Sandbox Code Playgroud)

我弄错了吗?两者都解决了这个问题,但我相信现在选择合适的问题可能会让我免于未来的问题.

google-analytics google-analytics-api

9
推荐指数
2
解决办法
7032
查看次数

用于监听范围的通配符在AngularJs上播放$ on

有没有办法在AngularJS上使用通配符捕获范围广播?

例:

$rootScope.$on('*created', function () { // do stuff });

angularjs

8
推荐指数
1
解决办法
1426
查看次数

UITableViewController:使用动态行高度滚动到底部会在错误的位置开始动画

我已经正确配置基于雷Wenderlich指南发现有动态的行高表视图在这里:

我设置约束以从单元格的顶部到底部具有明确的约束线.我还设置了内容拥抱和内容压缩阻力优先级和估计行高.

这是我用来设置表视图的代码:

func configureTableView() {
    // its called on viewDidLoad()
    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 100.0
}

override func viewDidLoad() {
    super.viewDidLoad()

    configureTableView()

    for i in 1...20 {
        messages.append([
            "title": "foo \(i)",
            "message": "bla \(i)\nbla\nbla"
        ])
    }

    // this is because the actual row heights are not available until the next layout cycle or something like that
    dispatch_async(dispatch_get_main_queue(), {self.scrollToBottom(false)})
}

func scrollToBottom(animated:Bool) {
    let indexPath = NSIndexPath(forRow: self.messages.count-1, inSection: 0)

    self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
}
Run Code Online (Sandbox Code Playgroud)

这就是我添加新行的方式: …

uitableview swift

8
推荐指数
1
解决办法
8434
查看次数

如何在django上获取当前语言环境的"short_date_format"?

我已经成功地在我的项目上设置了L10N,并且我能够将日期转换为正确的格式.但是现在我需要在SHORT_DATE_FORMAT模板上或在context_processor中使用当前语言环境.

从它获取它django.conf.settings总是给我默认值,m/d/Y.区域设置当前设置为pt_BR,因此格式应该是d/m/Y.

In [42]: settings.LANGUAGE_CODE
Out[42]: 'pt-br'

In [43]: settings.USE_L10N
Out[43]: True

In [44]: settings.SHORT_DATE_FORMAT
Out[44]: 'm/d/Y'
Run Code Online (Sandbox Code Playgroud)

有线索吗?

顺便说一下,我真正想做的是:获取当前语言环境的格式,以便将其传递给bootstrap-datepicker插件.它目前正在使用,m/d/Y而django正在以d/m/Y格式提供日期.

django localization

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

如何让“setup.py bdist_egg”忽略特定的源文件?

我正在尝试为 django 应用程序构建一个包,但不包括所有测试模块。我试过设置

exclude = ["*.tests", "*.tests.*", "tests.*", "tests"]
Run Code Online (Sandbox Code Playgroud)

onfind_packages并定义 a MANIFEST.in,但测试总是被编译并包含在包中。

有什么线索吗?

python setuptools

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

从 tastypie 上的资源中删除列表端点

我的 api 上有一个资源,它总是返回登录的用户。该资源是只读的。我希望列表 uri 充当详细 uri,并删除详细 url。

因此,/api/v1/user/将返回登录的用户,任何其他 url 都会失败。这就是我为实现这一目标所做的事情:

class UserResource(ModelResource):
    class Meta:
        queryset = User.objects.all()
        fields = ['email', 'name']
        authentication = MultiAuthentication(SessionAuthentication(), BasicAuthentication())
        authorization = Authorization()
        list_allowed_methods = []
        detail_allowed_methods = ['get']

    def base_urls(self):
        '''
        The list endpoint behaves as the list endpoint.
        '''
        return [
            url(r"^(?P<resource_name>%s)%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
            url(r"^(?P<resource_name>%s)/schema%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_schema'), name="api_get_schema")
        ]

    def obj_get(self, bundle, **kwargs):
        '''
        Always returns the logged in user.
        '''
        return bundle.request.user

    def get_resource_uri(self, bundle_or_obj=None, …
Run Code Online (Sandbox Code Playgroud)

python rest tastypie

4
推荐指数
1
解决办法
2207
查看次数

如何让RadioSelect将图像作为无线电值?

我有以下表格:

class ReviewForm(forms.ModelForm):
class Meta:
    model = Review

    widgets = {
        'tipo' : forms.RadioSelect(),
    }
Run Code Online (Sandbox Code Playgroud)

但我想使用图像作为我的单选按钮的值,图像会根据选项而有所不同,如下所示:

<input type="radio" id="id_tipo_0" value="UP" name="tipo" /><img src="/images/thumb_up.gif"/>
<input type="radio" id="id_tipo_1" value="DOWN" name="tipo" /><img src="/images/thumb_DOWN.gif"/>
Run Code Online (Sandbox Code Playgroud)

我没有关于如何实现这一目标的线索.

django django-forms

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

Odoo:重用选项卡中另一个模型的树视图

我试图在 res.partner 的 formview 笔记本中放入一个新选项卡,其中包含一个带有相关对象列表的树视图(我实现的“调度”模型,其中有一个指向 res.partner 的 Many2one)。

我找不到办法做到这一点,谷歌搜索并没有多大帮助。如何将此树视图指向模型的现有树视图?以及如何指定域以便只显示正确的数据?]

res.partner 表单的当前代码是

<odoo>
    <data>
        <record model="ir.ui.view" id="partner_form">
            <field name="name">res.partner.form</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <xpath expr="//notebook/page[3]" position="attributes">
                    <attribute name="invisible">1</attribute>
                </xpath>
                <xpath expr="//notebook/page[3]" position="after">
                    <page string='Consultas'>
                    </page>
                </xpath>
            </field>
        </record>
    </data>
</odoo>
Run Code Online (Sandbox Code Playgroud)

python xml odoo

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

Freeradius:请求没有用户密码属性的休息模块

我正在尝试使用休息后端进行身份验证来设置半径服务器。我以以下项目为例:https : //github.com/fgsants/REST-API-FreeRADIUS

一切都已经设置好了,如果我使用以下命令来模拟在 radius 上的登录,一切都可以正常工作:

radtest bar passwd 127.0.0.1 10 testing123

其余后端接收/user/:username/mac?action=authorize然后/user/:username/mac?action=authenticate&password=passwd.

当我将 AP 配置为使用此半径服务器时,请求似乎与预期不同并且身份验证失败。这是尝试通过 AP 登录时半径服务器的输出:

(0) Received Access-Request Id 105 from 172.21.0.1:46358 to 172.21.0.3:1812 length 126
(0)   User-Name = "bar"
(0)   NAS-IP-Address = 192.168.0.21
(0)   NAS-Identifier = "RalinkAP1"
(0)   NAS-Port = 0
(0)   Called-Station-Id = "1A-0D-2C-1B-49-11"
(0)   Calling-Station-Id = "D4-9A-20-70-F4-0E"
(0)   Framed-MTU = 1400
(0)   NAS-Port-Type = Wireless-802.11
(0)   EAP-Message = 0x0201000801626172
(0)   Message-Authenticator = 0xbffda6639904c9026259be2a45b378c4
(0) # Executing section authorize from …
Run Code Online (Sandbox Code Playgroud)

freeradius

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