示例#1
0
def send_lead(request):
    full_name = request.POST['full_name']
    email = request.POST['email']
    phone = request.POST['phone']
    msg = request.POST['msg']

    if request.method == 'POST' and recaptcha(request) and '' not in (
            full_name, email, phone, msg):
        query = Query()

        data = query.create(
            'crm.lead', 'create', {
                'name': 'plate-heat-exchanger.com.mx',
                'user_id': 110,
                'contact_name': full_name,
                'email_from': email,
                'phone': phone,
                'description': msg
            })

        return redirect('thanks')
    else:
        messages.add_message(
            request, messages.INFO,
            'Favor de llenar los campos con la información correcta.')
        return redirect('contact')
示例#2
0
 def test_filter_without_label(self):
     """Test filtering using default label."""
     q = Query('Host')
     q.filter('hostname', '=', 'somehostname')
     expected = 'WHERE host.hostname = $filterval0'
     self.assertTrue(expected in str(q))
     self.assertEquals(q.params['filterval0'], 'somehostname')
示例#3
0
 def test_count(self, m_connection):
     """Tests counting number of results."""
     data = FakeRecords()
     data.append({'total': 13})
     data = [data]
     m_connection.return_value = FakeConnection(data)
     q = Query('Environment')
     self.assertEquals(q.count(), 13)
示例#4
0
 def test_page_with_page(self, m_fetch):
     """Test providing page with a page and a size."""
     q = Query('Environment')
     q.page(page=3, pagesize=500)
     expected = "SKIP 1000"
     self.assertTrue(expected in str(q))
     expected = "LIMIT 500"
     self.assertTrue(expected in str(q))
示例#5
0
 def test_page_with_negative_index(self, m_fetch):
     """Test providing page with a negative index and a size."""
     q = Query('Environment')
     q.page(index=-10, pagesize=500)
     expected = "SKIP 0"
     self.assertTrue(expected in str(q))
     expected = "LIMIT 500"
     self.assertTrue(expected in str(q))
示例#6
0
    def test_page_defaults(self, m_fetch):
        """Test default arguments to page() method."""
        q = Query('Environment')
        q.page()

        expected = 'SKIP 0'
        self.assertTrue(expected in str(q))
        expected = 'LIMIT 100'
        self.assertTrue(expected in str(q))
示例#7
0
def index(request):
    query = Query()
    data = query.get(
        'product.template', 'search_read',
        [['type', '=', 'product'], ['categ_id', '=', 153],
         ['x_studio_field_OaF3K', '=', True]], {
             'fields': [
                 'id', 'name', 'default_code', 'x_studio_field_QlEui',
                 'create_date', 'create_date'
             ],
             'order':
             'create_date'
         })

    context = {"products": data}
    return render(request, 'pages/index.html', context)
示例#8
0
 def test_match_with_state(self):
     """Test match clause including a model with state."""
     q = Query('Host')
     expected = (
         "MATCH (environment:Environment)-[r0:HAS_HOST]->(host:Host) "
         "\nMATCH (host)-[r_host_state:HAS_STATE]->(host_state:HostState)")
     self.assertTrue(expected in str(q))
示例#9
0
def single(request, product_id):
    query = Query()

    data = query.get(
        'product.template', 'search_read',
        [['type', '=', 'product'], ['categ_id', '=', 153],
         ['x_studio_field_OaF3K', '=', True], ['id', '=', product_id]], {
             'fields': [
                 'id', 'name', 'default_code', 'x_studio_field_QlEui',
                 'create_date', 'create_date'
             ]
         })

    random_number = random.randint(0, 3)

    context = {
        "product": data[0],
        "content_random": 'products/content/{}.html'.format(random_number)
    }

    return render(request, 'products/single.html', context)
示例#10
0
def search(request):
    q = request.GET['q']

    query = Query()

    data = query.get(
        'product.template', 'search_read',
        [['type', '=', 'product'], ['categ_id', '=', 153],
         ['x_studio_field_OaF3K', '=', True],
         ['x_studio_field_QlEui', 'ilike', q]], {
             'fields': [
                 'id', 'name', 'default_code', 'x_studio_field_QlEui',
                 'create_date', 'create_date'
             ],
             'limit':
             20
         })

    context = {"products": data}

    return render(request, 'products/search.html', context)
示例#11
0
def send_lead(request):
    if request.method == 'POST' and recaptcha(request):
        full_name = request.POST['full_name']
        email = request.POST['email']
        phone = request.POST['phone']
        msg = request.POST['msg']

        query = Query()

        data = query.create(
            'crm.lead', 'create', {
                'name': 'enfriadores-aire.com.mx',
                'user_id': 110,
                'contact_name': full_name,
                'email_from': email,
                'phone': phone,
                'description': msg
            })
        return redirect('thanks')
    else:
        return redirect('index')
示例#12
0
 def test_default_time(self, m_now):
     """Test that default time parameter."""
     q = Query('Environment')
     self.assertEquals(q.params['time'], 10)
     q = Query('Environment')
     q.time(None)
     self.assertEquals(q.params['time'], 10)
