• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python shortcuts.get_document_or_404函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mongoengine.django.shortcuts.get_document_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_document_or_404函数的具体用法?Python get_document_or_404怎么用?Python get_document_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: delete_message

def delete_message(request, group, message_id):
    get_document_or_404(GroupMessage, id=message_id).delete()
    if request.is_ajax():
        objects = paginate(request,
                           GroupMessage.objects(group=group),
                           GroupMessage.objects(group=group).count(),
                           settings.MESSAGES_ON_PAGE)
        return direct_to_template(request, 'groups/_comments.html', dict(
            group=group,
            is_admin=group.is_admin(request.user) or request.user.is_superuser,
            objects=objects,
        ))
    else:
        return redirect(reverse('groups:group_view', args=[group.id]))
开发者ID:Rudy24,项目名称:modnoemesto,代码行数:14,代码来源:views.py


示例2: category_posts

def category_posts(request, category_anchor):
    """
    The below anchor of Category can contain: #anchor or page (domain/page).

    NOTE(DATABASE): We don't interested to use Index to anchor field
    because Category collection is very small the performance result is no
    significant
    """
    is_container = False
    anchor_exists = get_document_or_404(models.Category,
                                        anchor__contains=category_anchor.lower())

    today = datetime.datetime.now()
    # TODO index sort (order_by)
    posts = models.Post.objects(categories=anchor_exists, published=True,
                                created_at__lte=today).order_by('-created_at')

    try:
        is_container = anchor_exists.is_container
    except AttributeError:
           pass

    if is_container:
        posts = posts.first()
        return post_view(request, posts.slug)

    return render_to_response('posts_by_category.html',
                              {'posts': posts, 'category': anchor_exists})
开发者ID:horacioibrahim,项目名称:oengraxate,代码行数:28,代码来源:views.py


示例3: edit

def edit(request, id=None):
    if id:
        item = get_document_or_404(AdminBlog, id=id)
        initial = item._data
    else:
        item = None
        initial = {}

    form = AdminBlogForm(request.POST or None, initial=initial)

    if form.is_valid():
        if not item:
            item = AdminBlog()

        for k, v in form.cleaned_data.items():
            if k.startswith("_"):
                continue
            if hasattr(item, k):
                setattr(item, k, v)

        item.author = request.user
        item.save()

        return redirect("admin_blog:list")

    return direct_to_template(request, "admin_blog/edit.html", dict(form=form, is_new=id is None))
开发者ID:Rudy24,项目名称:modnoemesto,代码行数:26,代码来源:views.py


示例4: show_config

def show_config(request, config_id):
    config = get_document_or_404(Config, id=config_id)
    return render_to_response('config/config.html', 
        {
            'config':config,
            'page_title': 'View Configuration: %s' % config.title,
        }, context_instance=RequestContext(request))
开发者ID:nexleaf,项目名称:NexleafGW,代码行数:7,代码来源:config.py


示例5: ombudsman_picture

def ombudsman_picture(request, slug):
    path = get_document_or_404(OmbudsmanOffice, slug = slug).picture
    if not path:
        path = '{0}img/ombudsman-avatar.jpg'.format(STATIC_URL)
    url = 'http://{0}{1}'.format(request.META['HTTP_HOST'], path)
    #return HttpResponse(urlopen(url).read(), mimetype="image/jpg")
    return HttpResponseRedirect(url)
开发者ID:adrielcafe,项目名称:Ouvidoria2.0,代码行数:7,代码来源:views.py


示例6: tag_edit

def tag_edit(request, id=None):
    if id:
        tag = get_document_or_404(CameraTag, id=id)
        initial = tag._data
    else:
        tag = None
        initial = {}

    form = CameraTagForm(request.POST or None, initial=initial)

    if form.is_valid():
        if not tag:
            tag = CameraTag()

        for k, v in form.cleaned_data.items():
            if k.startswith('_'):
                continue
            if hasattr(tag, k):
                setattr(tag, k, v)
        tag.save()
        return HttpResponseRedirect(reverse('cam:tag_list'))

    return direct_to_template(request, 'cam/tag_edit.html',
                              dict(form=form, is_new=id is None)
                              )
开发者ID:Rudy24,项目名称:modnoemesto,代码行数:25,代码来源:views.py


示例7: get_access_to_camera

