From 297419f370ea87458017ee506a2e551e9068b66b Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 17 Nov 2013 19:15:30 +0200 Subject: Swicthing machines --- apps/checkin/models.py | 3 ++ apps/core/forms.py | 47 ++++++++++++++++++++---- apps/core/models.py | 60 +++++++++++++++++++++++++++--- apps/core/templates/login.html | 2 - apps/core/views.py | 79 ++++++++++++++++++++++++++++++++++++---- apps/docs/models.py | 11 +++--- apps/issues/__init__.py | 0 apps/issues/forms.py | 7 ++++ apps/issues/models.py | 33 +++++++++++++++++ apps/issues/tests.py | 16 ++++++++ apps/issues/views.py | 18 +++++++++ apps/troubleshooting/__init__.py | 0 apps/troubleshooting/models.py | 19 ---------- apps/troubleshooting/tests.py | 16 -------- apps/troubleshooting/views.py | 1 - 15 files changed, 247 insertions(+), 65 deletions(-) delete mode 100644 apps/core/templates/login.html create mode 100644 apps/issues/__init__.py create mode 100644 apps/issues/forms.py create mode 100644 apps/issues/models.py create mode 100644 apps/issues/tests.py create mode 100644 apps/issues/views.py delete mode 100644 apps/troubleshooting/__init__.py delete mode 100644 apps/troubleshooting/models.py delete mode 100644 apps/troubleshooting/tests.py delete mode 100644 apps/troubleshooting/views.py (limited to 'apps') diff --git a/apps/checkin/models.py b/apps/checkin/models.py index efea6ff..82874a4 100644 --- a/apps/checkin/models.py +++ b/apps/checkin/models.py @@ -85,6 +85,9 @@ class ServiceOrder(models.Model): devices = models.ManyToManyField(Device, null=True) tags = models.ManyToManyField(TaggedItem) + servo_id = models.CharField(max_length=7, default='', editable=False) + status = models.TextField(default='', blank=True) + def add_accessory(self, accessory): tag = TaggedItem() tag.kind = 'accessory' diff --git a/apps/core/forms.py b/apps/core/forms.py index 66a6287..051663b 100644 --- a/apps/core/forms.py +++ b/apps/core/forms.py @@ -1,12 +1,43 @@ from django import forms +from django.contrib import auth +from apps.core.models import ServiceProvider, User +from django.forms.extras.widgets import SelectDateWidget class LoginForm(forms.Form): - username = forms.CharField(widget=forms.TextInput(attrs={ - 'class': 'form-control', - 'placeholder': 'Email address' - })) - password = forms.CharField(widget=forms.PasswordInput(attrs={ - 'class': 'form-control', - 'placeholder': 'password' - })) + username = forms.CharField() + password = forms.CharField(widget=forms.PasswordInput()) + + def clean(self): + cleaned_data = super(LoginForm, self).clean() + user = auth.authenticate( + username=cleaned_data['username'], + password=cleaned_data['password'] + ) + if user is not None and user.is_active: + cleaned_data['user'] = user + else: + raise forms.ValidationError('Incorrect username or password') + + return cleaned_data + + +class EditProviderForm(forms.ModelForm): + class Meta: + model = ServiceProvider + widgets = { + 'date_started': SelectDateWidget(), + 'date_ends': SelectDateWidget() + } + + +class ProfileEditForm(forms.ModelForm): + class Meta: + model = User + fields = ('first_name', 'last_name', 'email') + + +class UserEditForm(forms.ModelForm): + class Meta: + model = User + exclude = ('groups', 'user_permissions') diff --git a/apps/core/models.py b/apps/core/models.py index 04d7582..7e98cbb 100644 --- a/apps/core/models.py +++ b/apps/core/models.py @@ -1,16 +1,36 @@ import uuid +import gsxws from django.db import models from django.contrib.contenttypes import generic from django.contrib.auth.models import AbstractUser from django.contrib.contenttypes.models import ContentType +from django.utils.translation import ugettext as _ from django.template.defaultfilters import slugify +class User(AbstractUser): + sp = models.ForeignKey('ServiceProvider', null=True) + + def __unicode__(self): + if self.first_name and self.last_name: + return self.first_name + ' ' + self.last_name + return self.username + + def get_absolute_url(self): + return '/manage/users/%d/' % self.pk + + class ServiceProvider(models.Model): + name = models.CharField( + unique=True, + max_length=128, + default='Apple Service Provider' + ) uuid = models.CharField( unique=True, max_length=36, + editable=False, default=lambda: str(uuid.uuid4()) ) BACKEND_CHOICES = ( @@ -23,19 +43,29 @@ class ServiceProvider(models.Model): default='servo', choices=BACKEND_CHOICES ) - name = models.CharField( - max_length=128, - default='Apple Service Provider' - ) + http_url = models.URLField(null=True, blank=True) http_username = models.CharField(max_length=128, null=True, blank=True) http_password = models.CharField(max_length=128, null=True, blank=True) smtp_address = models.EmailField(null=True, blank=True) servo_url = models.URLField(null=True, blank=True) + install_id = models.CharField(max_length=2) + is_active = models.BooleanField(default=True) + main_user = models.ForeignKey(User, null=True) -class User(AbstractUser): - sp = models.ForeignKey(ServiceProvider, null=True) + def __unicode__(self): + return self.name + + def get_absolute_url(self): + return '/manage/providers/%d/' % self.pk + + +class Subscription(models.Model): + sp = models.ForeignKey(ServiceProvider) + start_date = models.DateField() + end_date = models.DateField() + billing_period = models.PositiveIntegerField(default=12) class TaggedItem(models.Model): @@ -57,3 +87,21 @@ class TaggedItem(models.Model): class Meta: unique_together = ("content_type", "object_id", "tag",) + + +class GsxAccount(models.Model): + sp = models.OneToOneField(ServiceProvider) + sold_to = models.CharField(max_length=10) + user_id = models.CharField(max_length=128) + password = models.CharField(max_length=256) + region = models.CharField( + max_length=3, + choices=gsxws.GSX_REGIONS, + verbose_name=_("Region") + ) + environment = models.CharField( + max_length=2, + verbose_name=_("Environment"), + choices=gsxws.ENVIRONMENTS, + default=gsxws.ENVIRONMENTS[0][0] + ) diff --git a/apps/core/templates/login.html b/apps/core/templates/login.html deleted file mode 100644 index 5f53b32..0000000 --- a/apps/core/templates/login.html +++ /dev/null @@ -1,2 +0,0 @@ -{% extends 'default.html' %} - diff --git a/apps/core/views.py b/apps/core/views.py index fc8f941..9e875e8 100644 --- a/apps/core/views.py +++ b/apps/core/views.py @@ -1,17 +1,80 @@ -from django.shortcuts import render -from django.views.generic.edit import FormView +from django.contrib import auth +from django.contrib import messages +from django.shortcuts import redirect from django.views.generic.list import ListView -from apps.core.forms import LoginForm +from django.views.generic.edit import FormView, CreateView, UpdateView +from apps.core.forms import LoginForm, EditProviderForm, UserEditForm +from django.utils.translation import ugettext as _ -from apps.core.models import ServiceProvider +from apps.core.models import ServiceProvider, User +from apps.docs.models import Article + +class DefaultListView(ListView): + template_name = 'core/list.html' + + +class DefaultEditView(UpdateView): + template_name = 'core/form.html' + def get_context_data(self, **kwargs): + context = super(DefaultEditView, self).get_context_data(**kwargs) + context['object_list'] = self.model.objects.all() + return context + + +class CreateSiteView(CreateView): + model = ServiceProvider + form_class = EditProviderForm + template_name = 'core/form.html' + success_url = '/manage/sites/' class LoginView(FormView): - template_name = 'login.html' form_class = LoginForm - success_url = '/manage/sites/' + template_name = 'login.html' + success_url = '/manage/providers/' + + def form_valid(self, form): + auth.login(self.request, form.cleaned_data['user']) + return super(LoginView, self).form_valid(form) + + +class ProvidersListView(DefaultListView): + model = ServiceProvider -class SitesListView(ListView): +class ProviderEditView(DefaultEditView): model = ServiceProvider - template_name = 'manage/sites.html' + + +class UserListView(DefaultListView): + model = User + + +class UserEditView(DefaultEditView): + model = User + form_class = UserEditForm + + +class UserCreateView(CreateView): + model = User + form_class = UserEditForm + template_name = 'core/form.html' + + +class ArticleListView(DefaultListView): + model = Article + + +class ArticleEditView(DefaultEditView): + model = Article + + +class ArticleCreateView(CreateView): + model = Article + template_name = 'core/form.html' + + +def logout(request): + auth.logout(request) + messages.success(request, _('You have signed out')) + return redirect('/manage/') diff --git a/apps/docs/models.py b/apps/docs/models.py index bd95207..f95da57 100644 --- a/apps/docs/models.py +++ b/apps/docs/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.db import models from django.template.defaultfilters import slugify @@ -11,17 +9,20 @@ class Image(models.Model): class Article(models.Model): slug = models.SlugField(editable=False) - title = models.CharField(max_length=255) - content = models.TextField() + title = models.CharField(max_length=255, default='New Article') + content = models.TextField(default='') published = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True) - images = models.ManyToManyField(Image, null=True) + images = models.ManyToManyField(Image, null=True, editable=False) def __unicode__(self): return self.title + def get_absolute_url(self): + return '/manage/docs/%d/' % self.pk + def save(self, *args, **kwargs): self.slug = slugify(self.title) super(Article, self).save(*args, **kwargs) diff --git a/apps/issues/__init__.py b/apps/issues/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/issues/forms.py b/apps/issues/forms.py new file mode 100644 index 0000000..eee223f --- /dev/null +++ b/apps/issues/forms.py @@ -0,0 +1,7 @@ +from django import forms +from apps.issues.models import Issue + + +class IssueForm(forms.ModelForm): + class Meta: + model = Issue diff --git a/apps/issues/models.py b/apps/issues/models.py new file mode 100644 index 0000000..bcded0c --- /dev/null +++ b/apps/issues/models.py @@ -0,0 +1,33 @@ +from django.db import models +from django.utils.translation import ugettext as _ + +from apps.core.models import ServiceProvider +from apps.checkin.models import ServiceOrder + + +class Issue(models.Model): + sp = models.ForeignKey(ServiceProvider) + description = models.CharField(max_length=256, default=_('No power')) + + def __unicode__(self): + return self.description + + def get_absolute_url(self): + return '/manage/issues/%d/' % self.pk + + +class Question(models.Model): + issue = models.ForeignKey(Issue) + question = models.CharField(max_length=256) + required = models.BooleanField(default=True) + + +class Choice(models.Model): + question = models.ForeignKey(Question) + choice = models.CharField(max_length=256) + + +class Answer(models.Model): + choice = models.ForeignKey(Choice) + answer = models.CharField(max_length=256) + so = models.ForeignKey(ServiceOrder) diff --git a/apps/issues/tests.py b/apps/issues/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/apps/issues/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/apps/issues/views.py b/apps/issues/views.py new file mode 100644 index 0000000..ed60ed7 --- /dev/null +++ b/apps/issues/views.py @@ -0,0 +1,18 @@ +from django.views.generic.list import ListView +from django.views.generic.edit import FormView, CreateView, UpdateView +from apps.core.views import DefaultEditView, DefaultListView +from apps.issues.models import Issue + + +class IssueListView(DefaultListView): + model = Issue + + +class IssueCreateView(CreateView): + model = Issue + template_name = 'core/form.html' + success_url = '/manage/issues/' + + +class IssueEditView(DefaultEditView): + model = Issue diff --git a/apps/troubleshooting/__init__.py b/apps/troubleshooting/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/troubleshooting/models.py b/apps/troubleshooting/models.py deleted file mode 100644 index cd1edf3..0000000 --- a/apps/troubleshooting/models.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.db import models -from apps.core.models import ServiceProvider -from apps.checkin.models import ServiceOrder - - -class Question(models.Model): - sp = models.ForeignKey(ServiceProvider) - required = models.BooleanField(default=True) - question = models.CharField(max_length=256) - - -class Choice(models.Model): - question = models.ForeignKey(Question) - choice = models.CharField(max_length=256) - - -class Answer(models.Model): - choice = models.ForeignKey(Choice) - so = models.ForeignKey(ServiceOrder) diff --git a/apps/troubleshooting/tests.py b/apps/troubleshooting/tests.py deleted file mode 100644 index 501deb7..0000000 --- a/apps/troubleshooting/tests.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) diff --git a/apps/troubleshooting/views.py b/apps/troubleshooting/views.py deleted file mode 100644 index 60f00ef..0000000 --- a/apps/troubleshooting/views.py +++ /dev/null @@ -1 +0,0 @@ -# Create your views here. -- cgit v1.2.3