from flask_restful import Resource
from wutu.compiler.common import *
from wutu.compiler.service import *
from wutu.decorators import stub


class Module(Resource):
    """
    Base class for all modules
    """
    def __init__(self):
        super(Module, self).__init__()

    @stub
    def get(self):
        """
        Responds to GET request
        """

    @stub
    def post(self):
        """
        Responds to POST request
        """

    @stub
    def put(self):
        """
        Responds to PUT request
        """

    @stub
    def delete(self):
        """
        Responds to DELETE request
        """

    @staticmethod
    def mediatypes():
        """
        Mediatypes override
        :return:
        """
        return ["application/json", "text/javascript"]

    def create_service(self, stream):
        """
        Constructs AngularJS service
        :param stream:
        :return:
        """
        create_service_js(stream, self)

    def create_controller(self, stream):
        """
        Constructs AngularJS controller
        :param stream:
        :return:
        """
        stream.write(self.get_controller())

    def get_service(self):
        """
        Constructs AngularJS service without stream
        :return:
        """
        stream = create_stream()
        self.create_service(stream)
        return get_data(stream)

    def get_controller(self):
        """
        Returns AngularJS controller
        :return:
        """
        return ""

    def get_name(self):
        """
        Returns module name
        :return:
        """
        return self.__name__

    def get_identifier(self):
        """
        Returns Ids for this module
        :return:
        """
        from wutu.util import get_identity
        return get_identity(self)

@@ -91,32 +91,71 @@
 ervice import *%0A
+from wutu.compiler.controller import *%0A
 from wutu.decora
@@ -1162,42 +1162,41 @@
     
-stream.write(self.get_controller()
+create_controller_js(stream, self
 )%0A%0A 
@@ -1536,17 +1536,103 @@
     
-return %22%22
+stream = create_stream()%0A        self.create_controller(stream)%0A        return get_data(stream)
 %0A%0A  

Use controller same as service