コード例 #1
0
ファイル: views.py プロジェクト: openstax/cnx-user
def delete_user_identity(request):
    # Grab the identity
    id = request.matchdict['identity_id']
    try:
        identity = DBSession.query(Identity) \
            .filter(Identity.id==id) \
            .first()
    except DBAPIError:
        raise httpexceptions.HTTPServiceUnavailable(
            connection_error_message,
            content_type='text/plain',
        )
    if identity is None:
        raise httpexceptions.HTTPNotFound()
    elif len(identity.user.identities) <= 1:
        raise httpexceptions.HTTPForbidden("Cannot delete the only remaining "
                                           "identity connection.")
    # Check that this user has permission to remove an identity.
    permissible = security.has_permission('delete', identity, request)
    if not permissible:
        raise httpexceptions.HTTPUnauthorized()

    # Remove the identity
    DBSession.delete(identity)
    raise httpexceptions.HTTPNoContent()
コード例 #2
0
def delete_attachment_view(request, file_field):
    utils.delete_attachment(request)

    # Remove metadata.
    record = {"data": {}}
    record["data"][file_field] = None
    utils.patch_record(record, request)

    raise httpexceptions.HTTPNoContent()
コード例 #3
0
ファイル: views.py プロジェクト: Cykooz/restfw
 def _process_result(self, result, created=False, context=None):
     if result is None:
         return httpexceptions.HTTPNoContent()
     if created:
         self.request.response.status = 201
         if ILocation.providedBy(result):
             self.request.response.headers[
                 'Location'] = self.request.resource_url(result)
     _try_add_etag(self.request, result, context=context)
     return result
コード例 #4
0
def retry_message(request):
    '''Unlocks and retries the message at a point in the future'''
    data = V.retry_schema.to_python(request.json, request)
    after = datetime.utcnow() + timedelta(seconds=data['delay'])
    M.HTTPMessage.m.update_partial(
        dict(_id=int(request.matchdict['message_id'])), {
            's.status': 'ready',
            's.after': after
        })
    M.HTTPMessage.channel.pub('enqueue', int(request.matchdict['message_id']))
    return exc.HTTPNoContent()
コード例 #5
0
ファイル: views.py プロジェクト: san123/chapman
def get(request):
    data = V.get_schema.to_python(request.params, request)
    sleep_ms = asint(request.registry.settings['sleep_ms'])
    # Ignore gets from the queue, as they skew our response time results
    messages = MessageGetter.get(request.matchdict['qname'], sleep_ms,
                                 data['client'], data['timeout'],
                                 data['count'])
    if messages:
        return dict((msg.url(request), msg.data) for msg in messages)
    else:
        return exc.HTTPNoContent()
コード例 #6
0
 def _hello_endpoint(request):
     helloid = int(request.matchdict["helloid"])
     if helloid == 500:
         raise exc.HTTPInternalServerError()
     if helloid == 404:
         raise exc.HTTPNotFound()
     if helloid == 302:
         raise exc.HTTPFound()
     if helloid == 204:
         raise exc.HTTPNoContent()
     if helloid == 900:
         raise NotImplementedError()
     return Response("Hello: " + str(helloid))
コード例 #7
0
def delete_pet(context, request):
    """
    Remove a pet

    request.matchdict:

        * 'pet_id'  Pet's Unique identifier  `{"type": "string", "required": true, "pattern": "^[a-zA-Z0-9-]+$"}`
    """
    pet_id = request.matchdict["pet_id"]
    if pet_id in PETS:
        logger.info('Deleting pet %s..', pet_id)
        del PETS[pet_id]
        raise httpexceptions.HTTPNoContent()
    else:
        raise httpexceptions.HTTPNotFound()
コード例 #8
0
def get(request):
    data = V.get_schema.to_python(request.params, request)
    sleep_ms = asint(request.registry.settings['chapman.sleep_ms'])
    # Ignore gets from the queue, as they skew our response time results
    try:
        import newrelic.agent
        newrelic.agent.set_background_task()
    except ImportError:
        pass
    messages = MessageGetter.get(request.matchdict['qname'], sleep_ms,
                                 data['client'], data['timeout'],
                                 data['count'])
    if messages:
        return dict((msg.url(request), msg.data) for msg in messages)
    else:
        return exc.HTTPNoContent()
コード例 #9
0
ファイル: views.py プロジェクト: bZichett/h
def leave(request):
    if request.authenticated_userid is None:
        raise exc.HTTPNotFound()

    pubid = request.matchdict["pubid"]
    group = models.Group.get_by_pubid(request.db, pubid)

    if group is None:
        raise exc.HTTPNotFound()

    if request.authenticated_user not in group.members:
        raise exc.HTTPNotFound()

    group.members.remove(request.authenticated_user)
    _send_group_notification(request, 'group-leave', group.pubid)

    return exc.HTTPNoContent()
コード例 #10
0
def scoreCMO(request):
    Helper.permissions(request)

    # Collect information
    try:
        mid = int(request.params["mid"])
        qid = int(request.params["qid"])
        score = int(request.params["score"])
    except:
        raise exc.HTTPBadRequest("Necessary content is missing")

    # TODO: decide upon score range and values
    score = float(int(score)) * 0.05  # Reduce score to between 0-5

    # Record the users opinion
    db.execute('labelModel', [request.session["username"], qid, mid, score])

    raise exc.HTTPNoContent()
コード例 #11
0
def collectCMO(request):
    Helper.permissions(request)

    # Collect the question id from the request
    try:
        qid = int(request.params["qid"])
    except:
        raise exc.HTTPBadRequest("Question ID not passed")

    # Collect the collection of unlabelled models for that user and question
    unlabelled = db.execute('collectUnlabelled',
                            [request.session["username"], qid])

    # Select and return a modelID at random
    # TODO: Include directed learning
    if len(unlabelled):
        modelID, = random.choice(unlabelled)
        return {"mid": modelID}

    # No models left to annotate, no model id to return
    raise exc.HTTPNoContent()
コード例 #12
0
ファイル: groups.py プロジェクト: st-fresh/h
def leave(group, request):
    """Route for leaving a group. Used by the Hypothesis client."""
    groups_service = request.find_service(name='group')
    groups_service.member_leave(group, request.authenticated_userid)

    return httpexceptions.HTTPNoContent()
コード例 #13
0
def delete_message(request):
    M.HTTPMessage.m.remove(dict(_id=int(request.matchdict['message_id'])))
    return exc.HTTPNoContent()
コード例 #14
0
ファイル: views.py プロジェクト: jkoelker/newtonian
def delete_network(request):
    uuid = request.matchdict['uuid']
    session = _get_session(request)
    network = _get_network(uuid, session)
    session.delete(network)
    return httpexc.HTTPNoContent()