Exemplo n.º 1
0
def load(filename):
    ''' Initate TrackEdit/ZStackEdit object and load object to database.
        Send specific attributes of the object to the .js file.
    '''
    start = timeit.default_timer()
    current_app.logger.info('Loading track at %s', filename)

    folders = re.split('__', filename)
    filename = folders[len(folders) - 1]
    subfolders = folders[2:len(folders) - 1]

    subfolders = '/'.join(subfolders)
    full_path = os.path.join(subfolders, filename)

    input_bucket = folders[0]
    output_bucket = folders[1]

    # arg is 'false' which gets parsed to True if casting to bool
    rgb = request.args.get('rgb', default='false', type=str)
    rgb = bool(distutils.util.strtobool(rgb))

    if not is_trk_file(filename) and not is_npz_file(filename):
        error = {
            'error':
            'invalid file extension: {}'.format(
                os.path.splitext(filename)[-1])
        }
        return jsonify(error), 400

    # Initate Edit object and entry in database
    caliban_file = CalibanFile(filename, input_bucket, full_path)
    edit = get_edit(caliban_file, output_bucket, rgb)
    project = Project.create_project(filename, edit, subfolders)

    if is_trk_file(filename):
        current_app.logger.debug('Loaded trk file "%s" in %s s.', filename,
                                 timeit.default_timer() - start)
        # Send attributes to .js file
        return jsonify({
            'max_frames': caliban_file.max_frames,
            'tracks': caliban_file.readable_tracks,
            'dimensions': (caliban_file.width, caliban_file.height),
            'project_id': project.id,
            'screen_scale': edit.scale_factor
        })

    if is_npz_file(filename):
        current_app.logger.debug('Loaded npz file "%s" in %s s.', filename,
                                 timeit.default_timer() - start)
        # Send attributes to .js file
        return jsonify({
            'max_frames': caliban_file.max_frames,
            'channel_max': caliban_file.channel_max,
            'feature_max': caliban_file.feature_max,
            'tracks': caliban_file.readable_tracks,
            'dimensions': (caliban_file.width, caliban_file.height),
            'project_id': project.id
        })
Exemplo n.º 2
0
 def create_new_project(self):
     Project.create_project(name=self.project_name_input.get())
     self.update_projects_list()
     self.popup.destroy()
Exemplo n.º 3
0
def project_new():
    """ Renders form to create new project or process the form """

    if not 'CURR_USER_KEY' in session:
        flash("Unauthorized access. Account needed to create.", "danger")
        if 'GUEST_GEOCODE' in session:
            return redirect("/search")
        else:
            return redirect("/")

    form = ProjectForm(prefix='form-project-new-')
    tags_full_list = Tag.list_all()

    if form.validate_on_submit():
        optional_date_keys = ['inquiry_deadline', 'work_start', 'work_end']
        optional_date_values = []
        for each in optional_date_keys:
            try:
                y, m, d = request.form.get(each).split('-')
                print(y, m, d, 'out of if')
                if y and m and d:
                    date = datetime(int(y), int(m), int(d))
                    optional_date_values.append(date)
                    print(date, 'in if', optional_date_values)
            except ValueError:
                optional_date_values.append(None)
                print('caught value error', optional_date_values)
            except AttributeError:
                optional_date_values.append(None)
                print('caught value error', optional_date_values)
        inquiry_deadline_date, work_start_date, work_end_date = optional_date_values

        project_obj = {
            'name': form.name.data,
            'description': form.description.data,
            'user_id': g.user.id,
            'contact_info_type': form.contact_info_type.data,
            'contact_info': form.contact_info.data,
            'lat': form.lat.data,
            'long': form.long.data,
            'inquiry_deadline': inquiry_deadline_date,
            'work_start': work_start_date,
            'work_end': work_end_date,
            'pic_url1': request.form.get('pic_url1'),
            'pic_url2': request.form.get('pic_url2'),
        }
        project_final = Project.create_project(project_obj)

        tags = request.form.get('tags')
        if tags:
            tags = tags.split('|')
            tag_objs = []
            if (len(tags) > 0):
                for name in tags:
                    tag_obj = Tag.lookup_tag(name)
                    if not tag_obj:
                        tag_obj = Tag.create_tag(name)

                    tag_objs.append(tag_obj)
                project_final.tags = tag_objs
                db.session.commit()

        flash("Project created successfully", "success")
        return redirect(f"/project/{project_final.id}")

    return render_template("project-new.html",
                           form=form,
                           tags_full_list=tags_full_list)
Exemplo n.º 4
0
 def create_new_project(self):
     Project.create_project(name=self.project_name_input.get())
     self.update_projects_list()
     self.popup.destroy()