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


Python shortcuts.get_document_or_404函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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