Esempio n. 1
0
def event_to_show(
    event: Event,
    session: Depends(get_db),
    user: Optional[User] = None,
) -> Optional[Event]:
    """Check the given event's privacy and return
    event/fixed private event/ nothing (hidden) accordingly"""
    is_owner = check_event_owner(event, session, user)
    if event.privacy == PrivacyKinds.Private.name and not is_owner:
        event_dict = event.__dict__.copy()
        if event_dict.get("_sa_instance_state", None):
            event_dict.pop("_sa_instance_state")
        event_dict.pop("id")
        private_event = Event(**event_dict)
        private_event.title = PrivacyKinds.Private.name
        private_event.content = PrivacyKinds.Private.name
        private_event.location = PrivacyKinds.Private.name
        private_event.color = Null
        private_event.invitees = PrivacyKinds.Private.name
        private_event.category_id = Null
        private_event.emotion = Null
        return private_event
    elif event.privacy == PrivacyKinds.Hidden.name and not is_owner:
        return
    elif event.privacy == PrivacyKinds.Public.name or is_owner:
        return event
Esempio n. 2
0
 def test_create_event_with_category(category):
     event = Event(title="OOO",
                   content="Guitar rocks!!",
                   owner_id=category.user_id,
                   category_id=category.id)
     assert event.category_id is not None
     assert event.category_id == category.id
Esempio n. 3
0
 def add_event(session, title, content, start, end, owner_id):
     event = Event(title=title,
                   content=content,
                   start=start,
                   end=end,
                   owner_id=owner_id)
     session.add(event)
     session.commit()
Esempio n. 4
0
    def add_event(session, title, content, owner_id):
        event = Event(title=title,
                      content=content,
                      start=datetime.today(),
                      end=datetime.today(),
                      owner_id=owner_id)

        session.add(event)
        session.commit()
Esempio n. 5
0
def create_month_shifts(start: datetime, end: datetime,
                        add_sixth_day: bool = False) -> List[Event]:
    shifts = []
    for i in range(4):
        for j in range(6):
            if j < 5 or add_sixth_day:
                shifts.append(Event(
                    start=start + timedelta(i) * 7 + timedelta(j),
                    end=end + timedelta(i) * 7 + timedelta(j)))
    return shifts
Esempio n. 6
0
def event(session, user):
    event1 = Event(title="Test Email",
                   content="Test TEXT",
                   start=datetime.datetime.now(),
                   end=datetime.datetime.now(),
                   owner_id=user.id)
    session.add(event1)
    session.commit()
    yield event1
    session.delete(event1)
    session.commit()
Esempio n. 7
0
def test_font_size_attribute(minutes, css_class, visiblity):
    start = datetime(year=2021, month=2, day=3, hour=7)
    end = start + timedelta(minutes=minutes)
    event = Event(
        title="test",
        content="test",
        start=start,
        end=end,
        owner_id=1,
    )
    div_attr = DivAttributes(event)
    assert div_attr.title_size_class == css_class
    assert div_attr.total_time_visible == visiblity
Esempio n. 8
0
def add_event(data):
    """Create event sent mail and store it to database."""
    email_subject = data.get('subject')
    email_content = data.get('content')
    timestamp = dt_utc(data.get('timestamp'))
    recipients = data.get('recipients')
    event = Event(email_subject, email_content, timestamp, datetime.utcnow(),
                  False, None)
    db.session.add(event)
    db.session.commit()
    list_recipients = add_recipients(recipients, event.id)
    schedule_mail(event.id, list_recipients, timestamp)
    return event.id
Esempio n. 9
0
def create_holiday_event(holiday: Match[str], owner_id: int) -> Event:
    valid_ascii_chars_range = 128
    title = holiday.groupdict()['title'].strip()
    title_to_save = ''.join(i if ord(i) < valid_ascii_chars_range else ''
                            for i in title)
    date = holiday.groupdict()['date'].strip()
    format_string = '%Y%m%d'
    holiday = Event(title=title_to_save,
                    start=datetime.strptime(date, format_string),
                    end=datetime.strptime(date, format_string) +
                    timedelta(days=1),
                    content='holiday',
                    owner_id=owner_id)
    return holiday
Esempio n. 10
0
def add_event():
    form = ItemsForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                new_event = Event(form.data)
                db.session.add(new_event)
                db.session.commit()
                message = Markup(
                    "<strong>Well done!</strong> Event added successfully!")
                flash(message, 'success')
                return redirect(url_for('all_events'))
            except:
                db.session.rollback()
                message = Markup(
                    "<strong>Oh snap!</strong>! Unable to add event.")
                flash(message, 'danger')
    return render_template('add_event.html', form=form)
Esempio n. 11
0
    def add_event(session: Session, title: str, content: str, owner_id: int):
        """Inserts an Event into the database.

        Args:
            session: The database fixture.
            title: The Event's title.
            content: The Event's content.
            owner_id: The User's ID.
        """
        event = Event(
            title=title,
            content=content,
            start=datetime.today(),
            end=datetime.today(),
            owner_id=owner_id,
        )

        session.add(event)
        session.commit()
