小编Pat*_*son的帖子

Sass错误:选择器组可能无法扩展

我在尝试将我的SCSS文件编译成CSS时遇到错误.错误内容为:"选择器组可能无法扩展"以引用此行@extend .btn, .btn-link;.

注意:我正在导入Bootstrap以在我的主scss文件中使用.

完整片段:

button {
    @extend .btn, .btn-link;
    background-color: $lf-green;
    color: #fff;
    font-size: 10px;
    padding: 2px 5px;
    text-transform: uppercase;

    &:hover {
        background: rgba(5,97,43,0.9);
        color: #fff;
        text-decoration: none;
    }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

谢谢!

更新:

后代:我无法做到这一点的原因是因为我通过node-sass使用lib-sass,它不与通过传统方式https://github.com/andrew/node提供的当前sass版本相匹配-sass#reporting-sass-compilation-and-syntax-issues.

css sass twitter-bootstrap

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

如何在Django模型上定义任何一年的月份范围?

我有一个名为Event的Django模型,它具有事件日期的日期字段:

class Event(models.Model):
    event_date = models.DateField()
Run Code Online (Sandbox Code Playgroud)

我希望能够在模型上设置一个方法来判断事件是"春季学期"事件还是"秋季学期"事件.

春季学期定义为1月至5月.秋天是八月到十二月.

我的目标是能够在一年的一般事件列表中按学期过滤.

我将如何编写定义每个学期的方法?

python django methods date

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

如何通过 sqlalchemy 查询从 Flask 流式传输 CSV?

我想使用他们在此处描述的技术从 Flask 流式传输 CSV :

from flask import Response

@app.route('/large.csv')
def generate_large_csv():
    def generate():
        for row in iter_all_rows():
            yield ','.join(row) + '\n'
    return Response(generate(), mimetype='text/csv')
Run Code Online (Sandbox Code Playgroud)

我有一个来自 sqlalchemy 的查询,它返回一个 Purchase 对象列表。我想将其写入 CSV,理想情况下可以自定义输出到文件的属性。

不幸的是,我目前得到一个空白的 CSV 作为输出:

@app.route('/sales_export.csv')
@login_required
def sales_export():
    """ Export a CSV of all sales data """
    def generate():
        count = 0
        fieldnames = [
            'uuid',
            'recipient_name',
            'recipient_email',
            'shipping_street_address_1',
            'shipping_street_address_2',
            'shipping_city',
            'shipping_state',
            'shipping_zip',
            'purchaser_name',
            'purchaser_email',
            'personal_message',
            'sold_at'
        ]
        for i, row in enumerate(Purchase.query.all()):
            if i == 0:
                yield …
Run Code Online (Sandbox Code Playgroud)

python csv flask

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

无法通过泛型类视图将'slug'字段传递到URL

我有两个出版物和员工模型:

class Publication(models.Model):
    BOOK_CHAPTER = 1
    ARTICLE = 2
    PUBLICATION_CHOICES = (
        (BOOK_CHAPTER, 'Book chapter'),
        (ARTICLE, 'Article'),
    )
    publication_type = models.IntegerField(choices=PUBLICATION_CHOICES)
    article_title = models.CharField(max_length=250, help_text='Limited to 250 characters. May also be used for book chapter titles.')
    slug = models.SlugField(help_text='Suggested value automatically generated from title.')
    primary_author = models.ForeignKey('Employee', limit_choices_to={'employee_type': 1}, help_text='Most of the time, this will be the faculty member to whom the publication is tied.')
    authors = models.CharField(max_length=250, help_text='Limited to 250 characters. Please adhere to accepted format for style. Include …
Run Code Online (Sandbox Code Playgroud)

django django-generic-views django-class-based-views

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

从JSON写入CSV时出现UnicodeEncodeError

尝试使用JSON写入CSV时出现以下错误:

Traceback (most recent call last):
File "twitter_search_csv.py", line 25, in <module>
status['retweet_count'],
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 139: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码:

import requests
import urllib2
from requests_oauthlib import OAuth1
import csv

auth = OAuth1('', '', '', '')
url = 'https://api.twitter.com/1.1/search/tweets.json?q=%23OpeningCeremony'

response = requests.get(url, auth=auth)

data = response.json()['statuses']

with open('olympic_search.csv', 'wb') as csvfile:
    f = csv.writer(csvfile)
    for status in data:
        f.writerow([
            status['id'],
            status['text'],
            status['created_at'],
            status['coordinates'],
            status['user']['id_str'],
            status['retweet_count'],
        ])
Run Code Online (Sandbox Code Playgroud)

python csv encoding json

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

测试不会在Django模型字段上引发ValidationError

如果上传的文件包含不在硬编码列表中的扩展名,我有一个基本的模型字段验证器来引发ValidationError.

模型表单仅从管理角度使用.但是在我的测试中,尽管给出了无效的文件扩展名,但我无法获得异常.我究竟做错了什么?

验证者:

import os
from django.core.exceptions import ValidationError


def validate_file_type(value):
    accepted_extensions = ['.png', '.jpg', '.jpeg', '.pdf']
    extension = os.path.splitext(value.name)[1]
    if extension not in accepted_extensions:
        raise ValidationError(u'{} is not an accepted file type'.format(value))
Run Code Online (Sandbox Code Playgroud)

型号:

from agency.utils.validators import validate_file_type
from django.db import models
from sorl.thumbnail import ImageField


class Client(models.Model):
    """
    A past or current client of the agency.
    """
    logo = ImageField(
        help_text='Please use jpg (jpeg) or png files only. Will be resized \
            for public display.',
        upload_to='clients/logos',
        default='', …
Run Code Online (Sandbox Code Playgroud)

python django unit-testing model

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

测试需要用Factory Boy进行用户身份验证的Django视图

我需要一个允许员工用户查看草稿状态对象的视图.但我发现很难为这个观点编写单元测试.

我正在使用Factory Boy进行设置:

class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User

    username = factory.LazyAttribute(lambda t: random_string())
    password = factory.PostGenerationMethodCall('set_password', 'mysecret')
    email = fuzzy.FuzzyText(
        length=12, suffix='@email.com').fuzz().lower()
    is_staff = True
    is_active = True

class ReleaseFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Release

    headline = factory.LazyAttribute(lambda t: random_string())
    slug = factory.LazyAttribute(lambda t: slugify(t.headline))
    author = factory.LazyAttribute(lambda t: random_string())
    excerpt = factory.LazyAttribute(lambda t: random_string())
    body = factory.LazyAttribute(lambda t: random_string())

class TestReleaseViews(TestCase):
    """
    Ensure our view returns a list of :model:`news.Release` objects.
    """

    def setUp(self):
        self.client = Client() …
Run Code Online (Sandbox Code Playgroud)

django django-unittest factory-boy

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

如何切换元素类,但是如果单击带有类的元素则删除类?

我想在点击img元素时切换"active"类.但是当点击具有"活动"类的元素时,我希望将其删除.

这是我目前正在使用的JS:

$('.employee_mugshot').click(function() {
      $(".employee_mugshot").removeClass("active");
      $(this).addClass('active');
});
Run Code Online (Sandbox Code Playgroud)

这是我在JSFiddle中的完整示例:http://jsfiddle.net/patrickbeeson/6ec2K/

jquery twitter-bootstrap

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