Пример #1
0
def cleaning():
    app.app_context().push()
    print("Starting cleaning job...")
    Company.company_cleaning()
    Announcement.announcement_cleaning()
    db.session.commit()
    print("Cleaning job completed...")
Пример #2
0
 def add_new_announcements(self, request, schema):
     anothers = dict(request.POST)
     for name, value in anothers.items():
         if name.startswith('n-a-'):
             announcement = Announcement(content=value[0],
                                         week_announcment=schema)
             announcement.save()
Пример #3
0
    def setUp(self):
        self.dir = os.path.dirname(os.path.abspath(__file__))
        #self.app = rubix.app.test_client()
        self.response = self.client.get("/")
        self.soup = BeautifulSoup(self.response.data, 'html.parser')

        db.create_all()
        db.session.add(
            User("Firstname", "Lastname", "*****@*****.**", "test123"))
        db.session.add(User("Mock", "User", "*****@*****.**", "mock123"))
        db.session.add(User("new", "User", "*****@*****.**", "new123"))
        db.session.add(User("Competitor", "Jones", "*****@*****.**",
                            "comp123"))
        db.session.add(
            User("delegate", "DeeDee", "*****@*****.**", "1234567890"))
        user = User.query.filter_by(email="*****@*****.**").first()
        user1 = User.query.filter_by(email="*****@*****.**").first()
        user2 = User.query.filter_by(email="*****@*****.**").first()
        delegateuser = User.query.filter_by(email='*****@*****.**',
                                            credentials=2).first()

        db.session.add(
            Competition(user.id, "Test name", "Test location", "Test City",
                        "Test State", "10031", datetime.date(2017, 12, 31)))
        db.session.add(
            Competition(20, "Cant view", "Cant view", "New York", "NY",
                        "10031", datetime.date(2017, 12, 31)))
        comp = Competition.query.filter_by(comp_id=1).first()
        comp.approved = True
        comp20 = Competition.query.filter_by(organizer_id=20).first()

        announce1 = Announcement(comp.comp_id, user.id, "Test announcement",
                                 "Test body")
        announce2 = Announcement(comp20.comp_id, 2, "Can i see this?", "maybe")
        db.session.add(announce1)
        db.session.add(announce2)

        event1 = Event('4x4x4 Cube', 'Round 1', datetime.time(11, 0, 0),
                       datetime.time(12, 0, 0))
        db.session.add(event1)
        comp.comp_events.append(event1)
        comp.competitors.append(user)
        comp.competitors.append(user1)
        comp.competitors.append(user2)

        register_user1 = EventUserLink(user=user1, event=event1)
        register_user2 = EventUserLink(user=user2, event=event1)
        db.session.add(register_user1)
        db.session.add(register_user2)
        register_user2.volunteer = True
        register_user2.volunteer_role = 'Judge'
        register_user1.staff = True
        register_user1.staff_role = 'Scrambler'

        db.session.commit()
Пример #4
0
def announcements(comp_id):
    comp = Competition.query.filter_by(comp_id=comp_id).first()
    query = Announcement.query.filter_by(comp_id=comp.comp_id).all()
    announcements = list(reversed(query))

    if request.method == 'POST':
        if form.validate_on_submit():
            new_announcement = Announcement(comp.comp_id, current_user.id,
                                            form.title.data, form.body.data)
            db.session.add(new_announcement)
            db.session.commit()

            flash('Posted!')
            return redirect(
                url_for('competitions.announcements', comp_id=comp.comp_id))
        else:
            flash('Somethings not working')
            return render_template('comp_announcements.html',
                                   form=form,
                                   comp=comp,
                                   announcements=announcements)

    return render_template('comp_announcements.html',
                           comp=comp,
                           announcements=announcements)
Пример #5
0
    def post(self):
        content = self.get_argument('content', None)
        username = self.current_user

        if content is None:
            raise exceptions.EmptyFields()
        yield gen.maybe_future(Announcement.create(username, content))
