Esempio n. 1
0
def submit_newcourse():
    """ create new course """
    #print_debug('submit_newcourse: {}'.format(request.form))
    name = request.form['name']  # e.g. "Intro Programming"
    path = request.form[
        'path']  # should have form term/folder e.g. fall2018/cs1
    copyfrom = request.form['copyfrom']  # e.g. "fall2017/cs1"
    startdate = path_to_startdate(path)
    title = name_to_htmltitle(name)
    print_debug(' submit_newcourse: name = "{}"'.format(name))
    print_debug('                   path = "{}"'.format(path))
    print_debug('                   copyfrom = "{}"'.format(copyfrom))
    newcourse = Course.create_course(name,
                                     path,
                                     start=startdate,
                                     name_as_title=title,
                                     copyfrom=copyfrom)
    for name in request.form['faculty'].split(','):
        try:
            faculty = Person.get(username=name.strip())
        except:
            faculty = None
        if not faculty:
            try:
                faculty = Person.get(username=name.strip())
            except:
                faculty = None
        if faculty:
            today = str(Time())[:10]
            newcourse.enroll(faculty, 'faculty', today, create_work=False)
    return newcourse.url
Esempio n. 2
0
    def login():
        form = LoginForm()
        if form.validate_on_submit():

            getPass = Get_password(form.email.data)

            if getPass == None:
                flash('Login Unsuccessful. Please check username and password',
                      'danger')
                return redirect(url_for('login'))

            if bcrypt.check_password_hash(getPass, form.password.data) is True:
                flash('You have been logged in!', 'success')
                session['user'] = form.email.data
                session['time'] = Time(form.email.data)
                # print(session.get('time'))
                return redirect(url_for('lounge'))
            else:
                flash('Login Unsuccessful. Please check username and password',
                      'danger')
        return render_template('login.html',
                               time=session.get('time'),
                               user_email=session.get("user"),
                               title='Login',
                               form=form,
                               enable=8)
Esempio n. 3
0
def parse_sampling_time(object_):
    """Parse an object into a sampling time.
    
    Parameters
    ----------
    object_ : datetime.datetime, model.Sample
        The object to be parsed into a Time object, representing the sampling
        time.
    """
    # Parse from datetime-like object
    try:
        time = Time.from_datetime(object_)
    except AttributeError:
        time = None
    else:
        return time
    # Parse from model.Sample
    try:
        sample_date = object_.sample_date
        sample_time = object_.sample_time
        default_date = datetime.date(1, 1, 1)
        default_time = datetime.time(0, 0, 0)
        if sample_date and sample_time:
            timestamp = datetime.datetime.combine(sample_date, sample_time)
        elif sample_date:
            timestamp = datetime.datetime.combine(sample_date, default_time)
        elif sample_time:
            timestamp = datetime.datetime.combine(default_date, sample_time)
        else:
            # Sample object has no date or time
            return None
        time = Time.from_datetime(timestamp)
    except AttributeError:
        time = None
    else:
        return time
    return time
Esempio n. 4
0
def submit_edit():
    """ handle file edit form """
    # ... including student work pages.
    # invoked from handle_post()
    # the form text data is in the form dict key, i.e. request.form['edit_text']
    # print_debug(' submit_edit: request.form : {}'.format(request.form.items()))
    #
    # request.form will look something like
    #  { 'submit_edit' : u'save page',                     # submit button
    #    'edit_text'   : u'page content\r\n===\r\n etc'    # textarea
    #  }
    #
    # If this is a work page, then update the Work database object.
    # (The Work object is created in Page.get_from_path)
    if request.page.is_work:
        now = str(Time())  # string with current time
        with db.atomic():
            if request.page.user_role.name == 'faculty':
                page = request.page
                page.work.faculty_modified = now
                # If checkbox for 'submitted' and that didn't have a value,
                # then set it - used to mark work as submitted,
                # i.e. student emails work & faculty submits.
                if "submitted_checkbox" in request.form \
                     and not page.work.submitted:
                    due = Time(page.work_due)
                    print_debug(" submit_edit: due = {}".format(str(due)))
                    if "on_time_checkbox" in request.form:
                        due.shift_minutes(-5)
                    else:
                        due.shift_minutes(5)
                    page.work.submitted = str(due)
                    print_debug(" submit_edit: submitted set to {}".format( \
                                page.work.submitted))
                if 'grade' in request.form:
                    page.work.grade = str(request.form['grade'])
            else:
                request.page.work.student_modified = now
                if not request.page.work.submitted:
                    request.page.work.submitted = now
            request.page.work.save()
    # Save the page content to a file and to git.
    bytes_written = request.page.write_content(request.form['edit_text'])
    print_debug(' submit_edit: bytes_written = {}'.format(bytes_written))
    git.add_and_commit(request.page)
    return request.base_url  # ... and reload it without ?action=edit