def get_access_to_camera(request, id, is_controlled):
    camera = get_document_or_404(Camera, id=id)
    if request.POST:
        form = AccessCamOrderForm(camera, is_controlled, request.user, request.POST)
        if form.is_valid():
            tariff = form.cleaned_data['tariff']
            try:
                if tariff.is_packet:
                    AccessCamOrder.create_packet_type(
                        tariff=tariff,
                        count_packets=form.cleaned_data['count_packets'],
                        user=request.user,
                        camera=camera,
                    )
                else:
                    AccessCamOrder.create_time_type(
                        tariff=tariff,
                        user=request.user,
                        camera=camera,
                    )
            except AccessCamOrder.CanNotAddOrder:
                pass
            return HttpResponseRedirect(reverse('social:user', args=[camera.owner.id]))
    else:
        form = AccessCamOrderForm(camera, is_controlled)
    return direct_to_template(request, 'billing/get_access_to_camera.html', { 'form': form, 'camera': camera })
开发者ID:Rudy24,项目名称:modnoemesto,代码行数:26,代码来源:views.py


示例8: folder_add

def folder_add(request, library, id=None):
    tree = get_library(library)

    if id:
        folder = get_document_or_404(Folder, id=id)
        parent = tree.get(folder.id)
        if not parent:
            raise Http404()
        current_folder = parent
    else:
        current_folder = None

    if request.POST:
        form = FolderEditForm(request.POST)

        if form.is_valid():
            folder = Folder(name=form.cleaned_data['name'])
            folder.save()

            if id:
                tree.add(folder, parent)
            else:
                tree.add(folder)
            tree.save()
            messages.add_message(request, messages.SUCCESS, _('Folder successfully added'))
            return redirect_by_id('media_library:%s_index' % library, id)
    else:
        form = FolderEditForm()
    return direct_to_template(request,
                              'media_library/folder_edit.html',
                              dict( breadcrumb='media_library/_%s_breadcrumb.html' % library,
                                    form=form,
                                    current_folder=current_folder ) )
开发者ID:django-social,项目名称:django-social,代码行数:33,代码来源:views.py


示例9: view_message_by_user

def view_message_by_user(request, user_id, action=''):
    by_user = get_document_or_404(User, id=user_id)
    owner  = request.user
    template = 'by_user.html'
    
    if action == 'sent':
        messages = Message.objects(sender=owner,
                               recipient=by_user,
                               sender_delete=None)
        template = 'by_user_sent.html'

    elif action == 'inbox':
        messages = Message.objects(recipient=request.user,
                               sender=by_user,
                               recipient_delete=None)
        template = 'by_user_inbox.html'

    else:
        messages = Message.objects(
                            Q(sender=owner, recipient=by_user, sender_delete=None) |
                            Q(sender=by_user, recipient=owner, recipient_delete=None),
                               )
    objects = paginate(request,
                       messages,
                       messages.count(),
                       10)
    return direct_to_template(request, 'user_messages/%s' % template,
                              { 'objects': objects,
                                'by_user': by_user,
                                'action': action,
                                })
开发者ID:django-social,项目名称:django-social,代码行数:31,代码来源:views.py


示例10: show_device

def show_device(request, device_id=None):
    device = get_document_or_404(Device, device_id=device_id)
    return render_to_response('device/device.html', 
        {
            'device':device,
            'page_title': 'View Device: %s' % device.device_id,
        }, context_instance=RequestContext(request))
开发者ID:nexleaf,项目名称:NexleafGW,代码行数:7,代码来源:device.py


示例11: get_forum

 def get_forum(self, *args, **kwargs):
     id = self.kwargs.get('id')
     object = get_document_or_404(
         Forum,
         id=int(id),
     )
     return object
开发者ID:LethusTI,项目名称:supportcenter,代码行数:7,代码来源:views.py


示例12: note_edit

def note_edit(request, note_id=None):
    fields = ('title', 'text', 'is_public')

    if note_id:
        note = get_document_or_404(Note, id=note_id, author=request.user)

        initial = {}

        for field in fields:
            initial[field] = getattr(note, field)

    else:
        note = None
        initial = {}

    form = NoteForm(request.POST or None, initial=initial)

    if form.is_valid():
        note = note or Note(author=request.user)

        for field in fields:
            setattr(note, field, form.cleaned_data[field])

        note.save()
        return HttpResponseRedirect(reverse('notes:note_list'))

    return direct_to_template(request, 'notes/note_edit.html',
                              { 'form': form, 'create': not note })
