1. Jinesh Narayanan
  2. mass mailer

Commits

CCMT  committed a418890

create group - csrf warning

  • Participants
  • Parent commits 2f14e77
  • Branches master

Comments (0)

Files changed (16)

File Group/__init__.py

Empty file added.

File Group/forms.py

View file
+'''
+Created on Apr 8, 2013
+
+@author: CCMT
+'''
+from django.forms import ModelForm
+from Group.models import Group
+from django import forms
+
+
+class GroupForm(ModelForm):
+
+    description = forms.CharField(widget=forms.Textarea(attrs={'class': 'span3'}))
+
+    class Meta:
+        model = Group
+        fields = ('name', 'description')
+
+    def save(self, commit=True):
+        pass

File Group/models.py

View file
+'''
+Created on Apr 9, 2013
+
+@author: CCMT
+'''
+from django.contrib.auth.models import User
+from django.db import models
+
+
+class Member(models.Model):
+    
+    GENDER_CHOICES = (('MALE', 'Male'),
+                      ('FEMALE', 'Female'))
+    
+    user = models.ForeignKey(User)
+    first_name = models.CharField(max_length=30)
+    last_name = models.CharField(max_length=30)
+    email = models.EmailField(max_length=150)
+    gender = models.CharField(max_length=6, choices=GENDER_CHOICES)
+    dob = models.DateField()
+    phone = models.CharField(max_length=20)
+    organization = models.CharField(max_length=50)
+    
+    
+class Group(models.Model):
+    user = models.ForeignKey(User)
+    name = models.CharField(max_length=30)
+    description = models.CharField(max_length=200)
+    short_code = models.CharField(max_length=30)
+    member = models.ManyToManyField(Member)
+    

File Group/templates/group/group_form.html

View file
+<h2 class="sub-header">Create Group</h2>
+<form id="create-group-form" class="well" action={% url create-group %} method="POST">
+    {% csrf_token %}
+    {{ form.as_table }}
+    <br/>
+    <input type="submit" class="btn btn-primary" id="add-contact-submit">
+</form>

File Group/templates/group/groups.html

Empty file added.

File Group/urls.py

View file
+'''
+Created on Apr 9, 2013
+
+@author: CCMT
+'''
+from django.conf.urls import patterns, url
+
+urlpatterns = patterns('Group.views',
+                       url(r'^$', 'group', name="group"),
+                       url(r'^create/$', 'create_group', name="create-group"),
+                       )

File Group/views.py

View file
+'''
+Created on Apr 9, 2013
+
+@author: CCMT
+'''
+from django.shortcuts import render_to_response
+from django.contrib.auth.decorators import login_required
+from django.template import RequestContext
+from django.template.loader import render_to_string
+from django.http import HttpResponse
+from django.utils import simplejson
+
+from Group.forms import GroupForm
+
+
+@login_required(login_url='/auth/')
+def group(request):
+    return render_to_response('home.html',context_instance=RequestContext(request))
+
+
+@login_required(login_url='/auth/')
+def create_group(request):
+    if request.method == 'POST':
+        form = GroupForm(data=request.POST)
+        if form.is_valid():
+            form.save()
+            html = render_to_string('group/groups.html', {'groups':'groups'})
+        else:
+            html = render_to_string('group/group_form.html', {'form':form})
+
+    else:
+        form = GroupForm()
+        html = render_to_string('group/group_form.html', {'form':form})
+
+    data = {'html': html}
+    json = simplejson.dumps(data)
+    return HttpResponse(json, mimetype='application/json')

File MassMail/db.sqlite3

Binary file modified.

File MassMail/models.py

View file
     approved = models.BooleanField(default=False)
     contact_size = models.IntegerField(default=0)
     emails_count = models.IntegerField(default=0)
-    
-class Group(models.Model):
-    user = models.ForeignKey(User)
-    name = models.CharField(max_length=30)
-    description = models.CharField(max_length=200)
-    short_code = models.CharField(max_length=30)
+
+    

