Exemple #1
0
def test_gene001_simple_callback(dash_duo):
    app = Dash()

    app.layout = Div([Alert("Test content", id="alert")])

    dash_duo.start_server(app)

    assert dash_duo.wait_for_element("#alert").text == "Test content"
def test_dbal001_alert_content(dash_duo):
    app = Dash()

    app.layout = Div([Alert("Test content", id="alert")])

    dash_duo.start_server(app)

    assert dash_duo.wait_for_element("#alert").text == "Test content"
Exemple #3
0
    def update_output(submit, date_value):
        string_prefix = 'You have selected: '
        if date_value is not None:
            date_object = datetime.fromisoformat(date_value)
            setDate = to_jd(date_object, fmt='mjd')
            date_string = date_object.strftime('%B %d, %Y')

            entries = list(collection('radialvelocity').find())
            for entry in entries:
                collection('radialvelocity').update_one(
                    {'_id': entry['_id']},
                    {'$set': {
                        'PUBLIC': (float(entry['MJD']) < setDate)
                    }})

            rv_plot(server)
            return Alert(
                ["Permissions set to " + date_string],
                id="alert-auto",
                is_open=True,
                duration=10000,
            )
Exemple #4
0
    def editUser(verify, reject, purge, active, email, table):
        changed_id = [p['prop_id'] for p in callback_context.triggered][0]
        df_table = DataFrame(table)
        if 'user-verify' in changed_id:
            if email is None or email == '':
                return Alert("Please select user",
                             id="alert-auto",
                             is_open=True,
                             duration=10000,
                             color='danger'), df_table.to_dict('records'), ''

            entry = collection('user').find_one({'email': email})

            if (entry):
                collection('user').update_one({'_id': entry['_id']},
                                              {"$set": {
                                                  'type': 'researcher'
                                              }})
            else:
                return Alert("Please select user",
                             id="alert-auto",
                             is_open=True,
                             duration=10000,
                             color='danger'), df_table.to_dict('records'), ''

            fullname = entry['firstName'] + ' ' + entry['lastName']
            messageBody = "Hello, " + fullname + " has been granted researcher access for the LOST telescope.\n" + (
                "Email: " + entry['email'] + "\nInstitution: " +
                entry['institution'] +
                "\n\nThis is your generated password:\n\n" + entry['password'])

            sendMail(entry['email'], "Database Access Granted to " + fullname,
                     messageBody)

            result = list(collection('user').find({}).sort('_id', DESCENDING))
            df = pd.DataFrame(eval(JSONEncoder().encode(result)))

            return Alert(
                ["User Verified"],
                id="alert-auto",
                is_open=True,
                duration=10000,
            ), df.to_dict('records'), ''
        elif 'user-reject' in changed_id:
            result = collection('user').find_one({'email': email})
            if (result):
                collection('user').delete_one({'_id': result['_id']})
                alert = Alert(
                    ["User Rejected"],
                    id="alert-auto",
                    is_open=True,
                    duration=10000,
                )
            else:
                alert = Alert("User does not exist",
                              id="alert-auto",
                              is_open=True,
                              duration=10000,
                              color='danger')
            news = list(collection('user').find().sort('_id', DESCENDING))
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))
            return alert, df.to_dict('records'), 'd-none'

        elif 'user-purge' in changed_id:
            removed = collection('user').remove({'type': 'unverified'})
            news = list(collection('user').find().sort('_id', DESCENDING))
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))
            return Alert("Applicants Deleted",
                         id="alert-auto",
                         is_open=True,
                         duration=10000,
                         color='danger'), df.to_dict('records'), ''
        elif 'user-table' in changed_id:
            return '', df_table.to_dict('records'), ''
        else:
            raise PreventUpdate