开发者ID:Rudy24,项目名称:modnoemesto,代码行数:28,代码来源:views.py


示例13: post

    def post(self, request, *args, **kwargs):
        spot = get_document_or_404(Spot, slug=kwargs['spot_slug'])
        
        if request.POST.get('action') == 'like' and not request.user.likes_spot(spot):
            if request.user.dislikes_spot(spot):
                Dislike.objects(user=request.user, spot=spot).first().delete()
                request.user.remove_dislike(spot)
            request.user.likes.append(spot)
            request.user.save()
            Like(user=request.user, spot=spot).save()
            return self.render_json_response({'action': 'like'})
        elif request.POST.get('action') == 'dislike' and not request.user.dislikes_spot(spot):
            if request.user.likes_spot(spot):
                Like.objects(user=request.user, spot=spot).first().delete()
                request.user.remove_like(spot)
            request.user.dislikes.append(spot)
            request.user.save()
            Dislike(user=request.user, spot=spot).save()
            return self.render_json_response({'action': 'dislike'})
        elif request.POST.get('action') == 'neutral':
            if request.user.likes_spot(spot):
                Like.objects(user=request.user, spot=spot).first().delete()
                request.user.remove_like(spot)   
            else:
                Dislike.objects(user=request.user, spot=spot).first().delete()
                request.user.remove_dislike(spot)

            request.user.save()
            return self.render_json_response({'action': 'neutral'})

        raise Http404
开发者ID:neerbee,项目名称:neerbee,代码行数:31,代码来源:views.py


示例14: get

    def get(self, request, *args, **kwargs):
        spot_slug = kwargs['spot_slug']
        s = get_document_or_404(Spot, slug=spot_slug)
        # take care of service-specific information
        # in the future I think it should be taken care of
        # in the form, not in the view. maybe override constructor
        for service in s._data['services']:
            if service.__class__ is ServiceFood:
                s._data['service_food'] = True
                s._data['food_category'] = service.category
                s._data['food_delivery'] = service.delivery
                s._data['food_take_out'] = service.take_out
            elif service.__class__ is ServiceBar:
                s._data['service_bar'] = True
                s._data['bar_category'] = service.category
            elif service.__class__ is ServiceCoffee:
                s._data['service_coffee'] = True
                s._data['coffee_board_games'] = service.board_games
            elif service.__class__ is ServiceClub:
                s._data['service_club'] = True
                s._data['club_coat_check'] = service.coat_check
                s._data['club_face_control'] = service.face_control

        if s._data.get('location'):
            s._data['longtitude'] = s._data['location'][0]
            s._data['latitude'] = s._data['location'][1]

        form = SpotForm(initial=s._data)

        return render(request, self.template_name, {
                                            'form': form,
                                            'spot_slug': spot_slug
                                            })
开发者ID:neerbee,项目名称:neerbee,代码行数:33,代码来源:views.py


示例15: password_reset_done

def password_reset_done(request):
    """ Make new password to user by email
    """
    if request.method == "POST":
        form = forms.PasswordConfirm(request.POST, )
        if form.is_valid():
            new_password = form.cleaned_data["new_password2"]
            email = request.session.get('email', False)
            user = get_document_or_404(models.User, email=email)
            user.set_password(new_password)
            user.save()

            auth_user = authenticate(username=user.username, password=new_password)
            if auth_user is not None:
                if auth_user.is_active:
                    login(request, auth_user)
                    return redirect(reverse("dashboard"))
                else:
                    pass # account disabled
            else:
                return HttpResponse('Invalid login (username or password)')

    else:
        form = forms.PasswordConfirm()

    return render(request, "password_reset_form.html", dict(form=form))
开发者ID:horacioibrahim,项目名称:oengraxate,代码行数:26,代码来源:views.py


示例16: view

def view(request, id):
    item = get_document_or_404(Ad, id=id)
    return direct_to_template(request, 'ads/view.html',
                                dict(
                                      item=item,
                                      )
                              )
开发者ID:django-social,项目名称:django-social,代码行数:7,代码来源:views.py


示例17: render_dashboard

