Esempio n. 1
0
def profile_page(id=None):
    if id == None:
        user = current_user
    else:
        user = User.find(id)
    if user == None:
        abort(404)

    profile_data = {}
    if user.role == ROLES.DEVELOPER:
        profile_data = { 'ongoing_projects': user.get_ongoing_projects(),
                         'completed_projects': user.get_completed_projects(),
                         'username': user.username,
                         'avatar': user.avatar,
                         'description': user.bio,
                         'skills': user.get_skills(),
                         'role' : user.role,
                         'codeacademy_badges': user.get_code_academy_badges() } 
    elif user.role == ROLES.PROPOSER:
        profile_data = { 'ongoing_proposals': user.get_ongoing_proposals(),
                         'pending_proposals': user.get_pending_proposals(),
                         'completed_proposals': user.get_completed_proposals(),
                         'name': user.name,
                         'description': user.bio,
                         'avatar': user.avatar,
                         'role' : user.role}
    else:
        abort(400)

    print current_user.role

    return render_template('profile.html', user=user, **profile_data)
Esempio n. 2
0
def signup(role=None):
    if current_user.is_authenticated():
        return redirect('/')
    print 'signup'
    signup_form = SignupForm()
    signup_form.role.choices = [(ROLES.DEVELOPER, 'I\'m a developer'),
                                (ROLES.PROPOSER, 'I\'m a proposer!')]
    print dir(signup_form.role)

    if signup_form.validate_on_submit():
        User.create(signup_form.username.data, signup_form.email.data,
                    signup_form.password.data, signup_form.role.data)
        return redirect('/login')
    if not role:
        return render_template('signup.html', signup_form=signup_form)
    role = role.lower().strip()
    if role == 'developer':
        signup_form.role.data = ROLES.DEVELOPER
        return render_template('signup.developer.html',
                               signup_form=signup_form)
    elif role == 'proposer':
        signup_form.role.data = ROLES.PROPOSER
        return render_template('signup.proposer.html', signup_form=signup_form)
Esempio n. 3
0
def login():
    print 'login'
    login_form = LoginForm()

    if login_form.validate_on_submit():
        user = User.find_by_identifier(login_form.identifier.data)
        if not user:
            abort(404)  # User not found
        if user.check_password(login_form.password.data):
            login_user(user)
            return redirect('/')
        else:
            flash('Wrong password')
            return redirect('/login')
    return render_template('login.html', login_form=login_form)
Esempio n. 4
0
def login():
    print 'login'
    login_form = LoginForm()

    if login_form.validate_on_submit():
        user = User.find_by_identifier(login_form.identifier.data)
        if not user:
            abort(404) # User not found
        if user.check_password(login_form.password.data):
            login_user(user)
            return redirect('/')
        else:
            flash('Wrong password')
            return redirect('/login')
    return render_template('login.html', login_form=login_form)
Esempio n. 5
0
def landing_page(id=None):
    if id == None:
        abort(404)

    user = User.find(id)

    if user == None:
        abort(404)

    landing_page_data = {}

    if user.role == ROLES.DEVELOPER:
        landing_page_data = {
            'avatar': user.avatar,
            'username': user.username,
            'role': user.role,
            'ongoing_projects': user.get_ongoing_projects(),
            'completed_projects': user.get_completed_projects(),
            'suggested_projects': get_suggestions()
        }
    elif user.role == ROLES.PROPOSER:
        landing_page_data = {
            'avatar': user.avatar,
            'name': user.name,
            'role': user.role,
            'ongoing_proposals': user.get_ongoing_proposals(),
            'pending_proposals': user.get_pending_proposals(),
            'completed_proposals': user.get_completed_proposals()
        }
    else:
        abort(400)

    def get_suggestions():
        pending_projects = Project.get_all_pending_projects()
        skills = user.get_skills()
        suggestions = []
        skills_needed = []
        for p in pending_projects:
            skills_needed = p.get_skills()
            for s in skills:
                if s in skills_needed:
                    suggestions.append(p)
                    break
        return suggestions

    return render_template('landing_page.html', **landing_page_data)
