Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create django.yml #29

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dfae2ed
Create django.yml
sindrelothe Mar 29, 2022
220f410
Change files to correct project in pylint command
sindrelothe Mar 29, 2022
1fa6248
change branch name to "main"
sindrelothe Mar 29, 2022
ee538f9
Merge branch 'main' into sindrelothe-patch-1
sindrelothe Apr 21, 2022
2b339e4
fix linting errors for some files
sindrelothe Apr 21, 2022
1835c9b
fix linting errors for choices.py, /fields/__init__, weekday.py
sindrelothe Apr 21, 2022
a4dabe5
Change pylint disable codes to names
sindrelothe Apr 26, 2022
ef09acb
Fix more pylint errors
sindrelothe Apr 26, 2022
6984709
Remove eval function from heroku.py
sindrelothe Apr 26, 2022
d68104b
fix final pylint errors
sindrelothe Apr 26, 2022
6b928a8
fix final pylint error
sindrelothe Apr 26, 2022
32ac51d
merge with main
sindrelothe Apr 26, 2022
79f7de5
remove help_text for Tag class
sindrelothe Apr 26, 2022
b468c80
add trailing comma for lists in tag.py
sindrelothe Apr 26, 2022
b0bcc49
added trailing comma to urls.py
sindrelothe Apr 26, 2022
b6f33be
Add specific exception to apps.py
sindrelothe Apr 26, 2022
bb0ddfb
disable fixme from pylint
sindrelothe Apr 26, 2022
443fd8d
fix migrate bug
sindrelothe Apr 26, 2022
0811664
fix error with github tests
sindrelothe Apr 26, 2022
13a4756
fix error with github tests
sindrelothe Apr 26, 2022
bd767eb
copy fix from rekenett for github tests
sindrelothe Apr 26, 2022
351a541
run migrate before pylint in django.yml'
sindrelothe Apr 26, 2022
576cad0
add settings config to apps.py
sindrelothe Apr 26, 2022
5dfa0d6
remove introduced error in apps.py
sindrelothe Apr 26, 2022
f64388d
add DJANGO_SETTINGS_MODULE to yml script
sindrelothe Apr 26, 2022
78b200c
Update django.yml
sindrelothe Apr 26, 2022
e0581c1
Update django.yml
sindrelothe Apr 26, 2022
2cf9ff5
add new line
sindrelothe Aug 23, 2022
ba0bcd2
fix pipeline
sindrelothe Aug 23, 2022
7df6683
fix pipeline
sindrelothe Aug 23, 2022
9111c6d
move verify migrations to before run pylint in yml
sindrelothe Aug 23, 2022
4946d49
add makemigrations to yml
sindrelothe Aug 23, 2022
227240a
merge main
sindrelothe Sep 27, 2022
31c5fe4
fix merge conflicts
sindrelothe Sep 27, 2022
e859ea0
fix merge conflicts
sindrelothe Sep 27, 2022
ba5254f
update python version in django.yml
sindrelothe Sep 27, 2022
4d1d07e
remove arguments from 'makemigrations' in djano.yml
sindrelothe Sep 27, 2022
a1fba86
remove migrations file
sindrelothe Sep 27, 2022
a0588f9
remove pylint from django.yml
sindrelothe Sep 27, 2022
095ba29
remove run pytest from infoscreen
sindrelothe Sep 27, 2022
b018e31
add linting to django.yml
sindrelothe Sep 27, 2022
ab1d4b3
remove linting of root
sindrelothe Sep 27, 2022
556722f
remove linting of root
sindrelothe Sep 27, 2022
0c2bd5f
use .sh structure to lint
sindrelothe Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Django CI

on:
push:
branches: [main]
pull_request:
branches: [main]

# Prevent multiple workflows with same branch/pull_request
concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true

env:
PIPENV_VENV_IN_PROJECT: 1
ENV: development
SECRET_KEY: NOT SET
DJANGO_SUPERUSER_USERNAME: admin
DJANGO_SUPERUSER_PASSWORD: Django123
DJANGO_SUPERUSER_EMAIL: [email protected]
DJANGO_SETTINGS_MODULE: root.settings

jobs:
job_build_django:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9.2' # Closest version to 3.7.3 available.

- name: Install dependencies
run: |
python -V
PY=$(which python)
echo $PY
python -m pip install --upgrade pip
python -m pip install pipenv
python -m pipenv install --python $PY

- name: Verify migrations
run: |
python -m pipenv run python manage.py makemigrations
python -m pipenv run python manage.py migrate

- name: Run pylint
run: python -m pipenv run pylint ./run-pylint.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm er dette riktig?