Пример #6
0
    def setUp(self):
        db.create_all()
        db.session.add(
            User("Firstname", "Lastname", "*****@*****.**", "test123"))
        db.session.add(User("Mock", "User", "*****@*****.**", "mock123"))
        db.session.add(User("new", "User", "*****@*****.**", "new123"))
        db.session.add(User("Competitor", "Jones", "*****@*****.**",
                            "comp123"))
        user = User.query.filter_by(email="*****@*****.**").first()
        user1 = User.query.filter_by(email="*****@*****.**").first()
        user2 = User.query.filter_by(email="*****@*****.**").first()

        db.session.add(
            Competition(user.id, "Test name", "Test location",
                        datetime.date(2017, 12, 31)))
        db.session.add(
            Competition(20, "Cant view", "Cant view",
                        datetime.date(2017, 12, 31)))
        comp = Competition.query.filter_by(comp_id=1).first()
        comp.approved = True
        comp20 = Competition.query.filter_by(organizer_id=20).first()

        announce1 = Announcement(comp.comp_id, user.id, "Test announcement",
                                 "Test body")
        announce2 = Announcement(comp20.comp_id, 2, "Can i see this?", "maybe")
        db.session.add(announce1)
        db.session.add(announce2)

        event1 = Event('Rubik\'s Cube', 'Round 1', datetime.time(11, 0, 0),
                       datetime.time(12, 0, 0))
        db.session.add(event1)
        comp.comp_events.append(event1)
        comp.competitors.append(user)
        comp.competitors.append(user1)
        comp.competitors.append(user2)

        register_user1 = EventUserLink(user=user1, event=event1)
        register_user2 = EventUserLink(user=user2, event=event1)
        db.session.add(register_user1)
        db.session.add(register_user2)
        register_user2.volunteer = True
        register_user2.volunteer_role = 'Judge'
        register_user1.staff = True
        register_user1.staff_role = 'Scrambler'

        db.session.commit()
Пример #7
0
    def get(self):
        count = int(self.get_argument('count', 4))

        ans = yield gen.maybe_future(Announcement.list_by_count(count))
        raise gen.Return({
            'total': len(ans),
            'announcements': [(yield gen.maybe_future(an.to_dict()))
                              for an in ans]
        })
Пример #8
0
def addAnnouncement():
    form = AnnouncementForm()
    if form.validate_on_submit():
        data = form.data
        announcement = Announcement(title=data["title"],
                                    content=data["content"])
        db.session.add(announcement)
        db.session.commit()
        flash("添加成功!")
        return redirect(url_for('admin.announcement', page=1))
    return render_template("admin/announcementAdd.html", form=form)
Пример #9
0
def account_info():
    token = session.get('google_token')[0]
    try:
        headers = {'Authorization': "OAuth {0}".format(token)}
        req = requests.get(GOOGLE_OAUTH_URL, headers=headers)
        response = req.json()
        user = User.lookup_by_google(response['id'])
        print(user.id)
        Announcement.make_announcement(
            user,
            "Balloons in Soda Courtyard",
            "Hey everyone, there are balloons in the soda courtyard right now. Like shit I'm tripping balls.",
            tags="balloons, fun time, soda hall, cs for lyfe")
        Announcement.make_announcement(user,
                                       "Hilfinger is in the Soda",
                                       "I repeat, the hilf is back.",
                                       tags="hilfinger, too, op")
        Announcement.make_announcement(
            user,
            "Classes canceled",
            "CS61A is canceled forever. BUT CS61B IS ALWAYS ON BABY",
            tags="what, testing, why tho")

        return jsonify(req.json())
    except requests.exceptions.RequestException:
        return "YOU F****D UP A-A-RON"
Пример #10
0
def publish_announcement(course_id):
    form = AnnouncementForm()
    if form.validate_on_submit():
        announcement = Announcement(
            course_id=course_id,
            timestamp=localtime(),
            title=form.title.data,
            body=form.content.data,
        )
        db.session.add(announcement)
        db.session.commit()
        return redirect(url_for('course.announcement', course_id=course_id))
    return render_template('course/publish_announcement.html', form=form)
