Ejemplo n.º 1
0
    def render(self, context):
        new_context = {}

        # Run through the dictionary and evaluate it
        for key, value_name in self.dictionary_info.iteritems():
            new_context_value = None

            # Try it as a variable first
            try:
                v = djangot.Variable(value_name)
                new_context_value = v.resolve(context)
            except:
                new_context_value = None

            # And as an actual python value second
            if new_context_value is None:
                try:
                    new_context_value = eval(value_name)
                except:
                    new_context_value = None

            new_context[key] = new_context_value

        # Render the template
        final_template = template.load(self.template_path)
        return final_template.render(template.Context(new_context))
Ejemplo n.º 2
0
    def get(self):
        if not super(Customizer, self).get(): return

        param_set = self.param_set

        for param in param_set.values():
            try:
                rows = DBCustomField.gql("where type=:type",
                                         type=param["type"])
                param["value"] = (rows[0].value).encode("utf-8")
            except:
                #self.insertContent("<br/>type: " + param["type"])
                pass

        tpl_cust = template.Template("""
        <form method="post" action="">
            <table>
            {% for param in params %}
                <tr>
                    <td>
                        {{param.caption}}
                    </td>
                    <td>
                    {% if param.txt_long %}
                        <textarea name="{{param.name}}">{{param.value}}</textarea>
                    {% else %}
                        <input type="text" name="{{param.name}}" size="40" value='{{param.value}}'>
                    {% endif %}
                    </td>
                </tr>
            {% endfor %}
                <tr>
                    <td>
                        
                    </td>
                    <td>
                        <input type="submit" value='Сохранить'>
                    </td>
                </tr>
            </table>
        <form>
        """)

        for param in param_set.values():
            if "txt_long" not in param:
                param["txt_long"] = True if len(
                    param["value"]) > 100 else False
        out = tpl_cust.render(template.Context({"params": param_set.values()}))
        self.insertContent(out)
        self.drawPage()
Ejemplo n.º 3
0
 def get(self):
     ctx = template.Context({"session": self.session})
     self.response.out.write(SIGNUP_VIEW.render(ctx))
Ejemplo n.º 4
0
    def post(self):
        self.checkSession(self.request.headers.get('Cookie'), False)
        event = int(self.request.uri.split('/')[-1])
        if not self.Session['authorized']:
            if self.request.get('name') != '' and self.request.get('surname') != '':
                user = db.GqlQuery("SELECT * FROM DBUser WHERE email = :email", 
                                   email = str(self.request.get('email')))
                if user.count() == 0:
                    newuser = DBUser()
                    newuser.name = self.request.get('name')
                    newuser.surname = self.request.get('surname')
                    newuser.login = str(cgi.escape(self.request.get('email'))).lower()
                    newuser.email = str(self.request.get('email'))
                    pwchars = "1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"
                    pwd = "".join(random.choice(pwchars) for _ in range(8))
                    newuser.password = hashlib.md5(str(pwd)).hexdigest()
                    confirmation = hashlib.md5(str(random.random())).hexdigest()
                    newuser.confirmation = confirmation
                    newuser.type = 'pending-email'
                    newuser.put()
                    try:
                        
                        tpl_body = template.Template (self.paramByName("tpl_eventRegMailBody"))
                        mail_body = tpl_body.render(template.Context({
                                                                      "event_url": self.paramByName("url") + "/event/" +  str(event),
                                                                      "confirm": self.paramByName("url") + "/confirm/" + confirmation,
                                                                      "login": str(cgi.escape(self.request.get('email'))),
                                                                      "password": str(pwd)
                                                                      }))
                        
                        mail.send_mail(sender = self.paramByName("email"), 
                                       to = str(self.request.get('email')), 
                                       subject = self.paramByName("eventRegMailSubj"), 
                                       body = mail_body)
                        self.insertContent("""Вы зарегистрированны. На вашу почту была выслана регистрационная информация.<br>""")
                    except:
                        self.insertContent("""Вы зарегистрировались на мероприятие, но в процессе обработки произошел сбой.<br> 
                                    Если вы получили регистрационное письмо, авторизуйтесь с указанными там реквизитами.<br>
                                    Или <a href="/contacts">свяжитесь с администрацией</a>""")
            else:
                self.insertContent("Данные были введены неверно!")
                self.drawPage()
                return

        dbuser = db.GqlQuery("SELECT * FROM DBUser WHERE email = :email", email = str(cgi.escape(self.request.get('email'))).replace("%40", "@"))
        userid = self.Session['userid'] if self.Session['authorized'] else dbuser.fetch(1)[0].key().id()

        anketa = DBEventAnketa()
        anketa.userid = int(userid)
        anketa.eventid = int(event)
        anketa.name = db.Text(self.Session['name'], "utf_8") if self.Session['authorized'] else self.request.get('name')
        anketa.surname = db.Text(self.Session['surname'], "utf_8") if self.Session['authorized'] else self.request.get('surname')
        anketa.phone = self.request.get('phone')
        anketa.email = self.Session['email'] if self.Session['authorized'] else self.request.get('email')
        anketa.company = self.request.get('company')
        anketa.position = self.request.get('position')
#        anketa.payway = int(self.request.get('payway'))
        if self.request.get('is_portfolio'):
            anketa.is_portfolio = bool(int(self.request.get('is_portfolio')))
        anketa.additional = self.request.get('additional')
        if self.request.get('isarhitect'):
            anketa.isarhitect = bool(int(self.request.get('isarhitect')))
        anketa.put()
        self.showMessage(""" Ваша заявка принята! """)