6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ argument-rgx=(([a-z_]+[a-z0-9_]*)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$
method-rgx=(([a-z_]+[a-z0-9_]*)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$
attr-rgx=(([a-z_]+[a-z0-9_]*)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$

[pylint-django]
django-settings-module=root.settings


[MESSAGES CONTROL]

disable=
Expand All @@ -22,6 +26,8 @@ disable=
too-many-locals,
too-many-statements,
unsubscriptable-object, # https://github.com/PyCQA/pylint/issues/1498
fixme,
; django-not-configured, # django-settings-module=root.settings doesn't work

[VARIABLES]

Expand Down
9 changes: 4 additions & 5 deletions infoscreen/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class ScreenAdmin(root_models.CustomBaseAdmin):
list_display = ['name']
ordering = []
list_filter = ['images', 'videos']
filter_horizontal = ['images','videos']
filter_horizontal = ['images', 'videos']
search_fields = ['name', 'slug']


class ScreenHasImageAdmin(admin.ModelAdmin):
list_display = ['screen', 'image', 'nr']
ordering = ['screen', 'nr']
Expand All @@ -36,8 +36,7 @@ class VideoAdmin(root_models.CustomBaseAdmin):
search_fields = ['name']



admin.site.register(infoscreen_models.Screen, ScreenAdmin)
# admin.site.register(infoscreen_models.ScreenHasImage, ScreenHasImageAdmin)
admin.site.register(infoscreen_models.Image, ImageAdmin)
admin.site.register(infoscreen_models.Video, VideoAdmin)
admin.site.register(infoscreen_models.Video, VideoAdmin)
1 change: 1 addition & 0 deletions infoscreen/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.apps import AppConfig
from django.core import management


class InfoScreenConfig(AppConfig):
Expand Down
13 changes: 2 additions & 11 deletions infoscreen/constants/choices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Weekday:
MON = 0
TUE = 1
Expand All @@ -7,13 +6,5 @@ class Weekday:
FRI = 4
SAT = 5
SUN = 6

CHOICES = [
(MON, "Mandag"),
(TUE, "Tirsdag"),
(WED, "Onsdag"),
(THU, "Torsdag"),
(FRI, "Fredag"),
(SAT, "Lørdag"),
(SUN, "Søndag")
]

CHOICES = [(MON, 'Mandag'), (TUE, 'Tirsdag'), (WED, 'Onsdag'), (THU, 'Torsdag'), (FRI, 'Fredag'), (SAT, 'Lørdag'), (SUN, 'Søndag')]
22 changes: 11 additions & 11 deletions infoscreen/models/color.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import re
from django.core.exceptions import ValidationError
from django.db import models

from root import models as root_models


class Color(root_models.CustomBaseModel):
name = models.CharField(max_length=200, null=True, blank=True, verbose_name='navn')
hex = models.CharField(max_length=6, null=True, blank=True, verbose_name="hex", help_text="Fargekode i hex (6 symboler)")
hex = models.CharField(max_length=6, null=True, blank=True, verbose_name='hex', help_text='Fargekode i hex (6 symboler)')

class Meta:
ordering = []
verbose_name = 'farge'
verbose_name_plural = 'farger'

def __str__(self):
return f"{self.get_name()}"
return f'{self.get_name()}'

def get_name(self):
if self.name:
return self.name
return self.hex

def as_css(self):
# TODO: handle COLOR_RANDOM
# if self.name == root_constants.COLOR_RANDOM:
# return
return f"#{self.hex}"
# return
return f'#{self.hex}'

def clean(self, *args, **kwargs):
super().clean(*args, **kwargs)
errors = {}
Expand All @@ -34,8 +35,7 @@ def clean(self, *args, **kwargs):
errors['hex'] = 'Ugyldig format. Bruk 0-9 og A-F'
if errors:
raise ValidationError(errors)

def save(self, *args, **kwargs):
self.clean()
super().save(*args, **kwargs)

2 changes: 1 addition & 1 deletion infoscreen/models/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .restricted_file import ContentTypeRestrictedFileField
# from .weekday import WeekdayField
# from .weekday import WeekdayField
13 changes: 9 additions & 4 deletions infoscreen/models/fields/restricted_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.db.models import FileField
from django import forms
from django.template.defaultfilters import filesizeformat
from django.utils.translation import gettext_lazy as _


class ContentTypeRestrictedFileField(FileField):
Expand All @@ -15,14 +18,16 @@ class ContentTypeRestrictedFileField(FileField):
250MB - 214958080
500MB - 429916160
"""
def __init__(self, content_types=None, max_upload_size=5242880,*args, **kwargs):

def __init__(self, *args, content_types=None, max_upload_size=5242880, **kwargs):
super().__init__(*args, **kwargs)
self.content_types = content_types
self.max_upload_size = max_upload_size

def clean(self, *args, **kwargs):
def clean(self, *args, **kwargs):
data = super().clean(*args, **kwargs)

# pylint: disable=protected-access
file = data.file
try:
content_type = file.content_type
Expand All @@ -32,6 +37,6 @@ def clean(self, *args, **kwargs):
else:
raise forms.ValidationError(_('Filetype ikke støttet.'))
except AttributeError:
pass
pass

return data
return data
10 changes: 5 additions & 5 deletions infoscreen/models/fields/weekday.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# from django.db.models import IntegerField
#
#
# class WeekDayField(IntegerField):
#
#
# def __init__(self, *args, **kwargs):
# kwargs['choices'] = self.DAYS
# super().__init__(*args, **kwargs)
#
# def clean(self, *args, **kwargs):
#
# def clean(self, *args, **kwargs):
# data = super().clean(*args, **kwargs)
# try:
# if data and 0 > data > 6: raise forms.ValidationError(_('Ikke eksisterende '))
# except AttributeError:
# pass
# pass
# return data
5 changes: 3 additions & 2 deletions infoscreen/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from root import models as root_models


class Image(root_models.CustomBaseModel):
name = models.CharField(max_length=140, null=True, blank=True)
url = models.URLField(null=False, blank=False)

def __str__(self):
return f"{self.name}"
return f'{self.name}'
8 changes: 4 additions & 4 deletions infoscreen/models/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
class Screen(root_models.CustomBaseModel):
name = models.CharField(max_length=140, unique=True, null=True, blank=True)
slug = models.CharField(max_length=140, unique=True, null=False, blank=False)

# images = models.ManyToManyField('Image', through='ScreenHasImage')
images = models.ManyToManyField('infoscreen.Image', blank=True)
videos = models.ManyToManyField('infoscreen.Video', blank=True)

def __str__(self):
return f"{self.name}"
return f'{self.name}'


# class ScreenHasImage(models.Model):
# screen = models.ForeignKey('infoscreen.Screen', on_delete=models.CASCADE, null=False, blank=False)
# image = models.ForeignKey('infoscreen.Image', on_delete=models.CASCADE, null=False, blank=False)
# nr = models.IntegerField(null=False, blank=False)
#
#
# class Meta:
# unique_together = ['screen', 'image']
69 changes: 44 additions & 25 deletions infoscreen/models/tag.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
# imports
import re

from django.db import models
from django.db.models import Q
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError

from root import models as root_models

# End: imports -----------------------------------------------------------------


class Tag(root_models.CustomBaseModel):
name = models.CharField(max_length=200, unique=True, null=False, blank=False, verbose_name='navn', help_text="En vilkårlig egenskap til en plante. (Tips: Du kan prefikse tags med kolon ':', f.eks. 'familie:fiola' )")
bg = models.ForeignKey('infoscreen.Color', on_delete=models.SET_NULL, null=True, blank=True, related_name='tag_bg', verbose_name='bakgrunnsfarge')
font = models.ForeignKey('infoscreen.Color', on_delete=models.SET_NULL, null=True, blank=True, related_name='tag_font', verbose_name='skriftfarge')
group = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='children', verbose_name='gruppe')

name = models.CharField(
max_length=200,
unique=True,
null=False,
blank=False,
verbose_name='navn',
)
bg = models.ForeignKey(
'infoscreen.Color',
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='tag_bg',
verbose_name='bakgrunnsfarge',
)
font = models.ForeignKey(
'infoscreen.Color',
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='tag_font',
verbose_name='skriftfarge',
)
group = models.ForeignKey(
'self',
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='children',
verbose_name='gruppe',
)

class Meta:
ordering = []
verbose_name = 'tag'
verbose_name_plural = 'tags'

def __str__(self):
return f"{self.full_name()}"
return f'{self.full_name()}'

def full_name(self):
if self.group:
return f"{self.group.full_name()} :: {self.name}"
return f"{self.name}"


return f'{self.group.full_name()} :: {self.name}'
return f'{self.name}'

def color_list(self):
"""Hierarchical list of colors from least to most significant"""
colors = []
if self.tag_group:
colors += self.tag_group.color_list()
if self.color:
colors.append(self.color)
if self.group:
colors += self.group.color_list()
if self.bg:
colors.append(self.bg)
return colors

def color_list_css(self):
return [color.as_css() for color in self.color_list()]


8 changes: 4 additions & 4 deletions infoscreen/models/video.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.db import models
from root import models as root_models
from ..utils.__init__ import parse_url

from root import models as root_models

class Video(root_models.CustomBaseModel):
name = models.CharField(max_length=140, null=True, blank=True)
youtube_code = models.CharField(max_length=140, null=False, blank=False)

def __str__(self):
return f"{self.name}"
return f'{self.name}'

def save(self, *args, **kwargs):
self.youtube_code = parse_url(self.youtube_code)
super().save(*args, **kwargs)
1 change: 1 addition & 0 deletions infoscreen/templates/infoscreen/screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
</div>
{% endblock %}


2 changes: 0 additions & 2 deletions infoscreen/templatetags/infoscreen_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# imports
from django import template
from django.conf import settings

# End: imports -----------------------------------------------------------------

register = template.Library()
Expand Down
Loading