Example #1
0
def lock(request):
    x, y = get_point(request.GET)
    ip = request.META['REMOTE_ADDR']
    if not Cell.is_locked(x, y):
        lock_res = Lock.can_lock(x, y, ip)
        if lock_res[0]:
            Cell.lock(x, y, ip)
            Lock.add(x, y, ip)
    
            return HttpResponse('success')
        else:
            return HttpResponse(lock_res[1]) # Error message
    
    else:
        return HttpResponse(u'Картинка заблокирована')
Example #2
0
    def extract(self, date, position):
        """
        Retrieve an atmospheric column for the given date and position.
        :param date: UTC valid datetime
        :param position: (lon, lat)
        :return: a `Column` object
        """
        (lon, lat) = self.model.round_position(position)
        self._update_array_and_shape(date)

        try:
            lon_idx = next(idx for (idx, lon2) in enumerate(self.shape['lons']) if abs(lon-lon2) < EPSILON)
            lat_idx = next(idx for (idx, lat2) in enumerate(self.shape['lats']) if abs(lat-lat2) < EPSILON)
        except StopIteration:
            raise ValueError("No preprocessed weather data for this position")

        np_column = self.array[lon_idx][lat_idx][:]
        column = []
        for p, cell in zip(self.shape['alts'], np_column):
            kwargs = {'p': p}
            for name, val in zip(SHORT_NAMES, cell):
                kwargs[name] = float(val)
            cell = Cell(**kwargs)
            column.append(cell)

        column = Column(
            grib_model=self.model,
            position=position,
            valid_date=self.model.round_time(date),
            analysis_date=parse(self.shape['analysis_date']),
            ground_altitude=self.extract_ground_altitude(position),
            cells=column,
            extrapolated_pressures=self.extrapolated_pressures)

        return column
Example #3
0
def index(request):
    locks = Cell.get_locks()
    context = {
        'cells': [ {'x': x+1,
                    'y': y+1,
                    'url': settings.MEDIA_URL + 'data/%s_%s.jpg' % (x+1, y+1),
                    'lock': locks.get((x+1, y+1), False),
        } for y in xrange(settings.TABLE[1]) for x in xrange(settings.TABLE[0]) ]
    }
    return render_to_response(request, 'index.html', context)
Example #4
0
def upload(request):
    if request.FILES:
        x, y = get_point(request.POST)
        if not Cell.is_locked(x, y):
            thumb = resize(StringIO(request.FILES['pic'].read()))
            thumb.save(os.path.join(settings.THUMBNAIL_PATH, '%s_%s.jpg' % (x, y)))

            log = get_logger('upload')
            log.info('%s (%s, %s)', request.META['REMOTE_ADDR'], x, y)
        #return render_to_response(request, 'upload_complete.html', {'x': x, 'y': y, 'thumb': thumb})
        return HttpResponseRedirect('/')

    else:
        x, y = get_point(request.GET)

        return render_to_response(request, 'upload.html', {'x': x, 'y': y})