File MassMail/settings.py

View file
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'MassMail',
+    'Group',
     # Uncomment the next line to enable the admin:
     'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:

File MassMail/static/css/styles.css

View file
     padding: 20px;
 }
 
+.sub-header{
+    height: 32px;
+    line-height: 32px;
+    text-transform: uppercase;
+    width: 300px;
+    border: 0;
+    font-size:18px;
+}
+
 #content{
     border-bottom: 1px solid #B9C6E4;
     min-height: 450px;

File MassMail/static/javascript/common.js

View file
         }
     });
 
-    $("#view-contacts").click(function (){
-        var content = $("#content");
+    $("#create-group").click(function (e){
+    	console.log('create group clicked');
+    	e.preventDefault();
+    	
+        var content = $("#formDiv");
+        
         $.ajax({
-            url:'/address/all/',
+            url:'/group/create/',
             type: 'GET',
             success: function (resp){
+                console.log('response received...',resp);
                 $(content).html(resp.html);
             }
         });
     });
 
 
-    $("#add-contact").click(function (){
-        var content = $("#content");
-        $.ajax({
-            url:'/address/add/',
-            type: 'GET',
-            success: function (resp){
-                $(content).html(resp.html);
-            }
-        });
-    });
-
     $("#add-contact-submit").live('click', function (e){
             e.preventDefault();
-            var form = $("#add-contact-form");
-            var content = $("#content");
+            var form = $("#create-group-form");
+            var content = $("#formDiv");
             $.ajax({
-                url:'/address/add/',
+                url:'/group/create/',
                 type: 'POST',
                 data: $(form).serialize(),
                 dataType: 'json',

File MassMail/templates/base.html

View file
 <!DOCTYPE html>
 <html>
   <head>
-    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css"/>
+    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}bootstrap/css/bootstrap.min.css"/>
     <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/styles.css"/>
     <script type="text/javascript" src="{{ STATIC_URL }}javascript/jquery.min.js"></script>
     <script type="text/javascript" src="{{ STATIC_URL }}bootstrap/js/bootstrap.min.js"></script>

File MassMail/templates/home.html

View file
 		     Contract
 		    </a>
 		  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
-		    <li><a href="#">Create Contract</a></li>
-		    <li><a href="#">Update Contract</a></li>
+		    <li><a href="#" id="create-contract">Create Contract</a></li>
+		    <li><a href="#" id="update-contract">Update Contract</a></li>
 		  </ul>
 	  </li>
       <li class="dropdown">
       	<a href="#" class="dropdown-toggle" data-toggle="dropdown">
-      	group 
+      	Group 
       	</a>
 		  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
-		    <li><a href="#">Create Group</a></li>
+		    <li><a href="#" id="create-group">Create Group</a></li>
 		  </ul>
       </li>
-      <li><a href="{% url logout %}" > logout </a></li>
+      <li><a href="{% url logout %}" > Logout </a></li>
     </ul>
   </div>
 </div>
 
+<div id="formDiv">
+
+</div>
+
 {% endblock %}

File MassMail/urls.py

View file
     url(r'^signup/$', 'MassMail.views.signup', name='signup'),
     url(r'^logout/$', 'MassMail.views.logout', name='logout'),
     url(r'^contract/$', 'MassMail.views.contract', name='contract'),
-    url(r'^group/$', 'MassMail.views.group', name='group'),
+    url(r'^group/', include('Group.urls')),
     url(r'^auth/$', 'django.contrib.auth.views.login', { 'template_name' : 'signup/login.html',
           'authentication_form' : LoginForm}, name='auth_login'),
  

File MassMail/views.py

View file
 def contract(request):
     return render_to_response('home.html',context_instance=RequestContext(request))
 
-@login_required(login_url='/auth/')
-def group(request):
-    return render_to_response('home.html',context_instance=RequestContext(request))