Exemplo n.º 1
0
        template_values[
            'is_member'] = True if 'member' in self.session else False
        if 'member' in self.session:
            email = self.session['member']
            member = Member.get_by_email(email)
            template_values['member'] = member
            if member.role == MEMBER_ROLE[MANAGER]:
                template_values['is_manager'] = True
            else:
                modules_count = modules.count() * 1.0
                completed_modules = []
                for module in modules:
                    if module.completed:
                        completed_modules.append(module)
                completed_modules_count = len(completed_modules)
                score = (completed_modules_count / modules_count) * 100.0
                engage_score = round(score * random(), 0)
                engage_score = int(engage_score) if engage_score > 1 else 1
                template_values['donuts'] = DonutFactory.get_donuts(
                    100, 0.875, [('Engineer1', [
                        DonutSegment(engage_score, '#1c758a'),
                        DonutSegment(score, '#58c4dd')
                    ], '/assets/img/tracks/mobile_dev.png')], 'transparent',
                    '#ddd')
        self.render_template(template_name='program_listing.html',
                             template_values=template_values)


app = RestApplication([('/tracks', TracksPage),
                       ('/tracks/program_listing', ProgramListingPage)])
Exemplo n.º 2
0
                        'status': 'success',
                        'email': to_email
                    }), 200, 'application/json')
            else:
                self.write(
                    json.dumps({
                        'status': 'error',
                        'email': to_email,
                        'name': result['error']
                    }), 200, 'application/json')


class SaveAssociationHandler(RequestHandler):
    def post(self):
        track_id = self['track']
        program_id = self['program']
        expert_email = self['expert']
        program = Program.get_by_key_name(
            program_id, parent=Track.get_by_key_name(track_id))
        program.expert = Expert.get_by_key_name(expert_email)
        program.put()
        self.redirect("/tracks/program_listing?program_id=%s&track_id=%s" %
                      (program_id, track_id))


app = RestApplication([
    ("/api/common/download_image/([^/]+)", ImageDownloadHandler),
    ("/api/common/save_newsletter", CreateNewsletterHandler),
    ("/api/common/subscribe_to_newsletter", SendNewsletterConfirmationEmail),
    ("/api/common/save_association", SaveAssociationHandler)
])
Exemplo n.º 3
0
class EnrollTrackHandler(RequestHandler):
    @login_required
    def post(self):
        email = self.session['member']
        track_id = self['track_id']
        program_id = self['program_id']
        program = Program.get_by_key_name(
            program_id, parent=Track.get_by_key_name(track_id))
        EnrollProgram.create(Member.get_by_email(email), program)
        self.redirect("/tracks/program_listing?program_id=%s&track_id=%s" %
                      (program_id, track_id))


app = RestApplication([
    ("/api/members/login", LoginHandler),
    ("/api/members/([^/]+)/update", MemberUpdateHandler),
    ("/api/members/create", MemberCreateHandler),
    ("/api/members/experts/create", ExpertCreateHandler),
    ("/api/members/update/expert", ExpertUpdateHandler),
    ("/api/members/add_email", AddMemberEmailHandler),
    ("/api/members/get_member", ExpertFetchHandler),
    ("/api/members/([^/]+)/image", ImageHandler),
    ("/api/members/get_all_members", AllMembersFetchHandler),
    ("/api/members/validate_access_code", ValidateAccessCodeHandler),
    ("/api/members/process_access_answer", ProcessAccessAnswerHandler),
    ("/api/members/fetch_access_question", FetchAccessQuestionHandler),
    ("/api/members/subscribe_to_newsletter", SubscribeNewsletterHandler),
    ("/api/members/enroll", EnrollTrackHandler)
])
Exemplo n.º 4
0
def setup_modules():
    for track in tracks:
        track_obj = Track.get_by_key_name(track.id)
        for program in track.programs:
            start_date = datetime.now()
            program_obj = Program.get_by_key_name(program.id, parent=track_obj)
            if program.modules:
                for module in program.modules:
                    start_date = start_date + timedelta(days=3)
                    ProgramModule(parent=program_obj, name=module.title, units=module.units, start_date=start_date).put()

