This simple script uses Discourse's REST API to duplicate a category, which is not possible directly through the frontend.
- Copy category colors
- Copy category images
- Copy category permission groups
- Optionally replace the original permission groups with new ones directly
- Copy category settings (wiki, subcategory display options, etc)
- Copy category description (the auto generated about post is edited with the contents of the origin category's about post)
- Sub categories are recursively copied
Unfortunately the list of allowed tags is not copied at this time.
Rename the config.ini.default
file to config.ini
.
Fill in the options:
[forum]
api_key= # put your API key here
api_user= # the username of the user associated with this API key
url= # Discourse installation base url, without trailing /
- Create a virtual environment
- Activate it
- Install the requirements
$ pip install -r requirements.txt
-
Activate the virtual environment you created
-
While in the main directory, run
python3 main.py
-
Choose a category to copy from (origin) by name
-
Choose the name of the new category (destination)
-
Choose the new category's slug
-
Optionally, type in "yes" to indicate a group replacement mapping.
For example, to replace astro-studs with math-studs and astro-teach with math-teach:
Would you like to replace groups from the previous category with different ones, already created? (yes/no) yes How many groups? 2 Old group 1/2: astro-studs New group 1/2: math-studs Old group 2/2: astro-teach New group 2/2: math-teach
Please note that math-studs and math-teach groups must already exist.
-
The script will now recursively duplicate the category and its subcategories