web-dev-qa-db-ja.com

ctags、vimおよびpython code

次のコマンドでctagsを生成します

ctags -R --fields=+l --languages=python --python-kinds=-iv -f ./tags apps/employees/models.py

これは私のコードです

from Django.contrib.auth.models import AbstractUser
from Django.contrib.postgres.fields import HStoreField
from Django.core.validators import MaxValueValidator, MinValueValidator
from Django.db import models
from Django.utils import timezone
from Django.utils.translation import ugettext_lazy as _

from author.decorators import with_author
from Django_extensions.db.models import TimeStampedModel
from Django_fsm import FSMField
from imagekit import models as imagekitmodels
from imagekit.processors import ResizeToFill
from phonenumber_field.modelfields import PhoneNumberField
from timezone_field import TimeZoneField

from libs import utils

# Solution to avoid unique_together for email
AbstractUser._meta.get_field('email')._unique = True


def upload_user_media_to(instance, filename):
    """Upload media files to this folder"""
    return '{}/{}/{}'.format(
        instance.__class__.__name__.lower(), instance.id,
        utils.get_random_filename(filename))


__all__ = [
    'Employee']


@with_author
class Employee(AbstractUser, TimeStampedModel):
    """Custom user model.

    Attributes:
        department (Department): What department the employee is in
        avatar (file): user's avatar, cropeed to fill 300x300 px
        notifications (dict): settings for notifications to user
        first_name (str): first name
        last_name (str): last name
        email (str): email (should be unique), this is our username field
        is_staff (bool): designates whether the user can log into
            this admin site
        is_active (bool): designates whether this user should be
            treated as active
        date_joined (datetime): when user joined
    """

    HIRED = 'H'
    ACTIVE = 'A'
    SICK = 'S'
    VACATION = 'V'
    PTO = 'P'
    FIRED = 'F'

    STATUSES = (
        (HIRED, 'hired'),
        (ACTIVE, 'active'),
        (SICK, 'sick'),
        (VACATION, 'vacation'),
        (PTO, 'pto'),
        (FIRED, 'fired'),
    )

    status = FSMField(
        default=HIRED,
        choices=STATUSES,
        protected=True)

    branch = models.ForeignKey(
        'company.Branch',
        null=True,
        related_name='employees',
        editable=True)

    department = models.ForeignKey(
        'company.Department',
        help_text='What department the employee is in',
        null=True,
        related_name='employees',
        editable=True)

    worktype = models.ForeignKey(
        'company.Worktype',
        null=True,
        related_name='employees',
        editable=True)

    recruiter = models.ForeignKey(
        'Employee',
        null=True,
        related_name='recruits',
        editable=True)

    # direct supervisor of the employee
    supervisor = models.ForeignKey(
        'Employee',
        null=True,
        related_name='supervisees',
        editable=True)

    # other people interested in this employee
    # activities
    followers = models.ManyToManyField(
        'self',
        related_name='following')

    username_ldap = models.CharField(
        max_length=255,
        null=True)

    is_utilized = models.BooleanField(
        default=True)

    is_contractor = models.BooleanField(
        default=False)

    is_daily_report_required = models.BooleanField(
        default=True)

    utilization = models.IntegerField(
        default=100,
        validators=[
            MinValueValidator(0),
            MaxValueValidator(100)])

    avatar = imagekitmodels.ProcessedImageField(
        upload_to=upload_user_media_to,
        processors=[ResizeToFill(300, 300)],
        format='PNG',
        options={'quality': 100},
        editable=True,
        null=True,
        blank=False)

    date_start = models.DateTimeField(
        _('date started'),
        null=True,
        default=timezone.now)

    address = models.CharField(
        max_length=255,
        blank=True)

    city = models.CharField(
        max_length=255,
        blank=True)

    state = models.CharField(
        max_length=50,
        blank=True)

    Zip_code = models.CharField(
        max_length=20,
        blank=True)

    phone_number = PhoneNumberField(
        blank=True)

    cell_number = PhoneNumberField(
        blank=True)

    skype = models.CharField(
        max_length=255,
        blank=True)

    linkedin = models.CharField(
        max_length=255,
        blank=True)

    Twitter = models.CharField(
        max_length=255,
        blank=True)

    instagram = models.CharField(
        max_length=255,
        blank=True)

    facebook = models.CharField(
        max_length=255,
        blank=True)

    website = models.CharField(
        max_length=255,
        blank=True)

    timezone = TimeZoneField()

    birthdate = models.DateField(
        null=True)

    is_birthdate_hidden = models.BooleanField(
        default=False)

    comment = models.TextField(
        blank=True)

    bucket_default_job = models.CharField(
        max_length=255,
        blank=True)

    notifications = HStoreField(
        null=True)

    # so authentication happens by email instead of username
    # and username becomes sort of nick
    USERNAME_FIELD = 'email'

    # Make sure to exclude email from required fields if authentication
    # is done by email
    REQUIRED_FIELDS = ['username']

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = 'Employee'
        verbose_name_plural = 'Employees'

VIMはメソッドの引数(フィールド定義)である多くの不正なタグ(空白、デフォルト、編集可能など)を表示します

TagBarプラグインを使用しています: https://github.com/majutsushi/tagbar

質問

そして、問題はctagsにあるようです、それがクラス属性のみを出力し、それらの定義パラメータを出力しないようにctagsをどのように構成するべきですか?

5
DmitrySemenov

niversal-ctags のctagsを使用してください この問題 が解決され、その他多くの修正が行われました。

universal-ctagsが生成したタグ:

branch  tagbar_bug.py   /^    branch = models.ForeignKey($/;"   v       class:Employee
7
georgexsh