Exemplo n.º 1
0
def newcalendar():
    # Standard conditions to check if the user has proper right to acces the page ***
    if DEBUG:
        pdb.set_trace()
    user = User.query.filter(
        User.ext_id_hashed == session.get('profile_ext_id_hashed')).first()
    if user is None:
        session.clear()
        return redirect(url_for('index'))
    elif user.account_status == 0:
        return render_template(
            "message.html",
            message=
            "Please wait for admin approval. Contact an admin if needed.",
            avatar_url=user.avatar_url)
    elif user.account_type != 2:
        return render_template(
            "message.html",
            message="You do not have proper right to access this site. "
            "Please contact an admin if needed.",
            avatar_url=user.avatar_url)
    # End of conditions ******************************
    calendar_action = request.values.get('calendar_action', '')
    if calendar_action:
        new_name = request.values.get('new_name', '')
        calendar_id = request.values.get('calendar_id', '')
        if calendar_action == "add":
            try:
                calendar = Calendar(name=new_name)
                db.session.add(calendar)
                db.session.commit()
            except Exception:
                db.session.rollback()
        if calendar_action == "rename":
            try:
                calendar = Calendar.query.filter(
                    Calendar.id == calendar_id).first()
                calendar.name = new_name
                db.session.commit()
            except Exception:
                db.session.rollback()
        if calendar_action == "delete":
            if calendar_id != 1:
                try:
                    calendar = Calendar.query.filter(
                        Calendar.id == calendar_id).first()
                    vacation_data = Holiday.query.filter(
                        Holiday.calendar_id == calendar_id).all()

                    for vacation in vacation_data:
                        db.session.delete(vacation)
                    db.session.delete(calendar)
                    db.session.commit()
                except Exception:
                    db.session.rollback()
        # elif calendar_action == "cancel":  # The default return function is enough
        return redirect("/calendars")
    return render_template("newcalendar.html", user=user, calendar=None)
Exemplo n.º 2
0
def load_baby_liebs():
    """Load sample calendar"""
    due_date = datetime(2016, 03, 06)
    baby_liebs = Calendar(due_date=due_date,
                          calendar_name="Baby Lieb's Bidding Pool",
                          num_timeblocks=50,
                          calendar_tz="US/Pacific",
                          fixed_price_blocks=2.00,
                          account_id=1)
    db.session.add(baby_liebs)
    db.session.commit()
    baby_liebs.generate_timeblocks()
Exemplo n.º 3
0
def create_calendar():
    """Instantiate calendar and generate associated workout instances"""

    title = request.form.get('title')
    cal = Calendar(user_id=session.get('user_id'), title=title)
    db.session.add(cal)
    db.session.commit()
    # instantiated calendar does not have columns for start-end dates ->
    # a workout w/ datetime values is generated for each day in the user specified ran

    start_date = request.form.get('schedule-start')
    start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
    end_date = request.form.get('schedule-end')
    end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")

    day_range = (end_date - start_date).days + 1

    for n in range(day_range):
        # gets day n days from the start date
        curr_start = start_date + datetime.timedelta(n)
        # gets the day of the week of the current start as 'mon', 'tue' etc ->
        # these match the column names for base_workout
        weekday_str = datetime.datetime.strftime(curr_start, '%a').lower()

        base_workouts = BaseWorkout.get_by_weekday(session.get('user_id'),
                                                   weekday_str)
        # gets all base workouts for a user where the day of the week is true

        # chooses one baseworkout to generate a workout from
        if base_workouts:
            base_workout = random.choice(base_workouts)
            generate_calendar_workout(base_workout, cal, curr_start)

    return redirect('/')
Exemplo n.º 4
0
def load_calendar():
    """Load a calendar into database."""

    calendar = Calendar(title="Fall Season", user_id=1)

    db.session.add(calendar)

    db.session.commit()
 def __init__(self, uid, uRank, nprocs):
     self.lamportClock = 0
     self.uid = uid
     self.theCalendar = Calendar(uid)
     self.tt = [[0 for j in range(nprocs)] for i in range(nprocs)]
     self.log = []
     self.uRank = uRank
     self.nprocs = nprocs
