def post(self):
     # provide an email: get one, no email, get all
     mkey = self.request.get('memberkey')
     if mkey:
         # get specific member
         member = Member.get_by_key_name(mkey)
         method = self.request.get('method')
         if method == 'delete':
             # delete member and his certs and scores
             for cert in member.certifications:
                 for sc in cert.scores:
                     sc.delete()
                 cert.delete()
             member.delete()
             self.redirect('/admin/members')
         elif method == 'update':
             # get admin changeable properties
             if self.request.get('level'): member.level = int(self.request.get('level'))
             if self.request.get('fnam'): member.fnam = self.request.get('fnam')
             if self.request.get('lnam'): member.lnam = self.request.get('lnam')
             member.put()
             self.redirect('/admin/members?memberkey=' + mkey)
     else:
         # no action to be done
         self.redirect('/admin/members')
    def get(self):
        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri)
        url_linktext = 'Logout'
        member = Member.get_by_key_name(user.email())
        # if there is a 'id' in query string then it is a view for a specific cert...
        if self.request.get('certid'):
            cid = int(self.request.get('certid'))
            template_file = 'templates/master/cert.html'
            user = users.get_current_user()
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
            c = Certification.get_by_id(cid)
            if c:
                # i dunno
                pass


            #get all cert_temps
            ctemps_query = CertificationTemplate.all()
            ctemps = ctemps_query.fetch(100)
            for ctemp in ctemps:
                ctemp.code4 = ctemp.key().name()
            template_values = {'url': url,'url_linktext': url_linktext,'cert': c, 'ctemps':ctemps}
        else:
            member.canteach = ['KB1','KB2','KB3','IK1','IK2','IK3','EX1','EX2']
            template_file = 'templates/master/certs.html'
            cs_query = Certification.gql("WHERE createdBy= :1", users.get_current_user())
            cs = cs_query.fetch(100)
            template_values = {'url': url,'url_linktext': url_linktext, 'member':member,'certs':cs}
        path = os.path.join(os.path.dirname(__file__), template_file)
        self.response.out.write(template.render(path, template_values))
 def get(self):
     template_file = 'templates/pubprof.html'
     profile = self.request.get('profile')
     if profile:
         # parse email from escaped profile parameter
         parsedemail = profile
         member = Member.get_by_key_name(parsedemail)
         for c in member.certifications:
             if c.completed > 0: pass
             else: c.incomplete = True
         template_values = {'member':member}
     path = os.path.join(os.path.dirname(__file__), template_file)
     self.response.out.write(template.render(path, template_values))
    def get(self):
        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri)
        url_linktext = "Logout"
        member = Member.get_by_key_name(user.email())
        # if there is a 'id' in query string then it is a view for a specific cert...
        if self.request.get("certid"):
            cid = int(self.request.get("certid"))
            template_file = "templates/examiner/cert.html"
            user = users.get_current_user()
            url = users.create_logout_url(self.request.uri)
            url_linktext = "Logout"
            c = Certification.get_by_id(cid)
            if c:
                # i dunno
                pass

            # get all cert_temps
            ctemps_query = CertificationTemplate.all()
            ctemps = ctemps_query.fetch(100)
            for ctemp in ctemps:
                ctemp.code4 = ctemp.key().name()
            template_values = {"url": url, "url_linktext": url_linktext, "cert": c, "ctemps": ctemps}
        else:
            if member.level == 7:
                member.canteach = [
                    {"level": "KB1"},
                    {"level": "KB2"},
                    {"level": "KB3"},
                    {"level": "IK1", "mustscore": True},
                    {"level": "IK2", "mustscore": True},
                ]
            elif member.level == 8:
                member.canteach = [
                    {"level": "KB1"},
                    {"level": "KB2"},
                    {"level": "KB3"},
                    {"level": "IK1"},
                    {"level": "IK2"},
                    {"level": "IK3", "mustscore": True},
                ]
            template_file = "templates/examiner/certs.html"
            cs_query = Certification.gql("WHERE createdBy= :1", users.get_current_user())
            cs = cs_query.fetch(100)
            template_values = {"url": url, "url_linktext": url_linktext, "member": member, "certs": cs}
        path = os.path.join(os.path.dirname(__file__), template_file)
        self.response.out.write(template.render(path, template_values))
 def get(self):
     url = users.create_logout_url(self.request.uri)
     url_linktext = 'Logout'
     # provide an email: get one, no email, get all
     mkey = self.request.get('memberkey')
     if mkey:
         # get specific member
         member = Member.get_by_key_name(mkey)
         ctemps_query = CertificationTemplate.all()
         ctemps = ctemps_query.fetch(100)
         template_file = 'templates/admin/member.html'
         template_values = {'url': url,'url_linktext': url_linktext,'member': member, 'ctemps': ctemps}
     else:
         # get all members
         members = Member.all()
         template_file = 'templates/admin/members.html'
         template_values = {'url': url,'url_linktext': url_linktext,'members': members}
     path = os.path.join(os.path.dirname(__file__), template_file)
     self.response.out.write(template.render(path, template_values))
 def get(self):
     user = users.get_current_user()
     url = users.create_logout_url(self.request.uri)
     url_linktext = 'Logout'
     member = Member.get_by_key_name(user.email())
     if member.level == 4:
         member.canteach = [{'level':'KB1','musttaskscore':True},{'level':'KB2','mustscore':True}]
         member.musttaskscore = {'KB1':True,'KB2':True}
         member.musttaskscorejson = "{'KB1':true,'KB2':true}"
     elif member.level == 5:
         member.canteach = [{'level':'KB1','mustscore':True},{'level':'KB2','mustscore':True},{'level':'KB3','mustscore':True}]
         member.musttaskscore = {'KB1':False,'KB2':False,'KB3':True}
         member.musttaskscorejson = "{'KB1':false,'KB2':false,'KB3':true}"
     elif member.level == 6:
         member.canteach = [{'level':'KB1'},{'level':'KB2'},{'level':'KB3','mustscore':True}]
         member.musttaskscore = {'KB1':False,'KB2':False,'KB3':False}
         member.musttaskscorejson = "{'KB1':false,'KB2':false,'KB3':false}"
         # if there is a 'id' in query string then it is a view for a specific cert...
     if self.request.get('certid'):
         cid = int(self.request.get('certid'))
         template_file = 'templates/instructor/cert.html'
         user = users.get_current_user()
         url = users.create_logout_url(self.request.uri)
         url_linktext = 'Logout'
         c = Certification.get_by_id(cid)
         if c:
             ctkn = c.template.key().name()
             c.musttaskscore = member.musttaskscore[ctkn]
         #get all cert_temps
         ctemps_query = CertificationTemplate.all()
         ctemps = ctemps_query.fetch(100)
         for ctemp in ctemps:
             ctemp.code4 = ctemp.key().name()
         template_values = {'url': url,'url_linktext': url_linktext,'cert': c,'member':member, 'ctemps':ctemps}
     else:
         template_file = 'templates/instructor/certs.html'
         cs_query = Certification.gql("WHERE createdBy= :1", users.get_current_user())
         cs = cs_query.fetch(100)
         template_values = {'url': url,'url_linktext': url_linktext,'member':member,'certs':cs}
     path = os.path.join(os.path.dirname(__file__), template_file)
     self.response.out.write(template.render(path, template_values))
    def post(self):
        method = self.request.get("method")
        if self.request.get("id"):
            cert_id = int(self.request.get("id"))
        email = self.request.get("recipient")
        fnam = self.request.get("fnam")
        lnam = self.request.get("lnam")
        if self.request.get("completed") == "1":
            completed = True
        else:
            completed = False
        templatekey = self.request.get("ctemp")
        if method == "update":
            # an edit
            c = Certification.get_by_id(cert_id)
            if completed:
                if c.completed:
                    # already completed
                    pass
                else:
                    # update their level (member record)
                    if templatekey == "KB1":
                        level = 1
                    elif templatekey == "KB2":
                        level = 2
                    elif templatekey == "KB3":
                        level = 3
                    elif templatekey == "IK1":
                        level = 4
                    elif templatekey == "IK2":
                        level = 5
                    elif templatekey == "IK3":
                        level = 6
                    elif templatekey == "EX1":
                        level = 7
                    elif templatekey == "EX2":
                        level = 8
                    elif templatekey == "M":
                        level = 9
                    else:
                        pass
                    c.completed = True
                    c.owner.level = level
                    # updated Member's level using an algorithm to evaluate elements
            if c.put() and c.completed:
                # triggers an email to email
                pass
            self.redirect("/examiner/certifications")
        elif method == "delete":
            # delete the record and related scores
            c = Certification.get_by_id(cert_id)
            for s in c.scores:
                s.delete()
            # also delete the member if there are no other certs related and the member has no user
            mem = c.owner
            c.delete()
            if mem.user:
                pass
            else:
                memcs = Certification.all()
                memcs = Certification.gql("WHERE owner= :1", c.owner)
                if memcs.count(limit=2) > 0:
                    pass
                else:
                    # also check to see if this user is the creater of the record...
                    if mem.createdBy == users.get_current_user():
                        mem.delete()

            self.redirect("/examiner/certifications")
            # TODO adjust level
        else:
            # a new post
            c = Certification()
            template = CertificationTemplate.get_by_key_name(templatekey)

            c.template = template
            mem = Member.get_by_key_name(email)
            if mem:
                # ... what if the fnam and lnam are different? an update?
                pass
            else:
                # create a new member
                mem = Member(key_name=email, fnam=fnam, lnam=lnam)
                mem.put()
            if completed:
                c.completed = True
                if templatekey == "KB1":
                    level = 1
                elif templatekey == "KB2":
                    level = 2
                elif templatekey == "KB3":
                    level = 3
                elif templatekey == "IK1":
                    level = 4
                elif templatekey == "IK2":
                    level = 5
                elif templatekey == "IK3":
                    level = 6
                elif templatekey == "EX1":
                    level = 7
                elif templatekey == "EX2":
                    level = 8
                elif templatekey == "M":
                    level = 9
                mem.level = level
            mem.put()
            c.owner = mem
            c.put()
            # Trigger email to certification recipient
            from google.appengine.api import mail

            message = mail.EmailMessage(
                sender="WorldKiteOrg-DoNotReply <*****@*****.**>",
                subject="Congratulations - your WorldKite Certification is completed",
            )
            message.to = mem.key().name()
            message.body = "Congratulations" + mem.fnam + " " + mem.lnam
            message.body += """

"""
            message.body += c.template.key().name() + " " + c.template.short
            message.body += """

Visit http://worldkite.org and login with the email address
you provided for your World Kite certification. We use Google's
system for authentication so if you email account is not already
registered with Google then you will be prompted to do so.

Please let us know if you have any questions by dropping an email to:
[email protected]

Welcome to our team!

World Kite Organization
"""
            message.send()
            # now check the template and create new scores for each Element related to the CertTemp
            # first, get all CertificationTemplate.elements
            for el in template.elements:
                # now for each el, create a new ElemScore
                elsc = ElemScore()
                elsc.certtemp_elem = el
                elsc.certification = c
                if completed:
                    elsc.score = 1
                else:
                    elsc.score = 0
                elsc.put()
            self.redirect("/examiner/certifications?certid=" + str(c.key().id()))
    def post(self):
        method = self.request.get('method')
        if self.request.get('id'): cert_id = int(self.request.get('id'))
        email = self.request.get('recipient')
        fnam = self.request.get('fnam')
        lnam = self.request.get('lnam')
        if self.request.get('completed') == '1': completed = True
        else: completed = False
        templatekey = self.request.get('ctemp')
        if method == "update":
            # an edit
            c = Certification.get_by_id(cert_id)
            if completed:
                if c.completed:
                    #already completed
                    pass
                else:
                    #update their level (member record)
                    if templatekey == 'KB1': level = 1
                    elif templatekey == 'KB2': level = 2
                    elif templatekey == 'KB3': level = 3
                    elif templatekey == 'IK1': level = 4
                    elif templatekey == 'IK2': level = 5
                    elif templatekey == 'IK3': level = 6
                    elif templatekey == 'EX1': level = 7
                    elif templatekey == 'EX2': level = 8
                    elif templatekey == 'M': level = 9
                    else: pass
                    c.completed = True
                    c.owner.level = level
                    #updated Member's level using an algorithm to evaluate elements
            if c.put() and c.completed:
                #triggers an email to email
                pass
            self.redirect('/master/certifications')
        elif method == "delete":
            # delete the record and related scores
            c = Certification.get_by_id(cert_id)
            for s in c.scores:
                s.delete()
            #also delete the member if there are no other certs related and the member has no user
            mem = c.owner
            c.delete()
            if mem.user: pass
            else:
                memcs = Certification.all()
                memcs = Certification.gql("WHERE owner= :1", c.owner)
                if memcs.count(limit=2) > 0: pass
                else:
                    # also check to see if this user is the creater of the record...
                    if mem.createdBy == users.get_current_user(): mem.delete()

            self.redirect('/master/certifications')
            # TODO adjust level
        else:
            # a new post
            c = Certification()
            template = CertificationTemplate.get_by_key_name(templatekey)

            c.template = template
            mem = Member.get_by_key_name(email)
            if (mem):
                #... what if the fnam and lnam are different? an update?
                pass
            else:
                # create a new member
                mem = Member(key_name=email,fnam=fnam,lnam=lnam)
                mem.put()
                # TODO don't forget to send them an email to confirm membership!!!
            if completed:
                c.completed = True
                if templatekey == 'KB1': level = 1
                elif templatekey == 'KB2': level = 2
                elif templatekey == 'KB3': level = 3
                elif templatekey == 'IK1': level = 4
                elif templatekey == 'IK2': level = 5
                elif templatekey == 'IK3': level = 6
                elif templatekey == 'EX1': level = 7
                elif templatekey == 'EX2': level = 8
                elif templatekey == 'M': level = 9
                mem.level = level
            mem.put()
            c.owner = mem
            c.put()
            # now check the template and create new scores for each Element related to the CertTemp
            # first, get all CertificationTemplate.elements
            for el in template.elements:
                # now for each el, create a new ElemScore
                elsc = ElemScore()
                elsc.certtemp_elem = el
                elsc.certification = c
                if completed: elsc.score = 1
                else: elsc.score = 0
                elsc.put()
            self.redirect('/master/certifications?certid=' + str(c.key().id()))
    def get(self):
        template_file = "anonymous.html"
        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = "Logout"
            template_values = {"url": url, "url_linktext": url_linktext}
            if users.is_current_user_admin():
                template_file = "templates/admin/admin.html"
            else:
                # check member database and pull member.level
                member = Member.get_by_key_name(user.email())
                if member:
                    url = users.create_logout_url(self.request.uri)
                    url_linktext = "Logout"
                    member.title = "Registered Member"
                    template_file = "templates/anonymous.html"
                    if member.level is None:
                        template_file = "templates/anonymous.html"
                    else:
                        # retrieve certifications for storage in template_values
                        if member.level == LevelsEnum.BEGINNER:
                            member.title = "Kiteboard Beginner"
                            template_file = "templates/rider/beginner.html"
                        elif member.level == LevelsEnum.INTERMEDIATE:
                            member.title = "Kiteboard Intermediate"
                            template_file = "templates/rider/intermediate.html"
                        elif member.level == LevelsEnum.RIDER:
                            member.title = "Kiteboard Rider"
                            template_file = "templates/rider/rider1.html"
                        elif member.level == LevelsEnum.RIDER2:
                            member.title = "Kitebaord Advanced Rider"
                            template_file = "templates/rider/rider2.html"
                        elif member.level == LevelsEnum.INSTRUCTOR1:
                            member.title = "Kiteboard Instructor Level I"
                            template_file = "templates/instructor/instructor1.html"
                        elif member.level == LevelsEnum.INSTRUCTOR2:
                            member.title = "Kiteboard Instructor Level II"
                            template_file = "templates/instructor/instructor2.html"
                        elif member.level == LevelsEnum.INSTRUCTOR3:
                            member.title = "Kiteboard Instructor Level III"
                            template_file = "templates/instructor/instructor3.html"
                        elif member.level == LevelsEnum.EXAMINER:
                            member.title = "Examiner"
                            template_file = "templates/examiner/examiner1.html"
                        elif member.level == LevelsEnum.EXAMINER2:
                            member.title = "Senior Examiner"
                            template_file = "templates/examiner/examiner2.html"
                        elif member.level == LevelsEnum.MASTER:
                            member.title = "Master Examiner"
                            template_file = "templates/master/master.html"
                        else:
                            # raise and handle error: member.level is beyond LevelsEnum constraints - invalid state.
                            pass
                    template_values = {"url": url, "url_linktext": url_linktext, "member": member}
                else:
                    # a google user but not registered
                    url = users.create_logout_url(self.request.uri)
                    url_linktext = "Logout"
                    template_file = "templates/anonymous.html"
                    template_values = {"url": url, "url_linktext": url_linktext, "register": True}
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = "Login|Register"
            template_file = "templates/anonymous.html"
            template_values = {"url": url, "url_linktext": url_linktext, "loginregister": True}

        path = os.path.join(os.path.dirname(__file__), template_file)
        self.response.out.write(template.render(path, template_values))
    def post(self):
        method = self.request.get('method')
        cert_id = None
        if self.request.get('id'): cert_id = int(self.request.get('id'))
        email = self.request.get('recipient')
        fnam = self.request.get('fnam')
        lnam = self.request.get('lnam')
        if self.request.get('completed') == '1': completed = True
        else: completed = False
        templatekey = self.request.get('ctemp')
        if method == "update":
            # an edit
            c = Certification.get_by_id(cert_id)
            if completed:
                if c.completed:
                    #already completed
                    pass
                else:
                    #update their level (member record)
                    if templatekey == 'KB1': level = 1
                    elif templatekey == 'KB2': level = 2
                    elif templatekey == 'KB3': level = 3
                    elif templatekey == 'IK1': level = 4
                    elif templatekey == 'IK2': level = 5
                    elif templatekey == 'IK3': level = 6
                    elif templatekey == 'EX1': level = 7
                    elif templatekey == 'EX2': level = 8
                    elif templatekey == 'M': level = 9
                    else: level = 0
                    c.completed = True
                    c.owner.level = level
                    #updated Member's level using an algorithm to evaluate elements
            if c.put() and c.completed:
                #triggers an email to email
                pass
            self.redirect('/admin/certifications')
        elif method == "delete":
            # delete the record and related scores
            c = Certification.get_by_id(cert_id)
            for s in c.scores:
                s.delete()
            c.delete()
            self.redirect('/admin/certifications')
            # todo : adjust level
        else:
            # a new post
            c = Certification()
            template = CertificationTemplate.get_by_key_name(templatekey)

            c.template = template
            mem = Member.get_by_key_name(email)
            # goddamit, email should be the keyname for a member!!!
            if mem:
                #... what if the fnam and lnam are different? an update?
                pass
            else:
                # create a new member
                mem = Member(key_name=email,fnam=fnam,lnam=lnam)
                mem.put()
                # todo : don't forget to send them an email to confirm membership!!!
            if completed:
                c.completed = True
                if templatekey == 'KB1': level = 1
                elif templatekey == 'KB2': level = 2
                elif templatekey == 'KB3': level = 3
                elif templatekey == 'IK1': level = 4
                elif templatekey == 'IK2': level = 5
                elif templatekey == 'IK3': level = 6
                elif templatekey == 'EX1': level = 7
                elif templatekey == 'EX2': level = 8
                elif templatekey == 'M': level = 9
                else: level = 0
                mem.level = level
            mem.put()
            c.owner = mem
            c.put()
            # now check the template and create new scores for each Element related to the CertTemp
            # first, get all CertificationTemplate.elements
            for el in template.elements:
                # now for each el, create a new ElemScore
                elsc = ElemScore()
                elsc.certtemp_elem = el
                elsc.certification = c
                if completed: elsc.score = 1
                else: elsc.score = 0
                elsc.put()
            self.redirect('/admin/members?memberkey=' + email)