Skip to content

Commit

Permalink
Merge pull request #281 from clabs/dev
Browse files Browse the repository at this point in the history
Improve player and web link refactor
  • Loading branch information
ethrgeist authored Aug 22, 2024
2 parents 9d8af2e + b538d07 commit 085b0c9
Show file tree
Hide file tree
Showing 25 changed files with 3,805 additions and 567 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.17.0
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.2-bookworm as base
FROM python:3.12.5-bookworm as base

######################################### [build] ########################

Expand Down
1,030 changes: 537 additions & 493 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "GNU General Public License v3.0"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12.2"
python = "^3.12.5"
blessed = "*"
brotli = "*"
dateparser = "*"
Expand Down
3 changes: 3 additions & 0 deletions src/rockon/api/serializers/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Meta:
"bid_status",
"federal_state",
"are_students",
"mean_age_under_27",
"is_coverband",
"bid_complete",
"press_photo",
]
Expand All @@ -61,6 +63,7 @@ class BandDetailSerializer(serializers.ModelSerializer):
songs = BandMediaSerializer(source="get_songs", read_only=True, many=True)
links = BandMediaSerializer(source="get_links", read_only=True, many=True)
documents = BandMediaSerializer(source="get_documents", read_only=True, many=True)
web_links = BandMediaSerializer(source="get_web_links", read_only=True, many=True)

class Meta:
model = Band
Expand Down
14 changes: 14 additions & 0 deletions src/rockon/bands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ class BandVoteAdmin(CustomAdminModel):
list_filter = ("event",)
search_fields = ("band__name", "user__username")

def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False

def get_fields(self, request, obj=None):
# Exclude 'vote' from the fields displayed in the detail view
fields = super().get_fields(request, obj)
return [field for field in fields if field != "vote"]


admin.site.register(Band, BandAdmin)
admin.site.register(BandMedia, BandMediaAdmin)
Expand Down
20 changes: 20 additions & 0 deletions src/rockon/bands/migrations/0013_band_mean_age_under_27.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1 on 2024-08-22 09:52

from __future__ import annotations

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("rockonbands", "0012_bandvote_event"),
]

operations = [
migrations.AddField(
model_name="band",
name="mean_age_under_27",
field=models.BooleanField(default=False),
),
]
20 changes: 20 additions & 0 deletions src/rockon/bands/migrations/0014_band_is_coverband.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1 on 2024-08-22 10:33

from __future__ import annotations

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("rockonbands", "0013_band_mean_age_under_27"),
]

operations = [
migrations.AddField(
model_name="band",
name="is_coverband",
field=models.BooleanField(default=False),
),
]
32 changes: 32 additions & 0 deletions src/rockon/bands/migrations/0015_alter_bandmedia_media_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.1 on 2024-08-22 11:08

from __future__ import annotations

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("rockonbands", "0014_band_is_coverband"),
]