def render_dashboard(request, title):
    if (not request.user.is_authenticated()):
        return login_user(request)
    
    dash = Dashboard.objects.filter(title=title)
    if len(dash) == 0:
        return redirect(settings.BASE_URL + "/list/")
    
    dashPerms = Dashboard_Permission.objects.filter(dashboard_title=title, user=request.user.username)
    if len(dashPerms)==0:
        return redirect(settings.BASE_URL + "/list/")

    template = loader.get_template('dashboard.html')
    dashboard = get_document_or_404(Dashboard, pk=title)
    topic_names = TopicWindowFunctions.get_topic_windows(dashboard.title)
    user_permissions_list = Dashboard_Permission.objects.filter(dashboard_title=dashboard.title)
    list_of_usernames = []
    for user_obj in user_permissions_list:
        list_of_usernames.append(user_obj.user)
    matched_usernames = check_for_active_users(list_of_usernames)
    print("connected users: " + str(matched_usernames))
    context = RequestContext(request, {
        'dashboard': dashboard,
        'topic_names': topic_names,
        'connected_users': matched_usernames,
    })
    return HttpResponse(template.render(context))
开发者ID:mike-parks,项目名称:ChatDashboard,代码行数:27,代码来源:views.py


示例18: user

def user(request, user_id=None):
    page_user = get_document_or_404(User, id=user_id)
    if page_user == request.user:
        return redirect("social:home")

    invitee_count = Invite.invitee_count(page_user)
    is_friend = not request.user.friends.can_add(page_user)
    camera = page_user.get_camera()

    data = {
        "camera": camera,
        "invitee_count": invitee_count,
        "page_user": page_user,
        "profile": page_user.profile.for_html(),
        "settings": settings,
        "show_friend_button": not is_friend,
    }

    if camera:
        data.update(
            {
                "billing": camera.billing(request.user, request.session),
                "show_bookmark_button": camera.can_bookmark_add(request.user),
                "show_view_access_link": camera.is_view_enabled
                and camera.is_view_paid
                and camera.is_view_public
                or is_friend,
                "show_manage_access_link": camera.is_management_enabled
                and camera.is_managed
                and camera.is_management_paid
                and (camera.is_management_public or is_friend),
            }
        )
    return direct_to_template(request, "social/home.html", data)
开发者ID:pavelm2007,项目名称:django-social,代码行数:34,代码来源:views.py


示例19: folder_edit

def folder_edit(request, library, id):
    tree = get_library(library)

    folder = get_document_or_404(Folder, id=id)
    current_folder = tree.get(folder.id)
    if not current_folder:
        raise Http404()

    if request.POST:
        form = FolderEditForm(request.POST, initial=folder._data)

        if form.is_valid():
            tree.rename(folder, form.cleaned_data['name'])
            current_folder.name = folder.name
            tree.save()
            messages.add_message(request, messages.SUCCESS, _('Folder successfully saved'))
            return redirect_by_id('media_library:%s_index' % library, id)
    else:
        form = FolderEditForm(initial=folder._data)
    return direct_to_template(request,
                              'media_library/folder_edit.html',
                              dict( breadcrumb='media_library/_%s_breadcrumb.html' % library,
                                    form=form,
                                    current_folder=current_folder,
                                    is_edit=True ) )
开发者ID:django-social,项目名称:django-social,代码行数:25,代码来源:views.py


示例20: wrapper

    def wrapper():
        if id:
            user = get_document_or_404(User, id=id)
            if not request.user.is_superuser and user.id != request.user.id:
                return HttpResponseNotFound()
        else:
            user = request.user

        context = profile_form(request, user)
        if not context:
            return

        answer = user_form(request, user)
        if not answer:
            return
        context.update(answer)

        dating = dating_form(request, user)
        if not dating:
            return
        context.update(dating)

        camera = user.get_camera()
        if camera or request.user.is_superuser:
            answer = cam_form(request, user, camera)
            if not answer:
                return
            context.update(answer)
            if answer["camera"]:
                answer = screen_form(request, user.get_camera())
                if not answer:
                    return
                context.update(answer)
        context.update({"user": user})
        return context
开发者ID:pavelm2007,项目名称:django-social,代码行数:35,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python python_support.b函数代码示例发布时间:2022-05-27
下一篇:
Python auth.User类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap