Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Commit

Permalink
Merge branch 'status_choices'
Browse files Browse the repository at this point in the history
  • Loading branch information
vbabiy committed Oct 30, 2015
2 parents 07139ca + cd7f0bf commit c96728e
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 26 deletions.
12 changes: 5 additions & 7 deletions botbot/apps/bots/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Django admin configuration for the bot objects.
"""
import redis
from django import forms
from django.conf import settings
from django.contrib import admin
from django.forms.models import BaseInlineFormSet
from django import forms
import redis

from . import models

Expand Down Expand Up @@ -58,14 +58,12 @@ def clean_private_slug(self):

class ChannelAdmin(admin.ModelAdmin):
form = ChannelForm
list_display = ('name', 'chatbot', 'is_active',
'is_public', 'is_featured', 'is_pending', 'created', 'updated')
list_filter = ('chatbot', 'is_active', 'is_public',
'is_featured', 'is_pending')
list_display = ('name', 'chatbot', 'status', 'is_featured', 'created', 'updated')
list_filter = ('status', 'is_featured', 'chatbot')
prepopulated_fields = {
'slug': ('name',)
}
list_editable = ('is_active',)
list_editable = ('status',)
readonly_fields = ('fingerprint', 'created', 'updated')
search_fields = ('name', 'chatbot__server')
inlines = [ActivePluginInline]
Expand Down
19 changes: 19 additions & 0 deletions botbot/apps/bots/migrations/0004_channel_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('bots', '0003_remove_channel_users'),
]

operations = [
migrations.AddField(
model_name='channel',
name='status',
field=models.CharField(default=b'PENDING', max_length=20, choices=[(b'PENDING', b'Pending'), (b'ACTIVE', b'Active'), (b'ARCHIVED', b'Archived')]),
),
]
28 changes: 28 additions & 0 deletions botbot/apps/bots/migrations/0005_move_to_status_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

def move_bools_to_status(apps, schema_editor):
Channel = apps.get_model("bots", "Channel")

for channel in Channel.objects.all():
if channel.is_active:
channel.status = "ACTIVE"
else:
channel.status = "PENDING"

channel.save()



class Migration(migrations.Migration):

dependencies = [
('bots', '0004_channel_status'),
]

operations = [
migrations.RunPython(move_bools_to_status),

]
22 changes: 22 additions & 0 deletions botbot/apps/bots/migrations/0006_auto_20151030_1406.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('bots', '0005_move_to_status_choices'),
]

operations = [
migrations.RemoveField(
model_name='channel',
name='is_active',
),
migrations.RemoveField(
model_name='channel',
name='is_pending',
),
]
33 changes: 25 additions & 8 deletions botbot/apps/bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,33 @@ def allocate_bot(cls, slug):

raise NoAvailableChatBots(slug)

class ChannelQuerySet(models.query.QuerySet):
def active(self):
return self.filter(status=Channel.ACTIVE)

class ChannelManager(models.Manager):

def get_queryset(self):
return ChannelQuerySet(self.model, using=self._db)

def public(self):
return self.get_queryset().filter(is_public=True)

def active(self):
self.get_queryset().active()


class Channel(TimeStampedModel):
PENDING = 'PENDING'
ACTIVE = 'ACTIVE'
ARCHIVED = 'ARCHIVED'

STATUS_CHOICES = (
(PENDING, 'Pending'),
(ACTIVE, 'Active'),
(ARCHIVED, 'Archived')
)

# These are the default plugin slugs.
DEFAULT_PLUGINS = ["logger", "ping", "last_seen", "help", "bangmotivate"]

Expand All @@ -118,16 +137,18 @@ class Channel(TimeStampedModel):

password = models.CharField(max_length=250, blank=True, null=True,
help_text="Password (mode +k) if the channel requires one")

status = models.CharField(choices=STATUS_CHOICES, default=PENDING, max_length=20)

# Flags
is_public = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_pending = models.BooleanField(default=False)
is_featured = models.BooleanField(default=False)
public_kudos = models.BooleanField(default=True)

plugins = models.ManyToManyField('plugins.Plugin',
through='plugins.ActivePlugin')

is_featured = models.BooleanField(default=False)
fingerprint = models.CharField(max_length=36, blank=True, null=True)
public_kudos = models.BooleanField(default=True)

notes = models.TextField(blank=True)

Expand Down Expand Up @@ -318,10 +339,6 @@ def save(self, *args, **kwargs):

self.fingerprint = uuid.uuid4()

# If a room is active, it can't be pending.
if self.is_active:
self.is_pending = False

super(Channel, self).save(*args, **kwargs)


Expand Down
4 changes: 3 additions & 1 deletion botbot/apps/bots/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def setUp(self):
chatbot=self.chatbot,
name="#Test",
slug="test",
is_public=True)
is_public=True,
status=models.Channel.ACTIVE
)
logs_models.Log.objects.create(
channel=self.public_channel,
command='PRIVMSG',
Expand Down
8 changes: 1 addition & 7 deletions botbot/apps/bots/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import json

from django import http
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse_lazy
from django.http.response import Http404
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.generic import (View)
from django.views.generic.list import ListView

from botbot.apps.accounts import models as accounts_models
from . import models


Expand Down Expand Up @@ -81,7 +75,7 @@ def get_channel(self, user, **kwargs):
return self._channel

def _channel_queryset(self):
return models.Channel.objects.filter(is_active=True)
return models.Channel.objects.filter(status__in=(models.Channel.ACTIVE, models.Channel.ARCHIVED))

def _get_identifiable_channel(self, bot_slug, channel_slug):
"""
Expand Down
3 changes: 2 additions & 1 deletion botbot/apps/logs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setUp(self):
chatbot=self.chatbot,
name="#Test",
slug="test",
status=bot_models.Channel.ACTIVE,
is_public=True)
self.log = log_models.Log.objects.create(
channel=self.public_channel,
Expand Down Expand Up @@ -92,7 +93,7 @@ def setUp(self):
server='testserver', nick='botbot', slug='botbot')

self.public_channel = bot_models.Channel.objects.create(
chatbot=self.chatbot, name="#Test", slug='test',
chatbot=self.chatbot, name="#Test", slug='test', status=bot_models.Channel.ACTIVE,
is_public=True)

def _add_log_line(self, text, nick="Nick"):
Expand Down
4 changes: 2 additions & 2 deletions botbot/apps/preview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class LandingPage(Signup):
def get_context_data(self, **kwargs):
kwargs.update({
'featured_channels': bots_models.Channel.objects \
.filter(is_public=True, is_featured=True, is_active=True) \
.filter(is_public=True, is_featured=True).active() \
.select_related('chatbot'),
'public_not_featured_channels': bots_models.Channel.objects \
.filter(is_public=True, is_featured=False, is_active=True) \
.filter(is_public=True, is_featured=False).active() \
.select_related('chatbot')
})
return kwargs

0 comments on commit c96728e

Please sign in to comment.