Пример #11
0
def post_ovr():
    """
    Add announce in database without id by /anns.
    :return:
    """
    args = request.json
    print(args)
    if args:
        a = Announcement(**args)
        db.session.add(a)
        db.session.commit()
        args['id'] = a.id
        return make_response(jsonify(args), 201)
    return abort(404)
Пример #12
0
def post_anon(idx):
    """
    Handling for posting - inserting new announces.
    :param idx:
    :return:
    """
    args = request.json
    if args:
        args['id'] = idx
        a = Announcement(**args)
        db.session.add(a)
        db.session.commit()
        return make_response(jsonify(args), 201)
    return abort(400)
Пример #13
0
def index():
    for user in User.query.all():
        if user.hp != user.hotpoints():
            user.hp = user.hotpoints()
            db.session.commit()
    users = (User.query.filter(User.retired == 0).order_by(
        User.hp.desc()).all())
    announcement = Announcement.query.order_by(
        Announcement.timestamp.desc()).limit(1).first()
    if announcement is None:
        announcement = Announcement(text='')
    return render_template('main/index.html',
                           users=users,
                           announcement=Markup(announcement.text),
                           current_user=current_user)
Пример #14
0
def create(id=None):
    form = AnnouncementForm()

    if form.validate_on_submit():
        announcement = Announcement(title=form.title.data,
                                    body=form.body.data,
                                    datetime=form.dt.data,
                                    location=form.location.data)
        db.session.add(announcement)

        db.session.commit()

        flash('Created Successfully!')
        return redirect(url_for('index'))

    return render_template('create.html', form=form)
Пример #15
0
def create_announcement():
    form = NewAnnouncementForm(request.form)
    if form.validate() and request.method == 'POST':
        if form.announcement.data is not None and form.name.data is not None and form.severity.data is not None:
            today = datetime.date.today().strftime("%m/%d/%Y")
            new_announcement = Announcement(
                name=form.name.data,
                announcement=form.announcement.data,
                date=today,
                severity=form.severity.data,
                user_id=flask_session['user_id'])
            database.session.add(new_announcement)
            database.session.commit()
            return redirect('/index')
    return render_template('new_announcement.html',
                           form=form,
                           is_admin=is_admin)
Пример #16
0
def add_announcement():
    """
    Adding new announcement in browser by routing to other temp-form
    :return:
    """
    form = AnnouncementForm()
    if form.validate_on_submit():
        u = Announcement(body=form.body.data,
                         name=form.name.data,
                         price=form.price.data,
                         user_id=current_user.id)
        db.session.add(u)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('add_announcement'))
    return render_template('add_announcement.html',
                           title='Dodaj ogłoszenie',
                           form=form)
Пример #17
0
def announce():
    if not current_user.admin:
        abort(403)
    announcement = Announcement.query.order_by(
        Announcement.timestamp.desc()).limit(1).first()
    form = AnnouncementForm(
        announcement=(announcement.text if announcement is not None else ''))
    if form.validate_on_submit():
        announcement = Announcement(
            text=form.announcement.data,
            announcer_id=current_user.get_id(),
        )
        db.session.add(announcement)
        db.session.commit()
        return redirect(url_for('main.index'))
    return render_template('main/announce.html',
                           form=form,
                           title='Announcement')
Пример #18
0
def post_announcement():
    if current_user.email != '*****@*****.**':
        abort(403)

    form = SendMailForm()
    if form.validate_on_submit():
        announcement = Announcement(title=form.title.data, content=form.content.data)
        db.session.add(announcement)

        for user in User.query.all():
            user.unread_announcements = user.unread_announcements + "," + str(announcement.id)

        db.session.commit()
        raw_email_data = db.session.query(User.email).filter(User.mailing_list).all()
        msg_html = form.content.data
        title = form.title.data
        recipients = [item[0] for item in raw_email_data]
        thr = Thread(target=send_async_email, args=[title, recipients, "", msg_html])
        thr.start()
        flash("Announcement posted and emails notifications sent.", "success")
        return redirect(url_for('post_announcement'))
    return render_template('post_announcement.html', form=form)