Esempio n. 5
0
def load_times(file_user):

    for row in (open(file_user)):
        row = row.strip()

        monday, tuesday, wednesday, thursday, friday, saturday, sunday, morning, late_morning, early_night, late_night = row.split(
            ",")

        time_preference = Time(monday=monday,
                               tuesday=tuesday,
                               wednesday=wednesday,
                               thursday=thursday,
                               friday=friday,
                               saturday=saturday,
                               sunday=sunday,
                               morning=morning,
                               late_morning=late_morning,
                               early_night=early_night,
                               late_night=late_night)

        db.session.add(time_preference)
        db.session.commit()
Esempio n. 6
0
def do_before_request():
    """ initialize database and session """

    # See http://docs.peewee-orm.com/en/latest/peewee/database.html .
    # This gives "connection already open" error if in console.
    # The current (kludgy) fix is to test for the console explicitly.
    if not in_console():
        db.connect()

    #print " db={}".format(db)
    #print " request={}".format(request)

    # See PERMANENT_SESSION_LIFETIME in env/settings.py
    session.permanent = True

    # site settings
    g.debug = umber_debug
    g.contact_url = contact_url
    g.about_url = about_url
    g.help_url = help_url
    g.umber_url = umber_url
    g.markup_url = markup_url
    g.site_url = site_url
    g.now = Time()
Esempio n. 7
0
def parse_sample_time(row, datetime_col):
    datetime = row[datetime_col]
    return Time.from_datetime(datetime)