Exemple #5
0
    def editNews(submit, delete, home, title, subtitle, author, text, table):
        changed_id = [p['prop_id'] for p in callback_context.triggered][0]
        if 'news-submit' in changed_id:
            for val in [title, subtitle, author, text]:
                if val is None or val == '':
                    return Alert("Please fill out all fields",
                                 id="alert-auto",
                                 is_open=True,
                                 duration=10000,
                                 color='danger'), table.to_dict('records')

            post = collection('news').find_one({'title': title})

            if (post):
                collection('news').replace_one(
                    {'_id': post['_id']}, {
                        '_id': post['_id'],
                        'title': title,
                        'subtitle': subtitle,
                        'author': author,
                        'content': text,
                        'datetime': datetime.now().strftime('%B %d, %Y')
                    })
            else:
                post = {
                    '_id': ObjectId(),
                    'title': title,
                    'subtitle': subtitle,
                    'author': author,
                    'content': text,
                    'datetime': datetime.now().strftime('%B %d, %Y')
                }

                collection('news').insert_one(post)

            url = url_for('post', post_id=str(post['_id']))

            news = list(collection('news').find({}))
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))

            return Alert(
                [
                    "Article posted to ",
                    html.A("this link", href=url, className="alert-link")
                ],
                id="alert-auto",
                is_open=True,
                duration=10000,
            ), df.to_dict('records')

        elif 'news-delete' in changed_id:
            post = collection('news').find_one({'title': title})
            if (post):
                collection('news').delete_one({'_id': post['_id']})
                alert = Alert(
                    ["Post Deleted"],
                    id="alert-auto",
                    is_open=True,
                    duration=10000,
                )
            else:
                alert = Alert("Post does not exist",
                              id="alert-auto",
                              is_open=True,
                              duration=10000,
                              color='danger')
            news = list(collection('news').find().sort('datetime', DESCENDING))
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))
            return alert, df.to_dict('records')
        elif 'news-home' in changed_id:
            post = collection('news').find_one({'title': title})
            if (post):
                home = collection('news').find_one({'location': 'home'})
                if (home):
                    collection('news').update_one(
                        {'location': 'home'},
                        {'$set': {
                            'location': 'default'
                        }}, True)
                collection('news').update_one({'_id': post['_id']},
                                              {'$set': {
                                                  'location': 'home'
                                              }}, True)
                alert = Alert(
                    ["Post set as home"],
                    id="alert-auto",
                    is_open=True,
                    duration=10000,
                )
            else:
                alert = Alert("Post does not exist",
                              id="alert-auto",
                              is_open=True,
                              duration=10000,
                              color='danger')
            news = list(collection('news').find().sort('datetime', DESCENDING))
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))
            return alert, df.to_dict('records')
        else:
            raise PreventUpdate
Exemple #6
0
    def editGlos(submit, delete, term, definition, table):
        changed_id = [p['prop_id'] for p in callback_context.triggered][0]
        if 'glos-submit' in changed_id:
            for val in [term, definition]:
                if val is None or val == '':
                    return Alert("Please fill out all fields",
                                 id="alert-auto",
                                 is_open=True,
                                 duration=10000,
                                 color='danger'), table.to_dict('records')
            entry = collection('glossary').find_one({'entry': term})
            if (entry):
                collection('glossary').replace_one({'_id': entry['_id']}, {
                    '_id': entry['_id'],
                    'entry': term,
                    'definition': definition,
                    'datetime': datetime.now()
                })
            else:
                entry = {
                    '_id': ObjectId(),
                    'entry': term,
                    'definition': definition,
                    'datetime': datetime.now()
                }

                collection('glossary').insert_one({
                    '_id': entry['_id'],
                    'entry': term,
                    'definition': definition,
                    'datetime': datetime.now()
                })

            glos = list(collection('glossary').find({}))
            df = pd.DataFrame(eval(JSONEncoder().encode(glos)))

            return Alert(
                ["Glossary Updated"],
                id="alert-auto",
                is_open=True,
                duration=10000,
            ), df.to_dict('records')
        elif 'glos-delete' in changed_id:
            result = collection('glossary').find_one({'entry': term})
            if (result):
                collection('glossary').delete_one({'_id': result['_id']})
                alert = Alert(
                    ["Post Deleted"],
                    id="alert-auto",
                    is_open=True,
                    duration=10000,
                )
            else:
                alert = Alert("Post does not exist",
                              id="alert-auto",
                              is_open=True,
                              duration=10000,
                              color='danger')
            news = list(collection('glossary').find())
            df = pd.DataFrame(eval(JSONEncoder().encode(news)))
            return alert, df.to_dict('records')
        else:
            raise PreventUpdate