Пример #19
0
def data_loading():
    app.app_context().push()
    # Load company (quote) details and announcement details
    print("Starting data loading job...")
    Company.company_scrape()
    announcements = Announcement.announcement_scrape()
    db.session.commit()

    if not Announcement.query.filter_by(
            announced_date=datetime.date.today()).first():
        print("No operation today, no announcement/stock update required")
        return

    # Send out announcements based on announcements loading
    for announcement in announcements:
        recipients = announcement.subscriber()
        chats = []
        for recipient in recipients:
            chats.append(recipient.chat_id)
        chats.append(os.environ.get('TARGET_CHANNEL'))

        response = announcement.announcement_message()
        if response:
            for chat in chats:
                time.sleep(0.1)
                telegram_bot.send_message(chat_id=chat,
                                          text=response,
                                          parse_mode='HTML')

    # Query all companies and run price check and price alert for each
    subs = Subscribe.query.all()
    for sub in subs:
        time.sleep(0.1)
        sub.company.price_change()
        sub.company.price_alert()

    db.session.commit()
    print("Data loading job completed...")
Пример #20
0
def make_announcement():
    """ End-Point handling making announcements """

    form = AnnouncementForm()
    academy = Academy.query.filter_by(id=current_user.academy_id).first()

    if form.validate_on_submit():
        if not current_user.is_master(
        ) and current_user.position != "Upper Management":
            if dict(form.academy.choices).get(
                    form.academy.data) != academy.name:
                flash(
                    "You don't have permissions to make announcements to academies other than your own."
                )
                return redirect(url_for('main.make_announcement'))
            if form.for_all.data == True:
                flash(
                    "You don't have permissions to make announcements to academies other than your own."
                )
                return redirect(url_for('main.make_announcement'))
        academy = Academy.query.filter_by(
            name=dict(form.academy.choices).get(form.academy.data)).first()
        announcement = Announcement(subject=form.subject.data,
                                    message=form.message.data,
                                    for_all=form.for_all.data,
                                    user_id=current_user.id,
                                    academy_id=academy.id)

        db.session.add(announcement)
        db.session.commit()
        flash('Announcement has been sent!')
        return redirect(url_for('main.index'))

    return render_template('make_announcement.html',
                           title='Make Announcement',
                           what='Make',
                           form=form)
Пример #21
0
# Add competitions
db.session.add(
    Competition(1, "City College Cube Day", "160 Convent Avenue", "New York",
                "NY", "10031", datetime.date(2017, 12, 31)))
db.session.add(
    Competition(user2.id, "Rubik's Cube Day", "Cubicle", "City", "State",
                "10009", datetime.date(2017, 12, 31)))
session_comp = Competition.query.filter_by(comp_id=1).first()
session_comp2 = Competition.query.filter_by(comp_id=2).first()

session_comp.approved = True

# Add announcement
announce = Announcement(
    session_comp.comp_id, user.id, "4x4 Evemt shorted to combined final",
    "Due to lack of time, we've shortened the 4x4 event to a combined final. We apologize for any inconvenience!"
)

db.session.add(Announcement(1, user.id, "Test Announcement", "Test Body"))
db.session.add(announce)

event = Event("Setup", "", datetime.time(8, 0, 0), datetime.time(9, 0, 0))
event1 = Event("Rubik's Cube", "Round 1", datetime.time(9, 0, 0),
               datetime.time(10, 0, 0))
event2 = Event("2x2x2 Cube", "Round 1", datetime.time(10, 0, 0),
               datetime.time(11, 0, 0))
event3 = Event("4x4x4 Cube", "Round 1", datetime.time(11, 0, 0),
               datetime.time(12, 0, 0))
event4 = Event("Lunch", "", datetime.time(12, 0, 0), datetime.time(13, 0, 0))
event5 = Event("Rubik's Cube", "Round 2", datetime.time(13, 0, 0),
               datetime.time(14, 0, 0))
Пример #22
0
def index():
    """ Root assistant view which holds all the announcements. """
    results = Announcement.all_announcements()
    results = sorted(results, key=lambda x: x['date'], reverse=True)
    return render_template("assistant/index.html", announcements=results)