Esempio n. 8
0
class SampleParserTest(unittest.TestCase):
    sample_test_file = './data/test_data/samp_metadata/sample1.txt'

    row = OrderedDict([
        ('sample_name', '317.F10'), ('age', '22'), ('age_unit', 'years'),
        ('altitude', '0'), ('anatomical_body_site', 'FMA:Palm'),
        ('anonymized_name', 'F10'), ('body_habitat', 'UBERON:skin'),
        ('body_product', 'UBERON:sebum'),
        ('body_site', 'UBERON:zone of skin of hand'),
        ('collection_date', '11/12/2006'),
        ('country', 'GAZ:United States of America'), ('depth', '0'),
        ('description', 'human skin metagenome'), ('dna_extracted', 'true'),
        ('dominant_hand', ''), ('elevation', '1591.99'),
        ('env_biome', 'ENVO:human-associated habitat'),
        ('env_feature', 'ENVO:human-associated habitat'),
        ('host_common_name', 'human'), ('host_subject_id', 'F1'),
        ('host_taxid', '9606'), ('latitude', '40'), ('longitude', '-105'),
        ('palm_size', ''), ('physical_specimen_remaining', 'false'),
        ('public', 'true'), ('qiita_study_id', '317'),
        ('sample_type', 'XXQIITAXX'), ('sex', 'female'),
        ('time_since_last_wash', '0'),
        ('title',
         'The influence of sex handedness and washing on the diversity of hand surface bacteriaS1_V160'
         )
    ])
    dayfirst_dict = {'collection_date': False}

    # TODO Update details of source (when necessary)
    source1 = Source(name='qiita',
                     type_='Database (Public)',
                     url='https://qiita.ucsd.edu/study/description/0')
    experiment1 = Experiment(source=source1, orig_study_id='317')
    subject1 = Subject(
        source=source1,
        orig_study_id='317',
        orig_subject_id='F1',
        sex='female',
        country='United States of America',
        race=None,
        csection=None,
        disease=None,
        dob=None,
    )
    subject2 = Subject(
        source=source1,
        orig_study_id='317',
        orig_subject_id='F2',
        sex='female',
        country='United States of America',
        race=None,
        csection=None,
        disease=None,
        dob=None,
    )
    sampling_site = SamplingSite(
        uberon_habitat_term='UBERON:skin',
        uberon_product_term='UBERON:sebum',
        uberon_site_term='UBERON:zone of skin of hand',
        env_biom_term='ENVO:human-associated habitat',
        env_feature_term='ENVO:human-associated habitat')
    sampling_time = Time(timestamp=datetime.datetime(2006, 11, 12),
                         uncertainty=None,
                         date=datetime.date(2006, 11, 12),
                         time=None,
                         year=2006,
                         month=11,
                         day=12,
                         hour=None,
                         minute=None,
                         second=None,
                         season='autumn')
    sample1 = Sample(source=source1,
                     orig_study_id='317',
                     orig_subject_id='F1',
                     orig_sample_id='317.F10',
                     age_units=ureg.years,
                     age=22.0,
                     latitude=40.0,
                     longitude=-105.0,
                     elevation=1591.99,
                     height_units=ureg.metres,
                     height=None,
                     weight_units=ureg.kilograms,
                     weight=None,
                     bmi=None,
                     sample_date=datetime.date(2006, 11, 12),
                     sample_time=None,
                     sampling_site=sampling_site,
                     sampling_time=sampling_time)
    sample2 = Sample(source=source1,
                     orig_study_id='317',
                     orig_subject_id='F1',
                     orig_sample_id='317.F12',
                     age_units=ureg.years,
                     age=22.0,
                     latitude=40.0,
                     longitude=-105.0,
                     elevation=1591.99,
                     height_units=ureg.metres,
                     height=None,
                     weight_units=ureg.kilograms,
                     weight=None,
                     bmi=None,
                     sample_date=datetime.date(2006, 11, 12),
                     sample_time=None,
                     sampling_site=sampling_site,
                     sampling_time=sampling_time)
    sample3 = Sample(source=source1,
                     orig_study_id='317',
                     orig_subject_id='F2',
                     orig_sample_id='317.F20',
                     age_units=ureg.years,
                     age=None,
                     latitude=40.0,
                     longitude=-105.0,
                     elevation=1591.99,
                     height_units=ureg.metres,
                     height=None,
                     weight_units=ureg.kilograms,
                     weight=None,
                     bmi=None,
                     sample_date=datetime.date(2006, 11, 12),
                     sample_time=None,
                     sampling_site=sampling_site,
                     sampling_time=sampling_time)
    # Not necessary to establish these relationships for purpose of
    # test_parse_objects:
    sample1._subject = subject1
    sample2._subject = subject1
    sample3._subject = subject2
    subject1._samples = {sample1, sample2}
    subject2._samples = {sample3}
    experiment1._subjects = {subject1, subject2}
    experiment1._samples = {sample1, sample2, sample3}

    def test_parse_objects(self):
        experiment_ids = parse_objects(self.sample_test_file)
        self.assertIn('317', experiment_ids)
        experiment = experiment_ids['317']
        self.assertEqual(self.experiment1, experiment)
        self.assertIn(self.subject1, experiment.subjects)
        self.assertIn(self.subject2, experiment.subjects)
        self.assertIn(self.sample1, experiment.samples)
        self.assertIn(self.sample2, experiment.samples)
        self.assertIn(self.sample3, experiment.samples)

    # TODO: We will have to test without the source keyword at some point.
    def test_parse_sample(self):
        self.maxDiff = None
        blacklist_attrs = [
            '_sa_instance_state', 'source', 'counts', '_experiments',
            '_subject', '_preparations'
        ]
        sample = parse_sample(self.row,
                              self.dayfirst_dict,
                              source=self.source1)
        sample_attrs = set((key, value)
                           for key, value in sample.__dict__.items()
                           if key not in blacklist_attrs)
        expected_attrs = set((key, value)
                             for key, value in self.sample1.__dict__.items()
                             if key not in blacklist_attrs)
        self.assertEqual(sample_attrs, expected_attrs)
        self.assertEqual(sample.source, self.source1)
        self.assertEqual(sample.counts, self.sample1.counts)
        # When sample is parsed, it is not yet associated with subject/experiments
        self.assertEqual(sample._subject, None)
        self.assertEqual(sample._experiments, set())
        self.assertEqual(sample._preparations, set())

    def test_parse_subject(self):
        self.maxDiff = None
        blacklist_attrs = [
            '_sa_instance_state', 'source', 'counts', 'perturbation_facts',
            '_experiments', '_samples', '_perturbations'
        ]
        subject = parse_subject(self.row, source=self.source1)
        subject_attrs = set((key, value)
                            for key, value in subject.__dict__.items()
                            if key not in blacklist_attrs)
        expected_attrs = set((key, value)
                             for key, value in self.subject1.__dict__.items()
                             if key not in blacklist_attrs)
        self.assertEqual(subject_attrs, expected_attrs)
        self.assertEqual(subject.source, self.source1)
        self.assertEqual(subject.counts, self.subject1.counts)
        self.assertEqual(subject.perturbation_facts,
                         self.subject1.perturbation_facts)
        # When subject is parsed, it is not yet associated with samples/experiments
        self.assertEqual(subject._experiments, set())
        self.assertEqual(subject._samples, set())
        self.assertEqual(subject._perturbations, set())

    def test_parse_processing(self):
        self.maxDiff = None
        processing1 = Processing(parent=None,
                                 parameter_values='{}',
                                 orig_prep_id='577',
                                 orig_proc_id='2593')
        processing2 = Processing(parent=processing1,
                                 parameter_values='{'
                                 '"barcode_type":"golay_12",'
                                 '"command":"Split libraries (QIIMEq2 1.9.1)",'
                                 '"disable_bc_correction":"False",'
                                 '"disable_primers":"False",'
                                 '"generated on":"2016-01-14 17:01",'
                                 '"input_data":"2593",'
                                 '"max_ambig":"6",'
                                 '"max_barcode_errors":"1.5",'
                                 '"max_homopolymer":"6",'
                                 '"max_primer_mismatch":"0",'
                                 '"max_seq_len":"1000",'
                                 '"min_qual_score":"25",'
                                 '"min_seq_len":"200",'
                                 '"qual_score_window":"0",'
                                 '"reverse_primer_mismatches":"0",'
                                 '"reverse_primers":"disable",'
                                 '"trim_seq_length":"False",'
                                 '"truncate_ambi_bases":"False"'
                                 '}',
                                 orig_prep_id='577',
                                 orig_proc_id='310')
        processing3 = Processing(
            parent=processing2,
            parameter_values='{'
            '"command":"Pick closed-reference OTUs (QIIMEq2 1.9.1)",'
            '"generated on":"2015-06-30 14:06",'
            '"input_data":"310",'
            '"reference-seq":"/databases/gg/13_8/rep_set/97_otus.fasta",'
            '"reference-tax":"/databases/gg/13_8/taxonomy/97_otu_taxonomy.txt",'
            '"similarity":"0.97",'
            '"sortmerna_coverage":"0.97",'
            '"sortmerna_e_value":"1",'
            '"sortmerna_max_pos":"10000",'
            '"threads":"1"'
            '}',
            orig_prep_id='577',
            orig_proc_id='2594')
        expected_processings = {
            '2593': processing1,
            '310': processing2,
            '2594': processing3
        }
        processings = parse_processings('./data/test_data/proc1.json')
        # TODO: Implement workflows and parents as mocks?
        blacklist_attrs = ['_sa_instance_state', 'workflows', 'parent']
        for proc_id, processing in processings.items():
            self.assertIn(proc_id, expected_processings)
            processing_attrs = set(
                (key, value) for key, value in processing.__dict__.items()
                if key not in blacklist_attrs)
            expected_attrs = set(
                (key, value) for key, value in
                expected_processings[proc_id].__dict__.items()
                if key not in blacklist_attrs)
            self.assertEqual(processing_attrs, expected_attrs)
