예제 #1
0
파일: views.py 프로젝트: adlius/osf.io
def conference_data(meeting):
    try:
        conf = Conference.find_one(Q('endpoint', 'iexact', meeting))
    except ModularOdmException:
        raise HTTPError(httplib.NOT_FOUND)

    nodes = Node.objects.filter(tags__id__in=Tag.objects.filter(name__iexact=meeting, system=False).values_list('id', flat=True), is_public=True, is_deleted=False)

    ret = [
        _render_conference_node(each, idx, conf)
        for idx, each in enumerate(nodes)
    ]
    return ret
예제 #2
0
def conference_data(meeting):
    try:
        conf = Conference.find_one(Q('endpoint', 'iexact', meeting))
    except ModularOdmException:
        raise HTTPError(httplib.NOT_FOUND)

    nodes = AbstractNode.objects.filter(tags__id__in=Tag.objects.filter(
        name__iexact=meeting, system=False).values_list('id', flat=True),
                                        is_public=True,
                                        is_deleted=False)

    ret = [
        _render_conference_node(each, idx, conf)
        for idx, each in enumerate(nodes)
    ]
    return ret
예제 #3
0
def populate_conferences(dev=False):
    if dev:
        Conference.remove()
    date_format = '%b %d %Y'
    for meeting, attrs in MEETING_DATA.iteritems():
        meeting = meeting.strip()
        admin_emails = attrs.pop('admins', [])
        admin_objs = []
        if not dev:
            for email in admin_emails:
                try:
                    user = OSFUser.find_one(Q('username', 'iexact', email))
                    admin_objs.append(user)
                except ModularOdmException:
                    raise RuntimeError(
                        'Username {0!r} is not registered.'.format(email))

        # Convert string into datetime object
        try:
            attrs['end_date'] = datetime.strptime(attrs.get('end_date'),
                                                  date_format)
            attrs['start_date'] = datetime.strptime(attrs.get('start_date'),
                                                    date_format)
        except TypeError:
            print '** Meeting {} does not have a start or end date. **'.format(
                meeting)
        custom_fields = attrs.pop('field_names', {})

        conf = Conference(endpoint=meeting, admins=admin_objs, **attrs)
        conf.field_names.update(custom_fields)
        try:
            conf.save()
        except ModularOdmException:
            conf = Conference.find_one(Q('endpoint', 'eq', meeting))
            for key, value in attrs.items():
                if isinstance(value, dict):
                    current = getattr(conf, key)
                    current.update(value)
                    setattr(conf, key, current)
                else:
                    setattr(conf, key, value)
            conf.admins = admin_objs
            changed_fields = conf.save()
            if changed_fields:
                print('Updated {}: {}'.format(meeting, changed_fields))
        else:
            print('Added new Conference: {}'.format(meeting))
예제 #4
0
def populate_conferences(dev=False):
    if dev:
        Conference.remove()
    date_format = '%b %d %Y'
    for meeting, attrs in MEETING_DATA.iteritems():
        meeting = meeting.strip()
        admin_emails = attrs.pop('admins', [])
        admin_objs = []
        if not dev:
            for email in admin_emails:
                try:
                    user = User.find_one(Q('username', 'iexact', email))
                    admin_objs.append(user)
                except ModularOdmException:
                    raise RuntimeError('Username {0!r} is not registered.'.format(email))

        # Convert string into datetime object
        try:
            attrs['end_date'] = datetime.strptime(attrs.get('end_date'), date_format)
            attrs['start_date'] = datetime.strptime(attrs.get('start_date'), date_format)
        except TypeError:
            print '** Meeting {} does not have a start or end date. **'.format(meeting)
        custom_fields = attrs.pop('field_names', {})

        conf = Conference(
            endpoint=meeting, admins=admin_objs, **attrs
        )
        conf.field_names.update(custom_fields)
        try:
            conf.save()
        except ModularOdmException:
            conf = Conference.find_one(Q('endpoint', 'eq', meeting))
            for key, value in attrs.items():
                if isinstance(value, dict):
                    current = getattr(conf, key)
                    current.update(value)
                    setattr(conf, key, current)
                else:
                    setattr(conf, key, value)
            conf.admins = admin_objs
            changed_fields = conf.save()
            if changed_fields:
                print('Updated {}: {}'.format(meeting, changed_fields))
        else:
            print('Added new Conference: {}'.format(meeting))
예제 #5
0
파일: views.py 프로젝트: adlius/osf.io
def conference_results(meeting):
    """Return the data for the grid view for a conference.

    :param str meeting: Endpoint name for a conference.
    """
    try:
        conf = Conference.find_one(Q('endpoint', 'iexact', meeting))
    except ModularOdmException:
        raise HTTPError(httplib.NOT_FOUND)

    data = conference_data(meeting)

    return {
        'data': data,
        'label': meeting,
        'meeting': serialize_conference(conf),
        # Needed in order to use base.mako namespace
        'settings': settings,
    }
예제 #6
0
def conference_results(meeting):
    """Return the data for the grid view for a conference.

    :param str meeting: Endpoint name for a conference.
    """
    try:
        conf = Conference.find_one(Q('endpoint', 'iexact', meeting))
    except ModularOdmException:
        raise HTTPError(httplib.NOT_FOUND)

    data = conference_data(meeting)

    return {
        'data': data,
        'label': meeting,
        'meeting': serialize_conference(conf),
        # Needed in order to use base.mako namespace
        'settings': settings,
    }