小编Nic*_*iou的帖子

Django 1.7数据迁移和用户组

我正在尝试使用django 1.7本机迁移系统实现数据迁移.这就是我所做的.

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations


def create_basic_user_group(apps, schema_editor):
    """Forward data migration that create the basic_user group

    """
    Group = apps.get_model('auth', 'Group')
    Permission = apps.get_model('auth', 'Permission')
    group = Group(name='basic_user')
    group.save()

    perm_codenames = (
        'add_stuff',
        '...',
    )

    # we prefere looping over all these in order to be sure to fetch them all
    perms = [Permission.objects.get(codename=codename)
             for codename in perm_codenames]

    group.permissions.add(*perms)
    group.save()


def remove_basic_user_group(apps, schema_editor):
    """Backward data migration that remove the basic_user …
Run Code Online (Sandbox Code Playgroud)

python migration django

8
推荐指数
2
解决办法
1817
查看次数

qmake - 清理额外的子目录

我有一个带有子目录的 Qt 4.8 项目。我将 *.pro 文件设置为在此目录中构建一个库,以便将它与我的应用程序的核心一起使用。这很好用。

子目录使用常规 Makefile。

我现在试图通过调用库的 Makefile 上的 clean 命令来增加清理这个子目录的可能性。

这是我现在得到的:

LIBS = bin/libfoo.a
QMAKE_EXTRA_TARGETS += somelib

# some lib
PRE_TARGETDEPS += somelib
somelib.commands = make -C lib/somelib LIB=../../bin/libfoo.a lib
somelib.clean_commands = make -C lib/somelib clean
Run Code Online (Sandbox Code Playgroud)

用这个库编译我的项目没有问题。

但是当我在 qmake 生成的 Makefile 上运行“make clean”时,不会调用“make -C lib/somelib clean”。

我怎样才能做到这一点?

c++ qt qmake makefile

5
推荐指数
0
解决办法
1957
查看次数

带有 ES6 导入的原始加载器

我正在尝试将 ES6 与 webpack 一起使用。javascript 模块导入/导出没问题,但我无法让 raw-loader 工作。

这是我打算在源文件中执行的操作

import template from './template.html'
Run Code Online (Sandbox Code Playgroud)

template.html 文件中包含原始 HTML。

module.exports = {
  context: __dirname,
  entry: [
    'babel-polyfill',
    './app/app.js',
  ],
  module: {
    preLoaders: [
      {
        test: /\.js$/,
        include: __dirname + '/app/',
        loader: 'eslint-loader',
      },
    ],
    loaders: [
      {
        test: /\.js$/,
        include: __dirname + '/app/',
        loader: 'babel-loader?presets[]=es2015',
      },
      {
        test: /\.html$/,
        include: __dirname + '/app/',
        loader: 'raw-loader',
      },
    ],
  },
  output: {
    path: './build/',
    filename: 'app.js',
  },
};
Run Code Online (Sandbox Code Playgroud)

当我启动 webpack 时,代码是这样生成的:

  module.exports = "module.exports = …
Run Code Online (Sandbox Code Playgroud)

ecmascript-6 webpack raw-loader

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

PyQt5 存根文件

我刚刚开始了一个当前在 virtualenv 中运行的 PyQt5 项目。PyQt5 是使用经典的pip install pyqt5 安装的

我想使用 mypy 键入检查我的应用程序。但是当我运行它时,我收到一个错误,告诉我没有 PyQt5 的存根文件。

myapp/__main__.py:3: error: No library stub file for module 'PyQt5.QtWidgets
Run Code Online (Sandbox Code Playgroud)

我检查了我的 virtualenv 的站点包,确实,里面没有任何.pyi文件。

检查文档,我看到如果编译,可以生成存根文件(并且至少可以从 PyQt5.6 开始存在,我使用的是 5.10)。

有没有办法在不需要手动编译库的情况下获取这些文件?

python-3.x pyqt5 mypy

5
推荐指数
2
解决办法
1725
查看次数

检查 std::filesystem::path 是否在目录中

我有一个由std::filesystem::path. 我想向此路径添加一些用户提供的文件名,并确保生成的路径不在根目录之外。

例如:

    std::filesystem::path root = "/foo/bar";
    std::filesystem::path userFile = "ham/spam";
    std::filesystem::path finalPath = root / userFile;
Run Code Online (Sandbox Code Playgroud)

最后的路径没问题,就在里面/foo/bar。但是如果我给../ham/spam这个userFile变量,这将导致一个文件在 define 之外rootPath

如何检查生成的文件是否保持在其允许的边界内?

c++ c++17 std-filesystem

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

Vue.js、Typescript 和 VeeValidate 打字

我正在尝试使用 Typescript 构建一个严格键入的 vue.js 项目。

我使用 VeeValidate 来构建表单。我使用对 VeeValidate ValidationObserver 的引用来处理提交的表单。我也使用 vue-class-component。

这是我尝试在代码中键入 ValidationObserver 组件的方式。

<template>
  <ValidationObserver tag="form" ref="repertoireForm" @submit.prevent="submitForm">
    <ValidationProvider rules="required"></ValidationProvider>
  </ValidationObserver>
</template>


<script lang="ts">

import Vue from 'vue';
import Component from 'vue-class-component';
import {ValidationObserver, ValidationProvider} from 'vee-validate';

@Component({
  components: {
    ValidationObserver,
    ValidationProvider,
  },
})
export default class RepertoireForm extends Vue 
  $refs!: {
    // here is what I'm trying to type
    repertoireForm: ValidationObserver,
  }

  async submitForm(e: Event): Promise<void> {
    const valid = await this.$refs.repertoireForm.validate();

    // some submit routine here …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js vee-validate

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