utils.py 935 Bytes
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
import re
Guilhem Saurel's avatar
Guilhem Saurel committed
2
3
import unicodedata
from enum import IntEnum
Guilhem Saurel's avatar
Guilhem Saurel committed
4
5

from django.utils.safestring import mark_safe
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
6

Guilhem Saurel's avatar
travis    
Guilhem Saurel committed
7
SOURCES = IntEnum('Sources', 'github gitlab redmine robotpkg travis')
Guilhem Saurel's avatar
Guilhem Saurel committed
8
TARGETS = IntEnum('Targets', '14.04 16.04 17.10 18.04 dubnium')
Guilhem Saurel's avatar
Guilhem Saurel committed
9
10
11
12
13
14
15
16
17


def slugify_with_dots(value):
    """
    slugify a name but keep dots
    """
    value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
    value = re.sub(r'[^\w\s\.-]', '', value).strip().lower()
    return mark_safe(re.sub(r'[-\s]+', '-', value))
Guilhem Saurel's avatar
Guilhem Saurel committed
18
19
20
21
22
23
24
25
26
27
28


def api_next(source, req):
    if source == SOURCES.github:
        if 'Link' in req.headers:
            for link in req.headers['Link'].split(','):
                if 'next' in link:
                    return int(re.search('page=(\d+)', link).group(1))
    if source == SOURCES.gitlab:
        if 'X-Next-Page' in req.headers and req.headers['X-Next-Page']:
            return int(req.headers['X-Next-Page'])