QuantumWings coder app

Discussion in 'Iconner/Coder Applications (closed/obsolet)' started by QuantumWings, Dec 10, 2014.

  1. QuantumWings

    QuantumWings Well-Known Member

    BYOND Name(Key): QuantumWings
    Past experience?: The last 3 years of university.
    Other Languages Known: C, Java, Python, Pascal, a touch of C++, lua, QBASIC and PHP.
    How long have you been coding?: I have been studying a double degree in BENG(Electronic and Computer Systems)/BSI(Computer Science and Software Engineering) since 2012, but have done very small projects since I was much younger(a dice roller in python, controlling robots using parallel port and QBASIC)
    Do you consider yourself a relatively competent coder?: Yes
    If you have never coded (in DreamMaker) before, are you willing to learn?: I have only played around in it a little, but I am willing to learn.
    Code:
    851UJU
    Random.org or bust
  2. Flavo

    Flavo Well-Known Member

    Can we see some of your work?
  3. QuantumWings

    QuantumWings Well-Known Member

    Code:
    '''
    Created on 19 Oct 2014
     
    @author: Thomas
    '''
    from bottle import request, response, SimpleTemplate as Template
    from OrderItemsController import OrderItemsController
    import re
    import pickle
    import enum
     
    def addOrderItems(app, cont):
        @app.get('/OrderItems')
        def OrderItems():
            itemList = cont.getItemList()
       
            pageTemp = Template('''
            % rebase('base.tpl', title='Order Items')
            <form method="post" action="/OrderItems/1" name="OrderItems_table">
                <table style="text-align: left;" border="1" cellpadding="2" cellspacing="0">
                    <tbody>
                        <tr>
                            <td>Name</td>
                            <td>Description</td>
                            <td>Price</td>
                            <td>Quantity</td>
                        </tr>
                        {{!rows}}
                    </tbody>
                </table>
                <br>
                <input type="submit" value="Next"/>
            </form>
            ''')
       
            rowTemp = Template('''
            <tr>
                <td>{{name}}</td>
                <td>{{description}}</td>
                <td>{{price}}</td>
                <td><input type=number name="id_{{itemNo}}" placeholder="0" min = "0" /></td>
            </tr>
            ''')
       
            htmlRows = []
            for i in itemList:
                htmlRows.append(rowTemp.render(name=i['Name'], price=i['Price'], description=i['Description'], itemNo=i['ItemNo']))
            return pageTemp.render(rows = ''.join(htmlRows))
     
        @app.post('/OrderItems/1')
        def OrderItems_1():
            params  = request.params
            forms  = request.forms
            items = []
            for param in params:
                if (re.match('^id_\d+$', param) != None) and (re.match('^\d+$', forms.get(param)) != None):
                    itemNo    = re.findall('\d+', param)[0]
                    numOrdered = forms.get(param)
                    if int(numOrdered) > 0:
                        items.append( (itemNo, numOrdered) )
            items = tuple(items) # makes items immutable
                     
            response.set_cookie('OrderItems_1', pickle.dumps(items), secret = 'f3a50753ca87478382f97fb16670a9ee')
           
            if len(items) == 0:
                return '''
                <!DOCTYPE html>
                <html><head>
                <meta content="text/html; charset=utf-8" http-equiv="content-type"><title>{{title}}</title>
           
                </head>
                <body>
                No items were selected.
                <br />
                <form method="get" action="/OrderItems" name="">
                <input type="submit" value="Back"/>
                </form>
                </body></html>
                ''' #Need to put things for when there are no items
       
            pageTemp = Template('''
            % rebase('base.tpl', title='Confirm Order')
            Is this your correct order?
            <form method="post" action="/OrderItems/2" name="ConfirmOrder_table">
                <table style="text-align: left;" border="1" cellpadding="2" cellspacing="0">
                    <tbody>
                        <tr>
                            <td>Name</td>
                            <td>Description</td>
                            <td>Price</td>
                            <td>Quantity</td>
                        </tr>
                        {{!rows}}
                    </tbody>
                </table>
                <br>
                <input type="submit" value="Confirm" />
            </form>
            ''')
       
            rowTemp = Template('''
            <tr>
                <td>{{name}}</td>
                <td>{{description}}</td>
                <td>{{price}}</td>
                <td>{{quantity}}</td>
            </tr>
            ''')
       
            htmlRows = []
            for i in items:
                print(i)
                it = cont.getItem(int(i[0]))
                htmlRows.append(rowTemp.render(name = it['Name'], price =it['Price'], description = it['Description'], quantity = i[1]))
            return pageTemp.render(rows = ''.join(htmlRows))
       
        @app.post('/OrderItems/2')
        def OrderItems_2():
            pageTemp = Template('''
            % rebase('base.tpl', title='Confirm Order')
            <form method="post" action="/OrderItems/3" name="Customer Details">
                <table>
                    <tbody>
                        <tr>
                            <td>Name: </td>
                            <td><input name="name"></td>
                        </tr>
                        <tr>
                            <td>Email: </td>
                            <td><input type="email" name="email"></td>
                        </tr>
                        <tr>
                            <td>Phone:</td>
                            <td><input type="tel" name="phone"></td>
                        </tr>
                        <tr>
                            <td>Notes:</td>
                            <td><textarea rows="4" cols="50" maxlength = "1024" name = "notes"></textarea></td>
                        </tr>
                    </tbody>
                </table>
                <input type="submit" value="Submit" />
            </form>
            ''')
            return pageTemp.render()
     
        @app.post('/OrderItems/3')
        def OrderItems_3():
            forms = request.forms
            customer = (forms.get('name'), forms.get('phone'), forms.get('email'), forms.get('notes'))
            print(forms.get('notes'))
            print(tuple(request.params))
            items = []
            items = pickle.loads(request.get_cookie('OrderItems_1', pickle.dumps(items), secret = 'f3a50753ca87478382f97fb16670a9ee'))
       
            errCode = cont.placeOrder(customer, items)
            errMessage = {
                        OrderItemsController.OrderErr.noErr    : '',
                        OrderItemsController.OrderErr.badEmail : 'Please input a valid email.',
                        OrderItemsController.OrderErr.badPhone : 'Please input a valid phone number.',
                        OrderItemsController.OrderErr.badName  : 'Please input a valid name.'
            }[errCode]
            if errCode == OrderItemsController.OrderErr.noErr :
                pageTemp = Template('''
                % rebase('base.tpl', title='Order Has been Placed')
                Your order has been placed.
                <form method="get" action="/" name="">
                    <input type="submit" value="Finish"/>
                </form>
                ''') #Need to put recipt in here
            else:
                pageTemp =Template('''
                    % rebase('base.tpl', title='Order has not been placed')
                    There has been an error and your order has not been placed. <br />
                ''' + errMessage +
                '''
                    <form method="post" action="/OrderItems/2" name="">
                        <input type="submit" value="Back"/>
                    </form>
                ''')
       
            return pageTemp.render()
    This is part of a project I did last semester. There are a few bits I am not happy with (cookies, spelling, lack of comments comments). The project allso involved some work with sqlite; the code for that isn't very exiting because most of the important parts are baked into the db.
    Chase likes this.
  4. Chase

    Chase Active Member

    Neat-O.
  5. Flavo

    Flavo Well-Known Member

    I have no clue what i'm looking at all. @_@

    Was hoping to see some DM work, I took a look at your fork and saw some map edits i was not comfortable with but then after providing input you managed to make it work and some sec bot stuff. Would like to see more little projects. We are open source after all, I think you have some good to offer so you should consider contacting wellington to maybe work with some of us on the source while you wait for spoffy to get back to you
    WellingtonTheThird likes this.
  6. Mabblies

    Mabblies Well-Known Member

    You sound like a competent coder to me.
  7. TheDracheX

    TheDracheX LS13 Coder Staff Member

    Dats Python, and Indeed I would like to see some DM work as well.

Share This Page