diff --git a/.prospector.yaml b/.prospector.yaml index 4dcd596..838b437 100644 --- a/.prospector.yaml +++ b/.prospector.yaml @@ -1,5 +1,5 @@ doc-warnings: true -strictness: medium +strictness: high ignore-paths: - migrations ignore-patterns: @@ -15,3 +15,6 @@ pylint: pep8: options: max-line-length: 120 +pep257: + disable: + - D203 diff --git a/choices/__init__.py b/choices/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/choices/admin.py b/choices/admin.py deleted file mode 100644 index bfb54f9..0000000 --- a/choices/admin.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Manage choices models.""" - -from django.contrib import admin - -from choices.models import ChoiceSet - -admin.site.register(ChoiceSet) diff --git a/choices/migrations/0001_initial.py b/choices/migrations/0001_initial.py deleted file mode 100644 index ab4a2fe..0000000 --- a/choices/migrations/0001_initial.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='ChoiceSet', - fields=[ - ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)), - ('name', models.CharField(max_length=20)), - ('choices', models.TextField()), - ], - ), - ] diff --git a/choices/migrations/__init__.py b/choices/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/choices/models.py b/choices/models.py deleted file mode 100644 index fcc7bfe..0000000 --- a/choices/models.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Define choice set models""" - -from django.db import models - - -class ChoiceSet(models.Model): - - """Define collections of possible choices.""" - - name = models.CharField(max_length=20) - choices = models.TextField() - - def __str__(self): - """String representation.""" - - return "{0:s} - {1:s}".format(self.name, self.choices) - - def choices_list(self): - """Return choices as a list.""" - return self.choices.split(',') diff --git a/choices/templates/choices/choiceset_detail.html b/choices/templates/choices/choiceset_detail.html deleted file mode 100644 index a689102..0000000 --- a/choices/templates/choices/choiceset_detail.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'base.html' %} - -{% block title %}choice set: {{ choiceset.name }}{% endblock %} - -{% block content %} -

{{ choiceset.name }}

-

Choices: {{ choiceset.choices_list|join:", " }}

-

Random Choice: {{ choiceset.choices_list|random }}

