Skip to content

Commit

Permalink
Contact Us page implemented
Browse files Browse the repository at this point in the history
Contact Us page implemented
  • Loading branch information
vidyasagar-r authored and ashwin31 committed Jul 20, 2016
1 parent 76b6223 commit d16a8fa
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 6 deletions.
41 changes: 41 additions & 0 deletions django_blog_it/django_blog_it/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ class Meta:
model = ContactUsSettings
exclude = ()

def __init__(self, *args, **kwargs):
super(ContactUsSettingsForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
if max(enumerate(iter(self.fields)))[0] != field:
self.fields[field].widget.attrs.update({
'class': 'form-control',
"placeholder": "Please enter your " + field.replace('_', ' ').capitalize()
})


class BlogThemeForm(forms.ModelForm):

Expand All @@ -180,3 +189,35 @@ def __init__(self, *args, **kwargs):
'class': 'form-control',
"placeholder": "Please enter your Theme " + field.capitalize()
})


class ContactForm(forms.Form):
contact_name = forms.CharField(max_length=128, required=True)
contact_email = forms.EmailField(required=True)
contact_website = forms.URLField(
max_length=200, required=True, help_text="Enter Your Website URL here")
content = forms.CharField(
required=True,
widget=forms.Textarea
)

def clean(self):
cleaned_data = super(ContactForm, self).clean()
contact_website = cleaned_data.get('contact_website')

if contact_website and not contact_website.startswith('http://'):
contact_website = 'http://' + contact_website
cleaned_data['contact_website'] = contact_website

return cleaned_data

def __init__(self, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
self.fields['contact_name'].widget.attrs['placeholder'] = "Enter Your Name (Required)"
self.fields['contact_email'].widget.attrs['placeholder'] = "Enter Your Email (Required)"
self.fields['contact_website'].widget.attrs['placeholder'] = "Enter Your Website (Required)"
self.fields['content'].widget.attrs['placeholder'] = "What do you want to say?"
for field in iter(self.fields):
self.fields[field].widget.attrs.update({
'class': 'form-control'
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{% extends 'dashboard/new_base.html' %}
{% load staticfiles %}
{% block title %}
Configure Contact Us.
{% endblock %}
{% block extra_css %}
{% endblock %}
{% block content %}
<div class="row no_row_margin heading_count">
<div class="heading col-md-6" id='page_title'></div>
</div>
<div class="row no_row_margin">
<div class="container-fluid">
<form action="" method="post" id="contact-us-configure-form" role="form">
{% csrf_token %}
<div class="row form_row no_row_margin">
<div class="col-md-12">
<div class="col-md-6">
{% for field in form %}
{% if field.name != 'email_admin' and field.name != 'subject' and field.name != 'body_admin' %}
<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>
{% endif %}
{% endfor %}
</div>
<div class="col-md-6">
{% for field in form %}
{% if field.name == 'email_admin' or field.name == 'subject' or field.name == 'body_admin' %}
<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>
{% endif %}
{% endfor %}
</div>
</div>
<br clear="all">
<div class=" col-md-12 buttons_row text-left">
<button type="submit" class="btn btn-default green_btn"> <i class="fa fa-floppy-o" aria-hidden="true"></i> Save</button>
<button type="reset" class="btn btn-default blue_btn"> <i class="fa fa-refresh" aria-hidden="true"></i> Reset</button>
</div>
</div>
</form>
</div>
</div>
<!-- end of add form div -->
{% endblock content %}
{% 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" %}',
uiColor: '#ffffff',
height: 175,
});
CKEDITOR.replace('body_admin',{
filebrowserUploadUrl: '{% url "upload_photos" %}',
filebrowserBrowseUrl: '{% url "recent_photos" %}',
uiColor: '#ffffff',
height: 175,
});
});

