Beispiel #1
0
async def dump(client, message, **kwargs):
    def decorate(s):
        return '```ruby\n' + s + '```'

    name_id_fmt = '{0.name} ({0.id})'
    maxChars = 1800
    what = kwargs.get('what')
    if what is None or what == 'commands':
        for page in paginate(cmds.dump(), maxChars):
            await client.send_message(message.author, decorate(page))
    if what is None or what == 'profile':
        pass
    if what is None or what == 'servers':
        a = ArrayFormater('Servers', 3)
        a.add('Server Name (ID)', 'Owner Name (ID)', 'Trigger')
        for s in db.get_servers():
            server = message.server
            if s.server_id:
                server = client.get_server(s.server_id)
                a.add(name_id_fmt.format(server),
                      name_id_fmt.format(server.owner), str(s.trigger))
        for page in paginate(a.get(), maxChars):
            await client.send_message(message.author, decorate(page))
    if what is None or what == 'users':
        a = ArrayFormater('Users', 2)
        a.add('User Name (ID)', 'Challonge username')
        for u in db.get_users():
            if u.discord_id:
                user = None
                for server in client.servers:
                    user = discord.utils.get(server.members, id=u.discord_id)
                    if user:
                        break
                a.add(name_id_fmt.format(user), str(u.challonge_user_name))
        for page in paginate(a.get(), maxChars):
            await client.send_message(message.author, decorate(page))
    if what is None or what == 'tournaments':
        acc, exc = await get_account(app_config['devid'])
        if not acc:
            return
        a = ArrayFormater('Tournaments', 3)
        a.add('Server Name (ID)', 'Host Name (ID)', 'Tournament Url')
        for server in client.servers:
            for t in db.get_tournaments(server.id):
                host = discord.utils.get(server.members, id=t.host_id)
                url = 'Not Found'
                try:
                    t = await acc.tournaments.show(t.challonge_id)
                    url = t['full-challonge-url']
                except ChallongeException as e:
                    url = T_OnChallongeException.format(e)
                a.add(name_id_fmt.format(server), name_id_fmt.format(host),
                      url)
        for page in paginate(a.get(), maxChars):
            await client.send_message(message.author, decorate(page))
Beispiel #2
0
def get_word_list(page=1, sort=None, keyword=None):
    if sort is None or sort == '':
        sort = [('count', -1)]
    per_page = page_default['per_page']
    offset = (page - 1) * per_page
    collection = db['bayesian']
    if keyword is None or keyword == '':
        data_list = collection.find({
            'type': 'word_count'
        }, sort=sort).limit(per_page).skip(offset)
        count = collection.count_documents({'type': 'word_count'})
    else:
        data_list = collection.find(
            {
                'type': 'word_count',
                'word': {
                    '$regex': keyword
                }
            }, sort=sort).limit(per_page).skip(offset)
        count = collection.count_documents({
            'type': 'word_count',
            'word': {
                '$regex': keyword
            }
        })
    paging = paginate(page, per_page, count)
    return paging, data_list
Beispiel #3
0
    def get_comment(self):
        """It will return a json with the psy favorites.
        Args:
            vars (dict): it can contain the field you want order the list: _orderby

        Returns: If successful, this method returns a response body with the following structure:

                    auth_user: {
                    first_name: "Charlesetta",
                    last_name: "Bambas",
                    f_photo: "None"
                    },
                    t_psychologist: {
                    f_ranking: 3,
                    id: 17
                    }
        """

        fields = [self.db.auth_user.first_name, self.db.t_comment.f_comment]
        orderby_filter=["first_name"]

        if self.request.vars['_orderby'] in orderby_filter:
            orderby = self.request.vars['_orderby']
        else:
            orderby = 'id'

        arguments = dict()
        arguments["orderby"] = self.db.auth_user.__getattr__(orderby)

        query = (self.db.t_comment.f_user_id == self.auth.user.id)

        return paginate(self.db, self.request.args, self.request.vars, self.MAXITEMS, query, arguments, fields)
Beispiel #4
0
def detail_api(id):
    page = request.args.get('page', type=int, default=1)
    api = JsonMethods.get_api(id)
    endpoints = api.get('endpoints')
    total = len(endpoints)
    if total:
        try:
            endpoints = paginate(endpoints, Globals.ITEM_PER_PAGE, page,
                                 lambda x: int(x.get('id')))
        except:
            flash(
                'There is no %d pages of endpoints for API %d' %
                (page, api_id), 'danger')
            return redirect(url_for('views.list_endpoints'))

    pagination = Pagination(page=page,
                            per_page=Globals.ITEM_PER_PAGE,
                            total=total,
                            record_name='endpoints',
                            css_framework='bootstrap4')
    edit_api_form = EditApiForm()
    add_endpoint_form = AddEndpointForm()
    edit_endpoint_form = EditEndpointForm()
    add_field_form = AddFieldForm()
    return render_template('api_detailing.html',
                           api=api,
                           endpoints=endpoints,
                           pagination=pagination,
                           edit_api_form=edit_api_form,
                           add_endpoint_form=add_endpoint_form,
                           edit_endpoint_form=edit_endpoint_form,
                           add_field_form=add_field_form)
Beispiel #5
0
 def get_by_category(category, include_inactive=False, paginate=True):
     qry = {'category': category.upper()}
     if not include_inactive:
         qry.update({'active':True})
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #6
0
 def get_by_category(category, include_inactive=False, paginate=True):
     qry = {'category': category.upper()}
     if not include_inactive:
         qry.update({'active': True})
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #7
0
    def get_comment(self):
        """It will return a json with the psy favorites.
        Args:
            vars (dict): it can contain the field you want order the list: _orderby

        Returns: If successful, this method returns a response body with the following structure:

                    auth_user: {
                    first_name: "Charlesetta",
                    last_name: "Bambas",
                    f_photo: "None"
                    },
                    t_psychologist: {
                    f_ranking: 3,
                    id: 17
                    }
        """

        fields = [self.db.auth_user.first_name, self.db.t_comment.f_comment]
        orderby_filter = ["first_name"]

        if self.request.vars['_orderby'] in orderby_filter:
            orderby = self.request.vars['_orderby']
        else:
            orderby = 'id'

        arguments = dict()
        arguments["orderby"] = self.db.auth_user.__getattr__(orderby)

        query = (self.db.t_comment.f_user_id == self.auth.user.id)

        return paginate(self.db, self.request.args, self.request.vars,
                        self.MAXITEMS, query, arguments, fields)