-{% endblock %} diff --git a/choices/templates/choices/index.html b/choices/templates/choices/index.html deleted file mode 100644 index 042f35b..0000000 --- a/choices/templates/choices/index.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'base.html' %} - -{% block title %}choices{% endblock %} - -{% block content %} - -{% endblock %} diff --git a/choices/urls.py b/choices/urls.py deleted file mode 100644 index 57c3970..0000000 --- a/choices/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -"""URL patterns for choices.""" - -from django.conf.urls import url - -from choices.views import index, choiceset_detail - -urlpatterns = [ - url(r'^$', index, name='choices_index'), - url(r'^(?P.+)/$', choiceset_detail, name='choices_choiceset_detail'), -] diff --git a/choices/views.py b/choices/views.py deleted file mode 100644 index ba5a34e..0000000 --- a/choices/views.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Display choice sets.""" - -import logging - -from django.shortcuts import get_object_or_404, render - -from choices.models import ChoiceSet - -log = logging.getLogger(__name__) - - -def index(request): - """Display nothing, for the moment.""" - - choicesets = ChoiceSet.objects.all() - - return render(request, 'choices/index.html', {'choicesets': choicesets}) - - -def choiceset_detail(request, set_name): - """Display info, and a random choice, for the requested choice set.""" - - choiceset = get_object_or_404(ChoiceSet, name=set_name) - - return render(request, 'choices/choiceset_detail.html', {'choiceset': choiceset}) diff --git a/dr_botzo/settings.py b/dr_botzo/settings.py index 770bd36..43f8ad9 100644 --- a/dr_botzo/settings.py +++ b/dr_botzo/settings.py @@ -43,7 +43,6 @@ INSTALLED_APPS = ( 'bootstrap3', 'registration', 'rest_framework', - 'choices', 'countdown', 'dispatch', 'facts', diff --git a/dr_botzo/urls.py b/dr_botzo/urls.py index ce22036..193d5eb 100644 --- a/dr_botzo/urls.py +++ b/dr_botzo/urls.py @@ -12,8 +12,8 @@ admin.autodiscover() urlpatterns = [ url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'), - url(r'^choices/', include('choices.urls')), url(r'^dispatch/', include('dispatch.urls')), + url(r'^itemsets/', include('facts.urls')), url(r'^karma/', include('karma.urls')), url(r'^markov/', include('markov.urls')), url(r'^races/', include('races.urls')), diff --git a/facts/__init__.py b/facts/__init__.py index e69de29..07e15d3 100644 --- a/facts/__init__.py +++ b/facts/__init__.py @@ -0,0 +1,7 @@ +"""Facts allows storage of arbitrarily defined sets of strings. + +The "fact" part is tongue-in-cheek, you can put random options for a decision, +roulette style game modes, 8-ball type functionality, and total falsehoods +in here too. When fact categories are queried, a random one is returned if +you don't know what you're looking for. +""" diff --git a/facts/admin.py b/facts/admin.py index 7764b7f..9b4f26f 100644 --- a/facts/admin.py +++ b/facts/admin.py @@ -1,7 +1,20 @@ +"""Admin interface for the facts app.""" from django.contrib import admin from facts.models import Fact, FactCategory +class FactInline(admin.TabularInline): + """Inline admin form for facts, for inclusion in fact categories.""" + + model = Fact + + +class FactCategoryAdmin(admin.ModelAdmin): + """Admin pages for the FactCategory model.""" + + inlines = [FactInline] + + admin.site.register(Fact) -admin.site.register(FactCategory) +admin.site.register(FactCategory, FactCategoryAdmin) diff --git a/facts/ircplugin.py b/facts/ircplugin.py index 2f0795f..d964e34 100644 --- a/facts/ircplugin.py +++ b/facts/ircplugin.py @@ -1,5 +1,4 @@ """IRC plugin for retrieval of facts.""" - import logging from irc.client import NickMask @@ -7,17 +6,14 @@ from irc.client import NickMask from ircbot.lib import Plugin, has_permission from facts.models import Fact, FactCategory - log = logging.getLogger('facts.ircplugin') class Facts(Plugin): - """Present facts to IRC.""" def start(self): """Set up the handlers.""" - self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!facts\s+add\s+(\S+)\s+(.*)$', self.handle_add_fact, -20) self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!facts\s+(\S+)(\s+(.*)$|$)', @@ -27,7 +23,6 @@ class Facts(Plugin): def stop(self): """Tear down handlers.""" - self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_add_fact) self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_facts) @@ -35,7 +30,6 @@ class Facts(Plugin): def handle_facts(self, connection, event, match): """Respond to the facts command with desired fact.""" - category = match.group(1) regex = None if match.group(2) != '': @@ -53,7 +47,6 @@ class Facts(Plugin): def handle_add_fact(self, connection, event, match): """Add a new fact to the database.""" - category_name = match.group(1) fact_text = match.group(2) diff --git a/facts/migrations/0006_factcategory_show_all_entries.py b/facts/migrations/0006_factcategory_show_all_entries.py new file mode 100644 index 0000000..b324817 --- /dev/null +++ b/facts/migrations/0006_factcategory_show_all_entries.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-02-11 15:00 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('facts', '0005_auto_20150814_1653'), + ] + + operations = [ + migrations.AddField( + model_name='factcategory', + name='show_all_entries', + field=models.BooleanField(default=False), + ), + ] diff --git a/facts/models.py b/facts/models.py index fd6de05..63b1225 100644 --- a/facts/models.py +++ b/facts/models.py @@ -1,43 +1,31 @@ """Store "facts".""" - import logging import random from django.db import models - log = logging.getLogger('facts.models') class FactCategory(models.Model): - """Define categories for facts.""" name = models.CharField(max_length=200, unique=True) + show_all_entries = models.BooleanField(default=False) show_source = models.BooleanField(default=False) class Meta: + """Meta options.""" + verbose_name_plural = 'fact categories' def __str__(self): """String representation.""" - return "{0:s}".format(self.name) - -class FactManager(models.Manager): - - """Queries against Fact.""" - - def random_fact(self, category, regex=None): - """Get a random fact from the database.""" - - try: - fact_category = FactCategory.objects.get(name=category) - except FactCategory.DoesNotExist: - return None - - facts = Fact.objects.filter(category=fact_category) + def random_fact(self, regex=None): + """Get a random fact in this category.""" + facts = self.fact_set.all() if regex: facts = facts.filter(fact__iregex=regex) @@ -47,8 +35,20 @@ class FactManager(models.Manager): return None -class Fact(models.Model): +class FactManager(models.Manager): + """Queries against Fact.""" + def random_fact(self, category, regex=None): + """Get a random fact from the database.""" + try: + factcategory = FactCategory.objects.get(name=category) + except FactCategory.DoesNotExist: + return None + + return factcategory.random_fact(regex) + + +class Fact(models.Model): """Define facts.""" fact = models.TextField() @@ -60,5 +60,4 @@ class Fact(models.Model): def __str__(self): """String representation.""" - return "{0:s} - {1:s}".format(self.category.name, self.fact) diff --git a/facts/templates/facts/base.html b/facts/templates/facts/base.html new file mode 100644 index 0000000..9abceb2 --- /dev/null +++ b/facts/templates/facts/base.html @@ -0,0 +1,4 @@ +{% extends 'base.html' %} +{% block extra_media %}{% load static %} + +{% endblock %} diff --git a/facts/templates/facts/factcategory_detail.html b/facts/templates/facts/factcategory_detail.html new file mode 100644 index 0000000..1496261 --- /dev/null +++ b/facts/templates/facts/factcategory_detail.html @@ -0,0 +1,11 @@ +{% extends 'facts/base.html' %} + +{% block title %}item set: {{ factcategory.name }}{% endblock %} + +{% block content %} +

{{ factcategory.name }}

+

{{ factcategory.random_fact.fact|linebreaks }}

+ {% if factcategory.show_all_entries %} +
Items: {{ facts|join:", " }}
+ {% endif %} +{% endblock %} diff --git a/facts/templates/facts/index.html b/facts/templates/facts/index.html new file mode 100644 index 0000000..72efb77 --- /dev/null +++ b/facts/templates/facts/index.html @@ -0,0 +1,11 @@ +{% extends 'facts/base.html' %} + +{% block title %}item sets{% endblock %} + +{% block content %} + +{% endblock %} diff --git a/facts/urls.py b/facts/urls.py new file mode 100644 index 0000000..826a334 --- /dev/null +++ b/facts/urls.py @@ -0,0 +1,9 @@ +"""URL patterns for the facts web views.""" +from django.conf.urls import url + +from facts.views import index, factcategory_detail + +urlpatterns = [ + url(r'^$', index, name='facts_index'), + url(r'^(?P.+)/$', factcategory_detail, name='facts_factcategory_detail'), +] diff --git a/facts/views.py b/facts/views.py new file mode 100644 index 0000000..3dfb112 --- /dev/null +++ b/facts/views.py @@ -0,0 +1,26 @@ +"""Display fact categories.""" +import logging + +from django.shortcuts import get_object_or_404, render + +from facts.models import FactCategory + +log = logging.getLogger(__name__) + + +def index(request): + """Display a simple list of the fact categories, for the moment.""" + factcategories = FactCategory.objects.all() + + return render(request, 'facts/index.html', {'factcategories': factcategories}) + + +def factcategory_detail(request, factcategory_name): + """Display info, and a random choice, for the fact category.""" + factcategory = get_object_or_404(FactCategory, name=factcategory_name) + + facts = [] + if factcategory.show_all_entries: + facts = [x.fact for x in factcategory.fact_set.all()] + + return render(request, 'facts/factcategory_detail.html', {'factcategory': factcategory, 'facts': facts}) diff --git a/static/css/facts.css b/static/css/facts.css new file mode 100644 index 0000000..0626d6a --- /dev/null +++ b/static/css/facts.css @@ -0,0 +1,4 @@ +.fact-category-items { + margin-top: 20px; + color: #999999; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 366370f..a2f6922 100644 --- a/templates/base.html +++ b/templates/base.html @@ -72,7 +72,7 @@ {% block navbar_menu %}