class PopulateTracksHandler(RequestHandler):
    def get(self):
        setup_tracks()
        self.redirect("/tracks")

class PopulateProgramsHandler(RequestHandler):
    def get(self):
        setup_programs()
        self.redirect("/tracks")

class PopulateModulesHandler(RequestHandler):
    def get(self):
        setup_modules()
        self.redirect("/tracks")

app = RestApplication([("/api/tracks/populate/tracks",PopulateTracksHandler),
                        ("/api/tracks/populate/programs",PopulateProgramsHandler),
                        ("/api/tracks/populate/modules",PopulateModulesHandler)])
Exemplo n.º 5
0
        url = typeform_url + '?' + urllib.urlencode(params)
        resp = urlfetch.fetch(url, deadline=60)
        result = json.loads(resp.content)
        if 200 <= result['http_status'] < 300:
            for response in result['responses']:
                project = {}
                for question in result['questions']:
                    q = question['question']
                    if q in self.questions_list:
                        qid = str(question['id'])
                        project[self.questions_list[q]] = response['answers'][
                            qid] if qid in response['answers'] else None
                if project:
                    p = Project()
                    p.title = project['title']
                    p.description = project['description']
                    p.end_date = datetime.strptime(
                        str(project['end_day']) + '-' +
                        str(project['end_month']) + '-' +
                        str(project['end_year']),
                        "%d-%m-%Y").date() if project['end_day'] and project[
                            'end_month'] and project['end_year'] else None
                    p.category = project['category']
                    p.put()  #logging.info(p)


app = RestApplication([('/api/projects/add_project', AddProjectHandler),
                       ('/api/projects/update_project_skills',
                        UpdateProjectSkillsHandler),
                       ('/api/projects/update_project', UpdateProjectHandler),
                       ('/api/projects/fetch_projects', FetchProjectsHandler)])
Exemplo n.º 6
0
import json
from handlers.rest.rest_application import RestApplication
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
from handlers import RequestHandler
from util.util import validate_captcha


class ImageDownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, picture_key):
        if picture_key:
            resource = str(urllib.unquote(picture_key))
            blob_info = blobstore.BlobInfo.get(resource)
            self.send_blob(blob_info)
            return


class ValidateCaptchaHandler(RequestHandler):
    def post(self):
        challenge = self['recaptcha_challenge_field']
        solution = self['recaptcha_response_field']
        remote_ip = self.request.remote_addr
        is_solution_correct = validate_captcha(solution, challenge, remote_ip)
        self.write(json.dumps({'solution_correct': is_solution_correct}), 200,
                   'application/json')


app = RestApplication([
    ("/api/common/download_image/([^/]+)", ImageDownloadHandler),
    ("/api/common/validate_captcha", ValidateCaptchaHandler)
])
Exemplo n.º 7
0
class TempHandler(WebRequestHandler):
    @login_required
    def get(self):
        self.response.out.write(self.session['member'])


class MemberProfileImagePage(WebRequestHandler):
    @login_required
    def get(self):
        path = 'member_profile_image.html'
        email = self.session['member']
        member = Member.get_by_email(email)
        image_upload_url = blobstore.create_upload_url('/api/members/' +
                                                       email + '/update')
        template_values = {
            'member': member,
            'image_upload_url': image_upload_url
        }
        template_values[
            'is_member'] = True if 'member' in self.session else False
        #if 'member' in self.session:
        #    template_values['member'] = Member.get_member_json(self.session['member'])
        self.write(self.get_rendered_html(path, template_values), 200)


app = RestApplication([("/members/login", LoginHandler),
                       ("/members/logout", LogoutHandler),
                       ('/members/profile', MemberProfilePage),
                       ('/members/profile/image', MemberProfileImagePage),
                       ("/members/temp", TempHandler)])