Beispiel #8
0
    def get(self, request, pk=None):
        '''
            Lists all AuthEvents if not pk. If pk show the event with this pk
        '''
        data = {'status': 'ok'}
        user, _, _ = get_login_user(request)

        if pk:
            e = AuthEvent.objects.get(pk=pk)
            if (user is not None and user.is_authenticated() and
                permission_required(
                    user,
                    'AuthEvent',
                    ['edit', 'view'],
                    e.id,
                    return_bool=True)):
                aes = e.serialize()
            else:
                aes = e.serialize_restrict()

            extend_info = plugins.call("extend_ae_info", user, e)
            if extend_info:
                for info in extend_info:
                    aes.update(info.serialize())

            data['events'] = aes
        else:
            events = AuthEvent.objects.all()
            aes = paginate(request, events,
                           serialize_method='serialize_restrict',
                           elements_name='events')
            data.update(aes)
        return json_response(data)
Beispiel #9
0
def main(request):
    entries_per_page = 3
    num_page_links = 4

    query = ""
    category = ""
    if request.method == 'GET':
        query = request.GET.get('query', '')
        category = request.GET.get('category', '')
    if query:
        entry_list = Entry.objects.all().filter(title__icontains=query).order_by('-pub_date')
    elif category:
        entry_list = Category.objects.get(title=category).entry_set.all().order_by('-pub_date')
    else:
        entry_list = Entry.objects.all().order_by('-pub_date')

    page = request.GET.get('page')
    entries, page_list = paginate(entry_list, page, entries_per_page, num_page_links)

    return render(request, 'blog/main.html',
                  {'entries': entries,
                   'page_list': page_list,
                   'query': query,
                   'category': category,
                   'categories': Category.objects.all(),
                  })
Beispiel #10
0
 def get_by_voltage(voltage, include_inactive=False, paginate=True):
     qry = {'voltage': voltage}
     if not include_inactive:
         qry.update({'active': True})
     cur = db.feeders.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #11
0
def pesquisa(request):

    tipo  = request.GET.get('tipo' , None)
    chave = request.GET.get('chave', None)
    page  = request.GET.get('page', None)
    
    resultados = []

    if tipo and chave:
        resultados = buscar_deputados_cache(tipo, chave)
    else:
        resultados = cache.get('deputados')

    deputados = paginate(request, resultados, 16)

    context = { 
        'deputados': deputados,
        'total' : len(cache.get('deputados')),
        'chave' : chave
    }

    print deputados.number

    if request.is_ajax():
        if int(page) <= deputados.number:
            return HttpResponse(simplejson.dumps({ 'deputados' : deputados.object_list }))
        else:
            return HttpResponse(None)

    return render_to_response('app/deputados.html', context)
Beispiel #12
0
 def get_by_voltage(voltage, include_inactive=False, paginate=True):
     qry = {'voltage': voltage}
     if not include_inactive:
         qry.update({'active': True})
     cur = db.feeders.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #13
0
 def get_by_type(is_public, include_inactive=False, paginate=True):
     qry = {'public': is_public}
     if not include_inactive:
         qry.update({'active': True})
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #14
0
    def get(self):
        " Get either the list of works or search. "
        q = None

        if 'q' in self.request.params:
            # If 'q' in params find offset if given and search
            offset = int(self.request.params.get('offset', 0))
            # Unquote if we are continuing in a result set
            q = offset and unquote_plus(self.request.params['q']) or \
                self.request.params['q']
            logging.error(q)
            # Execute the search here
            works, info = models.Scene.search(q, 
                limit=self.PER_PAGE, offset=offset)
        else:
            # Otherwise just get the words in genre order.
            works, info = models.Work.all().order('genre').fetch(100), None
        
        path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html')
        self.response.out.write(template.render(path, { 
            'results':works, 
            'q':q,
            'info':info,
            'pagination': q and paginate(self, q, offset, self.PER_PAGE, info) or ''
        }))
Beispiel #15
0
 def get_by_type(is_public, include_inactive=False, paginate=True):
     qry = {'public': is_public}
     if not include_inactive:
         qry.update({'active':True})
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #16
0
def product_management():
    """
    A view to return all the products and sort and paginates them.

    Gets the sort search perameter. Code is from https://www.kite.com/python/
    answers/ how-to-get-parameters-from-a-url-using-flask-in-python
    """
    sort_by = request.args.get("sort")
    """
    Sort method is from https://docs.mongodb.com/manual/reference/
    method/cursor.sort/index.html
    """
    if sort_by:
        products = list(mongo.db.products.find().sort(sort_items(sort_by)))

    else:
        products = list(mongo.db.products.find().sort('name', 1))
    """
    Pagination code is from https://gist.github.com/mozillazg/
    69fb40067ae6d80386e10e105e6803c9
    """
    page, per_page, offset = get_page_args(page_parameter='page',
                                           per_page_parameter='per_page',
                                           per_page=10)
    pagination_products = paginate_items(products, offset, per_page)
    pagination = paginate(products, page, per_page)

    return render_template("product_management.html",
                           page_title="Product Management",
                           products=pagination_products,
                           pagination=pagination)
Beispiel #17
0
    def get(self, request, pk=None):
        '''
            Lists all AuthEvents if not pk. If pk show the event with this pk
        '''
        data = {'status': 'ok'}

        if pk:
            e = AuthEvent.objects.get(pk=pk)
            u = request.user
            if (u.is_authenticated()
                    and u.userdata.has_perms("AuthEvent", "admin", e.id)):
                aes = e.serialize()
            else:
                aes = e.serialize_restrict()
            data['events'] = aes
        else:
            events = AuthEvent.objects.all()
            aes = paginate(request,
                           events,
                           serialize_method='serialize_restrict',
                           elements_name='events')
            data.update(aes)

        jsondata = json.dumps(data)
        return HttpResponse(jsondata, content_type='application/json')
