コード例 #1
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def applicant_approval(applicant_id):
    """
    The '/applicant_approval/<applicant_id>' route directs a superuser to approve an application with
    the id of [applicant_id].
    """
    if session['type_of_user'] == 'user':
        return redirect(url_for('dashboard'))
    if session['type_of_user'] == 'applicant':
        return redirect(url_for('dashboard_applicant'))

    form = ApplicantApprovalForm()
    info = Applicant.get_applicant_info(applicant_id)

    if request.method == 'GET':
        return render_template("applicant_approval.html",
                               applicant_id=applicant_id,
                               info=info,
                               form=form)

    if request.method == 'POST':
        if form.decision.data == 'approve':
            Applicant.approve(applicant_id)
            return redirect(url_for('dashboard_superuser'))
        else:
            if form.validate():
                Applicant.reject(applicant_id, form.reason.data)
                return redirect(url_for('dashboard_superuser'))
            else:
                flash(
                    'Approval form is invalid. Please make sure all fields are completed correctly'
                )
                return render_template("applicant_approval.html",
                                       applicant_id=applicant_id,
                                       info=info,
                                       form=form)
コード例 #2
0
ファイル: controller.py プロジェクト: tubav/OpenTeagle_API
	def register(self, request):	
		form = self.__forms.get_register_form()()
		
		vals = form.validate(request.REQUEST)
		
		if vals:
			repo = self.repo
			
			username = vals["username"]
			
			try:
				users = Applicant.objects.get(username = username)
			except Applicant.DoesNotExist: 
				users = repo.list_entities(Person, commonName = username)
					
			if users or vals["username"] == "admin":
				form.get_field("username").error = "This username is already taken"
			elif vals["password"] != vals["password2"]:
				form.get_field("password").error = "Passwords do not match"
			else:		
				applicant = Applicant(
					username = vals["username"],
					fullname = vals["firstname"] + " " + vals["lastname"],
					password = md5(vals["password"]).hexdigest(), 
					email = vals["email"],
					organisation = vals["organisation"]
				)
		
				applicant.save()
				
			return redirect(reverse("repogui", args = ("register_done", )))
	
		return redirect(reverse("repogui", args = ("register", )))
コード例 #3
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def dashboard_applicant():
    """
    The 'dashboard_applicant' route directs an applicant to their dashboard. 
    They can view the status of their application here.
    """
    if session['username']:
        form = BecomeUserForm()
        info = Applicant.get_applicant_info(session['username'])

        if session['type_of_user'] == 'applicant' and request.method == 'GET':
            return render_template("dashboard_applicant.html",
                                   info=info,
                                   form=form)
        if session['type_of_user'] == 'applicant' and request.method == 'POST':
            info = Applicant.get_applicant_info(session['username'])
            if form.use_prev_credentials.data == 'yes':
                User.use_old_credentials(info['user_id'], info['email'])
                session['type_of_user'] = '******'
                session['role'] = info['type_of_user']
                # Create a new client or developer in database depending on type of user
                if info['type_of_user'] == 'client':
                    Client(info['user_id'])
                elif info['type_of_user'] == 'developer':
                    Developer(info['user_id'])
                return redirect(url_for('dashboard'))

            elif form.validate():
                User.set_credentials(form.username.data, form.password.data,
                                     info['email'])
                session['username'] = form.username.data
                session['type_of_user'] = '******'
                session['role'] = info['type_of_user']
                # Create a new client or developer in database depending on type of user
                if info['type_of_user'] == 'client':
                    Client(form.username.data)
                elif info['type_of_user'] == 'developer':
                    Developer(form.username.data)
                return redirect(url_for('dashboard'))
            else:
                flash(
                    'Login credentials are invalid. Please check that all fields are filled correctly.'
                )
                return render_template("dashboard_applicant.html",
                                       info=info,
                                       form=form)
        elif session['type_of_user'] == 'user':
            return redirect(url_for('dashboard'))
        elif session['type_of_user'] == 'superuser':
            return redirect(url_for('dashboard_superuser'))

    else:
        return render_template("index.html")
コード例 #4
0
ファイル: views.py プロジェクト: seshadrs/shopperapp
def new_applicant():
	""" Attempts to create an applicant object, persist it, commit an application event and return the questionnare HTML. 
	Returns appropriate error msg if unable to do so. """
	form=request.form
	try:
		applicant = Applicant(form['email'],form['firstname'],form['lastname'],form['phone'],form['zipcode'])
		applicant.commit()
		Event(applicant.id,constants.EVENT_APPLIED).commit()
	except ValueError as error:
		return constants.ERROR_INVALID_VALUES
	except:
		return constants.ERROR_USER_EXISTS
	return render_template('questionnaire_page.html')
コード例 #5
0
def add_interview(id):
    from models import Applicant
    if session['logged_in']:
        applicant = Applicant.select().where(id == Applicant.id)[0]
        if not applicant.assign_slot_with_mentors():
            flash('Not enough interview slot at the assigned school!')
    return redirect(url_for('list_applicants'))
