当前位置: 首页>>代码示例>>Python>>正文


Python Event.objects方法代码示例

本文整理汇总了Python中models.Event.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Event.objects方法的具体用法?Python Event.objects怎么用?Python Event.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Event的用法示例。


在下文中一共展示了Event.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: detail

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def detail(request, event_id):
    event = get_document_or_404(Event, id=event_id)
    
    if event.date_start:
        event.date_start = event.date_start.strftime('%d/%m/%Y %H:%M') 
    if event.date_end:
        event.date_end = event.date_end.strftime('%d/%m/%Y %H:%M')
    if event.location:
        event.lat = event.location[0]
        event.lng = event.location[1]

    if request.session.get('userid'):
        template = 'event/event_detail.html'

        user = Account.objects(id=request.session.get('userid'))[0]
        event.going = Event.objects(user_going__in=[user], id=event_id)
        event.going = 'active' if event.going else ''
        event.maybe = Event.objects(user_maybe__in=[user], id=event_id)
        event.maybe = 'active' if event.maybe else ''
        event.decline = Event.objects(user_decline__in=[user], id=event_id)
        event.decline = 'active' if event.decline else ''

    else:
        template = 'event/event_detail_nologin.html'


    params = {'event':event,
             'request':request}
   
    return render_to_response(template, params, context_instance=RequestContext(request))
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:32,代码来源:views.py

示例2: events

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def events(id=None):
    if id:
        event = Event.objects.get(pk=id)
        event.update_timezone()
        add_form = EventForm(request.form, obj=event)
        title_aside = u'Éditer l\'événement'
    else:
        event = Event()
        add_form = EventForm()
        title_aside = u'Créer un événement'

    if add_form.organisations.data:
        add_form.organisations.choices = make_choices(add_form.orgas_choices, selected=add_form.organisations.data, name='Organisations')

    if add_form.places.data:
        add_form.places.choices = make_choices(add_form.places_choices, selected=add_form.places.data, name='Lieux')

    if add_form.validate_on_submit():
        event.title = add_form.title.data
        event.description = add_form.description.data
        event.organisations = add_form.organisations.data
        event.places = add_form.places.data

        if not event.author:
            event.author = current_user.to_dbref()

        event.datetime_first = arrow.get(add_form.datetime_first.data).datetime
        event.datetime_last = arrow.get(add_form.datetime_last.data).datetime
        event.update_timezone()

        if current_user.has_role('Administrateur') or current_user.has_role('Éditeur'):
            event.status = 'published' if 'publish' in request.form else 'draft'
        else:
            event.status = 'validation' if 'publish' in request.form else 'draft'

        event.save()
        if id:
            return redirect('/events')

    # Filter the events for non-admin users
    if not current_user.has_role('Administrateur'):
        filter_role = {'organisations__in': current_user.associations}
    else:
        filter_role = {}

    today = arrow.now().date()
    events_draft = Event.objects(status='draft', **filter_role).order_by('datetime_first')
    events_validation = Event.objects(status='validation', datetime_first__gte=today, **filter_role).order_by('datetime_first')
    events_published = Event.objects(status='published', datetime_first__gte=today).order_by('datetime_first')

    return render_template('events.html', events_draft=events_draft, events_validation=events_validation, events_published=events_published, add_form=add_form, title_aside=title_aside, icons=icons)
开发者ID:cynddl,项目名称:federation-backend,代码行数:53,代码来源:views.py

示例3: crawl_listing

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
    def crawl_listing(self, url, ctx='', **kwargs):
        prefix_url = url.rsplit('/', 1)[0] + '/'
        r = req.get(url)
        event_id, data = re.compile(r'parse_sale_(\w+)\((.*)\);$').search(r.text).groups()
        data = json.loads(data)
        event = Event.objects(event_id=event_id).first()
        if not event: event = Event(event_id=event_id)

        for product_data in data['asins']: # ensure we download the complete data once
            if 'cAsin' not in product_data:
                r = req.get(url)
                event_id, data = re.compile(r'parse_sale_(\w+)\((.*)\);$').search(r.text).groups()
                data = json.loads(data)

        product_ids = []
        for product_data in data['asins']:
            ret = self._parse_product(event_id, event.asin_detail_page, event.casin_soldout_info, prefix_url, product_data, ctx)
            product_ids.append(ret)

        if event.urgent == True:
            event.urgent = False
            ready = True
        else: ready = False
        event.product_ids = product_ids
        event.update_time = datetime.utcnow()
        event.save()
        common_saved.send(sender=ctx, obj_type='Event', key=event_id, is_new=False, is_updated=False, ready=ready)
开发者ID:mobishift2011,项目名称:amzn,代码行数:29,代码来源:server.py