Beispiel #18
0
    def get(self, request, pk=None):
        '''
            Lists all AuthEvents if not pk. If pk show the event with this pk
        '''
        data = {'status': 'ok'}
        user, _ = get_login_user(request)

        if pk:
            e = AuthEvent.objects.get(pk=pk)
            if (user is not None and user.is_authenticated()
                    and permission_required(
                        user, 'AuthEvent', 'edit', e.id, return_bool=True)):
                aes = e.serialize()
            else:
                aes = e.serialize_restrict()

            extend_info = plugins.call("extend_ae_info", user, e)
            if extend_info:
                for info in extend_info:
                    aes.update(info.serialize())

            data['events'] = aes
        else:
            events = AuthEvent.objects.all()
            aes = paginate(request,
                           events,
                           serialize_method='serialize_restrict',
                           elements_name='events')
            data.update(aes)
        return json_response(data)
Beispiel #19
0
    def process_list(self, api_version, data): # pylint: disable=unused-argument
        """
        This method returns details for given set of Errata.

        :param data: data obtained from api, we're interested in data["errata_list"]

        :returns: dictionary containing detailed information for given errata list}

        """
        validate(data, JSON_SCHEMA)

        modified_since = data.get("modified_since", None)
        modified_since_dt = parse_datetime(modified_since)
        errata_to_process = data.get("errata_list", None)
        page = data.get("page", None)
        page_size = data.get("page_size", None)

        response = {"errata_list": {}}
        if modified_since:
            response["modified_since"] = modified_since

        if not errata_to_process:
            return response

        if len(errata_to_process) == 1:
            # treat single-label like a regex, get all matching names
            errata_to_process = self.find_errata_by_regex(errata_to_process[0])

        filters = []
        # if we have information about modified/published dates and receive "modified_since" in request,
        # compare the dates
        if modified_since:
            filters.append((self._filter_modified_since, [modified_since_dt]))

        errata_list = {}
        errata_page_to_process, pagination_response = paginate(errata_to_process, page, page_size, filters=filters)
        for errata in errata_page_to_process:
            errata_detail = self.cache.errata_detail.get(errata, None)
            if not errata_detail:
                continue

            errata_list[errata] = {
                "synopsis": none2empty(errata_detail[ERRATA_SYNOPSIS]),
                "summary": none2empty(errata_detail[ERRATA_SUMMARY]),
                "type": none2empty(errata_detail[ERRATA_TYPE]),
                "severity": none2empty(errata_detail[ERRATA_SEVERITY]),
                "description": none2empty(errata_detail[ERRATA_DESCRIPTION]),
                "solution": none2empty(errata_detail[ERRATA_SOLUTION]),
                "issued": none2empty(format_datetime(errata_detail[ERRATA_ISSUED])),
                "updated": none2empty(format_datetime(errata_detail[ERRATA_UPDATED])),
                "cve_list": errata_detail[ERRATA_CVE],
                "package_list": pkgidlist2packages(self.cache, errata_detail[ERRATA_PKGIDS]),
                "bugzilla_list": errata_detail[ERRATA_BUGZILLA],
                "reference_list": errata_detail[ERRATA_REFERENCE],
                "url": none2empty(errata_detail[ERRATA_URL])
                }
        response["errata_list"] = errata_list
        response.update(pagination_response)
        return response
async def get_environmental_readings(request: Request, db: Session = Depends(get_db)):
    has_permission(request, PermissionSet.RoomRead.value)
    return paginate(
        db=db,
        db_model=EnvironmentalReading,
        serializer=EnvironmentalReadingModel,
        request=request
    )
Beispiel #21
0
async def get_floors(request: Request, db: Session = Depends(get_db)):
    has_permission(request, PermissionSet.FloorRead.value)
    return paginate(
        db=db,
        db_model=Floor,
        serializer=FloorModel,
        request=request
    )
Beispiel #22
0
async def get_meter_snapshots(request: Request, db: Session = Depends(get_db)):
    has_permission(request, PermissionSet.MeterSnapshotRead.value)
    return paginate(
        db=db,
        db_model=MeterSnapshot,
        serializer=MeterSnapshotModel,
        request=request
    )
Beispiel #23
0
async def get_building_types(
        request: Request,
        db: Session = Depends(get_db),
):
    has_permission(request, PermissionSet.BuildingTypeRead.value)
    return paginate(db=db,
                    db_model=BuildingType,
                    serializer=BuildingTypeModel,
                    request=request)
def get_all_created_invitations(request: Request, *args, **kwargs):
    query = Invite.objects.filter(inviter=request.user).filter(
        invitee__activated=False)
    return paginate(
        db_model=Invite,
        serializer=InviteSerializer,
        request=request,
        query=query,
    )
 def get(self, request: Request, *args, **kwargs):
     if not has_permission(request.headers, PermissionSet.SupplyContractRead.value):
         return Response(data={'detail': 'User has no permissions for this action'},
                         status=status.HTTP_403_FORBIDDEN)
     return paginate(
         db_model=SupplyContract,
         serializer=SupplyContractSerializer,
         request=request,
     )
Beispiel #26
0
    def get(self, request, pk):
        permission_required(request.user, 'AuthEvent', 'edit', pk)
        e = get_object_or_404(AuthEvent, pk=pk)

        filter_str = request.GET.get('filter', None)
        query = ACL.objects.filter(object_type='AuthEvent', perm='vote', object_id=pk)

        if filter_str is not None:
            q = (Q(user__user__username__icontains=filter_str) |
              Q(user__user__email__icontains=filter_str) |
              Q(user__tlf__icontains=filter_str) |
              Q(user__metadata__icontains=filter_str))

            query = query.filter(q)

        # filter, with constraints
        query = filter_query(
            filters=request.GET,
            query=query,
            constraints=dict(
                filters=dict(
                    user__user__id=dict(
                        lt=int,
                        gt=int,
                    ),
                    user__user__is_active=dict(
                        equals=bool
                    ),
                    user__user__date_joined=dict(
                        lt=datetime,
                        gt=datetime
                    )
                ),
                order_by=[
                    'user__user__id',
                    'user__user__is_active',
                    'user__user__date_joined']
            ),
            prefix='census__',
            contraints_policy='ignore_invalid')

        def serializer(acl):
          return {
            "id": acl.user.user.pk,
            "username": acl.user.user.username,
            "active": acl.user.user.is_active,
            "date_joined": acl.user.user.date_joined.isoformat(),
            "metadata": acl.user.serialize_data()
          }

        acls = paginate(
          request,
          query,
          serialize_method=serializer,
          elements_name='object_list')
        return json_response(acls)