Esempio n. 6
0
def settings():

    user = User.find(current_user.id)
    settings_form = SettingsForm()

    #setattr(current_user, key, getattr(settings_form, key))
    print dir(settings_form.skills)
    print settings_form.skills.data
    settings_form.skills.choices = [(skill.id, skill.name)
                                    for skill in Skill.query.all()]

    if settings_form.validate_on_submit():
        if settings_form.name.data:
            current_user.set_name(settings_form.name.data)
        if settings_form.email.data:
            current_user.set_email(settings_form.email.data)
        if settings_form.bio.data:
            current_user.set_bio(settings_form.bio.data)
        if settings_form.code_academy_username.data:
            current_user.set_code_academy_username(
                settings_form.code_academy_username.data)
            current_user.get_code_academy_badges()

        existing_skill_ids = [skill.id for skill in user.skills]
        if settings_form.skills.data and settings_form.skills.data != existing_skill_ids:
            print 'editing skills'
            for skill_id in settings_form.skills.data:
                if skill_id not in existing_skill_ids:
                    user.add_skill_id(skill_id)
            for skill_id in existing_skill_ids:
                if skill_id not in settings_form.skills.data:
                    user.remove_skill_id(skill_id)

        flash('Settings changed')

    settings_form.name.data = user.name
    settings_form.email.data = user.email
    settings_form.avatar.data = user.avatar
    settings_form.bio.data = user.bio
    settings_form.code_academy_username.data = user.code_academy_username

    settings_form.skills.data = [skill.id for skill in user.skills]

    return render_template('settings.html',
                           settings_form=settings_form,
                           skills=Skill.query.all())
Esempio n. 7
0
def settings():
    
    user = User.find(current_user.id)
    settings_form = SettingsForm()

    #setattr(current_user, key, getattr(settings_form, key))
    print dir(settings_form.skills)
    print settings_form.skills.data
    settings_form.skills.choices = [(skill.id, skill.name) for skill in Skill.query.all()]

    if settings_form.validate_on_submit():
        if settings_form.name.data:
            current_user.set_name(settings_form.name.data)
        if settings_form.email.data:
            current_user.set_email(settings_form.email.data)
        if settings_form.bio.data:
            current_user.set_bio(settings_form.bio.data)
        if settings_form.code_academy_username.data:
            current_user.set_code_academy_username(settings_form.code_academy_username.data)
            current_user.get_code_academy_badges()

        existing_skill_ids = [skill.id for skill in user.skills]
        if settings_form.skills.data and settings_form.skills.data != existing_skill_ids:
            print 'editing skills'
            for skill_id in settings_form.skills.data:
                if skill_id not in existing_skill_ids:
                    user.add_skill_id(skill_id)
            for skill_id in existing_skill_ids:
                if skill_id not in settings_form.skills.data:
                    user.remove_skill_id(skill_id)
            
        flash('Settings changed')

    settings_form.name.data = user.name
    settings_form.email.data = user.email
    settings_form.avatar.data = user.avatar
    settings_form.bio.data = user.bio
    settings_form.code_academy_username.data = user.code_academy_username

    settings_form.skills.data = [skill.id for skill in user.skills]

    return render_template('settings.html', settings_form=settings_form, skills=Skill.query.all())
Esempio n. 8
0
def landing_page(id=None):
    if id == None:
        abort(404)

    user = User.find(id)

    if user == None:
        abort(404)

    landing_page_data = {}

    if user.role == ROLES.DEVELOPER:
        landing_page_data = { 'avatar': user.avatar,
                              'username': user.username,
                              'role' : user.role,
                              'ongoing_projects': user.get_ongoing_projects(),
                              'completed_projects': user.get_completed_projects(),
                              'suggested_projects': get_suggestions() }
    elif user.role == ROLES.PROPOSER:
        landing_page_data = { 'avatar': user.avatar,
                              'name': user.name, 
                              'role' : user.role,
                              'ongoing_proposals': user.get_ongoing_proposals(),
                              'pending_proposals': user.get_pending_proposals(),
                              'completed_proposals': user.get_completed_proposals() }
    else:
        abort(400)
     
    def get_suggestions():
        pending_projects = Project.get_all_pending_projects()
        skills = user.get_skills()
        suggestions = []
        skills_needed = []
        for p in pending_projects:
            skills_needed = p.get_skills()
            for s in skills:
                if s in skills_needed:
                    suggestions.append(p)
                    break
        return suggestions       

    return render_template('landing_page.html', **landing_page_data)
Esempio n. 9
0
def profile_page(id=None):
    if id == None:
        user = current_user
    else:
        user = User.find(id)
    if user == None:
        abort(404)

    profile_data = {}
    if user.role == ROLES.DEVELOPER:
        profile_data = {
            'ongoing_projects': user.get_ongoing_projects(),
            'completed_projects': user.get_completed_projects(),
            'username': user.username,
            'avatar': user.avatar,
            'description': user.bio,
            'skills': user.get_skills(),
            'role': user.role,
            'codeacademy_badges': user.get_code_academy_badges()
        }
    elif user.role == ROLES.PROPOSER:
        profile_data = {
            'ongoing_proposals': user.get_ongoing_proposals(),
            'pending_proposals': user.get_pending_proposals(),
            'completed_proposals': user.get_completed_proposals(),
            'name': user.name,
            'description': user.bio,
            'avatar': user.avatar,
            'role': user.role
        }
    else:
        abort(400)

    print current_user.role

    return render_template('profile.html', user=user, **profile_data)
