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

dynamic news additions #3149

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions codalab/apps/teams/migrations/0004_auto_20220409_2242.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2022-04-09 22:42
from __future__ import unicode_literals

import codalab.azure_storage
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('teams', '0003_auto_20220328_1713'),
]

operations = [
migrations.AlterField(
model_name='team',
name='image',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='public'), upload_to='team_logo', verbose_name='Logo'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

On my side I'd like to look into the deconstruct method/decorator a bit to see if we can solve this before-hand.

),
]
2 changes: 2 additions & 0 deletions codalab/apps/web/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ class PageAdmin(admin.ModelAdmin):
admin.site.register(models.CompetitionSubmission)
admin.site.register(models.CompetitionSubmissionMetadata)
admin.site.register(models.CompetitionDefBundle)

admin.site.register(models.NewsPost)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: No newline at EOF

162 changes: 162 additions & 0 deletions codalab/apps/web/migrations/0006_auto_20220409_2242.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2022-04-09 22:42
from __future__ import unicode_literals

import apps.web.models
import codalab.azure_storage
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('web', '0005_auto_20220328_1713'),
]

operations = [
migrations.CreateModel(
name='NewsPost',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=40, unique=True)),
('link', models.URLField()),
('date', models.DateTimeField(blank=True, null=True, verbose_name='Post Date (UTC)')),
('post', models.TextField(blank=True, null=True)),
],
),
migrations.AlterField(
model_name='competition',
name='image',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='public'), upload_to=apps.web.models._uuidify('logos'), verbose_name='Logo'),
),
migrations.AlterField(
model_name='competitiondefbundle',
name='config_bundle',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('competition-bundles')),
),
migrations.AlterField(
model_name='competitiondump',
name='data_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('competition_dump'), verbose_name='Data file'),
),
migrations.AlterField(
model_name='competitionphase',
name='ingestion_program',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('ingestion_program')),
),
migrations.AlterField(
model_name='competitionphase',
name='input_data',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('phase_input_data_file'), verbose_name='Input Data'),
),
migrations.AlterField(
model_name='competitionphase',
name='public_data',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('public_data'), verbose_name='Public Data'),
),
migrations.AlterField(
model_name='competitionphase',
name='reference_data',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('phase_reference_data_file'), verbose_name='Reference Data'),
),
migrations.AlterField(
model_name='competitionphase',
name='scoring_program',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('phase_scoring_program_file'), verbose_name='Scoring Program'),
),
migrations.AlterField(
model_name='competitionphase',
name='starting_kit',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('starting_kit'), verbose_name='Starting Kit'),
),
migrations.AlterField(
model_name='competitionsubmission',
name='coopetition_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_coopetition')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='detailed_results_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_detailed_results')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_file_name')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='history_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_history')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='ingestion_program_stderr_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('predict_submission_stderr')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='ingestion_program_stdout_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('predict_submission_stdout')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='inputfile',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_inputfile')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='output_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_output')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='prediction_output_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_prediction_output')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='prediction_runfile',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_prediction_runfile')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='prediction_stderr_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('predict_submission_stderr')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='prediction_stdout_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('predict_submission_stdout')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='private_output_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_private_output')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='runfile',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_runfile')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='scores_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_scores')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='stderr_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_stderr')),
),
migrations.AlterField(
model_name='competitionsubmission',
name='stdout_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('submission_stdout')),
),
migrations.AlterField(
model_name='organizerdataset',
name='data_file',
field=models.FileField(blank=True, null=True, storage=codalab.azure_storage.AzureStorage(account_key='qY4fuziQqP0N63JurVsEvp7rioAsqnwPdRRgpLKDoCTNrVj1Xwt0l/EJVP3Yxn2IySXqjgMFYnvWd+B1mgPUAA==', account_name='codalabpython3test', azure_container='bundles'), upload_to=apps.web.models._uuidify('dataset_data_file'), verbose_name='Data file'),
),
]
18 changes: 18 additions & 0 deletions codalab/apps/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2722,3 +2722,21 @@ def filename(self):
def competitiondump_post_delete_handler(sender, **kwargs):
comp_dump = kwargs['instance']
delete_key_from_storage(comp_dump, 'data_file')

