Repository: cobbler/cobbler

Issue:
Cobbler-web 3: Unable to sort columns on name
### Describe the bug

When in the Cobbler web 3.1.x webUI, for instance in "Systems", clicking on "Name" to perform a sort will give an error.

### To Reproduce

1. Go to Cobbler web URI, eg. `http://cobbler.example.com/cobbler_web/` and login.
2. Click on Systems under Configuration on the left.
3. Click "Name ↓"
4. See error

### Expected behavior

Column sorting, no error.

### Version

````
Cobbler 3.1.1
  source: ?, ?
  build time: Sat Feb  8 14:38:00 2020
````

### Screenshots

![Cobbler_Django_error](https://user-images.githubusercontent.com/519955/74467603-aac19e80-4e99-11ea-828c-0efb443fae26.png)

### Additional context

**!! IMPORTANT !!**
To get the right Django error page set these lines in `/usr/share/cobbler/web/settings.py`:

```
TIME_ZONE = 'UTC'
USE_TZ = True
```

To get things sane again, clear all cobbler related cookies too.

Debian 10 Buster
python3-django 1:1.11.27-1~deb10u1

FYI Django 1.11 will be EOL soon (April 2020)! https://www.djangoproject.com/download/#supported-versions


Discussion:
Okay I just looked this up for Debian Buster: Without the backports there is no way we can use Django 2.2 (next LTS). I think we should consider splitting the web-ui out of the main cobbler project and start developing with Django 2.2 a new UI. Refactoring and forcing an LTS upgrade inside this repo I personally think is not the best idea. I like the idea of having separate repos for the core cobbler server (which is managed via cli) and the web-ui.
@SchoolGuy FWIW - just did some more testing here with Cobbler 3.1.2

Added the Buster backports repo to apt and ran `apt update`.
This makes Django 2.2.10 available:
```
root@cobbler:~# apt-cache policy python3-django
python3-django:
  Installed: 1:1.11.28-1~deb10u1
  Candidate: 1:1.11.28-1~deb10u1
  Version table:
     2:2.2.10-1~bpo10+1 100
        100 http://deb.debian.org/debian buster-backports/main amd64 Packages
 *** 1:1.11.28-1~deb10u1 500
        500 http://security.debian.org/debian-security buster/updates/main amd64 Packages
        100 /var/lib/dpkg/status
     1:1.11.27-1~deb10u1 500
        500 http://httpredir.debian.org/debian buster/main amd64 Packages
```

Ran `apt-get -t buster-backports install python3-django` and restarted apache2.
The Cobbler webUI is still running with the same issues as in Django 1.11. 😇

It will also remove `python-django-common`:
```
root@cobbler:~# dpkg -l | grep django
rc  python-django-common           1:1.11.28-1~deb10u1                 all          High-level Python web development framework (common)
ii  python3-django                 2:2.2.10-1~bpo10+1                  all          High-level Python web development framework
```

So it seems to be do-able, maybe even useable.
@hbokh Ouch... Okay if you want to do that feel free. I in the meantime have learnt a lot about Django and have to say that I think this is not a good idea because we would not be able to develop the web-ui seperate from cobbler when applying Django philosophy. But that is not coming soonish because there is a lot to fix before a graphical user interface is a priority. 
We want a working webUI, so I'll see what I can do here (though I am no programmer IRL).
I do see Python2 code is still being used:

`sortdata.sort(lambda a, b: cmp(b, a))`

https://github.com/cobbler/cobbler/blob/master/cobbler/remote.py#L455

Look at the `cmp()` and the `lambda` without `key`.

References:
- https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
   *The `cmp()` function should be treated as gone*
- https://docs.python.org/3/howto/sorting.html#the-old-way-using-the-cmp-parameter
  *In Py3.0, the cmp parameter was removed entirely*
Replacing https://github.com/cobbler/cobbler/blob/master/cobbler/remote.py#L455 with `sortdata.sort(reverse=True)` resolved ~the~ my issue.
@hbokh Is this a general problem, or just one for you?

Resolving patch:
diff --git a/cobbler/items/item.py b/cobbler/items/item.py
--- a/cobbler/items/item.py
+++ b/cobbler/items/item.py
@@ -280,7 +280,7 @@ def set_uid(self, uid):
         """
         self.uid = uid
 
-    def get_children(self, sorted=True):
+    def get_children(self, sorted=False):
         """
         Get direct children of this object.
 
diff --git a/cobbler/remote.py b/cobbler/remote.py
--- a/cobbler/remote.py
+++ b/cobbler/remote.py
@@ -18,7 +18,6 @@
 02110-1301  USA
 """
 
-from past.builtins import cmp
 from future import standard_library
 standard_library.install_aliases()
 from builtins import str
@@ -615,7 +614,7 @@ def __sort(self, data, sort_field=None):
             sort_fields.insert(0, sort_field)
         sortdata = [(x.sort_key(sort_fields), x) for x in data]
         if sort_rev:
-            sortdata.sort(lambda a, b: cmp(b, a))
+            sortdata.sort(reverse=True)
         else:
             sortdata.sort()
         return [x for (key, x) in sortdata]


Test patch: