Exemplo n.º 1
0
def list(Model, Message=None, ListMessage=None, query=None, name='list'):
    """
    Implements a very simple list method for the given model.

    .. warning:: No limiting logic is applied to the query so this will attempt to get all results.
        It is almost always preferable to use :func:`paginated_list`.

    """
    if not Message:
        Message = ferris3.model_message(Model)

    if not ListMessage:
        ListMessage = ferris3.list_message(Message)

    if not query:
        query = Model.query()

    if callable(query):
        query = query()

    @ferris3.auto_method(returns=ListMessage, name=name)
    def inner(self, request):
        return list_impl(ListMessage, query)

    return inner
Exemplo n.º 2
0
def searchable_list(Model=None,
                    Message=None,
                    ListMessage=None,
                    limit=50,
                    index=None,
                    name='search'):
    """
    Implements a search method by using the :mod:`~ferris3.search` module. This method assumes you are
    using the common use case of indexing datastore entities and does not work for generic searches.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    if not ListMessage:
        ListMessage = ferris3.list_message(Message)

    if not index:
        index = ferris3.search.index_for(Model)

    @ferris3.auto_method(returns=ListMessage, name=name)
    def inner(self,
              request,
              query=(str, ''),
              sort=(str, None),
              page_token=(str, '')):
        return searchable_list_impl(ListMessage, index, query, limit, sort,
                                    page_token)

    return inner
Exemplo n.º 3
0
def paginated_list(Model,
                   Message=None,
                   ListMessage=None,
                   query=None,
                   limit=50,
                   name='paginated_list'):
    """
    Similar to :func:`list` but returns results in pages of ``limit`` size.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    if not ListMessage:
        ListMessage = ferris3.list_message(Message)

    if not query:
        query = Model.query()

    if callable(query):
        query = query()

    @ferris3.auto_method(returns=ListMessage, name=name)
    def inner(self, request, page_token=(str, '')):
        return paginated_list_impl(ListMessage, query, limit, page_token)

    return inner
Exemplo n.º 4
0
def searchable_list(Model=None, Message=None, ListMessage=None, limit=50, index=None, name='search'):
    """
    Implements a search method by using the :mod:`~ferris3.search` module. This method assumes you are
    using the common use case of indexing datastore entities and does not work for generic searches.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    if not ListMessage:
        ListMessage = ferris3.list_message(Message)

    if not index:
        index = ferris3.search.index_for(Model)

    @ferris3.auto_method(returns=ListMessage, name=name)
    def inner(self, request, query=(str, ''), sort=(str, None), pageToken=(str, '')):
        return searchable_list_impl(ListMessage, index, query, limit, sort, pageToken)

    return inner
Exemplo n.º 5
0
def paginated_list(Model, Message=None, ListMessage=None, query=None, limit=50, name='paginated_list'):
    """
    Similar to :func:`list` but returns results in pages of ``limit`` size.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    if not ListMessage:
        ListMessage = ferris3.list_message(Message)

    if not query:
        query = Model.query()

    if callable(query):
        query = query()

    @ferris3.auto_method(returns=ListMessage, name=name)
    def inner(self, request, pageToken=(str, '')):
        return paginated_list_impl(ListMessage, query, limit, pageToken)

    return inner
Exemplo n.º 6
0
import ferris3
import endpoints
from google.appengine.ext import ndb
import datetime


# We use ferris3.ndb.Model instead of ndb.Model so that we can use behaviors if we wanted.
class GuestbookPost(ferris3.ndb.Model):
    author = ndb.UserProperty(indexed=False)
    content = ndb.TextProperty()
    date = ndb.DateTimeProperty(indexed=True)


GuestbookPostMessage = ferris3.model_message(GuestbookPost)
GuestbookPostMessageCollection = ferris3.list_message(GuestbookPostMessage)


@ferris3.auto_service
class GuestbookService(ferris3.Service):

    @ferris3.auto_method(returns=GuestbookPostMessage)
    # The weird syntax on the request method is an annotation. We're telling
    # Ferris that we want the request to be of the type "GuestbookMessage".
    def insert(self, request=(GuestbookPostMessage,)):
        # Turn the request message into a ndb entity.
        post = ferris3.messages.deserialize(GuestbookPost, request)

        # Update the author field with the current user.
        post.author = endpoints.get_current_user()
        # And the date field with the current datetime
        post.date = datetime.datetime.utcnow()
