Пример #1
0
def validate_submission_rev(name, rev):
    if not rev:
        return 'Revision not found'

    try:
        rev = int(rev)
    except ValueError:
        return 'Revision must be a number'
    else:
        if not (0 <= rev <= 99):
            return 'Revision must be between 00 and 99'

        expected = 0
        existing_revs = [
            int(i.rev) for i in Document.objects.filter(name=name)
            if i.rev and i.rev.isdigit()
        ]
        log.assertion(
            '[ i.rev for i in Document.objects.filter(name=name) if not (i.rev and i.rev.isdigit()) ] == []'
        )
        if existing_revs:
            expected = max(existing_revs) + 1

        if rev != expected:
            return 'Invalid revision (revision %02d is expected)' % expected

    replaced_by = has_been_replaced_by(name)
    if replaced_by:
        return 'This document has been replaced by %s' % ",".join(
            rd.name for rd in replaced_by)

    return None
Пример #2
0
 def is_decendant_of(self, sought_parent):
     parent = self.parent
     decendants = [ self, ]
     while (parent != None) and (parent not in decendants):
         decendants = [ parent ] + decendants
         if parent.acronym == sought_parent:
             return True
         parent = parent.parent
     log.assertion('parent not in decendants')
     return False
Пример #3
0
def can_manage_group_type(user, group, type_id=None):
    if type_id is None:
        type_id = group.type_id
    log.assertion("isinstance(type_id, (type(''), type(u'')))")
    if type_id == "rg":
        return has_role(user, ('IRTF Chair', 'Secretariat'))
    elif type_id == "wg":
        return has_role(user, ('Area Director', 'Secretariat'))
    elif type_id == "team":
        if group and group.is_decendant_of("ietf"):
            return has_role(user, ('Area Director', 'Secretariat'))
        elif group and group.is_decendant_of("irtf"):
            return has_role(user, ('IRTF Chair', 'Secretariat'))
    elif type_id == "program":
        return has_role(user, (
            'IAB',
            'Secretariat',
        ))
    return has_role(user, ('Secretariat'))
Пример #4
0
def ensure_person_email_info_exists(name, email):
    addr = email
    email = None
    person = get_person_from_name_email(name, addr)

    # make sure we have a person
    if not person:
        person = Person()
        person.name = name
        log.assertion('isinstance(person.name, six.text_type)')
        person.ascii = unidecode_name(person.name).decode('ascii')
        person.save()

    # make sure we have an email address
    if addr and (addr.startswith('unknown-email-') or is_valid_email(addr)):
        active = True
        addr = addr.lower()
    else:
        # we're in trouble, use a fake one
        active = False
        addr = u"unknown-email-%s" % person.plain_ascii().replace(" ", "-")

    try:
        email = person.email_set.get(address=addr)
    except Email.DoesNotExist:
        try:
            # An Email object pointing to some other person will not exist
            # at this point, because get_person_from_name_email would have
            # returned that person, but it's possible that an Email record
            # not associated with any Person exists
            email = Email.objects.get(address=addr, person__isnull=True)
        except Email.DoesNotExist:
            # most likely we just need to create it
            email = Email(address=addr)
            email.active = active

        email.person = person
        if email.time is None:
            email.time = datetime.datetime.now()
        email.save()

    return person, email
Пример #5
0
def update_authors(draft, submission):
    persons = []
    for order, author in enumerate(submission.authors):
        person, email = ensure_person_email_info_exists(
            author["name"], author.get("email"))

        a = DocumentAuthor.objects.filter(document=draft,
                                          person=person).first()
        if not a:
            a = DocumentAuthor(document=draft, person=person)

        a.email = email
        a.affiliation = author.get("affiliation") or ""
        a.country = author.get("country") or ""
        a.order = order
        a.save()
        log.assertion('a.email_id != "none"')

        persons.append(person)

    draft.documentauthor_set.exclude(person__in=persons).delete()