Esempio n. 9
0
        with app.app_context():

            for k, v in data.hours.items():
                hour = Hour(code=k, name=v)
                db.session.add(hour)

            for k, v in data.week.items():
                day = Day(code=k, name=v)
                db.session.add(day)

            for k, v in data.goals.items():
                goal = Goal(code=k, name=v)
                db.session.add(goal)

            for k, v in data.times.items():
                time = Time(code=k, name=v)
                db.session.add(time)

            for t in data.teachers:
                teacher = Teacher(id=t['id'],
                                  name=t['name'],
                                  about=t['about'],
                                  rating=t['rating'],
                                  picture=t['picture'],
                                  price=t['price'],
                                  free=t['free'])
                db.session.add(teacher)
                for g in t['goals']:
                    new_goal = Goal.query.filter(Goal.code == g).first()
                    teacher.goals.append(new_goal)
Esempio n. 10
0
def new_show_page_process():

    user_id = session.get("user_id")

    monday = request.json.get("monday")
    tuesday = request.json.get("tuesday")
    wednesday = request.json.get("wednesday")
    thursday = request.json.get("thursday")
    friday = request.json.get("friday")
    saturday = request.json.get("saturday")
    sunday = request.json.get("sunday")
    morning = request.json.get("morning")
    late_morning = request.json.get("late_morning")
    early_night = request.json.get("early_night")
    late_night = request.json.get("late_night")

    new_time = Time(monday=monday,
                    tuesday=tuesday,
                    wednesday=wednesday,
                    thursday=thursday,
                    friday=friday,
                    saturday=saturday,
                    sunday=sunday,
                    morning=morning,
                    late_morning=late_morning,
                    early_night=early_night,
                    late_night=late_night)

    db.session.add(new_time)
    db.session.commit()
    db.session.refresh(new_time)

    berkeley = request.json.get("berkeley")
    burlingame = request.json.get("burlingame")
    daly_city = request.json.get("daly_city")
    dublin = request.json.get("dublin")
    emeryville = request.json.get("emeryville")
    palo_alto = request.json.get("palo_alto")
    san_francisco = request.json.get("san_francisco")
    san_jose = request.json.get("san_jose")
    santa_clara = request.json.get("santa_clara")
    sunnyvale = request.json.get("sunnyvale")

    new_location = Location(berkeley=berkeley,
                            burlingame=burlingame,
                            daly_city=daly_city,
                            dublin=dublin,
                            emeryville=emeryville,
                            palo_alto=palo_alto,
                            san_francisco=san_francisco,
                            san_jose=san_jose,
                            santa_clara=santa_clara,
                            sunnyvale=sunnyvale)

    db.session.add(new_location)
    db.session.commit()
    db.session.refresh(new_location)

    show_name = request.json.get("show_name")
    show_type = request.json.get("show_type")
    show_url = request.json.get("show_url")
    show_amount_people = request.json.get("show_amount_people")
    show_dressing_room = request.json.get("show_dressing_room")
    show_length = request.json.get("show_length")
    show_location_preferred = request.json.get("show_location_preferred")
    show_ticket_price = request.json.get("show_ticket_price")
    show_rent = request.json.get("show_rent")

    new_show = Show(user_id=user_id,
                    show_name=show_name,
                    show_type=show_type,
                    show_url=show_url,
                    show_amount_people=show_amount_people,
                    show_dressing_room=show_dressing_room,
                    show_length=show_length,
                    location_id=new_location.location_id,
                    show_ticket_price=show_ticket_price,
                    time_id=new_time.time_id,
                    show_rent=show_rent)

    db.session.add(new_show)
    db.session.commit()
    db.session.refresh(new_show)

    show_rarking = adding_ranking("show", new_show.show_id)

    user = User.query.filter_by(user_id=user_id).first()

    return jsonify(user_fname=user.user_fname,
                   monday=monday,
                   tuesday=tuesday,
                   wednesday=wednesday,
                   thursday=thursday,
                   friday=friday,
                   saturday=saturday,
                   sunday=sunday,
                   morning=morning,
                   late_morning=late_morning,
                   early_night=early_night,
                   late_night=late_night,
                   show_name=show_name,
                   show_type=show_type,
                   show_url=show_url,
                   show_amount_people=show_amount_people,
                   show_dressing_room=show_dressing_room,
                   show_length=show_length,
                   show_ticket_price=show_ticket_price,
                   show_rent=show_rent,
                   show_id=new_show.show_id,
                   berkeley=berkeley,
                   burlingame=burlingame,
                   daly_city=daly_city,
                   dublin=dublin,
                   emeryville=emeryville,
                   palo_alto=palo_alto,
                   san_francisco=san_francisco,
                   san_jose=san_jose,
                   santa_clara=santa_clara,
                   sunnyvale=sunnyvale)
