-
Notifications
You must be signed in to change notification settings - Fork 129
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
base: develop
Are you sure you want to change the base?
dynamic news additions #3149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: No newline at EOF |
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'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: No newline at EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: More descriptive var name: Flake8/PEP8 formatting:
|
||
news_list.append(nc) | ||
except: | ||
logger.info("No new news") | ||
|
||
context['news'] = news_list | ||
|
||
|
||
return context | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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("\\", "/") | ||
|
||
|
@@ -38,7 +41,7 @@ | |
def clean_name(name): | ||
return os.path.normpath(name).replace("\\", "/") | ||
|
||
|
||
@deconstructible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
class AzureStorage(Storage): | ||
chunk_size = 65536 | ||
|
||
|
@@ -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: | ||
|
There was a problem hiding this comment.
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.