Esempio n. 12
0
def get_event_by_category(*args, **kwargs):
    """Mock function for event by category search."""
    # Code revision required after categories feature is added
    day_1 = Event(start=datetime(2021, 1, 10, 9),
                  end=datetime(2021, 1, 10, 19))
    day_2 = Event(start=datetime(2021, 1, 11, 9),
                  end=datetime(2021, 1, 11, 17))
    day_3 = Event(start=datetime(2021, 1, 12, 9),
                  end=datetime(2021, 1, 12, 17))
    day_4 = Event(start=datetime(2021, 1, 13, 9),
                  end=datetime(2021, 1, 13, 18))
    day_5 = Event(start=datetime(2021, 1, 14, 9),
                  end=datetime(2021, 1, 14, 17))
    day_6 = Event(start=datetime(2021, 1, 15, 9),
                  end=datetime(2021, 1, 15, 14, 58))

    return (day_1, day_2, day_3, day_4, day_5, day_6)
Esempio n. 13
0
def test_get_event_by_category() -> None:
    # Code revision required after categories feature is added
    shifts = (
        Event(start=datetime(2021, 1, 10, 9),
              end=datetime(2021, 1, 10, 19)),
        Event(start=datetime(2021, 1, 11, 9),
              end=datetime(2021, 1, 11, 17)),
        Event(start=datetime(2021, 1, 12, 9),
              end=datetime(2021, 1, 12, 17)),
        Event(start=datetime(2021, 1, 13, 9),
              end=datetime(2021, 1, 13, 18)),
        Event(start=datetime(2021, 1, 14, 9),
              end=datetime(2021, 1, 14, 17)),
        Event(start=datetime(2021, 1, 15, 9),
              end=datetime(2021, 1, 15, 14, 58)),
    )
    events = utils.get_event_by_category()
    assert len(events) == len(shifts)
    for i, event in enumerate(events):
        assert event.start == shifts[i].start and event.end == shifts[i].end
Esempio n. 14
0
def event3():
    start = datetime(year=2021, month=2, day=3, hour=7, minute=5)
    end = datetime(year=2021, month=2, day=3, hour=9, minute=15)
    return Event(title='test3', content='test',
                 start=start, end=end, owner_id=1)
Esempio n. 15
0
def small_event():
    start = datetime(year=2021, month=2, day=3, hour=7)
    end = datetime(year=2021, month=2, day=3, hour=8, minute=30)
    return Event(title='test3', content='test',
                 start=start, end=end, owner_id=1)
Esempio n. 16
0
    (datetime(2021, 1, 2, 14), datetime(2021, 1, 3, 0), (16, 3))
]

SHIFTS = [
    # Regular shift
    (datetime(2021, 1, 4, 9), datetime(2021, 1, 4, 19), 315),
    # Night shift
    (datetime(2021, 1, 4, 18), datetime(2021, 1, 5, 4), 330),
    # Off-day shift
    (datetime(2021, 1, 2, 9), datetime(2021, 1, 2, 19), 465),
    # Night off-day shift
    (datetime(2021, 1, 2, 14), datetime(2021, 1, 3, 0), 480),
]

WEEK_SHIFTS = [
    ((Event(start=datetime(2021, 1, 10, 9),
            end=datetime(2021, 1, 10, 19)),), 0.0),
    ((Event(start=datetime(2021, 1, 10, 9),
            end=datetime(2021, 1, 10, 19)),
      Event(start=datetime(2021, 1, 11, 9),
            end=datetime(2021, 1, 11, 17)),
      Event(start=datetime(2021, 1, 12, 9),
            end=datetime(2021, 1, 12, 17)),
      Event(start=datetime(2021, 1, 13, 9),
            end=datetime(2021, 1, 13, 18)),
      Event(start=datetime(2021, 1, 14, 9),
            end=datetime(2021, 1, 14, 17))), 0.0),
    ((Event(start=datetime(2021, 1, 10, 9),
            end=datetime(2021, 1, 10, 19)),
      Event(start=datetime(2021, 1, 11, 9),
            end=datetime(2021, 1, 11, 17)),
      Event(start=datetime(2021, 1, 12, 9),
Esempio n. 17
0
def event2():
    start = datetime(year=2021, month=2, day=1, hour=13, minute=13)
    end = datetime(year=2021, month=2, day=1, hour=15, minute=46)
    return Event(title='test2', content='test',
                 start=start, end=end, owner_id=1, color='blue')
Esempio n. 18
0
def multiday_event():
    start = datetime(year=2021, month=2, day=1, hour=13)
    end = datetime(year=2021, month=2, day=3, hour=13)
    return Event(title='test_multiday', content='test',
                 start=start, end=end, owner_id=1, color='blue')
Esempio n. 19
0
def event_with_no_minutes_modified():
    start = datetime(year=2021, month=2, day=3, hour=7)
    end = datetime(year=2021, month=2, day=3, hour=8)
    return Event(title='test_no_modify', content='test',
                 start=start, end=end, owner_id=1)