コード例 #6
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def apply():
    """
    The '/apply route directs a user that is not logged in to the application page.
    """

    # If the user is logged into the system, direct them to their dashboard
    if 'username' in session:
        if session['type_of_user'] == 'user':
            return redirect(url_for('dashboard'))
        if session['type_of_user'] == 'applicant':
            return redirect(url_for('dashboard_applicant'))
        if session['type_of_user'] == 'superuser':
            return redirect(url_for('dashboard_superuser'))

    form = SignupForm()

    if request.method == 'POST':
        if form.validate():
            new_user = Applicant(form.role.data, form.first_name.data,
                                 form.last_name.data, form.email.data,
                                 form.phone.data, form.credit_card.data,
                                 form.user_id.data, form.password.data)
            session['username'] = form.user_id.data
            session['type_of_user'] = '******'
            session['role'] = form.role.data
            return redirect(url_for('dashboard_applicant'))
        else:
            flash(
                'Applicant submission is invalid. Please check that all fields are filled correctly.'
            )
            return render_template('application.html', form=form)
    elif request.method == 'GET':
        return render_template('application.html', form=form)
コード例 #7
0
def delete_applicant(id):
    print(id)
    if session['logged_in']:
        applicant = Applicant.select().where(Applicant.id == id)[0]
        try:
            interview = Interview.select().where(Interview.id == applicant.interview_slot)[0]
            interview.free = True
            interview.save()
            AssignMentor.delete().where(AssignMentor.interview == interview).execute()
        except IndexError:
            pass

        Question.delete().where(Question.applicant == applicant).execute()

        Applicant.delete().where(Applicant.id == id).execute()
        return redirect(url_for('list_applicants'))
コード例 #8
0
def validate_email(form, field):
    """
	Custom validator for username
	:returns: True if username is unique and False if username is not unique.
	"""
    if not Applicant.is_unique_email(field.data):
        raise ValidationError(
            'There already exists an account with this email.')
        return False
    return True
コード例 #9
0
def validate_user_id(form, field):
    """
	Custom validator for username
	:returns: True if username is unique and is not equal to ' ', False if username is not unique or is equal to ' '.
	"""
    if not Applicant.is_unique_user_id(field.data) or field.data == ' ':
        raise ValidationError(
            'User ID is taken. Please enter another User ID.')
        return False
    return True
コード例 #10
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def login():
    """
    The '/login' route directs the user to the login page if they are not already logged in.
    """

    # If the user is logged into the system, direct them to their dashboard

    if 'username' in session:
        if session['type_of_user'] == 'user':
            return redirect(url_for('dashboard'))
        if session['type_of_user'] == 'applicant':
            return redirect(url_for('dashboard_applicant'))
        if session['type_of_user'] == 'superuser':
            return redirect(url_for('dashboard_superuser'))

    form = LoginForm()
    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data
        # Check if username exists and if password matches
        if BlacklistedUser.is_blacklisted(username):
            session['username'] = username
            return redirect(url_for('blacklist'))
        if User.check_password(username, password):
            session['username'] = username
            session['role'] = User.get_user_info(username)['type_of_user']
            session['type_of_user'] = '******'
            if SystemWarning.should_be_blacklisted(username):
                BlacklistedUser(username)
                return redirect(url_for('blacklist'))
            return redirect(url_for('dashboard'))
        if Applicant.check_password(username, password):
            session['username'] = username
            session['type_of_user'] = '******'
            return redirect(url_for('dashboard_applicant'))
        if SuperUser.check_password(username, password):
            session['username'] = username
            session['type_of_user'] = '******'
            return redirect(url_for('dashboard_superuser'))

        # If username or password is invalid, notify user
        else:
            flash('Invalid username or password.')
            return render_template('login.html', form=form)

    elif request.method == 'GET':
        return render_template('login.html', form=form)

    return render_template('login.html', form=form)
コード例 #11
0
ファイル: models_factory.py プロジェクト: agar3s/recluta
    def get_instance_form(self, form):
        mail = form.cleaned_data['mail']
        if Applicant.objects.filter(mail=mail).exists():
            applicant = Applicant.objects.get(mail=mail)
        else:
            applicant = Applicant()
            applicant.first_name = form.cleaned_data['first_name']
            applicant.last_name = form.cleaned_data['last_name']
            applicant.mail = mail
            applicant.save()

        return applicant
コード例 #12
0
def filter_applicants(form, interview_ids):
    query = Applicant.select().join(School, JOIN.LEFT_OUTER).switch(Applicant).join(Interview, JOIN.LEFT_OUTER)
    if form.applicant_app_code.data != "":
        query = query.where(Applicant.application_code.contains(form.applicant_app_code.data))
    if form.applicant_first_name.data != "":
        query = query.where(Applicant.first_name.startswith(form.applicant_first_name.data))
    if form.applicant_last_name.data != "":
        query = query.where(Applicant.last_name.startswith(form.applicant_last_name.data))
    if form.applicant_email.data != "":
        query = query.where(Applicant.email.contains(form.applicant_email.data))
    if form.applicant_city.data != "":
        query = query.where(Applicant.city.startswith(form.applicant_city.data))
    if form.applicant_school.data != "":
        query = query.where(School.location.startswith(form.applicant_school.data))
    if form.applicant_interview.data != "":
        query = query.where(Interview.id << interview_ids)

    return query
コード例 #13
0
ファイル: views.py プロジェクト: mcdermott-scholars/mcdermott
def add_applicant(request, event_name):
    applicant = Applicant()
    if request.method == 'POST':
        form = ApplicantForm(request.POST, request.FILES, instance=applicant)
        if (form.is_valid()):
            app = form.save(commit=False)
            if not Applicant.objects.filter(norm_name=app.norm_name).exists():
                event = Event.objects.get(name=event_name)
                app.event = event
                app.save()
                log_slack(
                    'Applicant %s added by %s' %
                    (app.get_full_name(), request.user.mcuser.get_full_name()))
                return redirect('feedback:applicant_profile', event_name,
                                applicant.norm_name)
    else:
        form = ApplicantForm(instance=applicant)
    context = {'form': form, 'event_name': event_name}
    return render(request, 'feedback/add_applicant.html', context)
コード例 #14
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def dashboard_superuser():
    """
    The 'dashboard_superuser' route directs a superuser to their dashboard.
    """
    if session['username']:
        if not session['type_of_user'] == "superuser":
            return render_template("access_denied.html")
        info = SuperUser.get_superuser_info(session['username'])
        pending_applicants = Applicant.get_pending_applicants()
        protests = SystemWarning.get_protests()
        pending_transactions = Transaction.get_pending_transactions()
        pending_delete_requests = DeleteRequest.get_pending_delete_requests()
        return render_template("dashboard_superuser.html",
                               info=info,
                               pending_applicants=pending_applicants,
                               protests=protests,
                               pending_transactions=pending_transactions,
                               pending_delete_requests=pending_delete_requests)
    else:
        return render_template("index.html")
コード例 #15
0
ファイル: routes.py プロジェクト: jchen2186/turkSystem
def editProfile():
    """
    The '/editProfile' route will direct a logged in user to edit their profile
    """
    if 'username' not in session:
        return redirect(url_for('index'))
    if session['type_of_user'] == 'superuser':
        return redirect(url_for('dashboard_superuser'))
    if session['type_of_user'] == 'applicant':
        return redirect(url_for('dashboard_applicant'))

    form = EditProfileForm()
    username = session['username']
    info = User.get_user_info(username)
    if request.method == 'GET':
        return render_template('editProfile.html', form=form, info=info)
    elif request.method == 'POST':
        if form.email.data != info['email'] and not Applicant.is_unique_email(
                form.email.data):
            flash('Email is taken. Please choose another email')
            return render_template('editProfile.html', form=form, info=info)
        else:
            User.set_email(username, form.email.data)

        if form.validate():
            if len(form.password.data) > 0:
                User.set_password(username, form.password.data)
            User.set_first_name(username, form.first_name.data)
            User.set_last_name(username, form.last_name.data)
            User.set_phone(username, form.phone.data)
            User.set_about(username, form.about.data)
            if len(form.resume.data) > 0:
                User.set_resume(username, form.resume.data)
            if len(form.interests.data) > 0:
                User.set_interests(username, form.interests.data)
            if len(form.portfolio.data) > 0:
                User.set_portfolio(username, form.portfolio.data)
            return redirect(url_for('user', name=username))
        else:
            return render_template('editProfile.html', form=form, info=info)
コード例 #16
0
    def inner(*args, **kwargs):
        from models import EmailLog, Mentor, Applicant
        subject = args[3]
        content = args[1][:144]
        mode = [i for i in modes if modes[i] == subject][0]
        recipient_email = args[2]
        if mode == 'mentor':
            mentor = Mentor.get(Mentor.email == recipient_email)
            recipient_name = mentor.first_name + " " + mentor.last_name
        else:
            applicant = Applicant.get(Applicant.email == recipient_email)
            recipient_name = applicant.first_name + " " + applicant.last_name

        timestamp = datetime.datetime.now()

        ret = func(*args, **kwargs)

        if ret is None:
            EmailLog.create(subject=subject, content=content, mode=mode, timestamp=timestamp,
                            recipient_name=recipient_name, recipient_email=recipient_email, status=True)
        else:
            EmailLog.create(subject=subject, content=content, mode=mode, timestamp=timestamp,
                            recipient_name=recipient_name, recipient_email=recipient_email, status=False)
コード例 #17
0
ファイル: applicants.py プロジェクト: apostrophest/ingroup
def create_applicant(session, user, reason):
    applicant = Applicant(user, reason)
    session.add(applicant)
    return applicant
コード例 #18
0
ファイル: forms.py プロジェクト: gasparrobi/school-system
def email_exists(form, field):
    if Applicant.select().where(Applicant.email == field.data).exists():
        raise ValidationError("Email already exists")
コード例 #19
0
def assign_school_all():
    if session['logged_in']:
        Applicant.finding_city()
        Applicant.set_app_code()
    return redirect(url_for('list_applicants'))
コード例 #20
0
def assign_interview_all():
    if session['logged_in']:
        Applicant.assign_interview_slot()
    return redirect(url_for('list_applicants'))