def project_create(request): if request.method == 'POST': ln_user_id = str(request.user)[3:] ln_user = LinkedInUserProfile.objects.get(linkedin_uid = ln_user_id) name = request.POST['name'] skills = extract_skills_from_user_string(request.POST['skills']) project = Project(name=name, skills_set=skills, creator = ln_user) project.save() """ prepare object with connections and skills """ li = LinkedIn(settings.LINKEDIN_CONSUMER_KEY,\ settings.LINKEDIN_CONSUMER_SECRET) access_token = request.session['access_token'] connections = li.connections_api.getMyConnections(access_token) members = [] for conn in connections: member = Member() member.proj = project member.linkedin_url = conn.profile_url member.pic = conn.picture_url member.first_name = conn.firstname member.last_name = conn.lastname member.info = {} member.info['summary'] = conn.summary.lower() member.info['specialties'] = conn.specialties.lower() members.append(member) request.session['members_' + str(project.id)] = members return redirect('web.views.project', project.id) return render_to_response('project/create.html', {}, RequestContext(request))
def project_create(request): if request.method == 'POST': ln_user = get_linkedin_user(request) name = request.POST['name'] #skills = extract_skills_from_user_string(request.POST['skills']) #project = Project(name=name, skills_set=skills, creator = ln_user) project = Project(name=name, creator = ln_user) project.save() """ prepare object with connections and skills """ members = build_member_data(project, request.session['access_token']) request.session['members_' + str(project.id)] = members return redirect('web.views.project', project.id) return render_to_response('project/create.html', {}, RequestContext(request))
def project_create(request): if request.method == 'POST': ln_user = get_linkedin_user(request) name = request.POST['name'] #skills = extract_skills_from_user_string(request.POST['skills']) #project = Project(name=name, skills_set=skills, creator = ln_user) project = Project(name=name, creator=ln_user) project.save() """ prepare object with connections and skills """ members = build_member_data(project, request.session['access_token']) request.session['members_' + str(project.id)] = members return redirect('web.views.project', project.id) return render_to_response('project/create.html', {}, RequestContext(request))
def project_manager(): form = request.form project_id = form.get('project_id') if project_id: _project = Project.objects.filter(id=project_id).first() else: _project = Project() _project.name = form.get('name') _project.alias = form.get('alias') _project.description = form.get('description') _project.egg = base64.encodestring(request.files['egg'].stream.read()) _project.save() return redirect(url_for('.project'))
def refresh_project(): app = current_app._get_current_object() spiderdir = app.config.get('SPIDERDIR') projects = os.listdir(spiderdir) for name in projects: _project = Project.objects.filter(name=name).first() if not _project: _project = Project() _project.name = name _project.alias = name _project.description = '' _project.save() # spider _spiderpath = os.path.join(spiderdir, name) scrapyexe = app.config.get('SCRAPY_EXE') p = subprocess.Popen([scrapyexe, 'list'], cwd=_spiderpath, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() stdout = p.stdout.readlines() spiders = [] for spider_name in stdout: spider_name = spider_name.strip() spider = Spider.objects.filter(name=spider_name, project=_project).first() if not spider: spider = Spider() spider.name = spider_name spider.project = _project spider.save() spiders.append(spider) _project.spiders = spiders _project.save() return redirect(url_for('.project'))
def import_projects(json_file): with open(json_file) as json_file: projects = json.loads(json_file.read()) for project in projects: new_project = Project( name=project['name'], short_description=project['short_description'], description=project['description'], website=project['website'], required_informations=project.get('required_informations', None), notification_email=project.get('notification_email', None), cve_vendor=project.get('cve_vendor', ''), cve_product=project.get('cve_product', ''), automatic_release_tracking=project.get( 'automatic_release_tracking', '')) organization = get_or_create(db.session, Organization, **project['organization']) new_project.organization_id = organization.id db.session.add(new_project) db.session.commit()
def process_form(project_id=None): form = AddProjectForm() form.organization_id.choices = [(0, '')] form.organization_id.choices.extend([(org.id, org.name) for org in Organization.query.all()]) if not form.validate(): return render_template('edit_project.html', form=form) if form.organization_id.data == 0: form.organization_id.data = None if project_id is not None: project = Project.query.filter(Project.id == project_id).first() # Tags new_tags = [tag for tag in form.tags.data.strip().split(',') if tag] for tag in project.tag_objs: if tag.text not in new_tags: db.session.delete(tag) db.session.commit() for tag in new_tags: get_or_create(db.session, Tag, **{ 'text': tag.strip(), 'project_id': project.id }) del form.tags # Licenses new_licenses = [] for license_id in form.licenses.data: license = License.query.filter(License.id == license_id).first() new_licenses.append(license) project.licenses = new_licenses del form.licenses # Logo f = form.logo.data if f: try: # Delete the previous icon icon_url = os.path.join(application.config['UPLOAD_FOLDER'], project.icon_url) os.unlink(icon_url) old_icon = Icon.query.filter(Icon.url == project.icon_url) \ .first() db.session.delete(old_icon) project.icon_url = None db.session.commit() except Exception as e: print(e) # save the picture filename = str(uuid.uuid4()) + '.png' icon_url = os.path.join(application.config['UPLOAD_FOLDER'], filename) f.save(icon_url) # create the corresponding new icon object new_icon = Icon(url=filename) db.session.add(new_icon) db.session.commit() project.icon_url = new_icon.url form.populate_obj(project) db.session.commit() flash( 'Project {project_name} successfully updated.'.format( project_name=form.name.data), 'success') return redirect(url_for('project_bp.form', project_id=project.id)) # Create a new project new_project = Project(name=form.name.data, short_description=form.short_description.data, description=form.description.data, website=form.website.data, organization_id=form.organization_id.data) db.session.add(new_project) db.session.commit() # Tags for tag in form.tags.data.split(','): get_or_create(db.session, Tag, **{ 'text': tag.strip(), 'project_id': new_project.id }) # Licenses new_licenses = [] for license_id in form.licenses.data: license = License.query.filter(License.id == license_id).first() new_licenses.append(license) new_project.licenses = new_licenses del form.licenses # Logo f = form.logo.data if f: # save the picture filename = str(uuid.uuid4()) + '.png' icon_url = os.path.join(application.config['UPLOAD_FOLDER'], filename) f.save(icon_url) # create the corresponding new icon object new_icon = Icon(url=filename) db.session.add(new_icon) new_project.icon_url = new_icon.url db.session.commit() flash( 'Project {project_name} successfully created.'.format( project_name=new_project.name), 'success') return redirect(url_for('project_bp.form', project_id=new_project.id))