示例#13
0
 def test_multiple_filters(self):
     """Tests more than one filters."""
     q = Query('Host')
     q.filter('hostname', '=', 'somehostname')
     q.filter('kernel', '=', 'somekernel')
     expected = ('WHERE host.hostname = $filterval0 AND '
                 'host_state.kernel = $filterval1')
     self.assertTrue(expected in str(q))
示例#14
0
 def test_orderby_multiple(self):
     """Test multiple orderby statements."""
     q = Query('Environment')
     q.orderby('account_number', 'ASC', label='Environment')
     q.orderby('name', 'DESC', label='Environment')
     expected = ("ORDER BY environment.account_number ASC, "
                 "environment.name DESC")
     self.assertTrue(expected in str(q))
示例#15
0
def index(request):
    page = request.GET.get('page', 1)

    # Template api function
    query = Query()
    data = query.get(
        'product.template', 'search_read',
        [['type', '=', 'product'], ['categ_id', '=', 153],
         ['x_studio_field_OaF3K', '=', True]], {
             'fields': [
                 'id', 'name', 'default_code', 'x_studio_field_QlEui',
                 'create_date', 'create_date'
             ],
             'order':
             'create_date'
         })

    # Django pagination
    paginator = Paginator(data, 20)
    pages = paginator.get_page(page)

    context = {"products": pages}

    return render(request, 'products/index.html', context)
示例#16
0
def lead(request):
    if request.method == 'POST' and recaptcha(request):
        full_name = request.POST['full_name']
        email = request.POST['email']
        phone = request.POST['phone']
        description = 'Producto: ' + request.POST[
            'product_name'], 'Número de parte Mesabi: ' + request.POST[
                'mpn'], 'Número de parte OEM: ' + request.POST[
                    'oempn'], 'Mensaje: ' + request.POST['msg']

        query = Query()

        data = query.create(
            'crm.lead', 'create', {
                'name': 'enfriadores-aire.com.mx',
                'user_id': 110,
                'contact_name': full_name,
                'email_from': email,
                'phone': phone,
                'description': description
            })
        return redirect('thanks')
    else:
        return redirect('index')
示例#17
0
 def test_limit_none(self):
     """Test query where no limit has been set."""
     q = Query('Environment')
     self.assertFalse('LIMIT' in str(q))
示例#18
0
 def test_filter_with_label(self):
     """Test filtering with a non default label."""
     q = Query('Host')
     q.filter('account_number', '=', 'somenumber', label='Environment')
     expected = 'WHERE environment.account_number = $filterval0'
     self.assertTrue(expected in str(q))
示例#19
0
 def test_filter_invalid_label(self):
     """Test filtering with invalid label."""
     q = Query('Host')
     with self.assertRaises(InvalidLabelError):
         q.filter('someprop', 'someop', 'someval', label='InvalidLabel')
示例#20
0
 def test_filter_invalid_prop(self):
     """Test filtering with invalid property."""
     q = Query('Host')
     with self.assertRaises(InvalidPropertyError):
         q.filter('someinvalidprop', 'someop', 'someval')
示例#21
0
 def test_return_with_state(self):
     """Test return clause that should include state."""
     q = Query('Host')
     expected = 'RETURN environment, host, host_state'
     self.assertTrue(expected in str(q))
示例#22
0
 def test_return_root_label(self):
     """Test return clause targeted at a root level model."""
     q = Query('Environment')
     expected = "RETURN environment"
     self.assertTrue(expected in str(q))
示例#23
0
 def test_rel_filters(self):
     """Test adding time filters on relationships."""
     q = Query('Virtualenv')
     expected = ("r0.from <= $time < r0.to AND r1.from <= $time < r1.to "
                 "AND r_host_state.from <= $time < r_host_state.to")
     self.assertTrue(expected in str(q))
示例#24
0
 def test_skip_none(self):
     """Test query where no skip has been set."""
     q = Query('Environment')
     self.assertFalse('SKIP' in str(q))
示例#25
0
 def test_limit(self):
     """Test query where a limit as been set."""
     q = Query('Environment')
     q.limit(5)
     q.limit(10)
     self.assertTrue('LIMIT 10' in str(q))
示例#26
0
 def test_orderby_invalid_label(self):
     """Test that orderby raises InvalidLabelError"""
     q = Query('Environment')
     with self.assertRaises(InvalidLabelError):
         q.orderby('aproperty', 'DESC', label='invalidlabel')
示例#27
0
 def test_orderby_state_property(self):
     """Test orderby on a state property."""
     q = Query('Host')
     q.orderby('kernel', 'DESC', label='Host')
     expected = 'ORDER BY host_state.kernel DESC'
     self.assertTrue(expected in str(q))
示例#28
0
 def test_match_root_label(self):
     """Test match clause targeted at a root level model."""
     q = Query('Environment')
     expected = "MATCH (environment:Environment)"
     self.assertTrue(expected in str(q))
示例#29
0
 def test_orderby_invalid_property(self):
     """Test that orderby raises InvalidPropertyError"""
     q = Query('Environment')
     with self.assertRaises(InvalidPropertyError):
         q.orderby('invalidproperty', 'ASC')
示例#30
0
 def test_skip(self):
     """Test query where skip has been set."""
     q = Query('Environment')
     q.skip(5)
     q.skip(10)
     self.assertTrue('SKIP 10' in str(q))