Beispiel #27
0
 def query(self, project_id=None, form_id=None, include_dropped=False,
             paginate=True, sort_by=None, show_only_field=None, **params):
     qry = {}
     if project_id:
         qry.update({'project_id': project_id})
     if form_id:
         qry.update({'_xform_id_string': form_id})
     if not include_dropped:
         qry.update({'$or': [{'dropped': False}, {'dropped': {'$exists': False}}]})
     if params:
         qry.update(params)
     
     # check if to restrict filter to duplicates only
     if show_only_field:
         # note: showing dropped records only does and doesn't qualify as 
         # duplicate records depending on how you think about it... In this
         # case we consider all records marked as dropped as duplicate and
         # it helps answer the question 'what records have been dropped?'
         if show_only_field == 'dropped':
             qry.update({show_only_field: True})
             
             # if query already contain references to dropped records
             # purge that and have just this criteria included... 
             if qry.get('$or') and 'dropped' in str(qry.get('$or')):
                 del qry['$or']
         elif show_only_field == 'updated':
             qry.update({
                 'last_updated': {'$exists': 1}, 
                 'last_updated': {'$ne': None}
             })
         elif show_only_field == 'with-updates':
             # setup a mumbo-jumbo non-record returning query if the query
             # is run against the captures update table
             if self._collection_name == 'updates':
                 qry = {'rseq': '~!@#$%^&*()_+'}
             else:
                 _rseqs = self.get_available_updates(show_only_field, **qry)
                 qry.update({'rseq': {'$in': _rseqs}})
         elif show_only_field == 'invalid-stations':
             codes = self.get_valid_station_codes(**qry)
             qry['station'] = {'$nin': codes}
         else:
             duplicates = self.get_duplicates(show_only_field, **qry)
             qry = {show_only_field: {'$in': duplicates[1]}}
     
     cur = self.db.find(qry)
     if not sort_by:
         cur = cur.sort((['datetime_today', pymongo.DESCENDING],
                         ['group', pymongo.ASCENDING],
                         ['rseq', pymongo.ASCENDING]))
     else:
         sort_args = []
         for sort_arg in sort_by:
             sort_args.append([sort_arg, pymongo.ASCENDING])
         cur = cur.sort(sort_args)
     return utils.paginate(cur, size=settings.NL_PAGE_SIZE) if paginate else cur
Beispiel #28
0
async def get_buildings(request: Request, db: Session = Depends(get_db)):
    has_permission(request, PermissionSet.BuildingRead.value)
    paginated = paginate(db=db,
                         db_model=Building,
                         serializer=BuildingModel,
                         request=request)
    for index, building in enumerate(paginated['items']):
        for user in building.responsible_people:
            user.user = get_user(user.user_id)
    return paginated
Beispiel #29
0
def index():
    if request.method == 'GET':

        context = utils.build_context(request)
        page = utils.get_page(request)

        all_entities = models.Entity.select()\
                            .where(models.Entity.active == True)\
                            .where(models.Entity.canonical_entity >> None)

        context['entities'] = all_entities\
                            .order_by(models.Entity.created.desc())\
                            .paginate(page, settings.ITEMS_PER_PAGE)

        context = utils.paginate(request, all_entities.count(), page, context)

        return render_template('entity_list.html', **context)

    if request.method == 'POST':
        payload = utils.clean_payload(dict(request.form))

        if not payload.get('name', None):
            return Response('bad request', 400)

        lookup = dict([(e.name, e.id) for e in models.Entity.select()])
        entity_list = list(lookup.keys())

        name = payload['name']
        score = 0

        if len(entity_list) > 0:
            name, score = process.extractOne(payload['name'], entity_list)

        response = {}
        response['request'] = {}
        response['request']['name'] = payload['name']
        response['request']['create_if_below'] = payload.get(
            'create_if_below', settings.MINIMUM_SCORE)
        response['response'] = {}
        response['response']['score'] = score

        if payload.get('create_if_below', None):
            if score < int(payload['create_if_below']):
                response = create_entity(response)
                return jsonify(response)

        if score < settings.MINIMUM_SCORE:
            response = create_entity(response)
            return jsonify(response)

        response['response']['created'] = False
        response['response']['name'] = name
        response['response']['uuid'] = lookup[name]

        return jsonify(response)
Beispiel #30
0
    def get_unassigned_xforms(include_inactive=False, paginate=True):
        xforms = []
        for p in Project.get_all(paginate=False):
            xforms.extend(p['xforms'])

        qry = {'id': {'$nin': xforms}}
        if not include_inactive:
            qry.update({'active': True})

        cur = db.xforms.find(qry)\
                .sort('id', pymongo.ASCENDING)
        return utils.paginate(cur) if paginate else cur
Beispiel #31
0
def getMyStock(account, page=1, is_paging=False):
    collection = db['stock']
    if is_paging:
        per_page = page_default['per_page']
        offset = (page - 1) * per_page
        data_list = collection.find({'account':account}, sort=[('date', -1)]).limit(per_page).skip(offset)
        count = data_list.count()
        paging = paginate(page, per_page, count)
        return paging, data_list
    else:
        data_list = collection.find({'account': account})
        return data_list
Beispiel #32
0
 def get(self, request, format=None):
     queryset = Files.objects.all()
     page = request.data.get('page')
     pagination = paginate(queryset, page, 10)
     serializer_class = FilesSerializer(pagination['objects'], many=True)
     response = {
         'result': serializer_class.data,
         'next': pagination['next_page'],
         'previous': pagination['prev_page'],
         'total_page': pagination['total_page']
     }
     return Response(response)
Beispiel #33
0
def routes_view():
    """
    curl -X get 'http://127.0.0.1:9093/routes/?size=2&page=1'
    """

    try:
        routes = mongo.db.route.find({}).sort('created', DESCENDING)
        result = paginate(request, data=routes)
        return send_response(request, result)

    except Error as e:
        return send_error(request, e.code)
Beispiel #34
0
    def retrieve_offers(payload):
        offers = Offer.query.order_by(
            Offer.id.desc()  # Latest first
        ).all()

        current_offers = paginate(request, offers)

        return jsonify({
            'success': True,
            'offers': [o.format() for o in current_offers],
            'total_offers': len(offers)
        }), 200