class NewsPost(models.Model):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would the newsletter app be a better fit than web if the newsletter app is not niche

"""
News section on /highlights page

Attributes or columns include:
* Title
"""
title = models.CharField(max_length=40, unique=True)
link = models.URLField(max_length=200)
date = models.DateTimeField(null=True, blank=True, verbose_name="Post Date (UTC)")
post = models.TextField(null=True, blank=True)

def __unicode__(self):
return self.title

def __str__(self):
return self.title
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: No newline at EOF

9 changes: 9 additions & 0 deletions codalab/apps/web/templates/web/highlights.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ <h3 class="ui purple header">Research and Education<br>
<div class="row">
<h1 class="ui purple header">News</h1>
</div>
<!-- Additional News -->
{% for news_component in news %}
<div class="row news-column-bottom-padding">
<h3><a href="{{ news_component.link }}">{{ news_component.title }}</a><br>
</h3>
<p><u>{{ news_component.date|date:'F Y' }}</u>: {{ news_component.post|safe }}
</p>
</div>
{% endfor %}
<div class="row news-column-bottom-padding">
<h3><a href="https://codalab.lisn.upsaclay.fr/">New
server</a><br>
Expand Down
24 changes: 18 additions & 6 deletions codalab/apps/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from apps.web import tasks
from apps.web.exceptions import ScoringException
from apps.web.forms import CompetitionS3UploadForm
from apps.web.models import SubmissionScore, SubmissionScoreDef, get_current_phase, \
from apps.web.models import NewsPost, SubmissionScore, SubmissionScoreDef, get_current_phase, \
get_first_previous_active_and_next_phases, Competition, CompetitionSubmission
from datetime import datetime, timedelta
from django.conf import settings
Expand Down Expand Up @@ -143,15 +143,15 @@ class Highlights(TemplateView):
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)

data = Competition.objects.aggregate(
comp = Competition.objects.aggregate(
Copy link
Collaborator

@Tthomas63 Tthomas63 Apr 14, 2022

Choose a reason for hiding this comment

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

Nit: comp -> comps (Multiple objects vs one)

(This may even not be competition objects but raw data, the reasoning for the orig var name)

count=Count('*'),
published_comps=Count(Case(When(published=True, then=1))),
unpublished_comps=Count(Case(When(published=False, then=1)))
)
total_competitions = data['count']
public_competitions = data['published_comps']
private_competitions = data['unpublished_comps']

total_competitions = comp['count']
public_competitions = comp['published_comps']
private_competitions = comp['unpublished_comps']
users = User.objects.all().count() # from authenz_cluser
competition_participants = models.CompetitionParticipant.objects.all().count()
submissions = models.CompetitionSubmission.objects.all().count()
Expand All @@ -165,6 +165,18 @@ def get_context_data(self, *args, **kwargs):
{'label': "Submissions", 'count': submissions},
]

news_list = []
try:
news = NewsPost.objects.all()
for news_component in news:
nc = {'title':news_component.title,'link':news_component.link,'date':news_component.date,'post':news_component.post}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: More descriptive var name:
news_component

Flake8/PEP8 formatting:

news_component = {
    'title': news_component.title,
    'link': news_component.link,
    'date': news_component.date,
    'post': news_component.post
}

news_list.append(nc)
except:
logger.info("No new news")

context['news'] = news_list


return context


Expand Down
8 changes: 7 additions & 1 deletion codalab/codalab/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from django.core.exceptions import ImproperlyConfigured
from io import RawIOBase

# https://docs.djangoproject.com/en/1.11/topics/migrations/#migration-serializing
from django.utils.deconstruct import deconstructible

# keep consistent path separators
pathjoin = lambda *args: os.path.join(*args).replace("\\", "/")

Expand All @@ -38,7 +41,7 @@
def clean_name(name):
return os.path.normpath(name).replace("\\", "/")


@deconstructible
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

class AzureStorage(Storage):
chunk_size = 65536

Expand All @@ -49,6 +52,9 @@ def __init__(self, *args, **kwargs):
super(AzureStorage, self).__init__(*args, **kwargs)
self._connection = None

def __eq__(self, other):
return self.foo == other.foo

@property
def connection(self):
if self._connection is None:
Expand Down