Exemple #1
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
Exemple #2
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
Exemple #3
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
Exemple #4
0
def insert(Model, Message=None, name='insert'):
    """
    Implements the insert method. The request fields are determined by the ``Message`` parameter.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    @ferris3.auto_method(returns=Message, name=name, http_method='POST')
    def inner(self, request=(Message,)):
        return insert_impl(Model, Message, request)

    return inner
Exemple #5
0
def get(Model, Message=None, name='get'):
    """
    Implements a straightfoward get method by using the urlsafe version of the entity's key.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    @ferris3.auto_method(returns=Message, name=name)
    def inner(self, request, itemId=(str,)):
        return get_impl(Model, Message, itemId)

    return inner
Exemple #6
0
def update(Model, Message=None, name='update'):
    """
    Implements the update method. The item updated is determined by the urlsafe key of that item.
    The request fields are determined by the ``Message`` parameter.
    """
    if not Message:
        Message = ferris3.model_message(Model)

    @ferris3.auto_method(returns=Message, name=name, http_method='POST')
    def inner(self, request=(Message,), itemId=(str,)):
        return update_impl(Model, Message, itemId, request)

    return inner
Exemple #7
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
Exemple #8
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
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)
Exemple #11
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()
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()
Exemple #13
0
import ferris3 as f3
import protopigeon
from protorpc import messages
from google.appengine.ext import ndb
from ferris3 import Model, Service, hvild, auto_service
from app.models.channel import Channel
from app.models.city import City

ChannelMessage = f3.model_message(Channel)
MultiMessage = protopigeon.list_message(ChannelMessage)


@auto_service
class ChannelsService(Service):
    list = hvild.list(Channel)
    get = hvild.get(Channel)
    delete = hvild.delete(Channel)
    insert = hvild.insert(Channel)
    update = hvild.update(Channel)

    @f3.auto_method(returns=MultiMessage,
                    http_method="GET",
                    name="get_featured")
    def by_channels(
        self,
        request,
    ):

        cha_msgs = Channel.query(Channel.is_featured == True)

        if cha_msgs is not None:
Exemple #14
0
import ferris3 as f3
import protopigeon
from protorpc import messages
from google.appengine.ext import ndb
from ferris3 import Model, Service, hvild, auto_service
from app.models.channel import Channel
from app.models.city import City

ChannelMessage = f3.model_message(Channel)
MultiMessage = protopigeon.list_message(ChannelMessage)

@auto_service
class ChannelsService(Service):
	list = hvild.list(Channel)
	get = hvild.get(Channel)
	delete = hvild.delete(Channel)
	insert = hvild.insert(Channel)
	update = hvild.update(Channel)


	@f3.auto_method(returns= MultiMessage, http_method="GET", name="get_featured")
	def by_channels(self,request,):
		
		cha_msgs= Channel.query(
			Channel.is_featured == True
		)
			
		if cha_msgs is not None:
			return f3.messages.serialize_list(MultiMessage, cha_msgs)
		else:
			 raise f3.NotFoundException()
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()