Commit d3b281d9 authored by Christophe Siraut's avatar Christophe Siraut

Initial commit.

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):
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 %}
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
<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 action="" method="post">
{% csrf_token %}
{{ form.as_table }}
<tr><td></td><td> <input type="submit" value="Send message" class="btn btn-primary"/> </td></tr>
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_table }}
<tr><td></td><td> <input type="submit" value="Save" class="btn btn-primary"/> </td></tr>
{% endblock %}
{% extends 'mailer/base.html' %}
{% block content %}
{% 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'),
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
class TemplateSelectForm(forms.Form):
template = forms.ModelChoiceField(
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.
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':,
'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':})
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