Esempio n. 11
0
def venue_page_process():
    """Process new venue"""
    user_id = session.get("user_id")

    user = User.query.filter_by(user_id=user_id).first()

    monday = request.json.get("monday")
    tuesday = request.json.get("tuesday")
    wednesday = request.json.get("wednesday")
    thursday = request.json.get("thursday")
    friday = request.json.get("friday")
    saturday = request.json.get("saturday")
    sunday = request.json.get("sunday")
    morning = request.json.get("morning")
    late_morning = request.json.get("late_morning")
    early_night = request.json.get("early_night")
    late_night = request.json.get("late_night")
    venue_name = request.json.get("venue_name")
    venue_url = request.json.get("venue_url")
    venue_email = request.json.get("venue_email")
    venue_address = request.json.get("venue_address")
    venue_city = request.json.get("venue_city")
    venue_type = request.json.get("venue_type")
    venue_backspace = request.json.get("venue_backspace")
    venue_capacity = request.json.get("venue_capacity")
    venue_license = request.json.get("venue_license")
    venue_rent = request.json.get("venue_rent")

    check_venue_info = Venue.query.filter_by(
        venue_address=venue_address).first()

    if check_venue_info:

        return jsonify("venue_already_register")

    else:

        new_time = Time(monday=monday,
                        tuesday=tuesday,
                        wednesday=wednesday,
                        thursday=thursday,
                        friday=friday,
                        saturday=saturday,
                        sunday=sunday,
                        morning=morning,
                        late_morning=late_morning,
                        early_night=early_night,
                        late_night=late_night)

        db.session.add(new_time)
        db.session.commit()
        db.session.refresh(new_time)

        new_venue = Venue(user_id=user_id,
                          venue_name=venue_name,
                          venue_url=venue_url,
                          venue_email=venue_email,
                          venue_address=venue_address,
                          venue_city=venue_city,
                          venue_type=venue_type,
                          venue_backspace=venue_backspace,
                          venue_capacity=venue_capacity,
                          venue_license=venue_license,
                          time_id=new_time.time_id,
                          venue_rent=venue_rent)

        db.session.add(new_venue)
        db.session.commit()
        db.session.refresh(new_venue)

        venue_rarking = adding_ranking("venue", new_venue.venue_id)

        return jsonify(time_id=new_time.time_id,
                       monday=new_time.monday,
                       tuesday=new_time.tuesday,
                       wednesday=new_time.wednesday,
                       thursday=new_time.thursday,
                       friday=new_time.friday,
                       saturday=new_time.saturday,
                       sunday=new_time.sunday,
                       morning=new_time.morning,
                       late_morning=new_time.late_morning,
                       early_night=new_time.early_night,
                       late_night=new_time.late_night,
                       venue_id=new_venue.venue_id,
                       venue_name=new_venue.venue_name,
                       venue_url=new_venue.venue_url,
                       venue_email=new_venue.venue_email,
                       venue_address=new_venue.venue_address,
                       venue_city=new_venue.venue_city,
                       venue_type=new_venue.venue_type,
                       venue_backspace=new_venue.venue_backspace,
                       venue_capacity=new_venue.venue_capacity,
                       venue_license=new_venue.venue_license,
                       venue_rent=new_venue.venue_rent)