Beispiel #35
0
    def retrieve_calls(payload):
        calls = Call.query.order_by(
            Call.id.desc()  # Latest first
        ).all()

        current_calls = paginate(request, calls)

        return jsonify({
            'success': True,
            'calls': [c.format() for c in current_calls],
            'total_calls': len(calls)
        }), 200
Beispiel #36
0
    def get_unassigned_xforms(include_inactive=False, paginate=True):
        xforms = []
        for p in Project.get_all(paginate=False):
            xforms.extend(p['xforms'])

        qry = {'id': {'$nin': xforms}}
        if not include_inactive:
            qry.update({'active': True})

        cur = db.xforms.find(qry)\
                .sort('id', pymongo.ASCENDING)
        return utils.paginate(cur) if paginate else cur
Beispiel #37
0
def getAccountInfo(account, page=1, is_paging=False):
    collection = db['account']
    if is_paging:
        per_page = page_default['per_page']
        offset = (page - 1) * per_page
        data_list = collection.find({'account':account}, sort=[('date', -1)]).limit(per_page).skip(offset)
        count = data_list.count()
        paging = paginate(page, per_page, count)
        return paging, data_list
    else:
        date, _ = getDate()
        accountInfo = collection.find_one({'date':date, 'account':account})
        return accountInfo
Beispiel #38
0
    def query(self,
              project_id=None,
              form_id=None,
              include_dropped=False,
              paginate=True,
              sort_by=None,
              duplicate_field=None,
              **params):
        qry = {}
        if project_id:
            qry.update({'project_id': project_id})
        if form_id:
            qry.update({'_xform_id_string': form_id})
        if not include_dropped:
            qry.update(
                {'$or': [{
                    'dropped': False
                }, {
                    'dropped': {
                        '$exists': False
                    }
                }]})
        if params:
            qry.update(params)

        # check if to restrict filter to duplicates only
        if duplicate_field:
            # note: showing dropped records only does and doesn't qualify as
            # duplicate records depending on how you think about it... In this
            # case we consider all records marked as dropped as duplicate and
            # it helps answer the question 'what records have been dropped?'
            if duplicate_field == 'dropped':
                qry.update({duplicate_field: True})
                if qry.get('$or') and 'dropped' in str(qry.get('$or')):
                    del qry['$or']
            else:
                duplicates = self.get_duplicates(duplicate_field, **qry)
                qry = {duplicate_field: {'$in': duplicates[1]}}

        cur = self.db.find(qry)
        if not sort_by:
            cur = cur.sort((['datetime_today',
                             pymongo.DESCENDING], ['group', pymongo.ASCENDING],
                            ['rseq', pymongo.ASCENDING]))
        else:
            sort_args = []
            for sort_arg in sort_by:
                sort_args.append([sort_arg, pymongo.ASCENDING])
            cur = cur.sort(sort_args)
        return utils.paginate(cur,
                              size=settings.NL_PAGE_SIZE) if paginate else cur
Beispiel #39
0
    def get(self, request, pk):
        permission_required(request.user, 'AuthEvent', 'edit', pk)
        e = get_object_or_404(AuthEvent, pk=pk)

        filter_str = request.GET.get('filter', None)
        query = ACL.objects.filter(object_type='AuthEvent',
                                   perm='vote',
                                   object_id=pk)

        if filter_str is not None:
            q = (Q(user__user__username__icontains=filter_str)
                 | Q(user__user__email__icontains=filter_str)
                 | Q(user__tlf__icontains=filter_str)
                 | Q(user__metadata__icontains=filter_str))

            query = query.filter(q)

        # filter, with constraints
        query = filter_query(filters=request.GET,
                             query=query,
                             constraints=dict(filters=dict(
                                 user__user__id=dict(
                                     lt=int,
                                     gt=int,
                                 ),
                                 user__user__is_active=dict(equals=bool),
                                 user__user__date_joined=dict(lt=datetime,
                                                              gt=datetime)),
                                              order_by=[
                                                  'user__user__id',
                                                  'user__user__is_active',
                                                  'user__user__date_joined'
                                              ]),
                             prefix='census__',
                             contraints_policy='ignore_invalid')

        def serializer(acl):
            return {
                "id": acl.user.user.pk,
                "username": acl.user.user.username,
                "active": acl.user.user.is_active,
                "date_joined": acl.user.user.date_joined.isoformat(),
                "metadata": acl.user.serialize_data()
            }

        acls = paginate(request,
                        query,
                        serialize_method=serializer,
                        elements_name='object_list')
        return json_response(acls)
Beispiel #40
0
    def process_list(self, api_version, data):  # pylint: disable=unused-argument
        """
        Returns repository details.

        :param data: json request parsed into data structure

        :returns: json response with repository details
        """
        validate(data, JSON_SCHEMA)

        repos = data.get('repository_list', None)
        page = data.get("page", None)
        page_size = data.get("page_size", None)
        repolist = {}
        if not repos:
            return repolist

        if len(repos) == 1:
            # treat single-label like a regex, get all matching names
            repos = self.find_repos_by_regex(repos[0])

        repo_page_to_process, pagination_response = paginate(
            repos, page, page_size)

        for label in repo_page_to_process:
            for repo_id in self.cache.repolabel2ids.get(label, []):
                repo_detail = self.cache.repo_detail[repo_id]
                repolist.setdefault(label, []).append({
                    "label":
                    label,
                    "name":
                    repo_detail[REPO_NAME],
                    "url":
                    repo_detail[REPO_URL],
                    "basearch":
                    none2empty(repo_detail[REPO_BASEARCH]),
                    "releasever":
                    none2empty(repo_detail[REPO_RELEASEVER]),
                    "product":
                    repo_detail[REPO_PRODUCT],
                    "revision":
                    repo_detail[REPO_REVISION]
                })

        response = {
            'repository_list': repolist,
        }
        response.update(pagination_response)

        return response