示例4: event

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
 def event(self, id ):
     """ Show the current user's events from all connected sheets """
     user = User.objects.get_or_404(id=id, alive=True)
     
     date_from = request.args.get('from', None)
     date_to = request.args.get('to',None)
   
     if (date_from is None or date_to is None  ):
         abort(400)
     
     # Get all the sheet's the user is connected to
     users_sheets = UserSheet.objects(user=user, alive=True)
     
     all_events = []
     events = []
     # foreach connected sheet, get the associated events
     for sheet in users_sheets:
         #add the event to the list of events
         for event in Event.objects(sheet=sheet, alive=True):
             all_events.append( event )
         
     isWithin = lambda frm, to, val: (val >= frm and val <= to)
   
     for event in all_events :
         if isWithin(date_from, date_to, event.event_date) :
             events.append( event.to_json() )
     
     return jsonify(ok=True, objects=events)
开发者ID:DeprecatedCode,项目名称:yearplan,代码行数:30,代码来源:user.py

示例5: search

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def search(request):
    # Get all events from DB
    lat = request.GET['lat']
    lng = request.GET['lng']
    radius = request.GET['radius']
    location = (float(lat),float(lng))
    date = request.GET['date'].ljust(10,'0')[0:10]
    date = datetime.datetime.fromtimestamp(int(date))
    events = Event.objects(
        Q(date_start__lte=date) & 
        (Q(date_end__gte=date) | Q(date_end__exists=False)) &
        Q(location__within_distance=[location, int(radius)])
        )
    # .values_list(
            # 'title', 
            # 'description', 
            # 'location',
            # 'date_start',
            # 'date_end')

    data = json.dumps( [{'id': str(e.id),
                           'title': e.title,
                           'description': e.description,
                           'location': e.location,
                           'date_start': str(e.date_start.strftime('%d/%m/%Y %H:%M')),
                           'date_end':  str(e.date_end.strftime('%d/%m/%Y %H:%M')) if e.date_end else ''} 
                        for e in events])

    return HttpResponse(data,content_type='application/json')
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:31,代码来源:views.py

示例6: list

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def list(request):
    # Get all events from DB
    user = Account.objects(id=request.session.get('userid'))[0]
    events = Event.objects(user=user)
    return render_to_response('event/event_list.html', {'event_list': events,
             'request':request},
                              context_instance=RequestContext(request))
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:9,代码来源:views.py

示例7: eventGoing

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def eventGoing(request):
    user = Account.objects(id=request.session.get('userid'))[0]
    events = Event.objects(user_going__in=[user])
    return render_to_response('event/event_list_readonly.html', {
        'event_list': events,
        'request':request },
        context_instance=RequestContext(request))
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:9,代码来源:views.py

示例8: sheet_event

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
 def sheet_event (self, id):
     """ Create an event """
     sheet = Sheet.objects.get_or_404(id = id)
     if request.method == 'GET' :
         """ Get all events """
         #if 'from' not in  request.args or 'to' not in request.args:
         #   abort(400, error = 'missing arguments from and to ')
         
         _sheetEvents = Event.objects(sheet=sheet, alive=True)
         
         _events = [e.to_json() for e in _sheetEvents ]
         return jsonify(ok=True, objects=_events),200
     
     if request.method == 'POST':
         
         new_event = Event( 
                         dates = request.json.get('dates',[]),
                         name = request.json['name'],
                         event_date = request.json['event_date'],
                         description = request.json['description'],
                         location = request.json['location'],
                         public = request.json.get('public',True),
                         links = request.json.get('links',[]),
                         color = request.json.get('color','#fff'),
                         tags = request.json['tags'],
                         alive = True,
                         created_by = str(sheet.created_by),
                         sheet= sheet
                         )
         new_event.save()
         
         return jsonify(ok=True,objects=[new_event.to_json()]), 201
开发者ID:DeprecatedCode,项目名称:yearplan,代码行数:34,代码来源:sheet.py

示例9: update_facebook_vars

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def update_facebook_vars():
    """
    Perform an update of all events with a Facebook id,
    to update the number of people attending the event.
    """
    graph = facebook.GraphAPI(app.config['FACEBOOK_AUTH'])
    events = Event.objects(facebook_id__exists=True)
    for event in events:
        count = len(graph.get_object(event.facebook_id + '/attending')['data'])
        event.attendees = count
        event.save()
    return '%i event(s) updated.' % len(events)
开发者ID:cynddl,项目名称:federation-backend,代码行数:14,代码来源:api.py

示例10: event_trash

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
 def event_trash (self, id):
     """ events recently deleted from this sheet within the last 24 hrs """
     sheet = Sheet.objects.get_or_404( id = id, alive=True)
     
     trashed = Event.objects(
                     alive = False,
                     sheet = sheet,
                     updated_at__lte = datetime.now(),
                     updated_at__gte = datetime.now() -timedelta(1)
                     )
     
     return jsonify(ok=True, objects=[item.to_json() for item in trashed]),200
开发者ID:DeprecatedCode,项目名称:yearplan,代码行数:14,代码来源:sheet.py

示例11: public_affiche

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def public_affiche():
    from api import get_week_bounds

    date_first, date_last = get_week_bounds()
    events = Event.objects(datetime_first__gte=date_first, datetime_first__lte=date_last, status='published').order_by('date_first')

    print events
    day_range = arrow.Arrow.span_range('day', date_first, date_last)
    day_events = [(d_1, [e for e in events if e['datetime_first'] > d_1.naive and e['datetime_first'] < d_2.naive]) for (d_1, d_2) in day_range]
    day_events = [(d_1, events) for (d_1, events) in day_events]

    template = texenv.get_template('affiche.tex')
    return template.render(day_events=day_events, day_range=day_range, arrow=arrow)
开发者ID:cynddl,项目名称:federation-backend,代码行数:15,代码来源:views.py

示例12: check_onsale_event

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
 def check_onsale_event(self, id, url):
     ev = Event.objects(event_id=id).first()
     ret = self.s.get(url, headers=self.headers)
     tree = lxml.html.fromstring(ret.content)
     text = tree.cssselect('div#okl-content div.sales-event')[0].get('class')
     if 'ended' in text:
         utcnow = datetime.utcnow()
         if not ev.events_end or ev.events_end > utcnow:
             ev.events_end = utcnow.replace(minute=0, second=0, microsecond=0)
             ev.update_history.update({ 'events_end': utcnow })
             ev.save()
     elif 'started' in text:
         return True
开发者ID:mobishift2011,项目名称:amzn,代码行数:15,代码来源:simpleclient.py

示例13: newsletter

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
def newsletter():
    news_form = Newsletter()
    events = []

    if news_form.validate_on_submit():
        date_first = arrow.get(news_form.datetime_first.data).datetime
        date_last = arrow.get(news_form.datetime_last.data).datetime
        events = Event.objects(datetime_first__gte=date_first, datetime_first__lte=date_last, status='published').order_by('date_first')

    if 'send' in request.form and news_form.validate_on_submit():
        day_range = arrow.Arrow.span_range('day', date_first, date_last)
        day_events = [(d_1, [e for e in events if e['datetime_first'] > d_1.naive and e['datetime_first'] < d_2.naive]) for (d_1, d_2) in day_range]
        day_events = [(d_1, events) for (d_1, events) in day_events if len(events) != 0]
        return render_template('newsletter_mail.html', news_form=news_form, day_first=arrow.get(date_first), day_last=arrow.get(date_last), day_events=day_events, arrow=arrow)
    else:
        return render_template('newsletter.html', news_form=news_form, events=events)
开发者ID:cynddl,项目名称:federation-backend,代码行数:18,代码来源:views.py

示例14: _parse_event

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
    def _parse_event(self, event_data, ctx):
        """.. :py:method::
            get product detail page by {asin: {url: url_str}},
            update soldout info by {casin: {soldout: 1/0, }}, can update them when crawl_listing
        """
        event_id = event_data['id']
        info = event_data['saleProps']

        is_new, is_updated = False, False
        event = Event.objects(event_id=event_id).first()
        if not event:
            is_new = True
            event = Event(event_id=event_id)
            event.urgent = True
            event.combine_url = 'http://www.myhabit.com/homepage#page=b&sale={0}'.format(event_id)
            event.sale_title = info['primary']['title']
            if 'desc' in info['primary']:
                event.sale_description = lxml.html.fromstring(info['primary']['desc']).text_content()
            event.image_urls = [ info['prefix']+val for key, val in info['primary']['imgs'].items() if key == 'hero']
            event.image_urls.extend( [ info['prefix']+val for key, val in info['primary']['imgs'].items() if key in ['desc', 'sale']] )
            if 'brandUrl' in info['primary']:
                event.brand_link = info['primary']['brandUrl']

        event.listing_url = event_data['prefix'] + event_data['url']
        # updating fields
        events_begin = time2utc(event_data['start'])
        events_end = time2utc(event_data['end'])
        if event.events_begin != events_begin:
            event.update_history.update({ 'events_begin': datetime.utcnow() })
            event.events_begin = events_begin 
        if event.events_end != events_end:
            event.update_history.update({ 'events_end': datetime.utcnow() })
            event.events_end = events_end

        [event.dept.append(dept) for dept in event_data['departments'] if dept not in event.dept]
        event.soldout = True if 'soldOut' in event_data and event_data['soldOut'] == 1 else False
        event.update_time = datetime.utcnow()

        # event_data['dataType'] == 'upcoming' don't have products
        if 'asins' in event_data: event.asin_detail_page = event_data['asins']
        if 'cAsins' in event_data: event.casin_soldout_info = event_data['cAsins']
        event.save()
        common_saved.send(sender=ctx, obj_type='Event', key=event.event_id, url=event.combine_url, is_new=is_new, is_updated=is_updated)
开发者ID:mobishift2011,项目名称:amzn,代码行数:45,代码来源:server.py

示例15: get

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import objects [as 别名]
 def get(self):
     logging.info('Get events list')
     return {'events': EventModel.objects().to_json()}
开发者ID:MichalJagiello,项目名称:android_todo_backend,代码行数:5,代码来源:views.py


注:本文中的models.Event.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。