예제 #1
0
def import_ballot(item, last_ballot, cache, fields=None):
    if fields is None:
        fields = ballot_fields
    entry = item.as_dict(fields)
    #if entry['number'] is None:
    #    return None
    try:
        number = entry['number'].as_int()
    except (ValueError, TypeError):
        return None
    if number == 0:
        number = cache.get_next_lb_number()
        cache.set_next_lb_number(number + 1)
    b = None
    try:
        b = Ballot.objects.get(number=number)
    except Ballot.DoesNotExist:
        b = Ballot(number=number)
    for field in b._meta.fields:
        if not field.primary_key:
            try:
                value = to_python(field, entry[field.attname].value) if entry[
                    field.attname] is not None else None
                setattr(b, field.attname, value)
            except KeyError:
                pass
    try:
        b.project = cache.get_project(
            task_group=entry['project.task_group'].value)
    except KeyError:
        b.project = Project.objects.get(
            task_group=entry['project.task_group'].value)
        cache.put_project(b.project)
    if b.opened is None:
        set_date(b, 'closed', entry['date'].value, format='%Y-%m-%d')
        b.opened = b.closed + datetime.timedelta(days=-15)
    if b.pool is None:
        try:
            b.pool = int(b.vote_for) + int(b.vote_against) + int(
                b.vote_abstain)
        except TypeError:
            pass
    #b.save()
    return b
예제 #2
0
def import_html_sponsor_ballot(item, last_ballot, cache):
    class Container(object):
        pass

    entry = item.as_dict(html_sponsor_ballot_fields)
    tg = entry['Group'].strip()
    if not tg:
        if entry['Disapprove'] and last_ballot is not None:
            try:
                last_ballot.vote_invalid = as_int(entry['Disapprove'])
            except ValueError:
                pass
        return None
    if entry['Draft'][0] == 'D':
        entry['Draft'] = entry['Draft'][1:]
    try:
        float(entry['Draft'])
    except (ValueError, TypeError):
        entry['Draft'] = 0
    if tg.lower().startswith('std. '):
        std = tg[5:]
        try:
            project = cache.get_project(name=std)
        except KeyError:
            try:
                project = Project.objects.get(name=std)
            except Project.DoesNotExist:
                return None
    else:
        if tg.lower().startswith('p802.11-rev'):
            tg = 'TG' + tg[11:]
        elif tg.lower().startswith('p802.11'):
            tg = 'TG' + tg[7:]
        try:
            project = cache.get_project(task_group=tg)
        except KeyError:
            try:
                project = Project.objects.get(task_group=tg)
            except Project.DoesNotExist:
                return None
    obj = Container()
    if '/' in entry['Closed']:
        set_date(obj, 'opened', entry['Opened'], format='%d/%m/%Y')
        set_date(obj, 'closed', entry['Closed'], format='%d/%m/%Y')
    else:
        set_date(obj, 'opened', entry['Opened'], format='%Y-%m-%d')
        set_date(obj, 'closed', entry['Closed'], format='%Y-%m-%d')
    try:
        b = Ballot.objects.get(project=project,
                               draft=entry['Draft'],
                               closed=obj.closed)
    except Ballot.DoesNotExist:
        lbnum = cache.get_next_lb_number()
        b = Ballot(project=project,
                   draft=entry['Draft'],
                   number=lbnum,
                   closed=obj.closed,
                   opened=obj.opened)
        cache.set_next_lb_number(lbnum + 1)
    if 'recirc' in entry['Ballot Type'].lower():
        b.ballot_type = 'SR'
    else:
        b.ballot_type = 'SI'
    #b.result = as_int(entry['Approve_pct'])
    b.vote_for = as_int(entry['Approve'])
    b.vote_against = as_int(entry['Disapprove'])
    b.vote_abstain = as_int(entry['Abstain'])
    if entry['Cmnt']:
        b.comments = as_int(entry['Cmnt'])
    b.pool = as_int(entry['Pool'])
    #b.save()
    return b