Beispiel #41
0
def organization_search():
    data = {'organizations': []}
    name = request.values.get('name', u'', type=unicode)
    distance = request.values.get('distance', 0.0, type=float)
    page = request.values.get('page', 1, type=int)
    if distance:
        latitude = request.values.get('latitude', 0.0, type=float)
        longitude = request.values.get('longitude', 0.0, type=float)
        if latitude and longitude:
            org_query = organization_filter_by_distance(
                distance, longitude, latitude)
        else:
            data['status'] = PARAMETER_ERROR
            return json.dumps(data)
    else:
        org_query = Organization.query
    organization_list = org_query.filter(
        Organization.name.like(u'%' + name + u'%'))
    if distance:
        cmp_list = [(org, longitude, latitude) for org in organization_list]
        organization_list = paginate(sorted(cmp_list, cmp=cmp_distance), page)
        organization_list = [org[0] for org in organization_list]
    else:
        organization_list = organization_list.paginate(page, PER_PAGE,
                                                       False).items

    for organization in organization_list:
        location = Location.query.get(organization.location_id)
        city = City.query.get(location.city_id) if location else None
        org_dict = {
            'id': organization.id,
            'name': organization.name,
            'city': city.city if city else '',
            'district': location.district if location else '',
            'photo':
            STATIC_URL + organization.photo if organization.photo else '',
            'logo':
            STATIC_URL + organization.logo if organization.logo else '',
            'intro': organization.detail
        }
        if distance:
            org_dict['distance'] = get_organization_distance(
                longitude, latitude, organization.longitude,
                organization.latitude)
            if org_dict['distance'] <= distance:
                data['organizations'].append(org_dict)
        else:
            data['organizations'].append(org_dict)
    data['status'] = SUCCESS
    return json.dumps(data)
Beispiel #42
0
def history_orders(request):
    display, objects, form = search_orders(request)
    if display == "by_product":
        total = sum([item.total_price() for item in objects])
    else:
        total = sum([history.price for history in objects.distinct()])
    
    return render(request, "history/orders.html", {
        'filter_form': form,
        'objects': paginate(request, objects.distinct()),
        'display': display,
        'url_args': request.GET.urlencode(),
        'total': total
    })
Beispiel #43
0
def tab_orders(request):
    # Commandes à saisir
    if request.user.has_perm('order.custom_goto_status_4') and not request.user.is_superuser:
        order_list = Order.objects.exclude(provider__is_local = True)
        order_list = order_list.filter(
            Q(status__in = [2, 3, 4]) |
            Q(status = 1, team = get_teams(request.user)[0]) |
            Q(status = 1, items__username = request.user.username)
        ).distinct()
    # Commandes en cours - toutes équipes
    elif request.user.has_perm("team.custom_view_teams") and not request.user.is_superuser:
        order_list = Order.objects.filter(
            status__in = [2, 3, 4]
        ).distinct()
    # Commandes en cours - par équipe
    else:
        order_list = Order.objects.filter(status__in = [1, 2, 3, 4])
        order_list = order_list.filter(
            Q(items__username = request.user.username) |
            Q(team__in = get_teams(request.user))
        ).distinct()

    # Exclude confidential orders
    if not request.user.has_perm('budget.custom_view_budget'):
        order_list = order_list.filter(
            Q(items__is_confidential = False) |
            Q(items__username = request.user.username)
        ).distinct()

    # 
    # Filter order depending on received GET data
    form = FilterForm(data = request.GET)
    if len(request.GET.keys()) > 0 and form.is_valid():
        Q_obj = Q()
        Q_obj.connector = form.cleaned_data.pop("connector")
        Q_obj.children = []

        for key, value in form.cleaned_data.items():
            if value:
                Q_obj.children.append((key, value))

        order_list = order_list.filter(Q_obj)

    return render(request, "order/index.html", {
        'orders': paginate(request, order_list),
        'filter_form': form,
        'next': 'order:tab_orders',
        'next_page': 'page' in request.GET and request.GET['page'] or 1
    })
Beispiel #44
0
def history_budgets(request):
    if not request.user.has_perm("budget.custom_view_budget"):
        not_allowed_msg(request)
        return redirect('home')
    
    budgets = Budget.objects.filter(is_active = False)
    
    if not request.user.has_perm('team.custom_view_teams'):
        budgets = budgets.filter(team__in = get_teams(request.user))
    
    # 
    # Filter history_list depending on received GET data
    form = BudgetHistoryFilterForm(user = request.user, data = request.GET)
    if len(request.GET.keys()) > 0 and form.is_valid():
        Q_obj = Q()
        Q_obj.connector = form.cleaned_data.pop("connector")
        Q_obj.children  = []
        for key, value in form.cleaned_data.items():
            if value:
                if key == 'team':
                    Q_obj.children.append((key, value.name))  # value if of type 'Team' here
                else:
                    Q_obj.children.append((key, value))

        budget_lines = BudgetLine.objects.filter(
            budget_id__in = budgets.values_list("id", flat=True) 
       ).filter(Q_obj)
    else:
        budget_lines = BudgetLine.objects.none()
    
    return render(request, 'history/budgets.html', {
        'filter_form': form,
        'budgets': paginate(request, budgets),
        'budget_lines': paginate(request, budget_lines),
        'url_args': request.GET.urlencode()
    })
Beispiel #45
0
def tab_validation(request):
    teams = get_teams(request.user)

    # ORDERS THAT CAN BE SEEN
    see_all_teams = 'see_all_teams' in request.GET and request.GET['see_all_teams'] == '1'

    if request.user.has_perms(['team.custom_view_teams', 'order.custom_validate']):
        order_list = Order.objects.filter(status = 1).order_by('-date_created')
        if see_all_teams:
            order_list = order_list.exclude(team__in = teams)
        else:
            order_list = order_list.filter(team__in = teams)
    elif request.user.has_perm('order.custom_validate'):
        order_list = Order.objects.filter(team__in = teams, status = 1).order_by('-date_created')
    else:
        not_allowed_msg(request)
        return redirect('home')

    # BUDGETS THAT CAN BE SELECTED
    if request.user.has_perms(['team.custom_view_teams', 'budget.custom_view_budget']):
        budget_list = Budget.objects.filter(is_active = True)
    elif request.user.has_perm('budget.custom_view_budget'):
        budget_list = Budget.objects.filter(team__in = teams, is_active = True)
    else:
        budget_list = Budget.objects.none()

    # TEAMS THAT CAN BE SELECTED
    if request.user.has_perm("order.custom_order_any_team") or request.user.has_perm("team.custom_is_admin"):
        team_choices = [(team.id, team.name) for team in Team.objects.all()]
    else:
        team_choices = []

    return render(request, 'tab_validation.html', {
        'orders': paginate(request, order_list.distinct()),
        'budgets': budget_list.distinct(),
        'team_choices': team_choices,
        'credit_form': AddCreditForm(),
        'debit_form': AddDebitForm(),
        'see_all_teams': see_all_teams,
        'next': 'order:tab_validation'
    })
