Ejemplo n.º 1
0
def project_edit_action(project_id, detail_view=False):
    """ Project editing handler """
    project = Project.query.filter_by(id=project_id).first_or_404()
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (isUserActive(current_user)
                             and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    if not detail_view:
        form = ProjectForm(obj=project, next=request.args.get('next'))
        form.category_id.choices = [(c.id, c.name)
                                    for c in project.categories_all()]
        if len(form.category_id.choices) > 0:
            form.category_id.choices.insert(0, (-1, ''))
        else:
            del form.category_id
    else:
        form = ProjectDetailForm(obj=project, next=request.args.get('next'))
    if form.validate_on_submit():
        del form.id
        form.populate_obj(project)
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Project updated.', 'success')
        project_action(project_id, 'update', False)
        return redirect(url_for('project.project_view', project_id=project.id))
    return render_template('public/projectedit.html',
                           detail_view=detail_view,
                           current_event=project.event,
                           project=project,
                           form=form)
Ejemplo n.º 2
0
def project_new(event_id):
    if not isUserActive(current_user):
        flash(
            "Your account needs to be activated - " +
            " please contact an organizer.", 'warning')
        return redirect(url_for('public.event', event_id=event_id))
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if event.lock_starting:
        flash('Starting a new project is disabled for this event.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    if isUserActive(current_user):
        project = Project()
        project.user_id = current_user.id
        form = ProjectNew(obj=project, next=request.args.get('next'))
        form.category_id.choices = [(c.id, c.name)
                                    for c in project.categories_all(event)]
        if len(form.category_id.choices) > 0:
            form.category_id.choices.insert(0, (-1, ''))
        else:
            del form.category_id
        if form.validate_on_submit():
            del form.id
            form.populate_obj(project)
            project.event = event
            if event.has_started:
                project.progress = 5  # Start as team
            else:
                project.progress = -1  # Start as challenge
            project.update()
            db.session.add(project)
            db.session.commit()
            flash('Invite your team to Join this page!', 'success')
            project_action(project.id, 'create', False)
            cache.clear()
            if event.has_started:
                project_action(project.id, 'star', False)  # Join team
            if len(project.autotext_url) > 1:
                return project_autoupdate(project.id)
            else:
                purl = url_for('project.project_view', project_id=project.id)
                return redirect(purl)
    return render_template('public/projectnew.html',
                           active="projectnew",
                           current_event=event,
                           form=form)
Ejemplo n.º 3
0
def project_star(project_id):
    if not isUserActive(current_user):
        flash(
            "User currently not allowed to join projects - please contact " +
            " organizers for activation.", 'warning')
        return redirect(url_for('project.project_view', project_id=project_id))
    flash('Welcome to the team!', 'success')
    return project_action(project_id, 'star', then_redirect=True)
Ejemplo n.º 4
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    if not isUserActive(user):
        # return "User deactivated. Please contact an event organizer."
        flash(
            'This user account is under review. Please contact the '
            + 'organizing team if you have any questions.',
            'warning'
        )
    submissions = user.posted_challenges()
    projects = user.joined_projects(False)
    score = sum([p.score for p in projects])
    posts = user.latest_posts()
    return render_template("public/userprofile.html", active="profile",
                           user=user, projects=projects, score=score,
                           submissions=submissions, posts=posts)
Ejemplo n.º 5
0
def IsProjectStarred(project, current_user):
    if not isUserActive(current_user):
        return False
    return Activity.query.filter_by(name='star',
                                    project_id=project.id,
                                    user_id=current_user.id).count() > 0
Ejemplo n.º 6
0
def project_star(project_id):
    if not isUserActive(current_user):
        return "User not allowed. Please contact event organizers."
    flash('Welcome to the team!', 'success')
    return project_action(project_id, 'star', then_redirect=True)
Ejemplo n.º 7
0
def project_new(event_id):
    if not isUserActive(current_user):
        flash(
            "Your account needs to be activated - " +
            " please contact an organizer.", 'warning')
        return redirect(url_for('public.event', event_id=event_id))
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if event.lock_starting:
        flash('Starting a new project is disabled for this event.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    if not isUserActive(current_user):
        flash('Your user account is not permitted to start projects.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    # Collect resource tips
    suggestions = []
    if not event.lock_resources:
        suggestions = getSuggestionsForStage(0)
    # Project form
    project = Project()
    project.user_id = current_user.id
    form = ProjectNew(obj=project, next=request.args.get('next'))
    form.category_id.choices = [(c.id, c.name)
                                for c in project.categories_all(event)]
    if len(form.category_id.choices) > 0:
        form.category_id.choices.insert(0, (-1, ''))
    else:
        del form.category_id
    if form.validate_on_submit():
        tpl_id = None
        if form.template.data:
            tpl_id = form.template.data
        del form.id
        del form.template
        form.populate_obj(project)
        if tpl_id:
            template = Project.query.get(tpl_id)
            project.longtext = template.longtext
            project.image_url = template.image_url
            project.source_url = template.source_url
            project.webpage_url = template.webpage_url
            project.download_url = template.download_url
        # Check event state
        project.event = event
        if event.has_started:
            project.progress = 5  # Start as team
        else:
            project.progress = -1  # Start as challenge
        # Update the project
        project.update()
        db.session.add(project)
        db.session.commit()
        flash('Now invite your team to Join this page!', 'success')
        project_action(project.id, 'create', False)
        cache.clear()
        if event.has_started:
            project_action(project.id, 'star', False)  # Join team
        if len(project.autotext_url) > 1:
            return project_autoupdate(project.id)
        else:
            purl = url_for('project.project_view', project_id=project.id)
            return redirect(purl)
    return render_template('public/projectnew.html',
                           current_event=event,
                           form=form,
                           suggestions=suggestions,
                           active="projects")