from google.appengine.api import search as gsearch
from google.appengine.ext import ndb
from endpoints import get_current_user as get_current_guser
from protorpc import messages

import ferris3 as f3

from framework.utils import t_ndb, set_namespace, \
    get_namespace, has_admin_privilege, get_google_user_from_db, \
    include_entity_owner, include_entity_owner_multi, get_org_from_name, \
    get_users_from_google_of_org, has_contributor_privilege
from app.timetracker.timetracker_models import Project


ProjectMessage = f3.model_message(Project)
ProjectMessageCollection = f3.list_message(ProjectMessage)


class ContributorAddedMessage(messages.Message):
    project_id = messages.StringField(1)
    contr_key = messages.StringField(3)


class UserMessage(messages.Message):
    key = messages.StringField(1)
    gmail_id = messages.StringField(2)


class UsersCollectionMessage(messages.Message):
    users = messages.MessageField(UserMessage, 1, repeated=True)
Exemplo n.º 8
0
import ferris3 as f3
from app.lots.lot_model import Lot

LotMessage = f3.model_message(Lot)
LotListMessage = f3.list_message(LotMessage)

@f3.auto_service
class LotService(f3.Service):
    list = f3.hvild.list(Lot)
    paginated_list = f3.hvild.paginated_list(Lot)
    get = f3.hvild.get(Lot)
    delete = f3.hvild.delete(Lot)
    insert = f3.hvild.insert(Lot)
    update = f3.hvild.update(Lot)

    @f3.auto_method(returns=LotListMessage, name="all")
    def list_all(self, request):
        '''
        return list of all posts as a LotMessage
        '''
        lots = Lot.query()
        if not posts:
            raise f3.NotFoundException()
        list_message = f3.messages.serialize_list(LotListMessage, lots)
        return list_message


    @f3.auto_method(returns=LotMessage, name="get_by_title")
    def get_by_address(self, request, address=(str,)):
        query = Lot.query(Lot.address==address)
        lot = query.get()
Exemplo n.º 9
0
import ferris3 as f3
from app.posts.post_model import Post

PostMessage = f3.model_message(Post)
PostListMessage = f3.list_message(PostMessage)

@f3.auto_service
class PostsService(f3.Service):
    list = f3.hvild.list(Post)
    paginated_list = f3.hvild.paginated_list(Post)
    get = f3.hvild.get(Post)
    delete = f3.hvild.delete(Post)
    insert = f3.hvild.insert(Post)
    update = f3.hvild.update(Post)

    @f3.auto_method(returns=PostListMessage, name="all")
    def list_all(self, request):
        '''
        return list of all posts as a PostMessage
        '''
        posts = Post.query()
        if not posts:
            raise f3.NotFoundException()
        list_message = f3.messages.serialize_list(PostListMessage, posts)
        return list_message


    @f3.auto_method(returns=PostMessage, name="get_by_title")
    def get_by_title(self, request, title=(str,)):
        query = Post.query(Post.title==title)
        post = query.get()
Exemplo n.º 10
0
import ferris3
import endpoints
from google.appengine.ext import ndb
import datetime


# We use ferris3.ndb.Model instead of ndb.Model so that we can use behaviors if we wanted.
class GuestbookPost(ferris3.ndb.Model):
    author = ndb.UserProperty(indexed=False)
    content = ndb.TextProperty()
    date = ndb.DateTimeProperty(indexed=True)


GuestbookPostMessage = ferris3.model_message(GuestbookPost)
GuestbookPostMessageCollection = ferris3.list_message(GuestbookPostMessage)


@ferris3.auto_service
class GuestbookService(ferris3.Service):
    @ferris3.auto_method(returns=GuestbookPostMessage)
    # The weird syntax on the request method is an annotation. We're telling
    # Ferris that we want the request to be of the type "GuestbookMessage".
    def insert(self, request=(GuestbookPostMessage, )):
        # Turn the request message into a ndb entity.
        post = ferris3.messages.deserialize(GuestbookPost, request)

        # Update the author field with the current user.
        post.author = endpoints.get_current_user()
        # And the date field with the current datetime
        post.date = datetime.datetime.utcnow()