示例#1
0
文件: event.py 项目: marian42/journal
	def add_tag(self, tag_name):
		from model.tag import Tag
		from model.tagtoevent import TagToEvent
		
		if any(tte.tag.name == tag_name for tte in self.tags):
			return
		
		tag = Tag.get_tag(tag_name)
		tag_to_event = TagToEvent(tag = tag, event = self)
		tag_to_event.save(force_insert=True)
示例#2
0
def get_days():
    global graph

    filter_include = request.args.get('include') == "true"
    tag_ids = [
        Tag.get_tag(tag).id for tag in json.loads(request.args.get('tags'))
    ]

    if graph is None or graph.outdated(filter_include, tag_ids):
        graph = CalendarGraph(filter_include, tag_ids)
    return jsonify(graph.to_dict())
示例#3
0
def get_events():
    time = request.args.get('time')
    before = request.args.get('before') == 'true'
    try:
        date = datetime.datetime.fromtimestamp(float(time) / 1000.0)
    except OSError:
        date = datetime.datetime.min

    filter_include = request.args.get('include') == "true"
    tag_ids = [
        Tag.get_tag(tag).id for tag in json.loads(request.args.get('tags'))
    ]
    filter_query = fn.EXISTS(TagToEvent.select().where(
        TagToEvent.tag.in_(tag_ids) & (TagToEvent.event == Event.id)))
    if not filter_include:
        filter_query = ~filter_query

    n = 100
    if any(tag_ids):
        if before:
            query = Event.select().where((Event.time < date)
                                         & filter_query).order_by(
                                             Event.time.desc())[:n]
        else:
            query = Event.select().where((Event.time > date)
                                         & filter_query).order_by(
                                             Event.time)[:n]
    else:
        if before:
            query = Event.select().where(Event.time < date).order_by(
                Event.time.desc())[:n]
        else:
            query = Event.select().where(Event.time > date).order_by(
                Event.time)[:n]

    result = [to_dict(event) for event in query]
    if before:
        result = reversed(result)

    return jsonify(list(result))