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 6 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
50 changes: 50 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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]

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.7.5' # 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: Run pylint
emilte marked this conversation as resolved.
Show resolved Hide resolved
run: python -m pipenv run pylint infoscreen root

- name: Verify migrations
run: |
python -m pipenv run python manage.py migrate
- name: Run tests
run: python -m pipenv run pytest
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)
8 changes: 4 additions & 4 deletions infoscreen/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
class InfoScreenConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'infoscreen'

def ready(self):

from django.core import management

try:
# https://docs.djangoproject.com/en/3.0/ref/django-admin/#createsuperuser
management.call_command('createsuperuser', interactive=False)
except:
pass
pass
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
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']
25 changes: 12 additions & 13 deletions infoscreen/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@

# 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' )")
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" )'
emilte marked this conversation as resolved.
Show resolved Hide resolved
)
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 = []
Expand All @@ -38,8 +39,6 @@ def color_list(self):
if self.color:
colors.append(self.color)
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: 0 additions & 1 deletion infoscreen/templatetags/infoscreen_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# imports
from django import template
from django.conf import settings
# End: imports -----------------------------------------------------------------

register = template.Library()
Expand Down
3 changes: 1 addition & 2 deletions infoscreen/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import path, include
from django.urls import path
from django.views.generic.base import RedirectView

from infoscreen import views
Expand All @@ -10,4 +10,3 @@
path('screen/<str:slug>/', views.ScreenView.as_view(), name='view_screen'),
path('screens/', views.ScreenListView.as_view(), name='screen_list'),
]

21 changes: 10 additions & 11 deletions infoscreen/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
TEST1 = "https://youtu.be/16GVZ6s5XEw"
TEST2 = "https://www.youtube.com/watch?v=16GVZ6s5XEw&ab_channel=BigLozOfficial"
TEST3 = "https://youtu.be/16GVZ6s5XEw/?id=1"
TEST1 = 'https://youtu.be/16GVZ6s5XEw'
TEST2 = 'https://www.youtube.com/watch?v=16GVZ6s5XEw&ab_channel=BigLozOfficial'
TEST3 = 'https://youtu.be/16GVZ6s5XEw/?id=1'


def parse_url(url):
if "https://youtu.be/" in url:
new = url.replace("https://youtu.be/", '')
new = new.split("/", 1)
if 'https://youtu.be/' in url:
new = url.replace('https://youtu.be/', '')
new = new.split('/', 1)
return new[0]
elif "https://www.youtube.com/" in url:
new = url.split("=", 1)
new = new[1].split("&", 1)
if 'https://www.youtube.com/' in url:
new = url.split('=', 1)
new = new[1].split('&', 1)
return new[0]
else:
return "oopsie woopsie, you made a fucky wucky"
return 'oopsie woopsie, you made a fucky wucky'
3 changes: 1 addition & 2 deletions root/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Environment:
"""
Useful in eg. templates
Expand All @@ -8,6 +7,6 @@ class Environment:
DEV = 'development'
HEROKU = 'heroku'
PROD = 'production'

ALL = [BASE, DEV, PROD, HEROKU]
VALID = [DEV, PROD, HEROKU]
2 changes: 1 addition & 1 deletion root/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .base import CustomBaseAdmin, CustomBaseModel, CustomModelForm
from .base import CustomBaseAdmin, CustomBaseModel, CustomModelForm
Loading