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

Commit

Permalink
Merge pull request #154 from BotBotMe/no-public-accounts
Browse files Browse the repository at this point in the history
Removes subscriptions, plans, and user accounts
  • Loading branch information
vbabiy committed Oct 27, 2015
2 parents 8827eb7 + 7699b40 commit 9a5b100
Show file tree
Hide file tree
Showing 74 changed files with 77 additions and 1,944 deletions.
20 changes: 1 addition & 19 deletions botbot/apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@
from . import models


class MembershipAdmin(admin.ModelAdmin):
search_fields = (
"user__username", "user__email", "channel__name", "channel__slug")
list_display = ("user", "channel", "get_channel_is_active",
"get_channel_is_public", "kind")
list_filter = ("kind", "is_admin", "is_owner", "channel__is_active")
raw_id_fields = ("user",)

def get_channel_is_active(self, obj):
return obj.channel.is_active
get_channel_is_active.short_description = "channel is actve"

def get_channel_is_public(self, obj):
return obj.channel.is_public
get_channel_is_public.short_description = "channel is public"


class CustomUserAdmin(UserAdmin):
list_display = (
'username', 'email', 'first_name', 'last_name', 'is_staff', 'date_joined')
'username', 'email', 'first_name', 'last_name', 'is_staff', 'date_joined')


admin.site.register(models.User, CustomUserAdmin)
admin.site.register(models.Membership, MembershipAdmin)
29 changes: 0 additions & 29 deletions botbot/apps/accounts/forms.py

This file was deleted.

35 changes: 35 additions & 0 deletions botbot/apps/accounts/migrations/0003_auto_20151026_1950.py

Large diffs are not rendered by default.

68 changes: 2 additions & 66 deletions botbot/apps/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import json

from django.db import models
from django.contrib.auth import models as auth_models
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
import pytz
from django.contrib.auth import models as auth_models
from django.db import models

TIMEZONE_CHOICES = [(tz, tz.replace('_', ' ')) for tz in pytz.common_timezones]

Expand All @@ -16,63 +12,3 @@ class User(auth_models.AbstractUser):

class Meta:
db_table = 'auth_user'

def get_quantity_per_membership_kind(self):
"""
Group the membership per kind and count them
The result is a list of dict:
[
{'kind': u'public', 'quantity': 1},
{'kind': u'personal', 'quantity': 2}
]
"""
return (
self.membership_set
.filter(channel__is_active=True)
.filter(
models.Q(kind=Membership.KIND_PERSONAL, channel__is_public=False) |
models.Q(kind=Membership.KIND_PUBLIC))
.values("kind")
.annotate(quantity=models.Count("kind"))
)


@receiver(user_logged_in)
def set_user_timezone(sender, request, user, **kwargs):
"""Set the session timezone on login"""
if user.timezone:
request.session['django_timezone'] = user.timezone


class Membership(models.Model):
KIND_PERSONAL = "personal"
KIND_PUBLIC = "public"
KIND_CHOICES = (
(KIND_PERSONAL, KIND_PERSONAL.title()),
(KIND_PUBLIC, KIND_PUBLIC.title()),
)

user = models.ForeignKey(User)
channel = models.ForeignKey('bots.Channel')
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
is_owner = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
kind = models.CharField(
max_length=30, choices=KIND_CHOICES, default=KIND_PERSONAL)

class Meta:
unique_together = ('user', 'channel')

def to_json(self):
return json.dumps(
{
'id': self.user.id,
'admin': self.is_admin,
'email': self.user.email
})

def save(self, *args, **kwargs):
if self.is_owner:
self.is_admin = True
return super(Membership, self).save(*args, **kwargs)
239 changes: 0 additions & 239 deletions botbot/apps/accounts/tests.py

This file was deleted.

13 changes: 0 additions & 13 deletions botbot/apps/accounts/urls.py

This file was deleted.

0 comments on commit 9a5b100

Please sign in to comment.