Commit d3b281d9 authored by Christophe Siraut's avatar Christophe Siraut

Initial commit.

parents
File added
from django.contrib import admin
# Register your models here.
File added
from django.db import models
class MailTemplate(models.Model):
name = models.CharField(max_length=128)
body = models.TextField()
def __unicode__(self):
return self.name
File added
{% extends 'base.html' %}
{% block breadcrumb %}
<ul class="breadcrumb">
<li><a href="{% url 'content:home' %}">ICT</a></li>
<li><a href="{% url 'mailer' %}">Mailer</a></li>
{% block bread %}{% endblock %}
</ul>
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
<h2>Mail</h2>
<form action="" method="get">
{{ templateselectform }}
<input type="submit" value="Select" class="btn btn-default"/>
<a class="btn btn-default" href="{% url 'mail-template-new' %}"/>New</a>
<a class="btn btn-default" href="{% url 'mail-template-list' %}"/>LIst</a>
</form>
<br/>
<form action="" method="post">
<table>
{% csrf_token %}
{{ form.as_table }}
<tr><td></td><td> <input type="submit" value="Send message" class="btn btn-primary"/> </td></tr>
</table>
</form>
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
<h2>Template</h2>
<form action="" method="post">
<table>
{% csrf_token %}
{{ form.as_table }}
<tr><td></td><td> <input type="submit" value="Save" class="btn btn-primary"/> </td></tr>
</table>
</form>
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
<h2>Templates</h2>
{% include 'tableview/table.html' %}
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import patterns, url
from .views import MailerView, TemplateCreateView, TemplateUpdateView, TemplateTableView
urlpatterns = patterns(
'',
url(r'^$', MailerView.as_view(), name='mailer'),
url(r'^templates/new/$',
TemplateCreateView.as_view(),
name='mail-template-new'),
url(r'^templates/(?P<pk>.*)/$',
TemplateUpdateView.as_view(),
name='mail-template'),
url(r'^templates/$',
TemplateTableView.as_view(),
name='mail-template-list'),
)
File added
from django.shortcuts import render
from django.views.generic.edit import FormView, CreateView, UpdateView
from django import forms
from .models import MailTemplate
from tableview.views import TableView
import django_tables2 as tables
from django_tables2.utils import A
class MailerForm(forms.Form):
sender = forms.CharField(
widget=forms.TextInput(attrs={'readonly': 'readonly'}))
to = forms.CharField()
message = forms.CharField(widget=forms.Textarea)
def send_email(self):
# send email using the self.cleaned_data dictionary
pass
class TemplateSelectForm(forms.Form):
template = forms.ModelChoiceField(
queryset=MailTemplate.objects.all())
class MailerView(FormView):
template_name = 'mailer/mailer.html'
form_class = MailerForm
success_url = '/mailer/'
template = None
def form_valid(self, form):
# This method is called when valid form data has been POSTed.
# It should return an HttpResponse.
form.send_email()
return super(MailerView, self).form_valid(form)
def get_initial(self):
if self.request.GET.getlist('template', None):
self.template = MailTemplate.objects.get(id=self.request.GET.getlist('template')[0])
return {'sender': self.request.user.email,
'message': self.template.body}
def get_context_data(self, **kwargs):
context = super(MailerView, self).get_context_data(**kwargs)
print context
context['templateselectform'] = TemplateSelectForm
if self.template:
context['templateselectform'] = TemplateSelectForm(initial={'template': self.template.pk})
print context
return context
class TemplateTable(tables.Table):
name = tables.LinkColumn('mail-template', args=[A('pk')])
class Meta:
model = MailTemplate
attrs = {"class": "table table-bordered table-striped"}
class TemplateTableView(TableView):
model = MailTemplate
table_class = TemplateTable
success_url = '/mailer/'
class TemplateCreateView(CreateView):
model = MailTemplate
success_url = '/mailer/'
class TemplateUpdateView(UpdateView):
model = MailTemplate
success_url = '/mailer/templates/'
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment