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


Python Account.objects方法代码示例

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


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

示例1: create

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def create(request):
    if request.method == 'POST':
        # save new evento
        title = request.POST['title']
        description = request.POST['description']
        date_start = request.POST['date_start']
        date_end = request.POST['date_end']
        lat = request.POST['lat']
        lng = request.POST['lng']
        #image = request.FILES['image']

        event = Event(title=title)
        event.last_update = datetime.datetime.now()
        event.description = description
        event.date_start =  datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
        if not date_end:
            event.date_end = None
        else:
            event.date_end =  datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
        event.location =  [float(lat),float(lng)]
        user_id = request.session.get('userid')
        user = Account.objects(id=user_id)[0]

        event.user = user
        event.user_going = [user]
        #im = Image.open(image)
        #event.image.put(open(im))
        event.save()
        Account.objects(id=user_id).update_one(push__event_going=event)

        return HttpResponseRedirect(reverse('event-list'))

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

示例2: delete

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def delete(request, event_id):
    user_id = request.session.get('userid')
    user = Account.objects(id=user_id)[0]
    event = get_document_or_404(Event, id=event_id, user=user)

    Account.objects().update(pull__event_going=event)
    Account.objects().update(pull__event_maybe=event)

    event.delete() 
    return HttpResponseRedirect(reverse('event-list'))
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:12,代码来源:views.py

示例3: list

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account 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

示例4: eventGoing

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account 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

示例5: detail

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account 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

示例6: edit

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def edit(request, event_id):
    user = Account.objects(id=request.session.get('userid'))[0]
    event = get_document_or_404(Event, id=event_id, user=user)
    
    if request.method == 'POST':
        # update field values and save to mongo
        title = request.POST['title']
        description = request.POST['description']
        date_start = request.POST['date_start']
        date_end = request.POST['date_end']
        lat = request.POST['lat']
        lng = request.POST['lng']
        #image = request.FILES['image']

        event.title = title
        event.last_update = datetime.datetime.now()
        event.description = description
        event.date_start =  datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
        if not date_end:
            event.date_end = None
        else:
            event.date_end =  datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
        event.location =  [float(lat),float(lng)]
        event.user = user
        #event.image = request.FILES['image']
        event.save()
        
        return HttpResponseRedirect(reverse('event-list'))

    elif request.method == 'GET':
        template = 'event/event_edit.html'
        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]
        params = {'event':event,
             'request':request}
   
    return render_to_response(template, params, context_instance=RequestContext(request))
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:44,代码来源:views.py

示例7: get_user

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def get_user(request):
	user_id = request.session.get('userid')
	return Account.objects(id=user_id)[0].name
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:5,代码来源:user.py

示例8: join

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def join(request, event_id):
    event = get_document_or_404(Event, id=event_id)
    user_id = request.session.get('userid')
    user = Account.objects(id=user_id)[0]

    action = request.POST['action']
    if action == 'going':
        Account.objects(id=user_id).update_one(push__event_going=event)
        Account.objects(id=user_id).update_one(pull__event_maybe=event)
        Account.objects(id=user_id).update_one(pull__event_decline=event)
        Account.objects(id=user_id).update_one(pull__event_invite=event)

        Event.objects(id=event_id).update_one(push__user_going=user)
        Event.objects(id=event_id).update_one(pull__user_maybe=user)
        Event.objects(id=event_id).update_one(pull__user_decline=user)
        Event.objects(id=event_id).update_one(pull__user_invite=user)

    elif action == 'maybe':
        Account.objects(id=user_id).update_one(pull__event_going=event)
        Account.objects(id=user_id).update_one(push__event_maybe=event)
        Account.objects(id=user_id).update_one(pull__event_decline=event)
        Account.objects(id=user_id).update_one(pull__event_invite=event)

        Event.objects(id=event_id).update_one(pull__user_going=user)
        Event.objects(id=event_id).update_one(push__user_maybe=user)
        Event.objects(id=event_id).update_one(pull__user_decline=user)
        Event.objects(id=event_id).update_one(pull__user_invite=user)

    elif action == 'decline':
        Account.objects(id=user_id).update_one(pull__event_going=event)
        Account.objects(id=user_id).update_one(pull__event_maybe=event)
        Account.objects(id=user_id).update_one(push__event_decline=event)
        Account.objects(id=user_id).update_one(pull__event_invite=event)

        Event.objects(id=event_id).update_one(pull__user_going=user)
        Event.objects(id=event_id).update_one(pull__user_maybe=user)
        Event.objects(id=event_id).update_one(push__user_decline=user)
        Event.objects(id=event_id).update_one(pull__user_invite=user)
    
    data = json.dumps({'sucess':'ok'})
    return HttpResponse(data,content_type='application/json')
开发者ID:PauloDuarte43,项目名称:tomada-social,代码行数:43,代码来源:views.py

示例9: rest

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import objects [as 别名]
def rest(request, event_id=None):
    
    if request.method == 'POST':
        title = request.POST['title']
        description = request.POST['description']
        date_start = request.POST['date_start']
        date_end = request.POST.get('date_end', None)
        lat = request.POST['lat']
        lng = request.POST['lng']
        #image = request.FILES['image']

        event = Event(title=title)
        event.last_update = datetime.datetime.now()
        event.description = description
        event.date_start =  datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
        if date_end:
            event.date_end =  datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
        event.location =  [float(lat),float(lng)]
        user_id = request.session.get('userid')
        user = Account.objects(id=user_id)[0]

        event.user = user
        event.user_going = [user]
        #im = Image.open(image)
        #event.image.put(open(im))
        event.save()
        Account.objects(id=user_id).update_one(push__event_going=event)

        data = json.dumps({'status':'ok'})

    elif event_id:
        user = Account.objects(id=request.session.get('userid'))[0]
        event = Event.objects(id=event_id, user=user)[0]

        if request.method == 'PUT':
            # update field values and save to mongo
            data = JSONParser().parse(request)
            title = data['title']
            description = data['description']
            date_start = data['date_start']
            date_end = data['date_end']
            lat = data['lat']
            lng = data['lng']
            #image = request.FILES['image']

            event.title = title
            event.last_update = datetime.datetime.now()
            event.description = description
            event.date_start =  datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
            if not date_end:
                event.date_end = None
            else:
                event.date_end =  datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
            event.location =  [float(lat),float(lng)]
            event.user = user
            #event.image = request.FILES['image']
            event.save()
            
            data = json.dumps({'status':'ok'})

        elif request.method == 'GET':

            data = {
                'id': str(event.id),
                'title': event.title,
                'description': event.description,
                'location': {
                    'lat': event.location[0],
                    'lng': event.location[1]
                },
                'date_start': str(event.date_start.strftime('%d/%m/%Y %H:%M')) if event.date_start else '',
                'date_end':  str(event.date_end.strftime('%d/%m/%Y %H:%M')) if event.date_end else ''
            } 
            data = json.dumps(data)

        elif request.method == 'DELETE':

            Account.objects().update(pull__event_going=event)
            Account.objects().update(pull__event_maybe=event)

            event.delete() 

            data = json.dumps({'status':'ok'})

    else:

        data = json.dumps({'status':'error'})


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


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