Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email form #273

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HTTP_200/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'debug_toolbar',
'import_export',
'wifi',
'emailform',
'rest_framework_docs',
'rest_framework.authtoken',
'notifications',
Expand Down Expand Up @@ -263,6 +264,7 @@
]

MEDIA_ROOT = os.path.join(TEMPLATE_DIR, 'media')
MEDIA_URL = '/media/'

SPAGHETTI_SAUCE = {
'apps': ['auth', 'notices', 'profiles', 'notifications'],
Expand Down
4 changes: 4 additions & 0 deletions HTTP_200/templates/bookmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<a href="{% url "student-wifi" %}">
<i class="fa fa-wifi"></i> &nbsp;Wifi-Form</a>
</li>
<li class=" move-in">
<a href="{% url "student-email" %}">
<i class="fa fa-envelope"></i> &nbsp;Email-Form</a>
</li>
{% endif %}
<li class="active move-in">
<a href="{% url "bookmark-list" %}">
Expand Down
539 changes: 539 additions & 0 deletions HTTP_200/templates/email/studentemailform.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions HTTP_200/templates/notices/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
<a href="{% url "student-wifi" %}">
<i class="fa fa-wifi"></i> &nbsp;Wifi-Form</a>
</li>
<li class=" move-in">
<a href="{% url "student-email" %}">
<i class="fa fa-envelope"></i> &nbsp;Email-Form</a>
</li>
{% endif %}
<li class="{% if request.get_full_path == '/notices/bookmark/' %}active{% endif %} move-in">
<a href="{% url "bookmark-list" %}">
Expand Down
4 changes: 4 additions & 0 deletions HTTP_200/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
<a href="{% url "student-wifi" %}">
<i class="fa fa-wifi"></i> &nbsp;Wifi-Form</a>
</li>
<li class=" move-in">
<a href="{% url "student-email" %}">
<i class="fa fa-envelope"></i> &nbsp;Email-Form</a>
</li>
{% endif %}
<li class=" move-in">
<a href="{% url "bookmark-list" %}">
Expand Down
4 changes: 4 additions & 0 deletions HTTP_200/templates/wifi/studentwifiform.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
<a href="{% url "student-wifi" %}">
<i class="fa fa-wifi"></i> &nbsp;Wifi-Form</a>
</li>
<li class=" move-in">
<a href="{% url "student-email" %}">
<i class="fa fa-envelope"></i> &nbsp;Email-Form</a>
</li>
{% endif %}
<li class=" move-in">
<a href="{% url "user-profile" user_id=request.user.username %}">
Expand Down
1 change: 1 addition & 0 deletions HTTP_200/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
url(r'^students/create/single/$', SingleUser.as_view(), name='single_user_create'),
url(r'^students/create/$', BulkUser.as_view(), name='bulk_students_create'),
url(r'wifi/', include('wifi.urls')),
url(r'emailforms/', include('emailform.urls')),

# api urls
url(r'^api/profiles/', include("profiles.api.urls", namespace='profiles_api')),
Expand Down
1 change: 1 addition & 0 deletions apps/emailform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'emailform.apps.AuthConfig'
11 changes: 11 additions & 0 deletions apps/emailform/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from .models import EmailDetail


class EmailAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'email', 'name', 'hod_approval', 'created', 'modified')
search_fields = ('email', 'name', 'email_purpose')
list_filter = ('hod_approval',)


admin.site.register(EmailDetail, EmailAdmin)
7 changes: 7 additions & 0 deletions apps/emailform/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class AuthConfig(AppConfig):
name = 'emailform'
verbose_name = _("Email Form")
10 changes: 10 additions & 0 deletions apps/emailform/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import forms
from .models import EmailDetail


class EmailForm(forms.ModelForm):

class Meta:
model = EmailDetail
fields = ['email_purpose', 'attachment', 'hod_approval']
exclude = ['user', ]
27 changes: 27 additions & 0 deletions apps/emailform/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='EmailDetail',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('email_purpose', models.TextField(default=None, max_length=200, null=True, blank=True)),
('attachment', models.FileField(null=True, upload_to=b'forms/email/', blank=True)),
('hod_approved_email', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True, verbose_name=b'Created', null=True)),
('modified', models.DateTimeField(auto_now=True, verbose_name=b'Last Modified', null=True)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
]
19 changes: 19 additions & 0 deletions apps/emailform/migrations/0002_auto_20210924_1514.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('emailform', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='emaildetail',
old_name='hod_approved_email',
new_name='hod_approval',
),
]
Empty file.
29 changes: 29 additions & 0 deletions apps/emailform/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import models
from django.contrib.auth.models import User


class EmailDetail(models.Model):
'''
It stores information about the email form of all users.
'''
user = models.OneToOneField(User)
email_purpose = models.TextField(max_length=200,
blank=True,
null=True,
default=None)
attachment = models.FileField(upload_to='forms/email/',
blank=True,
null=True)
hod_approval = models.BooleanField(default=False)

