Ejemplo n.º 1
0
    def get(self, request, team_id, user_id, format=None):
        membership = get_object_or_404(TeamMembership, team=team_id, user=user_id)
        self.check_object_permissions(self.request, membership)

        PARAM_POLYLINE = 'polyline'
        include_polyline = request.query_params.get(PARAM_POLYLINE, 0)

        start, limit = loco_utils.get_query_start_limit(request)
        start = int(start)
        limit = int(limit)

        timezone = pytz.timezone('Asia/Kolkata')
        end_date = datetime.now(timezone) 
        if start:
            end_date -= relativedelta(months=start - 1)
            end_date = end_date.replace(day=1)
            end_date -= relativedelta(days=1)

        start_date = end_date - relativedelta(months=limit-1)
        start_date = start_date.replace(day=1, hour=0, minute=0, second=0)

        locations = analyzer.get_analyzed_user_locations(membership.user, start_date, end_date)
        dates = {l[0]:analyzer.remove_location_events(l[1]) for l in locations if l[1]}
        if include_polyline:
            response = Response(dates)
        else:
            response = Response(dates.keys())
            
        patch_response_headers(response, 3600*10)
        return response
Ejemplo n.º 2
0
def get_user_events(request, team_id, user_id, format=None):
    team = get_object_or_404(Team, id=team_id)
    if not team.is_admin(request.user):
        return Response(status=403)

    add_last_location = False
    user = team.members.get(id=user_id)
    timestamp = utils.get_query_datetime(request)

    if timestamp:
        events = team.get_visible_events_by_date(user, timestamp)
        if timestamp.date() == datetime.now().date():
            add_last_location = True
    else:
        start, limit = utils.get_query_start_limit(request)
        events = team.get_visible_events_by_page(user, start, limit)
        if start in [0, '0']:
            add_last_location = True

    data = serialize_events(events)
    if add_last_location:
        last_location = cache.get_user_last_location(user.id)
        if last_location:
            last_location['type'] = TYPE_LAST_LOCATION
            data.insert(0, last_location)

    return Response(data)
Ejemplo n.º 3
0
    def get(self, request, team_id, format=None):
        team = get_object_or_404(Team, id=team_id)
        self.check_object_permissions(self.request, team)

        PARAM_QUERY = 'query'
        query = request.query_params.get(PARAM_QUERY)

        start, limit = utils.get_query_start_limit(request)
        offset = timedelta(hours=5, minutes=30)
        date = timezone.now() + offset
        date = date.strftime('%Y-%m-%d')
        members = get_team_members(team.id, date, query)
        count = len(members)
        if members:
            members = members[start:start + limit]

        data = []
        for member in members:
            data.append({
                "name": member[3],
                "role": member[1],
                "user_id": member[2],
                "action": member[0],
            })

        results = {'count': count, 'data': data}
        return Response(results)
Ejemplo n.º 4
0
    def get(self, request, team_id, format=None):
        team = get_object_or_404(Team, id=team_id)
        self.check_object_permissions(self.request, team)

        PARAM_QUERY = 'query'
        PARAM_FILTERS = 'filters'
        search_options = {}
        query = request.query_params.get(PARAM_QUERY)
        if query:
            search_options['query'] = query

        filters = request.query_params.get(PARAM_FILTERS, '')
        if filters:
            search_options['filters'] = filters

        start, limit = utils.get_query_start_limit(request)
        merchants = solr.search_members(team.id, search_options, start, limit)
        if merchants.get('data'):
            merchants['csv'] = utils.get_csv_url('members', team.id, 0,
                                                 merchants.get('count'), query,
                                                 filters)
        else:
            merchants['csv'] = ''

        return Response(merchants)
Ejemplo n.º 5
0
    def get(self, request, team_id, format=None):
        team = get_object_or_404(Team, id=team_id)
        self.check_object_permissions(self.request, team)
        timestamp = utils.get_query_datetime(request)
        if timestamp:
            events = team.get_visible_events_by_date(request.user, timestamp)
        else:
            start, limit = utils.get_query_start_limit(request)
            events = team.get_visible_events_by_page(request.user, start,
                                                     limit)

        data = serialize_events(events)
        return Response(data)
Ejemplo n.º 6
0
    def get(self, request, team_id, format=None):
        PARAM_QUERY = 'query'
        filter_query = request.query_params.get(PARAM_QUERY)

        start, limit = utils.get_query_start_limit(request)
        team = get_object_or_404(Team, id=team_id)
        self.check_object_permissions(self.request, team)
        items = team.item_set.all()
        if filter_query:
            items = items.filter(name__icontains=filter_query)

        items = items.order_by('-created')[start:start + limit]
        serialized_items = serializers.ItemSerializer(items, many=True).data
        return Response(serialized_items)
Ejemplo n.º 7
0
    def get(self, request, format=None):
        PARAM_STATE = 'state'
        filter_state = request.query_params.get(PARAM_STATE)
        PARAM_QUERY = 'query'
        query = request.query_params.get(PARAM_QUERY)

        start, limit = utils.get_query_start_limit(request)
        cities = models.City.objects.all()
        if filter_state:
            cities = cities.filter(state__name__icontains=filter_state)

        if query:
            cities = cities.filter(name__icontains=query)

        cities = cities.order_by('-created')[start:start + limit]
        data = serializers.CitySerializer(cities, many=True).data
        return Response(data)
Ejemplo n.º 8
0
    def get(self, request, team_id, format=None):
        PARAM_USER_ID = "user"
        team = get_object_or_404(Team, id=team_id)
        self.check_object_permissions(self.request, team)
        start, limit = utils.get_query_start_limit(request)
        start = int(start)
        limit = int(limit)
        user_id = request.query_params.get(PARAM_USER_ID)
        plans = TourPlan.objects.filter(user__id=user_id,
                                        team=team).order_by("-dated")
        data = TourPlanSerializer(plans[start:start + limit], many=True).data
        count = plans.count()
        csv_url = ''
        if count > 0:
            csv_url = "/web/teams/{0}/plans/download/?user={1}&start={2}&limit={3}&format=csv".format(
                team_id, user_id, 0, count)

        response = {'data': data, 'count': count, 'csv': csv_url}

        return Response(data=response)