예제 #1
0
def create_calendar_entry(req, reqId, rangeId, startDate, hours, energy):
    result = ""

    if reqId:
        title = req.title
        beam = True
    else:
        title = 'Downtime'
        beam = False

    entry = Calendar(
        username = req.username,
        facility = req.facility,
        integrator = req.integrator,
        totalTime = hours,
        startDate = startDate,
        private = False,
        title = title,
        requestId = reqId,
        rangeId = rangeId,
        beam = beam,
        energy = float(energy)
    )
    
    result = entry.create_entry()

    return result
예제 #2
0
def create_new_calendar(user: User, data: dict) -> Calendar:
    new_calendar = Calendar(user=user,
                            date=datetime.strptime(data['date'], date_format),
                            season=data['season'],
                            season_week=data['season_week'],
                            weekday=data['weekday'])
    db.session.add(new_calendar)
    db.session.commit()
    return new_calendar
예제 #3
0
 def createCalendar(user_id):
     try:
         user_id = ObjectId(user_id)
     except:
         return "fail"
     calendar = Calendar(user_id)  #create the calendar
     cal = calendar.save()
     print "created calendar:", cal.id
     return dumps(cal)  #return the calendar object
예제 #4
0
def reset_calendars():
    """
    This function, used only for testing purposes, resets the calendars list to
    its initial states.
    :return: a simple status
    """
    # Removing all calendars and dates:
    with orm.db_session:
        # Deleting all dates and calendars
        Date.select().delete(bulk=True)
        Calendar.select().delete(bulk=True)

        # Creating sample calendars and dates
        Calendar(id=0, title="Empty calendar")
        c2 = Calendar(id=1, title="Sport and activities")
        Date(id=0, calendar=c2, date="2018-01-01", event="Go fishing")
        Date(id=1, calendar=c2, date="2018-01-11", event="Go surfing")
        Date(id=2, calendar=c2, date="2018-02-12", event="Go skying")
        Date(id=3, calendar=c2, date="2018-03-09", event="Go swimming")

    return dict(status="done")
예제 #5
0
def add_calendar():
    calendar_info = request.get_json()
    print("CALENDAR INFO", calendar_info)
    new_calendar = Calendar(notes=calendar_info['notes'],
                            start_date=calendar_info['startDate'],
                            end_date=calendar_info['endDate'],
                            title=calendar_info['title'])
    db.session.add(new_calendar)
    db.session.commit()
    response = Calendar.query.all()
    response = list(map(lambda x: x.serialize(), response))

    return jsonify(response), 200
예제 #6
0
def optionnal_calendar(sender, **kwargs):
    event = kwargs.pop('instance')

    if not isinstance(event, Event):
        return True
    if not event.calendar:
        try:
            calendar = Calendar._default_manager.get(name='default')
        except Calendar.DoesNotExist:
            calendar = Calendar(name='default', slug='default')
            calendar.save()

        event.calendar = calendar
    return True
예제 #7
0
    def update(self):
        #self.get_settings()

        #		str_link_status = u'link_state"<span style=" font-weight:600; color:#ff0000;">М\'яке посилання не встановлене</span>'
        #		link_state = self.link_check()
        #		if link_state:
        #			str_link_status = link_state
        #		self.ui.labelLinkStatus.setText(str_link_status)

        model = MoodleCourseModel(self.db)
        self.ui.treeViewCourse.setModel(model)

        cal = Calendar()
        self.ui.treeViewCourse.setItemDelegateForColumn(2, cal)
        self.ui.treeViewCourse.show()
예제 #8
0
def create_default_calendar(current_user, name):
    try:
        get_calendar(current_user, name)
        raise RepeatCalendarException('Calendar already exists')
    except DoesNotExistError:
        pass

    # creating the actual calendar object
    calendar = Calendar(parent=current_user.key,
                        owner=current_user.key,
                        name=name)
    calendar.column_names = Calendar.default_columns
    calendar.put()
    insert_row(calendar, current_user, datetime.today().date())
    return calendar