created = models.DateTimeField("Created", null=True, auto_now_add=True)
modified = models.DateTimeField("Last Modified", null=True, auto_now=True)

def email(self):
return "%s" % (self.user.email)

def name(self):
return "%s" % (self.user.first_name)

def __unicode__(self):
return "%s" % (self.user)
1 change: 1 addition & 0 deletions apps/emailform/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
7 changes: 7 additions & 0 deletions apps/emailform/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import url
from emailform.views import StudentEmailForm


urlpatterns = [
url(r'^email$', StudentEmailForm.as_view(), name="student-email"),
]
47 changes: 47 additions & 0 deletions apps/emailform/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from .models import EmailDetail
from profiles.models import StudentDetail
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from braces.views import LoginRequiredMixin
from django.views.generic import View
from django.core.urlresolvers import reverse
from notices.decorators import student_profile_complete, default_password_change
from django.utils.decorators import method_decorator
from django.contrib import messages
from django.shortcuts import render
from .forms import EmailForm


class StudentEmailForm(LoginRequiredMixin, View):

@method_decorator(default_password_change)
@method_decorator(student_profile_complete)
def get(self, request):
user = User.objects.get(username=request.user.username)
details = StudentDetail.objects.get(user=user)
try:
email_data = EmailDetail.objects.get(user=user)
if email_data:
return render(request, 'email/studentemailform.html', {"user": user, "details": details, "email_data": email_data})
except BaseException:
return render(request, 'email/studentemailform.html', {"user": user, "details": details})

def post(self, request):
user = User.objects.get(username=request.user.username)

try:
email_data = EmailDetail.objects.get(user=user)
email_form = EmailForm(request.POST, request.FILES, instance=email_data)
except BaseException:
email_form = EmailForm(request.POST, request.FILES)

if email_form.is_valid():
email_form = email_form.save(commit=False)
email_form.user = user
email_form.save()
messages.success(request, "Successfully Registered for Email")
return HttpResponseRedirect(reverse("relevent-notice-list"))
else:
print email_form.errors
messages.error(request, "Enter Valid data in the form.")
return HttpResponseRedirect(reverse("student-email"))
11 changes: 5 additions & 6 deletions apps/notices/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.core.urlresolvers import reverse
from django.contrib.auth.hashers import check_password
from django.contrib import messages
import re


def student_profile_complete(function):
Expand All @@ -18,15 +17,15 @@ def wrapper(request, *args, **kwargs):
except BaseException:
return function(request, *args, **kwargs)

if re.split(r'(\d+)', str(user))[2] == "mca" or re.split(r'(\d+)', str(user))[2] == "mba" or re.split(r'(\d+)', str(user))[2] == "MCA" or re.split(r'(\d+)', str(user))[2] == "MBA":

if user.first_name == "" or user.email == "" or profile.course is None or profile.year is None or profile.contact_no == "None" or profile.address == "None" or profile.father_name == "None" or profile.father_name == "" or profile.address == "" or profile.contact_no == "":
try:
if user.first_name == "" or user.email == "" or profile.course is None or profile.branch is None or profile.year is None or profile.contact_no == "None" or profile.address == "None" or profile.father_name == "None" or profile.father_name == "" or profile.address == "" or profile.contact_no == "":
print("not MBA")
messages.warning(request, "Fill in details to continue")
return HttpResponseRedirect(reverse("user-profile", kwargs={"user_id": str(request.user.username)}))
else:
return function(request, *args, **kwargs)
else:
if user.first_name == "" or user.email == "" or profile.course is None or profile.branch is None or profile.year is None or profile.contact_no == "None" or profile.address == "None" or profile.father_name == "None" or profile.father_name == "" or profile.address == "" or profile.contact_no == "":
except AttributeError:
if user.first_name == "" or user.email == "" or profile.course is None or profile.year is None or profile.contact_no == "None" or profile.address == "None" or profile.father_name == "None" or profile.father_name == "" or profile.address == "" or profile.contact_no == "":
messages.warning(request, "Fill in details to continue")
return HttpResponseRedirect(reverse("user-profile", kwargs={"user_id": str(request.user.username)}))
else:
Expand Down
6 changes: 3 additions & 3 deletions apps/wifi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

urlpatterns = [

url(r'^student/$', StudentWifiForm.as_view(), name="student-wifi"),
url(r'^faculty/$', FacultyWifiForm.as_view(), name="faculty-wifi"),
url(r'^download_excel/$', excel_writer.as_view(), name="excel_writer"),
url(r'^student/$', StudentWifiForm.as_view(), name="student-wifi"),
url(r'^faculty/$', FacultyWifiForm.as_view(), name="faculty-wifi"),
url(r'^download_excel/$', excel_writer.as_view(), name="excel_writer"),
]
2 changes: 1 addition & 1 deletion requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ django-haystack==2.4.0
django-allauth==0.21.0
django-filter==0.11.0
PyJWT==1.7.1
django-braces==1.14.0
django-braces==1.13.0
django-autofixture==0.12.1
django-ckeditor==5.0.2
django-spaghetti-and-meatballs==0.1.1
Expand Down