Edit a post.

    If requested over GET, shows the edit UI.
    If requested over POST, saves the post and shows the edit UI.

    :param path: Path to post to edit.
178873
def edit(path):
    
    context = {'path': path, 'site': site}
    post = find_post(path)
    if post is None:
        return error("No such post or page.", 404)

    current_auid = int(post.meta('author.uid') or current_user.uid)

    if (not current_user.can_edit_all_posts and
            current_auid != current_user.uid):
        return error("Cannot edit posts of other users.", 401)

    if request.method == 'POST':
        meta = {}
        for k, v in request.form.items():
            meta[k] = v
        meta.pop('_wysihtml5_mode', '')
        try:
            meta['author'] = get_user(meta['author.uid']).realname
            current_auid = int(meta['author.uid'])
            author_change_success = True
        except Exception:
            author_change_success = False
        if (not current_user.can_transfer_post_authorship or
                not author_change_success):
            meta['author'] = post.meta('author') or current_user.realname
            meta['author.uid'] = str(current_auid)

        twofile = post.is_two_file
        onefile = not twofile
        post.compiler.create_post(post.source_path, onefile=onefile,
                                  is_page=False, **meta)

        context['post_content'] = meta['content']

        if twofile:
            meta_path = os.path.splitext(path)[0] + '.meta'
            # We cannot save `content` as meta, otherwise things break badly
            meta.pop('content', '')
            with io.open(meta_path, 'w+', encoding='utf-8') as fh:
                fh.write(write_metadata(meta))
        scan_site()
        if db is not None:
            db.set('site:needs_rebuild', '1')
        else:
            site.coil_needs_rebuild = '1'
        post = find_post(path)
        context['action'] = 'save'
    else:
        context['action'] = 'edit'
        with io.open(path, 'r', encoding='utf-8') as fh:
            context['post_content'] = fh.read()
            if not post.is_two_file:
                context['post_content'] = context['post_content'].split(
                    '\n\n', 1)[1]

    context['post'] = post
    users = []
    if db is not None:
        uids = db.hgetall('users').values()
        for u in uids:
            u = u.decode('utf-8')
            realname, active = db.hmget('user:{0}'.format(u),
                                        'realname', 'active')
            if active in (u'1', b'1'):
                users.append((u, realname.decode('utf-8')))
    else:
        for u, d in app.config['COIL_USERS'].items():
            if d['active']:
                users.append((int(u), d['realname']))
    context['users'] = sorted(users)
    context['current_auid'] = current_auid
    context['title'] = 'Editing {0}'.format(post.title())
    context['is_html'] = post.compiler.name == 'html'
    return render('coil_post_edit.tmpl', context)
993886
def add_patch(self, path: str, handler: _WebHandler,
                  **kwargs: Any) -> AbstractRoute:
        
        return self.add_route(hdrs.METH_PATCH, path, handler, **kwargs)
1301358
def post_request(path, options = {}, &block)
      loop do
        response = self.class.post(path, options, &block)

        if response.code == 400 && response.body =~ /Load in progress/
          # We can't send data too fast, when the previous request is still loaded we
          # have to wait so sleep 10 seconds and try again
          sleep(10)
        elsif response.code == 200
          return
        else
          raise('Bad Post')
        end
      end
    end
844259
def comply(self, path):
        
        dirname = os.path.dirname(path)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        self.pre_write()
        render_and_write(self.template_dir, path, self.context())
        utils.ensure_permissions(path, self.user, self.group, self.mode)
        self.run_service_actions()
        self.save_checksum(path)
        self.post_write()
1296185
def _get_url(self, path):
        
        options = self._options.copy()
        options.update({'path': path})
        return self._base_url.format(**options)
1109691
def edit(self, **kwargs):
        
        part = '/library/sections/%s?%s' % (self.key, urlencode(kwargs))
        self._server.query(part, method=self._server._session.put)

        # Reload this way since the self.key dont have a full path, but is simply a id.
        for s in self._server.library.sections():
            if s.key == self.key:
                return s
1263504
def value_edited(self, path, new_value_str):
        
        tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
        if self.tree_store[tree_store_path][self.VALUE_STORAGE_ID] == new_value_str:
            return

        dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
        self.model.state.add_semantic_data(dict_path[0:-1], new_value_str, key=dict_path[-1])
        self.reload_tree_store_data()
627153
def add_options(self, path: str, handler: _WebHandler,
                    **kwargs: Any) -> AbstractRoute:
        
        return self.add_route(hdrs.METH_OPTIONS, path, handler, **kwargs)
1081377
def open(self, path):
        
        self.current.append(self.create(path))
        return self.current[-1]
1341210
def put(path, options={}, raw=false, unformatted=true)
      request(:put, path, options, raw, unformatted)
    end
1128241
def put(self, path, data, **options):
        
        data, options = self._update_request(data, options)
        return self.request('put', path, data=data, **options)
1094627
def add_path(self, path):
        # type: (_BaseSourcePaths, str) -> None
        
        if isinstance(path, pathlib.Path):
            self._paths.append(path)
        else:
            self._paths.append(pathlib.Path(path))
1073781
def post(path, options = {}, headers = {}, raw = false)
      request(:post, path, options, headers, raw)
    end
705955
def add_path(self, path):
        

        if os.path.exists(path):
            self.paths.add(path)
            return path
        else:
            #logger.debug('Path {} doesn\'t exist'.format(path))
            return None
953109
def post(self, path, data={}):
        ''' '''
        response = requests.post(API_URL + path, data=json.dumps(data), headers=self._set_headers())
        return self._check_response(response, self.post, path, data)
878509
def add_posts(self, path='posts'):
		
		path = os.path.join(self.root_path, path)
		self.cm.add_posts([
			self.cm.Post.from_file(file)
			for file in _listfiles(path)
		])
784590
def post(self, path, **kwargs):
        ''''''
        resp = self._session.post(self._url(path), **self._builder(**kwargs))
        if 'stream' in kwargs:
            return resp
        else:
            return self._resp_error_check(resp)