예제 #1
0
    def get_api(self, vendor_id, api_name):
        """Returns an API object for a specific vendor."""
        if vendor_id not in MWSActor.apis:
            with app.app_context():
                q = db.session.query(Vendor.extra['mws_keys'],
                                     Vendor.extra['pa_keys'])
                if vendor_id:
                    mws_keys, pa_keys = q.filter(Vendor.id == vendor_id).one()
                else:
                    mws_keys, pa_keys = q.filter(
                        db.and_(
                            Vendor.extra.op('->')('mws_keys') != None,
                            Vendor.extra.op('->')('pa_keys') !=
                            None)).first() or (None, None)

            if None in (mws_keys, pa_keys):
                raise ValueError('MWS and PA API keys not found.')

            MWSActor.apis[vendor_id] = {'_keys': (mws_keys, pa_keys)}

        if api_name not in MWSActor.apis[vendor_id]:
            mws_keys, pa_keys = MWSActor.apis[vendor_id]['_keys']
            api_type = getattr(amazonmws, api_name)
            api_keys = pa_keys if api_name == 'ProductAdvertising' else mws_keys
            MWSActor.apis[vendor_id][api_name] = api_type(
                **api_keys, make_request=requests.request)

        return MWSActor.apis[vendor_id][api_name]
예제 #2
0
def DamagedReport(name, location, damage):
    with app.app_context():
        msg = Message(
            subject="Damaged Report!",
            sender=app.config.get("MAIL_USERNAME"),
            recipients=["*****@*****.**"
                        ],  # replace with your email for testing
            body=
            "The following tablet {} from {} has been reported with a {} issue."
            .format(name, location, damage))
        mail.send(msg)
    return jsonify({'message': 'Your message has been sent successfully'}), 200
예제 #3
0
    def __call__(self, *, _ctx=None, _msg_id=None, **params):
        """Process a call to action."""
        # Load or create the context
        if _ctx is None or isinstance(_ctx, dict):
            message = self.message(**params)
            context = TaskContext(message, data=_ctx)
            self.context = context
            self.message_id = message.message_id
        else:
            context = TaskContext(id=_ctx)
            self.context = context
            self.message_id = _msg_id

        # Update the keyword arguments using values from the context
        fields = list(self.Schema._declared_fields)  # Use _declared_fields because it preserves declaration order
        ctx_data = context.data
        kwargs = {field: ctx_data[field] for field in fields if field in ctx_data}

        # Override with actual keyword args if they we provided
        kwargs.update(params)

        # Validate against the schema
        loaded = self.Schema().load(kwargs)

        if loaded.errors:
            exc = mm.ValidationError(message=loaded.errors)
            context.log_error(_msg_id, str(exc))
            raise exc

        # Perform the action
        with app.app_context():
            try:
                result = self.perform(**loaded.data)
            except Exception as e:
                context.log_error(_msg_id, str(e))
                raise e
            else:
                context.complete(_msg_id)
                context.send()
                return result
예제 #4
0
파일: api.py 프로젝트: roughcoding/flawcode
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
예제 #5
0
from flask import request, abort

from core.models.core.model import Model
from core.models.core.with_templates import WithTemplates
from core.models.core.has_routes import HasRoutes

from core.helpers.validation_rules import validation_rules
from core.helpers.json import to_json

from core.models.cms.author import Author

from bson.objectid import ObjectId
import markdown


with app.app_context():
	class List(WithTemplates, HasRoutes, Model):

		collection_name = 'lists'

		schema = {
			'title': validation_rules['text'],
			'route': validation_rules['text'],
			'thumbnail': validation_rules['image'],
			'image': validation_rules['image'],
			'template': {
				'type': 'dict',
				'schema': {
					'thumbnail': validation_rules['image'],
					'image': validation_rules['image'],
					'content': validation_rules['content'],
예제 #6
0
from core import app
from core.models.core.has_routes import HasRoutes

from core.models.auth.chimp import Chimp

from core.helpers.validation_rules import validation_rules
from core.helpers.json import to_json

from flask import request
from mailchimp3 import MailChimp

with app.app_context():

    class Newsletter(HasRoutes):

        endpoint = '/_newsletter'
        routes = [{
            'route': '/signup',
            'view_function': 'signup_view',
            'methods': ['POST']
        }]

        schema = {
            'email': validation_rules['email'],
            'shop': validation_rules['text']
        }

        @classmethod
        def signup_view(cls):
            data = cls.validate(cls._get_json_from_request())
예제 #7
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
예제 #8
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
예제 #9
0
 def _wrapper(self, *args, **kwargs):
     f(self, *args, **kwargs)
     db = self.get_db()
     with app.app_context():
         db.commit()
예제 #10
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return self.run(*args, **kwargs)