Ejemplo n.º 1
0
def get_countdown(request):
    """
    Gets the countdown representation for the hackathon
    """
    # Update the date_updated to your current time if you modify the return value of the countdown
    date_updated = datetime(year=2016,
                            month=5,
                            day=13,
                            hour=17,
                            minute=20,
                            second=0,
                            microsecond=0,
                            tzinfo=utc)

    client_updated = parse_date_last_updated(request)
    if client_updated and client_updated >= date_updated:
        return Response(data={'date_updated': now_as_utc_epoch()})

    start_time = datetime(year=2016,
                          month=9,
                          day=10,
                          hour=12,
                          minute=0,
                          second=0,
                          microsecond=0,
                          tzinfo=timezone('US/Eastern'))
    return Response(
        data={
            'start_time': to_utc_epoch(start_time),
            'countdown_duration': 129600000,  # 36 hours
            'hacks_submitted': 118800000,  # 33 hours
            'date_updated': now_as_utc_epoch()
        })
Ejemplo n.º 2
0
def get_map(request):
    """
    Gets the map with the pin location for the map and a URL from where to download the map

    Optional parameter low_res: use `True` or `1` if the client cannot handle high resolution images,
        defaults to False when not specified. Use only `0` if you wish to explicitly specify a high resolution.
    """
    # Update the date_updated to your current time if you modify the return value of the countdown
    date_updated = datetime(year=2016,
                            month=5,
                            day=13,
                            hour=17,
                            minute=20,
                            second=0,
                            microsecond=0,
                            tzinfo=utc)

    client_updated = parse_date_last_updated(request)
    if client_updated and client_updated >= date_updated:
        return Response(data={'date_updated': now_as_utc_epoch()})

    try:
        low_resolution_image = bool(
            int(request.query_params.get('low_res', False)))
    except ValueError:
        low_resolution_image = True

    static_file = 'assets/[email protected]' if not low_resolution_image else 'assets/grand-map.png'

    return Response(
        data={
            'image_url': request.build_absolute_uri(static(static_file)),
            'south_west_lat': 42.291820,
            'south_west_lon': -83.716611,
            'north_east_lat': 42.293530,
            'north_east_lon': -83.713641,
            'date_updated': now_as_utc_epoch()
        })
Ejemplo n.º 3
0
 def get_queryset(self):
     self.date_of_update = now_as_utc_epoch()
     return parse_date_last_updated(self.request)
Ejemplo n.º 4
0
def perform_scan(request):
    from scan_event import error_field
    if request.method == 'POST':
        information = request.POST
    else:
        information = request.GET

    scan_event_id = information.get('scan_event', None)
    user_id = information.get('user_id', None)
    if not scan_event_id or not user_id:
        raise ValidationError('Invalid fields provided')

    try:
        scan_event = ScanEvent.objects.get(pk=scan_event_id)
        user = get_user_model().objects.get(email=user_id)
    except (ScanEvent.DoesNotExist, get_user_model().DoesNotExist):
        raise ValidationError('Invalid scan event or user')

    if scan_event.expiry_date:
        if scan_event.deleted or to_utc_epoch(
                scan_event.expiry_date) < now_as_utc_epoch():
            raise ValidationError('Scan event is no longer valid')

    successful_scan = True
    error = None
    data = []
    scan_event_user_join = None
    if scan_event.number_of_allowable_scans:
        try:
            scan_event_user_join = ScanEventUser.objects.get(
                user=user, scan_event=scan_event)
            number_of_scans = scan_event_user_join.count
        except (ScanEventUser.DoesNotExist, get_user_model().DoesNotExist):
            number_of_scans = 0

        if number_of_scans >= scan_event.number_of_allowable_scans:
            successful_scan = False
            error = error_field('Can\'t scan again')

    success = True
    if scan_event.custom_verification:
        import MHacks.v1.scan_event as scan_event_verifiers
        try:
            success, data = getattr(scan_event_verifiers,
                                    scan_event.custom_verification)(request,
                                                                    user)
        except AttributeError:
            pass  # This shouldn't happen normally but we defensively protect against it
    successful_scan = successful_scan and success
    if error:
        data.append(error)
    scan_result = {'scanned': successful_scan, 'data': data}

    # Only if its a POST request do we actually "do" the scan
    # GET requests are peeks i.e. they don't modify the database at all
    # If there is no number_of_allowable_scans we don't do anything on a POST either (unlimited)
    if successful_scan and scan_event.number_of_allowable_scans and request.method == 'POST':
        if scan_event_user_join:
            scan_event_user_join.count += 1
        else:
            scan_event_user_join = ScanEventUser(user=user,
                                                 scan_event=scan_event,
                                                 count=1)
        scan_event_user_join.save()

    return Response(data=scan_result)