operations = [
migrations.AlterField(
model_name="bandmedia",
name="media_type",
field=models.CharField(
choices=[
("unknown", "Unbekannt"),
("audio", "Audio"),
("document", "Dokument"),
("link", "Link"),
("logo", "Logo"),
("press_photo", "Pressefoto"),
("web", "Webseite"),
],
default="unknown",
max_length=32,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.1 on 2024-08-22 11:10

from __future__ import annotations

from django.db import migrations


def copy_urls_to_bandmedia(apps, schema_editor):
Band = apps.get_model("rockonbands", "Band")
BandMedia = apps.get_model("rockonbands", "BandMedia")
for band in Band.objects.all():
if band.facebook:
BandMedia.objects.create(
band=band,
media_type="web",
url=band.facebook,
)
if band.homepage:
BandMedia.objects.create(
band=band,
media_type="web",
url=band.homepage,
)


class Migration(migrations.Migration):

dependencies = [
("rockonbands", "0015_alter_bandmedia_media_type"),
]

operations = [
migrations.RunPython(copy_urls_to_bandmedia),
migrations.RemoveField(
model_name="band",
name="facebook",
),
migrations.RemoveField(
model_name="band",
name="homepage",
),
]
7 changes: 5 additions & 2 deletions src/rockon/bands/models/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Band(CustomModel):
name = models.CharField(max_length=255, default=None, blank=True, null=True)
has_management = models.BooleanField(default=False)
are_students = models.BooleanField(default=False)
mean_age_under_27 = models.BooleanField(default=False)
is_coverband = models.BooleanField(default=False)
genre = models.CharField(max_length=128, default=None, blank=True, null=True)
federal_state = models.CharField(
max_length=255,
Expand All @@ -35,8 +37,6 @@ class Band(CustomModel):
null=True,
choices=FederalState.choices,
)
homepage = models.URLField(default=None, blank=True, null=True)
facebook = models.URLField(default=None, blank=True, null=True)
cover_letter = models.TextField(default=None, blank=True, null=True)
contact = models.OneToOneField(
User,
Expand Down Expand Up @@ -109,3 +109,6 @@ def get_links(self):

def get_documents(self):
return self.media.filter(media_type="document")

def get_web_links(self):
return self.media.filter(media_type="web")
5 changes: 3 additions & 2 deletions src/rockon/bands/models/band_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class MediaType(models.TextChoices):
"""Media type."""

UNKNOWN = "unknown", "Unbekannt"
DOCUMENT = "document", "Dokument"
AUDIO = "audio", "Audio"
DOCUMENT = "document", "Dokument"
LINK = "link", "Link"
PRESS_PHOTO = "press_photo", "Pressefoto"
LOGO = "logo", "Logo"
PRESS_PHOTO = "press_photo", "Pressefoto"
WEB = "web", "Webseite"


class BandMedia(CustomModel):
Expand Down
59 changes: 52 additions & 7 deletions src/rockon/bands/static/js/bandbewerbung-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ console.debug('bandbewerbung-form.js loaded')
const DateTime = luxon.DateTime

$(document).ready(() => {
console.debug('document ready')
const toastAudioPlayerElement = document.getElementById('toastAudioPlayer')
const toastAudioPlayer = bootstrap.Toast.getOrCreateInstance(
toastAudioPlayerElement
Expand All @@ -21,9 +22,18 @@ $(document).ready(() => {
const url = $('#url_input').val()
if (url === '') return
$('#url_input').val('')
api_add_url(url)
api_add_url(url, 'link')
$('#add_url').prop('disabled', true)
})
$('#add_web_url').on('click', event => {
event.preventDefault()
console.debug('add url')
const url = $('#web_url_input').val()
if (url === '') return
$('#web_url_input').val('')
api_add_web_url(url, 'web')
$('#add_web_url').prop('disabled', true)
})
$(document).on('click', '[data-remove-url]', event => {
event.preventDefault()
const id = event.currentTarget.dataset.removeUrl
Expand All @@ -50,6 +60,14 @@ $(document).ready(() => {
$('#add_url').prop('disabled', true)
}
})
$('#web_url_input').on('blur change', function () {
const url = $(this).val()
if (isValidURL(url)) {
$('#add_web_url').prop('disabled', false)
} else {
$('#add_web_url').prop('disabled', true)
}
})
$('#selectedFileDocument').on('change', event => {
console.debug('file selected', event)
const file = event.target.files[0]
Expand Down Expand Up @@ -132,6 +150,11 @@ const li_add_url = url => {
$('#url_list').append(element)
}

const li_add_web_url = url => {
const element = `<li id="url-${url.id}"><a href="${url.url}" target="_blank">${url.url}</a><span class="btn btn-default btn-xs" data-remove-url="${url.id}"><i class="fa fa-trash"></i></span></li>`
$('#web_url_list').append(element)
}

const li_add_document = document => {
const element = `<li id="document-${document.id}" class="list-group-item d-flex justify-content-between align-items-center"><a href="${document.file}" target="_blank">${document.file_name_original}</a><span class="btn btn-default btn-xs" data-remove-document="${document.id}"><i class="fa fa-trash"></i></span></li>`
$('#document_list').append(element)
Expand Down Expand Up @@ -176,6 +199,8 @@ const send_form = () => {
}
form_obj['are_students'] = form_obj['are_students'] || false
form_obj['has_management'] = form_obj['has_management'] || false
form_obj['mean_age_under_27'] = form_obj['mean_age_under_27'] || false
form_obj['is_coverband'] = form_obj['is_coverband'] || false
form_obj['federal_state'] = $('#federal_state').val() || null

console.debug('form obj', form_obj)
Expand All @@ -202,11 +227,11 @@ const save_success = data => {
alert("Bandbewerbung gespeichert.")
}

const api_add_url = url => {
console.debug('add url')
const api_add_url = (url, type) => {
console.debug('add url api')
media_obj = {
url: url,
media_type: 'link',
media_type: type,
band: window.rockon_data.band_id
}
$.ajax({
Expand All @@ -225,6 +250,29 @@ const api_add_url = url => {
})
}

const api_add_web_url = (url, type) => {
console.debug('add web url api')
media_obj = {
url: url,
media_type: type,
band: window.rockon_data.band_id
}
$.ajax({
type: 'POST',
url: window.rockon_data.api_url_new_media + 'upload/',
data: JSON.stringify(media_obj),
contentType: 'application/json',
headers: {
'X-CSRFToken': $('[name=csrfmiddlewaretoken]').val()
},
mode: 'same-origin',
dataType: 'json',
success: data => li_add_web_url(data),
error: data => ajax_error(data),
complete: data => ajax_complete(data)
})
}

const api_remove_url = id => {
console.debug('remove url')
$.ajax({
Expand Down Expand Up @@ -289,9 +337,6 @@ ajax_error = (data, form_obj, url) => {
// FIXME: needs error handling
console.error(data)
const response = responseJSON
if (response.homepage || response.facebook) {
return alert('Bitte gibt bei Homepage und Facebook die URL immer mit http:// oder https:// am Anfang ein.')
}
$('#api_message').html(`
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Fehler!</strong> Bitte schicke uns folgenden Text an <a href="mailto:[email protected]">[email protected]</a>: <br>
Expand Down
Loading

0 comments on commit 085b0c9

Please sign in to comment.