예제 #3
0
def import_html_letter_ballot(item, last_ballot, cache):
    entry = item.as_dict(html_ballot_fields)
    if entry['number'] and entry['task_group']:
        lbnum = as_int(entry['number'])
        try:
            b = Ballot.objects.get(number=lbnum)
        except Ballot.DoesNotExist:
            b = Ballot(number=lbnum)
        if entry['task_group'] == 'TGm':
            # TODO: Find a better solution
            entry['task_group'] = 'TGma'
        try:
            wg = cache.get_project(task_group=entry['task_group'])
        except KeyError:
            try:
                wg = Project.objects.get(task_group=entry['task_group'])
            except Project.DoesNotExist:
                entry['task_group'] = entry['task_group'][:-1] + entry[
                    'task_group'][-1].lower()
                try:
                    wg = Project.objects.get(task_group=entry['task_group'])
                except Project.DoesNotExist:
                    return None
        b.project = wg
        try:
            index = entry['comments'].index('Draft ')
            b.draft = entry['comments'][index + 6:]
        except ValueError:
            try:
                index = entry['documents'].index('_D')
                index2 = entry['documents'].index('.pdf')
                b.draft = entry['documents'][index + 2:index2]
            except ValueError:
                b.draft = 0
        try:
            b.instructions_url = entry['instructions'].anchor
        except AttributeError:
            b.instructions_url = entry['instructions']
        try:
            b.draft_url = entry['documents'].anchor
        except AttributeError:
            b.draft_url = make_url(
                entry['documents'],
                '/11/private/Draft_Standards/11%s/' % (wg.task_group[2:]))
        b.pool = as_int_or_none(entry['result'])
        set_date(b, 'opened', entry['opened'])
        set_date(b, 'closed', entry['closed'])
        if b.opened is None or b.closed is None:
            raise Exception("Failed to find date in " + str(entry))
        comments = entry['comments'].lower()
        if comments.find('recirculation') >= 0:
            b.ballot_type = Ballot.WGRecirc.code
        elif comments.find('procedural') >= 0:
            b.ballot_type = Ballot.Procedural.code
        else:
            b.ballot_type = Ballot.WGInitial.code
        return b
    if last_ballot is None:
        return None
    if entry['draft']:
        draft = entry['draft'].lower()
        if 'redline' in draft:
            try:
                last_ballot.redline_url = entry['documents'].anchor
            except AttributeError:
                last_ballot.redline_url = None  #make_url(entry['documents'],'/11/private/Draft_Standards/11%s/'%(last_ballot.project.task_group[2:]))
        elif 'resolution' in draft:
            try:
                last_ballot.resolution_url = entry['documents'].anchor
            except AttributeError:
                last_ballot.resolution_url = make_url(
                    entry['documents'], '/11/private/Draft_Standards/11%s/' %
                    (last_ballot.project.task_group[2:]))
        elif 'comment' in draft:
            try:
                last_ballot.template_url = entry['documents'].anchor
            except AttributeError:
                last_ballot.template_url = '/11/LetterBallots/LB%ds/LB%d_comment_form.xls' % (
                    last_ballot.number, last_ballot.number)
        elif 'pool' in draft:
            try:
                last_ballot.pool_url = entry['documents'].anchor
            except AttributeError:
                last_ballot.pool_url = '/11/LetterBallots/LB%ds/LB%d_voters_list.xls' % (
                    last_ballot.number, last_ballot.number)
    result_type = entry['result_type'].lower(
    ) if entry['result_type'] is not None else None
    #if result_type =='approve%':
    #    last_ballot.result  = as_int_or_none(item[-1])
    if result_type == 'approve':
        last_ballot.vote_for = as_int_or_none(entry['result'])
    elif result_type == 'disapprove':
        last_ballot.vote_against = as_int_or_none(entry['result'])
    elif result_type == 'abstain':
        last_ballot.vote_abstain = as_int_or_none(entry['result'])
    return None