Beispiel #46
0
 def get_unassigned_uforms(include_inactive=False, paginate=True,
                           excluded_project=None):
     uforms = []
     for p in Project.get_all(paginate=False):
         if excluded_project and excluded_project['code'] != p['code']:
             uforms.extend(p['uforms'])
     
     # HACK: included the cust_updform regex pattern to support update
     # forms used for Hotoro 11KV Feeder...
     qry = { 
         'id_string': {
             '$nin': uforms,
             '$regex': '(f[0-9a-f]{3}_cu.+|cust_updform.+)'
         }
     }
     if not include_inactive:
         qry.update({'active': True})
     
     cur = db.xforms.find(qry)\
             .sort('object_id', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #47
0
    def get(self, request):
        object_type = request.GET.get('object_type', None)
        object_id = request.GET.get('object_id', None)
        perm = request.GET.get('perm', None)

        data = {'status': 'ok', 'perms': []}
        q = Q()
        if object_type:
            q = Q(object_type=object_type)
        if object_id:
            q &= Q(object_id=object_id)
        if perm:
            q &= Q(perm=perm)

        query = request.user.userdata.acls.filter(q)

        acls = paginate(request, query,
                       serialize_method='serialize',
                       elements_name='perms')
        data.update(acls)
        return json_response(data)
Beispiel #48
0
def knowledge_list(request,
                   category_slug=None,
                   template='django_knowledge/list.html',
                   Form=QuestionForm):

    if settings.LOGIN_REQUIRED and not request.user.is_authenticated():
        return HttpResponseRedirect(settings.LOGIN_URL+"?next=%s" % request.path)

    search = request.GET.get('title', None)
    questions = Question.objects.can_view(request.user)\
                                .prefetch_related('responses__question')

    if search:
        questions = questions.filter(
            Q(title__icontains=search) | Q(body__icontains=search)
        )

    category = None
    if category_slug:
        category = get_object_or_404(Category, slug=category_slug)
        questions = questions.filter(categories=category)

    paginator, questions = paginate(questions,
                                    50,
                                    request.GET.get('page', '1'))
    # this is for get_responses()
    [setattr(q, '_requesting_user', request.user) for q in questions]

    return render(request, template, {
        'request': request,
        'search': search,
        'questions': questions,
        'my_questions': get_my_questions(request),
        'category': category,
        'categories': Category.objects.all(),
        'form': Form(request.user, initial={'title': search}),  # prefill title
        'BASE_TEMPLATE' : settings.BASE_TEMPLATE,
    })
Beispiel #49
0
 def query(self, project_id=None, form_id=None, include_dropped=False,
             paginate=True, sort_by=None, duplicate_field=None, **params):
     qry = {}
     if project_id:
         qry.update({'project_id': project_id})
     if form_id:
         qry.update({'_xform_id_string': form_id})
     if not include_dropped:
         qry.update({'$or': [{'dropped': False}, {'dropped': {'$exists': False}}]})
     if params:
         qry.update(params)
     
     # check if to restrict filter to duplicates only
     if duplicate_field:
         # note: showing dropped records only does and doesn't qualify as 
         # duplicate records depending on how you think about it... In this
         # case we consider all records marked as dropped as duplicate and
         # it helps answer the question 'what records have been dropped?'
         if duplicate_field == 'dropped':
             qry.update({duplicate_field: True})
             if qry.get('$or') and 'dropped' in str(qry.get('$or')):
                 del qry['$or']
         else:
             duplicates = self.get_duplicates(duplicate_field, **qry)
             qry = {duplicate_field: {'$in': duplicates[1]}}
     
     cur = self.db.find(qry)
     if not sort_by:
         cur = cur.sort((['datetime_today', pymongo.DESCENDING],
                         ['group', pymongo.ASCENDING],
                         ['rseq', pymongo.ASCENDING]))
     else:
         sort_args = []
         for sort_arg in sort_by:
             sort_args.append([sort_arg, pymongo.ASCENDING])
         cur = cur.sort(sort_args)
     return utils.paginate(cur, size=settings.NL_PAGE_SIZE) if paginate else cur
Beispiel #50
0
    def get(self, request, pk):
        permission_required(request.user, 'AuthEvent', ['edit', 'view-census'], pk)
        e = get_object_or_404(AuthEvent, pk=pk)

        filter_str = request.GET.get('filter', None)
        query = e.get_census_query()

        if filter_str is not None:
            if len(e.extra_fields):
                filter_str = "%" + filter_str + "%"
                raw_sql = '''
                             SELECT "api_acl"."id", "api_acl"."user_id", "api_acl"."perm", 
                                    "api_acl"."object_type", "api_acl"."object_id", "api_acl"."created", 
                                    "api_userdata"."id", "api_userdata"."user_id",
                                    "api_userdata"."event_id", "api_userdata"."tlf",
                                    "api_userdata"."metadata", "api_userdata"."status"
                            FROM "api_acl" 
                            INNER JOIN "api_userdata" 
                            ON ("api_acl"."user_id" = "api_userdata"."id") 
                            INNER JOIN "auth_user" 
                            ON ("api_userdata"."user_id" = "auth_user"."id") 
                            WHERE 
                                ("api_acl"."object_id"::int = %s
                                AND "api_acl"."perm" = 'vote'
                                AND "api_acl"."object_type" = 'AuthEvent'
                                AND (UPPER("auth_user"."username"::text) LIKE UPPER(%s) 
                                OR UPPER("auth_user"."email"::text) LIKE UPPER(%s) 
                                OR UPPER("api_userdata"."tlf"::text) LIKE UPPER(%s)'''
                params_array = [pk, filter_str, filter_str, filter_str]
                for field in e.extra_fields:
                    raw_sql += '''
                                OR UPPER(api_userdata.metadata::jsonb->>%s) LIKE UPPER(%s)'''
                    params_array += [field['name'], filter_str]
                raw_sql += '''
                                ))'''
                raw_query = ACL.objects.raw(raw_sql, params=params_array)
                id_list = [obj.id for obj in raw_query]
                query = query.filter(id__in=id_list)

            else:
                q = (Q(user__user__username__icontains=filter_str) |
                  Q(user__user__email__icontains=filter_str) |
                  Q(user__tlf__icontains=filter_str))
                query = query.filter(q)

        has_voted_str = request.GET.get('has_voted__equals', None)
        if has_voted_str is not None:
            if 'false' == has_voted_str:
                query = query.annotate(logins=Count('user__successful_logins')).filter(logins__exact=0)
            elif 'true' == has_voted_str:
                query = query.annotate(logins=Count('user__successful_logins')).filter(logins__gt=0)

        # filter, with constraints
        query = filter_query(
            filters=request.GET,
            query=query,
            constraints=dict(
                filters=dict(
                    user__user__id=dict(
                        lt=int,
                        gt=int,
                    ),
                    user__user__is_active=dict(
                        equals=bool
                    ),
                    user__user__date_joined=dict(
                        lt=datetime,
                        gt=datetime
                    )
                ),
                order_by=[
                    'user__user__id',
                    'user__user__is_active',
                    'user__user__date_joined']
            ),
            prefix='census__',
            contraints_policy='ignore_invalid')

        def serializer(acl):
          return {
            "id": acl.user.user.pk,
            "username": acl.user.user.username,
            "active": acl.user.user.is_active,
            "date_joined": acl.user.user.date_joined.isoformat(),
            "metadata": acl.user.serialize_data()
          }

        acls = paginate(
          request,
          query,
          serialize_method=serializer,
          elements_name='object_list')
        return json_response(acls)
Beispiel #51
0
 def get_by_feeder(feeder_code, paginate=True):
     qry = {'source_feeder': feeder_code.upper()}
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #52
0
 def get_all(include_inactive=True, paginate=True):
     qry = {} if include_inactive else {'active': True}
     cur = db.stations.find(qry)\
             .sort('code', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #53
0
def fdi_home():
    per_page = 100

    form = FDI(request.args)

    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    if form.format.data == 'chart-json':
        # chart data in json format
        return jsonify(ActivityChartHelper(form).chart_data())

    elif form.format.data == 'places-json':
        # places in json format
        query = Document.query.options(joinedload('places').joinedload('place'))
        query = form.filter_query(query)

        return jsonify(DocumentPlace.summary_for_docs(query.all()))

    elif form.format.data == 'xlsx' and current_user.admin:
        # excel spreadsheet
        excel = XLSXExportBuilder(form).build()

        response = make_response(excel)
        response.headers["Content-Disposition"] = "attachment; filename=%s" % form.filename()
        response.headers["Content-Type"] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        return response

    elif form.format.data == 'children-ratings.xlsx' and current_user.admin:
        # excel spreadsheet
        excel = ChildrenRatingExport(form.document_ids()).build()

        response = make_response(excel)
        response.headers["Content-Disposition"] = "attachment; filename=%s" % form.filename()
        response.headers["Content-Type"] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        return response

    elif form.format.data == 'media-diversity-ratings.xlsx' and current_user.admin:
        # excel spreadsheet
        excel = MediaDiversityRatingExport(form.document_ids()).build()

        response = make_response(excel)
        response.headers["Content-Disposition"] = "attachment; filename=%s" % form.filename()
        response.headers["Content-Type"] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        return response

    # setup pagination for doc ids
    query = db.session.query(Document.id).order_by(Document.created_at.desc())
    query = form.filter_query(query)
    all_doc_ids = [str(d[0]) for d in query]
    pagination = paginate(query, page, per_page)

    doc_ids = [t.id for t in pagination.items]

    # get documents
    docs = Document.query \
        .options(joinedload(Document.created_by),
                 joinedload(Document.medium),
                 joinedload(Document.topic),
                 joinedload(Document.origin),
                 joinedload(Document.fairness),
                 joinedload(Document.sources).lazyload('*')
                 ) \
        .filter(Document.id.in_(doc_ids)) \
        .order_by(Document.created_at.desc()) \
        .all()

    # group by date added
    doc_groups = []
    for date, group in groupby(docs, lambda d: d.created_at.date()):
        doc_groups.append([date, list(group)])

    # tags
    tag_summary = db.session \
        .query(DocumentTag.tag, func.count(1).label('count')) \
        .filter(DocumentTag.doc_id.in_(doc_ids)) \
        .group_by(DocumentTag.tag) \
        .order_by(desc('count'), DocumentTag.tag) \
        .all()

    session[str(current_user.id)]['search'] = request.url

    return render_template('fdi/activity.haml',
                           form=form,
                           pagination=pagination,
                           doc_groups=doc_groups,
                           tag_summary=tag_summary,
                           all_doc_ids=all_doc_ids,
                           )
Beispiel #54
0
 def get_all(paginate=True):
     qry = {}
     cur = db.user_profiles.find(qry)\
             .sort('id', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #55
0
 def get_by_project(self, project_id, paginate=True):
     query = {'$regex': '%s.*' % project_id, '$options':'i'}
     cur = self.db\
               .find({'project_id': query})\
               .sort('date_created', pymongo.DESCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #56
0
 def get_by_project(self, project_id, paginate=True):
     cur = self.db\
               .find({'project_id': project_id})\
               .sort('date_created', pymongo.DESCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #57
0
 def get_by_form(self, ref_id, paginate=True):
     cur = self.db\
               .find({'_xform_id_string': ref_id})\
               .sort((['datetime_today', pymongo.ASCENDING],
                      ['rseq', pymongo.ASCENDING]))
     return utils.paginate(cur) if paginate else cur
Beispiel #58
0
 def get_all(include_inactive=False, paginate=True):
     qry = {} if include_inactive else {'active': True}
     cur = db.xforms.find(qry)\
             .sort('id', pymongo.DESCENDING)
     return utils.paginate(cur) if paginate else cur
Beispiel #59
0
 def get_by_date_form(self, ref_date, ref_id, paginate=True):
     cur = self.db\
               .find({'datetime_today': ref_date,
                      '_xform_id_string': ref_id})
     return utils.paginate(cur) if paginate else cur
Beispiel #60
0
 def get_by_date(self, ref_date, paginate=True):
     cur = self.db\
               .find({'datetime_today': ref_date})\
               .sort('rseq', pymongo.ASCENDING)
     return utils.paginate(cur) if paginate else cur