def project_edit(project_id): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous 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) form = ProjectForm(obj=project, next=request.args.get('next')) form.progress.choices = projectProgressList(event.has_started or event.has_finished) form.category_id.choices = [(c.id, c.name) for c in project.categories_all()] form.category_id.choices.insert(0, (-1, '')) 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('public.project', project_id=project.id)) return render_template('public/projectedit.html', current_event=event, project=project, form=form)
def project_autoupdate(project_id): project = Project.query.filter_by(id=project_id).first_or_404() starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) if not allow_edit or project.is_hidden or not project.is_autoupdate: flash('You may not sync this project.', 'warning') return project_action(project_id, None) data = GetProjectData(project.autotext_url) if not 'name' in data: flash("Project could not be synced: check the autoupdate link.", 'warning') return project_action(project_id, None) if 'name' in data and data['name']: project.name = data['name'] if 'summary' in data and data['summary']: project.summary = data['summary'] if 'description' in data and data['description']: project.longtext = data['description'] if 'homepage_url' in data and data['homepage_url']: project.webpage_url = data['homepage_url'] if 'contact_url' in data and data['contact_url']: project.contact_url = data['contact_url'] if 'source_url' in data and data['source_url']: project.source_url = data['source_url'] if 'image_url' in data and data['image_url']: project.image_url = data['image_url'] project.update() db.session.add(project) db.session.commit() flash("Project data synced.", 'success') return project_action(project.id, 'update')
def project_post(project_id): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous 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) form = ProjectPost(obj=project, next=request.args.get('next')) form.progress.choices = projectProgressList(event.has_started or event.has_finished) if not form.note.data: form.note.data = "---\n`%s` " % datetime.utcnow().strftime( "%d.%m.%Y %H:%M") if form.validate_on_submit(): del form.id form.populate_obj(project) project.longtext += "\n\n" + form.note.data 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('public.project', project_id=project.id)) return render_template('public/projectpost.html', current_event=event, project=project, form=form)
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)
def project_autoupdate(project_id): project = Project.query.filter_by(id=project_id).first_or_404() if not project.is_autoupdateable: return project_action(project_id) # Check user permissions starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) if not allow_edit or project.is_hidden: flash('You may not sync this project.', 'warning') return redirect(url_for('project.project_view', project_id=project_id)) # Start update process has_autotext = project.autotext and len(project.autotext) > 1 data = GetProjectData(project.autotext_url) if not data or 'name' not in data: flash("To Sync: ensure a README on the remote site.", 'warning') return redirect(url_for('project.project_view', project_id=project_id)) SyncProjectData(project, data) # Confirmation messages if not has_autotext: if project.autotext and len(project.autotext) > 1: project_action(project.id, 'update', action='sync', text=str(len(project.autotext)) + ' bytes') flash("Thanks for contributing on %s" % data['type'], 'success') else: flash("Could not sync: remote README has no data.", 'warning') return redirect( url_for('project.project_view_posted', project_id=project_id))
def project_action(project_id, of_type=None, as_view=True, then_redirect=False, action=None, text=None, resource=None): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event if of_type is not None: ProjectActivity(project, of_type, current_user, action, text, resource) if not as_view: return True if then_redirect: return redirect(url_for('public.project', project_id=project.id)) starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) allow_edit = allow_edit and not event.lock_editing project_team = project.team() latest_activity = project.latest_activity() project_signals = project.all_signals() suggestions = SuggestionsByProgress(project.progress) return render_template('public/project.html', current_event=event, project=project, project_starred=starred, project_team=project_team, project_signals=project_signals, suggestions=suggestions, allow_edit=allow_edit, latest_activity=latest_activity)
def project_post(project_id): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event starred = IsProjectStarred(project, current_user) allow_post = starred # or (not current_user.is_anonymous and current_user.is_admin) # allow_post = allow_post and not event.lock_resources if not allow_post: flash('You do not have access to post to this project.', 'warning') return project_action(project_id, None) form = ProjectPost(obj=project, next=request.args.get('next')) # Evaluate project progress stage, all_valid = validateProjectData(project) # Process form if form.validate_on_submit(): if form.has_progress.data: # Check and update progress found_next = False if all_valid: for a in projectProgressList(True, False): # print(a[0]) if found_next: project.progress = a[0] flash('Your project has been promoted!', 'info') break if a[0] == project.progress or \ not project.progress or \ project.progress < 0: found_next = True # print("Founddd") if not all_valid or not found_next: flash('Your project did not meet stage requirements.', 'info') # Update project data del form.id del form.has_progress form.populate_obj(project) project.update() db.session.add(project) db.session.commit() cache.clear() project_action(project_id, 'update', action='post', text=form.note.data) return redirect( url_for('project.project_view_posted', project_id=project.id)) return render_template( 'public/projectpost.html', current_event=event, project=project, form=form, stage=stage, all_valid=all_valid, )
def project_action(project_id, of_type): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event if of_type is not None: ProjectActivity(project, of_type, current_user) starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) project_stars = GetProjectTeam(project) return render_template('public/project.html', current_event=event, project=project, project_starred=starred, project_stars=project_stars, allow_edit=allow_edit)
def project_autoupdate(project_id): project = Project.query.filter_by(id=project_id).first_or_404() starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) if not allow_edit or project.is_hidden or not project.is_autoupdate: flash('You may not sync this project.', 'warning') return project_action(project_id) data = GetProjectData(project.autotext_url) if not 'name' in data: flash("Could not sync: check the Remote Link.", 'warning') return project_action(project_id) SyncProjectData(project, data) project_action(project.id, 'update', action='sync', text=str(len(project.autotext)) + ' bytes') flash("Project data synced from %s" % data['type'], 'success') return redirect(url_for('public.project', project_id=project.id))
def project_post(project_id): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous 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) form = ProjectPost(obj=project, next=request.args.get('next')) # Populate progress dialog form.progress.choices = projectProgressList(event.has_started or event.has_finished) # Populate resource list resources = Resource.query.filter_by(is_visible=True).order_by( Resource.type_id).all() resource_list = [(0, '')] resource_list.extend([(r.id, r.of_type + ': ' + r.name) for r in resources]) form.resource.choices = resource_list # Process form if form.validate_on_submit(): del form.id if form.resource.data == 0: form.resource.data = None form.populate_obj(project) project.update() db.session.add(project) db.session.commit() cache.clear() flash('Thanks for your commit!', 'success') project_action(project_id, 'update', action='post', text=form.note.data, resource=form.resource.data) return redirect(url_for('public.project', project_id=project.id)) return render_template('public/projectpost.html', current_event=event, project=project, form=form)
def project_action(project_id, of_type, as_view=True, then_redirect=False): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event if of_type is not None: ProjectActivity(project, of_type, current_user) if not as_view: return True starred = IsProjectStarred(project, current_user) allow_edit = starred or (not current_user.is_anonymous and current_user.is_admin) allow_edit = allow_edit and not event.lock_editing project_stars = GetProjectTeam(project) latest_activity = project.latest_activity() if then_redirect: return redirect(url_for('public.project', project_id=project.id)) return render_template('public/project.html', current_event=event, project=project, project_starred=starred, project_stars=project_stars, allow_edit=allow_edit, latest_activity=latest_activity)
def project_action(project_id, of_type=None, as_view=True, then_redirect=False, action=None, text=None, for_user=current_user): project = Project.query.filter_by(id=project_id).first_or_404() event = project.event if of_type is not None: ProjectActivity(project, of_type, for_user, action, text) if not as_view: return True if then_redirect: return redirect(url_for('project.project_view', project_id=project.id)) # The next line seems rather inefficient starred = IsProjectStarred(project, for_user) # Figure out permissions (hackybehack!) allow_edit = not current_user.is_anonymous and current_user.is_admin lock_editing = event.lock_editing allow_post = starred allow_edit = (starred or allow_edit) and not lock_editing # Obtain list of team members (performance!) project_team = project.get_team() if allow_post: # Evaluate project progress stage, all_valid = validateProjectData(project) # Collect resource tips suggestions = [] if not event.lock_resources: suggestions = getSuggestionsForStage(project.progress) # Suggest missing team roles missing_roles = project.get_missing_roles() else: suggestions, stage, all_valid, missing_roles = None, None, None, None # latest_activity = project.latest_activity() # obsolete project_dribs = project.all_dribs() project_badge = [s for s in project_dribs if s['name'] == 'boost'] # Select available project image if project.image_url: project_image_url = project.image_url elif event.logo_url: project_image_url = event.logo_url else: project_image_url = url_for('static', filename='img/badge-black.png', _external=True) return render_template('public/project.html', current_event=event, project=project, project_starred=starred, project_team=project_team, project_badge=project_badge, project_dribs=project_dribs, project_image_url=project_image_url, allow_edit=allow_edit, allow_post=allow_post, lock_editing=lock_editing, missing_roles=missing_roles, stage=stage, all_valid=all_valid, suggestions=suggestions, active="projects")