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

Add "site flags" mechanism and convert 'schedule_published' to it #65

Closed
wants to merge 4 commits into from
Closed
Diff settings

Always

Just for now

@@ -0,0 +1,11 @@
from django.contrib import admin

from .models import SiteFlag


class SiteFlagAdmin(admin.ModelAdmin):
fields = ['name', 'value_type', 'switch_time']
list_display = ['name', 'value_type', 'switch_time', 'current_value']

This comment has been minimized.

Copy link
@starenka

starenka Mar 6, 2019

Contributor

pro pohodlnost mozna neco hodit do list_editable


admin.site.register(SiteFlag, SiteFlagAdmin)
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-03-01 17:18
from __future__ import unicode_literals

from django.db import migrations, models

from pyconcz.common.models import SiteFlag


def create_initial_flag(apps, schema_editor):
SiteFlag(name='schedule_published', value_type='off').save()


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='SiteFlag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('value_type', models.CharField(choices=[('on', 'on'), ('off', 'off'), ('on_at', 'on_at'), ('off_at', 'off_at')], max_length=200)),
('switch_time', models.DateTimeField(blank=True, null=True)),
],
),
migrations.RunPython(
create_initial_flag,
migrations.RunPython.noop,
),
]
No changes.
@@ -0,0 +1,54 @@
from enum import Enum

from django.db import models
from django.utils import timezone


class SiteFlag(models.Model):
name = models.CharField(max_length=200, unique=True)
value_type = models.CharField(
max_length=200,
choices=[
# Human-readable titles are the same as the value
(v, v) for v in ("on", "off", "on_at", "off_at")

This comment has been minimized.

Copy link
@starenka

starenka Mar 6, 2019

Contributor

ty choices bejva fajn mit jako "konstantu" na ty tride (kdyz se to meni, tak se to meni na jednom miste, pouziva se to pak z klasy, je to takovy vic jasny, co to dela), ale nevidim to jako velkej trabl....

neco ala:

VALUE_TYPE_ON = 'on', nebo se na to pouzivaj libky ala django-choices

],
)
switch_time = models.DateTimeField(null=True, blank=True)

def clean(self):
if self.value_type in ("on_at", "off_at"):
if not self.switch_time:
self.switch_time = timezone.now()

@property
def current_value(self):
now = timezone.now()
if self.value_type == "on":
return True
if self.value_type == "off":
return False

if self.switch_time:
switched = self.switch_time <= now
else:
switched = False

if self.value_type == "on_at":
return switched
if self.value_type == "off_at":
return not switched

def __str__(self):
return self.name

class Meta:
ordering = ('name', )

@classmethod
def get_active_flags(cls):
now = timezone.now()
return [obj.name for obj in (

This comment has been minimized.

Copy link
@starenka

starenka Mar 6, 2019

Contributor
  • tady bejva usus si poslat "jen to, co potrebujes - tedy selectnout jen fieldy, ktery chces", tedy cls.objects.filter(value_type='on').values_list('name', flat=True) viz. values_list

  • jinak by asi bylo pro "djangisty" citelnejsi pouzit Q misto tohohole chainu (a taky je mozna lepsi jeden dotaz nez tri)....

samo to de zkombinovat oboje dohromady. nicmene hele jestli to funguje, nestoural bych do toho ;)

*cls.objects.filter(value_type="on"),
*cls.objects.filter(value_type="on_at", switch_time__lte=now),
*cls.objects.filter(value_type="off_at", switch_time__gt=now),
)]
@@ -0,0 +1,5 @@
from .models import SiteFlag


def site_flag_processor(request):
return {'site_flags': SiteFlag.get_active_flags()}
@@ -118,6 +118,7 @@
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
'pyconcz.common.site_flags.site_flag_processor',
],
},
},
@@ -9,8 +9,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_sponsors %}{% endblock %}
@@ -7,8 +7,6 @@

{% block link_about %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_call_for_papers %}{% endblock %}
@@ -9,8 +9,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_sponsors %}{% endblock %}
@@ -9,8 +9,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_sponsors %}{% endblock %}
@@ -9,8 +9,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_sponsors %}{% endblock %}
@@ -9,8 +9,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_sponsors %}{% endblock %}
@@ -7,8 +7,6 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_call_for_papers %}{% endblock %}
@@ -7,6 +7,4 @@

{% block link_workshops %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}
{% block link_board_game_night %}{% endblock %}
@@ -3,8 +3,6 @@

{% block link_about %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}

{% block link_call_for_papers %}{% endblock %}
@@ -3,6 +3,4 @@

{% block link_about %}{% endblock %}

{% block link_schedule %}{% endblock %}

{% block link_board_game_night %}{% endblock %}
{% block link_board_game_night %}{% endblock %}
@@ -57,11 +57,13 @@
{% block link_workshops %}
{% include "__nav-link.html" with url="speakers_list" type="workshops" link_text="Workshops" %}
{% endblock %}
{% endcomment %}

{% block link_schedule %}
{% if 'schedule_published' in site_flags %}
{% include "__nav-link.html" with url="programme_schedule" link_text="Schedule" %}
{% endblock %}
{% endif %}

{% comment %}
{% block link_board_game_night %}
{% include "__nav-link.html" with url="board_game_night" link_text="Board Game Night" %}
{% endblock %}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.