aboutsummaryrefslogtreecommitdiffstats
path: root/apps/core
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-11-17 19:15:30 +0200
committerFilipp Lepalaan <f@230.to>2013-11-17 19:15:30 +0200
commit297419f370ea87458017ee506a2e551e9068b66b (patch)
tree429d3e1b6c7f2facfb3e361b4b708f0d36e8aac8 /apps/core
parentf077badf3163fc36c111dc45fe8d7d6f57d8712a (diff)
downloadmotor.old-297419f370ea87458017ee506a2e551e9068b66b.tar.gz
motor.old-297419f370ea87458017ee506a2e551e9068b66b.tar.bz2
motor.old-297419f370ea87458017ee506a2e551e9068b66b.zip
Swicthing machines
Diffstat (limited to 'apps/core')
-rw-r--r--apps/core/forms.py47
-rw-r--r--apps/core/models.py60
-rw-r--r--apps/core/templates/login.html2
-rw-r--r--apps/core/views.py79
4 files changed, 164 insertions, 24 deletions
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/')