当前位置: 首页>>代码示例>>Python>>正文


Python Node.clean方法代码示例

本文整理汇总了Python中models.Node.clean方法的典型用法代码示例。如果您正苦于以下问题:Python Node.clean方法的具体用法?Python Node.clean怎么用?Python Node.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Node的用法示例。


在下文中一共展示了Node.clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_from_path

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import clean [as 别名]
def create_from_path(path):
    """ Create a Node, Subject, Period, Assignment or AssignmentGroup from
    ``path``.

    Examples::

        assignmentgroup = create_from_path(
                'ifi:inf1100.spring05.oblig1.student1,student2')
        oblig1 = create_from_path(
                'ifi:inf1100.spring05.oblig1')
    """
    split = path.split(':', 1)
    nodes = split[0].split('.')
    for nodename in nodes:
        node = Node(short_name=nodename, long_name=nodename.capitalize())
        try:
            node.clean()
            node.save()
        except:
            node = Node.objects.get(short_name=nodename)
        last = node

    if len(split) != 2:
        return last
    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(parentnode=node, short_name=subjectname,
            long_name=subjectname.capitalize())
    try:
        subject.clean()
        subject.save()
    except:
        subject = Subject.objects.get(short_name=subjectname)
    last = subject

    # Period
    if len(pathsplit) > 1:
        periodname = pathsplit[1]
        period = Period(parentnode=subject, short_name=periodname,
                long_name=periodname.capitalize(), start_time=datetime.now(),
                end_time=datetime.now() + timedelta(10))
        try:
            period.clean()
            period.save()
        except:
            period = Period.objects.get(parentnode=subject,
                    short_name=periodname)
        last = period

    # Assignment
    if len(pathsplit) > 2:
        assignmentname = pathsplit[2]
        assignment = Assignment(parentnode=period, short_name=assignmentname,
                long_name=assignmentname.capitalize(), publishing_time=datetime.now())
        
        assignment.clean()
        try:
            assignment.save()
        except:
            assignment = Assignment.objects.get(parentnode=period,
                    short_name=assignmentname)
        last = assignment

    # Candidates
    if len(pathsplit) > 3:
        usernames = pathsplit[3].split(',')
        users = []
        for u in usernames:
            user = User(username=u)
            try:
                user.save()
            except:
                user = User.objects.get(username=u)
            users.append(user)
        assignment_group = AssignmentGroup(parentnode=assignment)
        assignment_group.clean()
        assignment_group.save()
        for user in users:
            assignment_group.candidates.add(Candidate(student=user))
        last = assignment_group
    return last
开发者ID:Amadiro,项目名称:devilry-django,代码行数:85,代码来源:testhelpers.py


注:本文中的models.Node.clean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。