Exemplo n.º 6
0
def seed_calendars(calendarsResult, user_id):

    calendars = calendarsResult.get('items', [])

    for calendar in calendars:

        calendar_id = calendar['id'].lower()
        timezone = calendar['timeZone']
        summary = calendar['summary']
        etag = calendar['etag']

        if 'primary' in calendar:
            primary = calendar['primary']

        else:
            primary = False

        if 'selected' in calendar:
            selected = calendar['selected']

        else:
            selected = False

        cal_exists = Calendar.query.get(calendar_id)
        usercal_exists = UserCal.query.filter_by(
            user_id=user_id, calendar_id=calendar_id).first()

        if cal_exists and usercal_exists is None:

            usercal = UserCal(user_id=user_id,
                              calendar_id=calendar_id,
                              primary=primary,
                              selected=selected)

            db.session.add(usercal)
            db.session.commit()

        elif cal_exists is None:

            calendar_obj = Calendar(calendar_id=calendar_id,
                                    etag=etag,
                                    summary=summary,
                                    timezone=timezone)

            db.session.add(calendar_obj)
            db.session.commit()

            usercal = UserCal(user_id=user_id,
                              calendar_id=calendar_id,
                              primary=primary,
                              selected=selected)

            db.session.add(usercal)
            db.session.commit()

    return calendar_id
Exemplo n.º 7
0
def is_user_managing_in_calendar(session, calendar_name, fas_user):
    """ Returns True if the user is in a group set as manager of the
    calendar and False otherwise. It will also return True if there are
    no groups set to manage the calendar.

    :arg session: the database session to use
    :arg calendar_name: the name of the calendar of interest.
    :arg fas_user: a FAS user object with all the info.
    """
    manager_groups = Calendar.get_manager_groups(session, calendar_name)
    admin_groups = Calendar.get_admin_groups(session, calendar_name)
    if not manager_groups:
        return True
    else:
        return len(
            set(manager_groups).intersection(set(fas_user.groups))
        ) >= 1 or len(
            set(admin_groups).intersection(set(fas_user.groups))
        ) >= 1
Exemplo n.º 8
0
def get_meetings_by_date(session, calendar_name, start_date, end_date):
    """ Return a list of meetings which have or will occur in between
    the two provided dates.

    :arg session: the database session to use
    :arg calendar_name: the name of the calendar of interest.
    :arg start_date: the date from which we would like to retrieve the
        meetings (this day is included in the selection).
    :arg start_date: the date until which we would like to retrieve the
        meetings (this day is excluded from the selection).
    """
    calendar = Calendar.by_id(session, calendar_name)
    return get_by_date(session, calendar, start_date, end_date)
Exemplo n.º 9
0
def get_calendars(session):
    """ Retrieve the list of Calendar from the database. """
    return Calendar.get_all(session)
Exemplo n.º 10
0
import thread
import time
import pika
import logging
import datetime
from helper import UserHelper
from model import Event, Calendar

cal = Calendar("MyCalendar")
ev = Event("Makan-makan", "D'Cost", datetime.datetime.now(), datetime.datetime.now(), "Yarwe")
ev2 = Event("Kuman", "Hupe", datetime.datetime.strptime("4 1 2014 15:58", "%d %m %Y %H:%M"), 
	datetime.datetime.strptime("6 1 2014 15:58", "%d %m %Y %H:%M"), "Gomul")
cal.add_event(ev)
cal.add_event(ev2)
x = datetime.datetime.strptime("4 1 2014 15:58", "%d %m %Y %H:%M")
z = x.strftime("%d:%m:%Y:%H:%M")
y = datetime.datetime.strptime(z, "%d:%m:%Y:%H:%M")
print y

print cal.is_conflict(
	datetime.datetime.strptime("5 1 2014 15:58", "%d %m %Y %H:%M"), 
	datetime.datetime.strptime("5 1 2014 15:58", "%d %m %Y %H:%M"))
    def register_calendar(self, calendar):

        remote_calendar = self._register_remote_calendar(calendar)
        return Calendar.from_remote_calendar(remote_calendar)
	def register_calendar(self, calendar):
		
		remote_calendar = self._register_remote_calendar(calendar)
		return Calendar.from_remote_calendar(remote_calendar)
Exemplo n.º 13
0
def create_calendar(calendar_url):
    new_calendar = Calendar(url=calendar_url)
    db.session.add(new_calendar)
    db.session.commit()