Add/remove an object to the user's favorites. Checks for existance and adds if not, else removes.
    This is the underlying mechanism for adding items to the user 'scrapbook' and favorite scripts.

    :param request:
    :param file_id:
    :return:
176054
def toggle_favorite(request):
    
    if not request.is_ajax():
        return HttpResponseForbidden()

    try:
        app, model, pk = request.POST['app'], request.POST['model'], int(request.POST['pk'])

    except ValueError:
        return HttpResponseBadRequest()

    try:
        ctype = ContentType.objects.get(app_label=app, model=model)
        obj = ctype.get_object_for_this_type(id=pk)

    except Favorite.DoesNotExist:
        return HttpResponseNotFound()

    try:
        fave = Favorite.objects.get(content_type=ctype, object_id=obj.id, user=request.user)

    except Favorite.DoesNotExist:
        # Does not exist, so create it
        fave = Favorite(content_object=obj, user=request.user)
        fave.save()
        is_favorite = True

    else:
        # Exists, so delete it
        fave.delete()
        is_favorite = False

    # Return the current total number for UI updates
    favorites_count = Favorite.objects.filter(content_type=ctype, user=request.user).count()

    return JsonResponse({
        'app': app,
        'model': model,
        'pk': pk,
        'is_favorite': is_favorite,
        'count': favorites_count,
    })
1150408
def add(self, req: Request):
        
        key = req.key
        if key not in self:
            self[key] = ReqState(req)
        return self[key]
890718
def files_comments_delete(self, *, file: str, id: str, **kwargs) -> SlackResponse:
        
        kwargs.update({"file": file, "id": id})
        return self.api_call("files.comments.delete", json=kwargs)
333889
def file_add(backend, kitchen, recipe, message, filepath):
    
    err_str, use_kitchen = Backend.get_kitchen_from_user(kitchen)
    if use_kitchen is None:
        raise click.ClickException(err_str)
    if recipe is None:
        recipe = DKRecipeDisk.find_recipe_name()
        if recipe is None:
            raise click.ClickException('You must be in a recipe folder, or provide a recipe name.')

    click.secho('%s - Adding File (%s) to Recipe (%s) in kitchen(%s) with message (%s)' %
                (get_datetime(), filepath, recipe, use_kitchen, message), fg='green')
    check_and_print(DKCloudCommandRunner.add_file(backend.dki, use_kitchen, recipe, message, filepath))
198633
def _add_user_to_file(file_id, service, user_email,
                      perm_type='user', role='writer'):
    
    new_permission = {
        'value': user_email,
        'type': perm_type,
        'role': role
    }
    try:
        service.permissions()\
            .insert(fileId=file_id, body=new_permission)\
            .execute()
    except errors.HttpError as error:
        show_error('An error adding users to spreadsheet: {0}'.format(error))
674891
def favorites_remove(photo_id):
    """"""
    method = 'flickr.favorites.remove'
    _dopost(method, auth=True, photo_id=photo_id)
    return True
76145
public BoxRequestsFile.AddFileToCollection getAddToCollectionRequest(String fileId, String collectionId) {
        BoxRequestsFile.AddFileToCollection request = new BoxRequestsFile.AddFileToCollection(fileId, collectionId, getFileInfoUrl(fileId), mSession);
        return request;
    }
1111392
def add_attachment(attachment, name = '')
      # Is it a file object or a string (url)?
      if attachment.respond_to?(:path) && attachment.respond_to?(:read)
        client.post("/cards/#{id}/attachments", {
            file: attachment,
            name: name
          })
      else
        client.post("/cards/#{id}/attachments", {
            url: attachment,
            name: name
          })
      end
    end
1196294
public static void addFavorite(@Nonnull User user, @Nonnull Item item) throws FavoriteException {
        try {
            if (!isFavorite(user, item)) {
                FavoriteUserProperty property = getProperty(user);
                property.addFavorite(item.getFullName());
                FavoriteListener.fireOnAddFavourite(item, user);
            } else {
                throw new FavoriteException("Favourite is already set for User: <" + user.getFullName() + "> Item: <" + item.getFullName() + ">");
            }
        } catch (IOException e) {
            throw new FavoriteException("Could not add Favorite. User: <" + user.getFullName() + "> Item: <" + item.getFullName() + ">", e);
        }
    }
561222
function requestIdMiddleware (req, res, next) {
    // get unique id object
    var uniqueId = randomUniqueId()
    // add data to req
    req.requestId = uniqueId.id
    req.requestCreateTime = uniqueId.timestamp
    // continue
    next()
}
634694
def get_file_by_id(self, file_id):
        
        file_ref = self.objects[file_id]
        if not isinstance(file_ref, PBXFileReference):
            return None
        return file_ref
1048858
async def getFile(self, file_id):
        
        p = _strip(locals())
        return await self._api_request('getFile', _rectify(p))
1280614
def add_page_if_missing(request):
    

    try:
        page = Page.objects.for_request(request, best_match=True)
        return {
            'leonardo_page': page,
            # DEPRECATED
            'feincms_page': page,
        }
    except Page.DoesNotExist:
        return {}
377515
def favorites_add(photo_id):
    """"""
    method = 'flickr.favorites.add'
    _dopost(method, auth=True, photo_id=photo_id)
    return True
1356398
def put(request, obj_id=None):
    
    res = Result()
    data = request.PUT or json.loads(request.body)['body']
    if obj_id:
        # -- Edit the tag
        tag = Tag.objects.get(pk=obj_id)
        tag.name = data.get('name', tag.name)
        tag.artist = data.get('artist', tag.artist)
        tag.save()
    else:
        tags = [_ for _ in data.get('tags', '').split(',') if _]
        guids = [_ for _ in data.get('guids', '').split(',') if _]

        _manageTags(tags, guids)

    return JsonResponse(res.asDict())
909843
def add_bookmark(request):
    
    if request.method == "POST":
        form = BookmarkForm(user=request.user, data=request.POST)
        if form.is_valid():
            bookmark = form.save()
            if not request.is_ajax():
                messages.success(request, 'Bookmark added')
                if request.POST.get('next'):
                    return HttpResponseRedirect(request.POST.get('next'))
                return HttpResponse('Added')
            return render_to_response(
                'admin_tools/menu/remove_bookmark_form.html',
                {'bookmark': bookmark, 'url': bookmark.url}
            )
    else:
        form = BookmarkForm(user=request.user)
    return render_to_response(
        'admin_tools/menu/form.html',
        {'form': form, 'title': 'Add Bookmark'}
    )
570358
def put(self, id):
        

        collection_name = self.request.headers.get("collection")

        if not collection_name:
            self.raise_error(400, "Missing a collection name header")

        self.client = BaseAsyncMotorDocument("%s_revisions" % collection_name)

        super(self.__class__, self).put(id)