Skip to content

Commit

Permalink
Merge pull request #63 from MicroPyramid/configurable_contact_us
Browse files Browse the repository at this point in the history
added configurable contactus page settings issue #22
  • Loading branch information
chaitu210 committed Jun 1, 2016
2 parents 62972c4 + c404c01 commit 1d3577c
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
9 changes: 8 additions & 1 deletion django_blog_it/django_blog_it/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from .models import Post, Category, Page, Menu
from .models import Post, Category, Page, Menu, ContactUsSettings
from django.template.defaultfilters import slugify
# for authentication
from django.contrib.auth import authenticate
Expand Down Expand Up @@ -87,3 +87,10 @@ class MenuForm(forms.ModelForm):
class Meta:
model = Menu
exclude = ('lvl',)


class ContactUsSettingsForm(forms.ModelForm):

class Meta:
model = ContactUsSettings
exclude = ()
27 changes: 27 additions & 0 deletions django_blog_it/django_blog_it/migrations/0009_contactussettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-01 08:34
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_blog_it', '0008_post_featured_image'),
]

operations = [
migrations.CreateModel(
name='ContactUsSettings',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('from_email', models.EmailField(max_length=254)),
('reply_to_email', models.EmailField(blank=True, max_length=254, null=True)),
('email_admin', models.EmailField(max_length=254)),
('subject', models.CharField(max_length=500)),
('body_user', models.TextField()),
('body_admin', models.TextField()),
],
),
]
9 changes: 9 additions & 0 deletions django_blog_it/django_blog_it/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,12 @@ def has_children(self):
if self.get_children():
return True
return False


class ContactUsSettings(models.Model):
from_email = models.EmailField()
reply_to_email = models.EmailField(blank=True, null=True)
email_admin = models.EmailField()
subject = models.CharField(max_length=500)
body_user = models.TextField()
body_admin = models.TextField()
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% extends 'dashboard/base.html' %}
{% load staticfiles %}
{% block title %}
Configure Contact Us.
{% endblock %}
{% block extra_css %}
{% endblock %}
{% block content %}
<div class="row" id="head_style">
<h3 id="page_title"></h3>
</div>
<div class="row">
<form action="" method="post" id="contact-us-configure-form" role="form">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label>{{ field.label }} :</label>
<div class="controls">
{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endfor %}
<div class="form-group">
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</form>
</div>
<!-- end of add form div -->
{% endblock %}
{% block js_script %}

<script type="text/javascript">
$(document).ready(function(){

// for form submission
CKEDITOR.replace('body_user',{
filebrowserUploadUrl: '{% url "upload_photos" %}',
filebrowserBrowseUrl: '{% url "recent_photos" %}'
});
CKEDITOR.replace('body_admin',{
filebrowserUploadUrl: '{% url "upload_photos" %}',
filebrowserBrowseUrl: '{% url "recent_photos" %}'
});
});

$('#contact-us-configure-form').submit(function(event){
event.preventDefault();
$('#id_body_user').val(CKEDITOR.instances.id_body_user.getData());
$('#id_body_admin').val(CKEDITOR.instances.id_body_admin.getData());
$.post("",$('#contact-us-configure-form').serialize(), function(data){
if(data.error){
$('p.error_required').remove();
for (var key in data.response) {
$('#id_' + key).after('<p class="error_required">* ' + data.response[key] + '</p>');
}
}else{
//alert(data['response']);
window.location='/dashboard/';
}
}, 'json');
});
</script>
{% endblock %}
25 changes: 25 additions & 0 deletions django_blog_it/django_blog_it/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,28 @@ def edit_menu(request, pk):
return HttpResponse(json.dumps(data))
context = {'form': form, 'menu_obj': menu_obj}
return render(request, 'dashboard/menu/manage.html', context)


@active_admin_required
def configure_contact_us(request):
contact_us_settings = ContactUsSettings.objects.all().last()
if request.method == 'POST':
if contact_us_settings:
form = ContactUsSettingsForm(instance=contact_us_settings, data=request.POST)
else:
form = ContactUsSettingsForm(request.POST)

if form.is_valid():
form.save()
messages.success(request, 'Successfully saved your contact us details.')
data = {'error': False, 'response': 'Successfully saved your contact us details.'}
else:
data = {'error': True, 'response': form.errors}
return HttpResponse(json.dumps(data))
else:
if contact_us_settings:
form = ContactUsSettingsForm(instance=contact_us_settings)
else:
form = ContactUsSettingsForm()
context = {'form': form}
return render(request, 'dashboard/contact_us_settings.html', context)

0 comments on commit 1d3577c

Please sign in to comment.