Skip to content

Commit

Permalink
Merge pull request #5 from ckarrie/django-5.1
Browse files Browse the repository at this point in the history
Django 5.1 to master
  • Loading branch information
ckarrie authored Sep 26, 2024
2 parents 73b2c5e + 49174cb commit aa910e7
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 130 deletions.
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
# Contribution
Feel free to hack around and create pull requests.

# Contributors
Many thanks to
- iaN [@ifalatik](https://github.com/ifalatik) for keeping the code up-to-date

## Developement

### 1. Create and activate Python 3.5.x virtual environment
### 1. Create and activate Python 3.6 or greater virtual environment
```shell
python3 -m venv wannspieltbig_dev
cd wannspieltbig_dev
source bin/activate
```

### 2. Install requirements
```
beautifulsoup4==4.8.1
bs4==0.0.1
Django==2.2.7
django-ical==1.7.0
django-recurrence==1.10.1
djangorestframework==3.10.3
icalendar==4.0.4
python-dateutil==2.8.1
python-memcached==1.59
python-telegram-bot==12.2.0
python-twitter==3.5
requests==2.22.0
```

### 3. Create your local Django project
```shell
django-admin startproject wsb
```

### 4. Install csgo-App
```shell
sudo apt-get install memcached
mkdir src
cd src
git clone https://github.com/ckarrie/ckw-csgo/
pip install -r ckw-csgo/requirements.txt
# install csgo app in editable mode
pip install -e ckw-csgo
```

### 5. Edit settings.py / add to INSTALLED_APPS

### 3. Set up local Django project
```shell
cd wannspieltbig_dev/
django-admin startproject wsb
cd wsb/
mkdir wsb/static
nano wsb/wsb/settings.py
```
Expand All @@ -51,6 +37,13 @@ nano wsb/wsb/settings.py
# Change
ALLOWED_HOSTS = ['*']

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
"LOCATION": "127.0.0.1:11211",
}
}

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -79,14 +72,14 @@ STATIC_URL = '/static/'
STATIC_ROOT = '/home/christian/workspace/venvs/wannspieltbig_dev/wsb/static' # CHANGE TO YOUR LOCAL FOLDER
```

### 6. Setup Database and symlink static files
### 4. Setup Database and symlink static files

```shell
python wsb/manage.py migrate
python wsb/manage.py collectstatic -l
```

### 7. Add initial data
### 5. Add initial data

```shell
python wsb/manage.py shell
Expand All @@ -106,12 +99,10 @@ from django.contrib.auth.models import User
User.objects.create_superuser(username="devuser", password="devuser", email="[email protected]")
```

### 7. Run Dev Server
### 6. Run Dev Server
```shell
python wsb/manage.py runserver 0.0.0.0:9001
```
Open Browser:
- Frontend: http://127.0.0.1:9001
- Django-Admin: http://127.0.0.1:9001/admin/


9 changes: 6 additions & 3 deletions csgomatches/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ def get_hltv_id_from_name(self, request, queryset):
obj.save()
self.message_user(
request,
"Found HLTV ID {} for {}".format(obj.hltv_id, obj.name),
f"Found HLTV ID {obj.hltv_id} for {obj.name}",
level=messages.SUCCESS
)

def hltv_link(self, obj):
url = obj.get_hltv_team_link()
if url:
return mark_safe('<a href="{}" target="_blank">{}</a>'.format(url, obj.name))
return mark_safe(f'<a href="{url}" target="_blank">{obj.name}</a>')
return ''

def lineup_logo(self, obj):
Expand All @@ -172,7 +172,7 @@ def build_players(self, request, queryset):
build_players(team_mdl=obj)
self.message_user(
request,
"Build player for Team {}".format(obj.name),
f"Build player for Team {obj.name}",
level=messages.SUCCESS
)

Expand All @@ -195,6 +195,9 @@ class MatchAdmin(admin.ModelAdmin):
search_fields = ['lineup_b__team__name', 'lineup_b__team__name_long', 'tournament__name']
autocomplete_fields = ['lineup_a', 'lineup_b', 'tournament']
inlines = [MatchMapInline, ExternalLinkInline]
# replace "Save and add another" button with "Save as new" to use previous matches as template
# https://docs.djangoproject.com/en/5.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_as
save_as = True

def overall_score(self, obj):
score = obj.get_overall_score()
Expand Down
4 changes: 2 additions & 2 deletions csgomatches/drf_api/ser_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def __init__(self, hltv_match_id, team_a_id, team_b_id, score_a, score_b, map_na
self.map_nr = map_nr

def __str__(self):
return "{} {} {}:{} {}".format(self.map_name, self.team_a_id, self.score_a, self.score_b, self.team_b_id)
return f"{self.map_name} {self.team_a_id} {self.score_a}:{self.score_b} {self.team_b_id}"

def __repr__(self):
return "<Map #{} - {}>".format(self.map_nr, self.map_name)
return f"<Map #{self.map_nr} - {self.map_name}>"


class HLTVMatch(object):
Expand Down
2 changes: 1 addition & 1 deletion csgomatches/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def items(self):
def item_title(self, item):
if item.is_live() or item.has_ended():
score_a, score_b = item.get_overall_score()
return "{} - {}:{}".format(item, score_a, score_b)
return f"{item} - {score_a}:{score_b}"
return str(item)

def item_description(self, item):
Expand Down
12 changes: 6 additions & 6 deletions csgomatches/management/commands/csgo_fetch_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def crawl_y0fl0w_de(self, include_archive_pages=True, fake=False):
response = requests.get(y_url)
response_json = response.json()
except JSONDecodeError as json_error:
print("[crawl_y0fl0w_de] ERROR reading {}, content={}".format(y_url, str(json_error)))
print(f"[crawl_y0fl0w_de] ERROR reading {y_url}, content={str(json_error}"))
continue
# raise json_error

Expand Down Expand Up @@ -245,7 +245,7 @@ def crawl_y0fl0w_de(self, include_archive_pages=True, fake=False):

hltv_livescore_data = None
if match_id:
hltv_url = 'https://www.hltv.org/matches/{}/match'.format(match_id)
hltv_url = f'https://www.hltv.org/matches/{match_id}/match'
apps.get_model('csgomatches.ExternalLink').objects.get_or_create(
url=hltv_url,
match=match,
Expand All @@ -271,13 +271,13 @@ def crawl_y0fl0w_de(self, include_archive_pages=True, fake=False):
if '_m' in vod_lang and 'https://twitch.tv/videos/' in vod_url:
link_type = 'twitch_vod'
mlang, mnr = vod_lang.split('_')
vod_title = 'VOD #{} ({})'.format(mnr, mlang)
vod_title = f'VOD #{mnr} ({mlang})'
if '/videos/v' in vod_url:
vod_url = vod_url.replace('/videos/v', '/videos/')
if '_m' in vod_lang and 'youtube' in vod_url:
link_type = 'youtube_vod'
mlang, mnr = vod_lang.split('_')
vod_title = 'VOD #{} ({})'.format(mnr, mlang)
vod_title = f'VOD #{mnr} ({mlang})'
if vod_lang == 'demo':
link_type = 'hltv_demo'
mlang = 'eu'
Expand Down Expand Up @@ -363,7 +363,7 @@ def crawl_y0fl0w_de(self, include_archive_pages=True, fake=False):
print("[crawl_y0fl0w_de] - Results by y0fl0w-API", results)

# Overwriting results
results = "{}:{}".format(t1_score, t2_score)
results = f"{t1_score}:{t2_score}"
print("[crawl_y0fl0w_de] - Results by WebSocket livescore", results)


Expand Down Expand Up @@ -510,7 +510,7 @@ def crawl_99damage_de(self, include_archive_pages=False, fake=False):
team_b.save()
lineup_b = apps.get_model('csgomatches.Lineup')(team=team_b, active_from=timezone.now(), team_logo_url=team_logos[1])
lineup_b.save()
print('[crawl_99damage_de] + Lineup created: "{}"'.format(str(lineup_b)))
print(f'[crawl_99damage_de] + Lineup created: "{lineup_b}"')

match = apps.get_model('csgomatches.Match').objects.filter(
tournament=tournament,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Generated by Django 5.1 on 2024-09-01 13:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('csgomatches', '0045_auto_20240727_1346'),
]

operations = [
migrations.RenameField(
model_name='game',
old_name='team_logo_url',
new_name='game_logo_url',
),
migrations.RenameField(
model_name='game',
old_name='team_logo_width',
new_name='game_logo_width',
),
migrations.AlterField(
model_name='csgositesetting',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='externallink',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='game',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='lineup',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='lineupplayer',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='map',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='match',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='matchmap',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='player',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='playerrole',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='staticpage',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='team',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='tournament',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
18 changes: 18 additions & 0 deletions csgomatches/migrations/0047_alter_csgositesetting_site_teams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2024-09-06 10:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('csgomatches', '0046_rename_team_logo_url_game_game_logo_url_and_more'),
]

operations = [
migrations.AlterField(
model_name='csgositesetting',
name='site_teams',
field=models.ManyToManyField(to='csgomatches.team'),
),
]
17 changes: 17 additions & 0 deletions csgomatches/migrations/0048_alter_match_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1 on 2024-09-06 10:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('csgomatches', '0047_alter_csgositesetting_site_teams'),
]

operations = [
migrations.AlterModelOptions(
name='match',
options={'ordering': ['-first_map_at'], 'verbose_name_plural': 'matches'},
),
]
Loading

0 comments on commit aa910e7

Please sign in to comment.