예제 #9
0
def handle_calendar_post(calendar_title):
    # Validate the user input
    if len(calendar_title) >= 256 or len(calendar_title) < 4:
        return {'success': False, 'error_msg': 'API returned error'}

    calendar_hash = sha1(calendar_title + \
        str(int(time.time())).encode('utf-8') + \
        'my_s3cr3t_s4lt'.encode('utf-8')).hexdigest()

    c = Calendar(hash=calendar_hash, title=calendar_title)
    db.session.add(c)
    db.session.commit()

    print(calendar_hash)
    return {'success': True, 'hash': calendar_hash}
예제 #10
0
def add_own_meal(user_id):
    check_user = do_user_check(user_id)
    if check_user:
        form = UserMealCalendarForm()
        if form.validate_on_submit():
            meal_name = form.meal_name.data
            dateSelected = myconverter(form.date.data)
            dateInfo = Calendar(user_id=user_id,
                                meal_name=meal_name,
                                selected_date=dateSelected)
            Calendar.save(dateInfo)
            return redirect(f'/users/{user_id}/calendar')
        else:
            return render_template('meal_add.html', form=form)
    else:
        return redirect('/')
예제 #11
0
def add_calendar(beam_request):
    result = ""

    try:
        entry = Calendar(username=beam_request.username,
                         facility=beam_request.facility,
                         integrator=beam_request.integrator,
                         totalTime=beam_request.hours,
                         startDate=beam_request.start,
                         private=False,
                         title=beam_request.title)
        result = entry.create_entry()

    except Exception as e:
        result = {'error': str(e), 'success': False}

    return result
예제 #12
0
def create_entry():

    req = request.get_json()
    result = ""

    try:
        entry = Calendar(username=req['username'],
                         facility=req['facility'],
                         integrator=req['integrator'],
                         totalTime=req['totalTime'],
                         startDate=req['startDate'],
                         private=req['private'],
                         title=req['title'])
        result = entry.create_entry()

    except Exception as e:
        result = {'error': str(e), 'success': False}

    return result
예제 #13
0
def add_recipe(user_id, meal_id, meal_name):
    check_user = do_user_check(user_id)
    if check_user:
        form = UserMealCalenderDateForm()
        if form.validate_on_submit():
            new_meal = Calendar(user_id=user_id,
                                meal_id=meal_id,
                                meal_name=meal_name,
                                selected_date=form.date.data)
            Calendar.save(new_meal)
            flash("You successfully saved your meal to calendar", "success")
            return redirect(
                f'/users/{user_id}/meals/{meal_id}/view/{meal_name}')
        else:
            return render_template('create_meal_calendar.html',
                                   form=form,
                                   meal_id=meal_id,
                                   meal_name=meal_name)
    else:
        return redirect('/')
예제 #14
0
def create_entry():

    username = get_jwt_identity()
    req = request.get_json()
    result = ""

    # date = datetime.strptime(form['date'], '%Y-%m-%dT%H:%M:%S.%fZ')

    try:
        entry = Calendar(
            username=req['username'],  # username
            facility=req['facility'],
            integrator=req['integrator'],
            totalTime=req['totalTime'],
            startDate=req['startDate'],
            private=req['private'],
            title=req['title'])
        result = entry.create_entry()

    except Exception as e:
        result = {'error': str(e), 'success': False}

    return result
예제 #15
0
def handle_calendar_create(info):
    calendar = Calendar(**info)
    db.session.add(calendar)
    db.session.commit()
    logger.info(f"Created calendar with key: {(info['id'], info['user_id'])}")
예제 #16
0
def put_calendar_for_user(email, calendar_name):
    user = get_user_from_email(email)
    calendar = Calendar(parent=user.key, name=calendar_name, owner=user.key)
    calendar.put()
    return calendar