Exemple #1
0
def get_manager(request, uid):
    manager = Manager.get_by_id(uid)
    if not manager:
        data = {'api_success': False,
                'api_msg': 'Manager %s not found' % uid}
        return render_json_response(data, status=404)

    if request.method == 'GET':
        return render_json_response(manager.to_json())

    if request.method == 'DELETE':
        manager.key.delete()
        data = {'api_success': True, 'api_msg': 'Manager %s deleted' % uid}
        return render_json_response(data)

    if request.method == 'PUT':
        model = simplejson.loads(request.data)
        manager.communication = Communication.from_json(model.get('communication', {}))
        manager.telephone = Telephone.from_json(model.get('telephone', {}))
        manager.address = Address.from_json(model.get('address', {}))
        manager.name = model.get('name', '')
        manager.last_name = model.get('last_name', '')
        manager.is_display = model.get('is_display', False)
        manager.put()
        data = {'api_success': True, 'api_msg': 'Manager %s updated' % uid}
        data.update(manager.to_json())
        return render_json_response(data)
Exemple #2
0
def send_to_manager(request, order_id):
    order = Order.get_by_id(order_id)
    if not order:
        return render_to_response({
            'api':{
                'success': False,
                'msg': 'Order %s not found' % order_id
            }
        }, status=404)
    managers = Manager.query()
    if not managers.count():
        return render_json_response({
            'api':{
                'success': False,
                'msg': 'Managers not found.'
            }
        }, status=404)
    subject = render_to_string('order/msg/subject.html', {'order':order})
    msg = render_to_string('order/msg/body.html', {'order': order})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = msg
    email.sender = settings.DEFAULT_MAIL_FROM
    for manager in managers:
       if manager.communication.email:
           email.to = manager.communication.email
           email.send()
    return render_json_response({
        'api':{
            'success': True,
            'msg': 'Order notifications were sent'
        }
    })
Exemple #3
0
def new_manager(request):
    model = simplejson.loads(request.data)
    try:
        communication = Communication.from_json(model.get('communications', {}))
        telephone = Telephone.from_json(model.get('telephone', {}))
        address = Address.from_json(model.get('address', {}))
        is_display = model.get('is_display', False)

        manager = Manager(
            name=model['name'],
            last_name=model['last_name'],
            communication=communication,
            telephone=telephone,
            address=address,
            is_display=is_display)
        manager.put()
    except Exception, e:
        data = {'api_success': False, 'api_msg': str(e)}
        return render_json_response(data, status=400)
Exemple #4
0
def send_request_to_manager(request, request_id):
    req = RegistrationRequest.get_by_id(request_id)
    if not req:
        logging.error("Registraion request #%s not found" % request_id)
        return Response('Ok')
    subject = render_to_string('reguest/admins/req_to_mng_subject.txt', {
        'id':request_id})
    body = render_to_string('reguest/admins/req_to_mng_body.txt', {
        'reg_request': req
    })
    managers = Manager.query()
    for manager in managers:
        if manager.communication.email:
            mail.send_mail(
                subject=subject, body=body,
                sender=settings.DEFAULT_MAIL_FROM,
                to=manager.communication.email)
    return Response('Ok')
Exemple #5
0
def contact(request):
    managers = Manager.query(Manager.is_display == True)
    return render_to_response('page/contact.html', {'managers':managers})
Exemple #6
0
def get_managers(request):
    managers = Manager.query()
    return render_json_response([manager.to_json() for manager in managers])