$('#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/blog/';
}
}, 'json');
});
</script>
{% endblock %}
75 changes: 75 additions & 0 deletions django_blog_it/django_blog_it/templates/posts/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% extends 'posts/new_base.html' %}
{% load blog_tags %}
{% block title %} Contact Us {% endblock %}
{% block blog_content %}
<!-- blog_detail_container starts here -->
<div class="blog_detail_container">
<div class="blog_details">
<div class="panel panel-default blog_panel">
<div class="panel-body">
<div class="blog_detail_content contact_container">
<div class="blog_heading">
<span class="head_line"></span>
<span class="heading">Contact Us</span>
</div>
<div class="contact_title">
<p href="#">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled </p>
</div>
<form action="" method="post" id="contact_form" role="form">
{% csrf_token %}
<div class="contact_form">
<div class="row form_row no_row_margin">
<div class="col-md-12">
{% for field in contact_form %}
<div class="form-group">
<div class="controls">
{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endfor %}
</div>
<br clear="all">
<div class=" col-md-12 buttons_row text-left">
<button type="submit" class="btn btn-default green_btn"> <i class="fa fa-send" aria-hidden="true"></i> SUBMIT YOUR COMMENT</button>
<button type="reset" class="btn btn-default blue_btn"> <i class="fa fa-refresh" aria-hidden="true"></i> RESET</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- blog_detail_container ends here -->
{% endblock %}
{% block js_script %}
<script>
$( document ).ready(function() {
$('#myModal').modal('hide');
$('#myModal').on('hidden', function () {
// Load up a new modal...
$('#myModal1').modal('show')
})
});

$('#contact_form').submit(function(event){
event.preventDefault();
$.post("",$('#contact_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="{% url 'contact_us' %}";
}
}, 'json');
});

</script>
{% endblock %}
11 changes: 6 additions & 5 deletions django_blog_it/django_blog_it/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,15 +730,16 @@ def configure_contact_us(request):
if request.method == 'POST':
if contact_us_settings:
form = ContactUsSettingsForm(instance=contact_us_settings,
data=request.POST
)
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.'}
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))
Expand All @@ -748,7 +749,7 @@ def configure_contact_us(request):
else:
form = ContactUsSettingsForm()
context = {'form': form}
return render(request, 'dashboard/contact_us_settings.html', context)
return render(request, 'dashboard/new_contact_us_settings.html', context)


class ThemesList(AdminMixin, ListView):
Expand Down
27 changes: 26 additions & 1 deletion django_blog_it/posts/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from datetime import datetime
from django.shortcuts import render, get_list_or_404, get_object_or_404
from django_blog_it.django_blog_it.models import Post, Category, Tags, Page
from django_blog_it.django_blog_it.forms import ContactForm
from django.db.models import Count
from django_blog_it import settings
from django.http import Http404
from django.contrib import messages
from django.http import Http404, JsonResponse
# cbv
from django.views.generic import ListView, DetailView

Expand Down Expand Up @@ -141,3 +143,26 @@ class PageView(DetailView):
model = Page
slug_url_kwarg = "page_slug"
context_object_name = "page"


def contact_us(request):
form = ContactForm()
if request.POST:
form = ContactForm(request.POST)
if form.is_valid():
# email sending
messages.success(
request, 'Successfully Sent your contact us details.')
data = {'error': False,
'response': 'Successfully Sent your contact us details.'}
else:
data = {'error': True, 'response': form.errors}
return JsonResponse(data)

context = {"description": settings.BLOG_DESCRIPTION,
"title": settings.BLOG_TITLE,
"keywords": settings.BLOG_KEYWORDS,
"author": settings.BLOG_AUTHOR,
"contact_form": form}
context.update(categories_tags_lists())
return render(request, 'posts/contact.html', context)
4 changes: 4 additions & 0 deletions django_blog_it/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

urlpatterns = [
url(r'^$', Home.as_view(), name='index'),
url(r'^blog/contact/$', contact_us, name='contact_us'),
url(r'^blog/category/(?P<category_slug>[-\w]+)/$', SelectedCategoryView.as_view(), name='selected_category'),
url(r'^blog/tags/(?P<tag_slug>[-\w]+)/$', SelectedTagView.as_view(), name='selected_tag'),
url(r'^blog/(?P<year>\w{0,})/(?P<month>\w{0,})/$', ArchiveView.as_view(), name='archive_posts'),
Expand Down Expand Up @@ -116,4 +117,7 @@
url(r'^dashboard/bulk_actions_themes/$',
bulk_actions_themes, name='bulk_actions_themes'),

url(r'^dashboard/contactUs/$',
configure_contact_us, name='configure_contact_us'),

] + static(MEDIA_URL, document_root=MEDIA_ROOT)

0 comments on commit d16a8fa

Please sign in to comment.