Esempio n. 10
0
 def validate_identifier(form, field):
     print field.data
     if not User.find_by_identifier(field.data):
         return ValidationError('No user found')
Esempio n. 11
0
 def validate_identifier(form, field):
     print field.data
     if not User.find_by_identifier(field.data):
         return ValidationError('No user found')
Esempio n. 12
0
 def validate_email(form, field):
     if User.find_by_email(field.data):
         raise ValidationError('That email address has already been registered to an account')
Esempio n. 13
0
from hackkings import db
from hackkings.constants import ROLES, STATES
from hackkings.models import User, Skill, Project

# Create users
sachin = User.create("sazap10", "*****@*****.**", "password",
                     ROLES.PROPOSER)
andrew = User.create("southrop", "*****@*****.**", "hunter2",
                     ROLES.DEVELOPER)
nic = User.create("nic", "*****@*****.**", "password", ROLES.DEVELOPER)
Ilija = User.create("Ilija", "*****@*****.**", "letmein", ROLES.DEVELOPER)
Microsoft = User.create("Microsoft", "*****@*****.**", "apple",
                        ROLES.PROPOSER)
Microsoft.set_bio(
    "Whether you are creating new code, algorithms or data structures, you are the link between abstract concepts and the technology products used daily by your friends, family and millions of other people around the world. While working on our projects you will improve your technical skills and develop next-generation software!"
)

# Create Skills
someSkills = ["Java", "C++", "JavaScript", "C", "Python", "Web Dev"]
skillObjects = map(Skill, someSkills)
map(db.session.add, skillObjects)
db.session.commit()

# Add skills to users
map(andrew.add_skill, skillObjects)
map(nic.add_skill, skillObjects)
map(Ilija.add_skill, skillObjects)

# Create Projects
names = [
    "Project", "Awesome Project", "Even Awesomer Project",
Esempio n. 14
0
 def load_user(userid):
     return User.find(userid)
Esempio n. 15
0
 def validate_email(form, field):
     u = User.find_by_email(field.data)
     if u and u != current_user:
         raise ValidationError('That email address has already been registered to an account')
Esempio n. 16
0
 def validate_username(form, field):
     if len(field.data) == 0:
         raise ValidationError('That\'s not a good username!')
     if User.find_by_username(field.data):
         raise ValidationError('That username has already been taken')
Esempio n. 17
0
from hackkings import db
from hackkings.constants import ROLES, STATES
from hackkings.models import User,Skill,Project

# Create users
sachin = User.create("sazap10", "*****@*****.**", "password", ROLES.PROPOSER)
andrew = User.create("southrop", "*****@*****.**", "hunter2", ROLES.DEVELOPER)
nic = User.create("nic", "*****@*****.**", "password", ROLES.DEVELOPER)
Ilija= User.create("Ilija", "*****@*****.**", "letmein", ROLES.DEVELOPER)
Microsoft=User.create("Microsoft", "*****@*****.**", "apple", ROLES.PROPOSER)
Microsoft.set_bio("Whether you are creating new code, algorithms or data structures, you are the link between abstract concepts and the technology products used daily by your friends, family and millions of other people around the world. While working on our projects you will improve your technical skills and develop next-generation software!")

# Create Skills
someSkills = ["Java", "C++","JavaScript", "C", "Python", "Web Dev"]
skillObjects = map(Skill,someSkills);
map(db.session.add, skillObjects)
db.session.commit()

# Add skills to users
map(andrew.add_skill, skillObjects)
map(nic.add_skill, skillObjects)
map(Ilija.add_skill, skillObjects)

# Create Projects
names = ["Project", "Awesome Project", "Even Awesomer Project", "Super Awesome Project", "Super Duper Awesomer Project"]
for name in names:
    project = Project(name, sachin, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eleifend tellus a tortor consequat, sit amet hendrerit massa hendrerit. Mauris nec lacus tortor. Praesent dictum erat at tortor varius gravida. Nulla ac orci eu risus pretium pulvinar. Nam vitae odio orci. Donec elit eros, hendrerit at diam id, eleifend placerat augue. Pellentesque sapien leo, imperdiet eget augue eu, adipiscing placerat urna. Maecenas diam ante, sodales non rhoncus eget, dictum sed libero.", "9000", "0")
    project.add_skill(skillObjects[1])
    if name == "Project":
    	project.add_developer(andrew)
    if name == "Even Awesomer Project":
Esempio n. 18
0
 def validate_email(form, field):
     u = User.find_by_email(field.data)
     if u and u != current_user:
         raise ValidationError(
             'That email address has already been registered to an account')