From 21a153e8c64afd38d9e20ce23543e53e65b5e2c3 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Thu, 15 Sep 2016 10:50:08 +0530 Subject: added attributes to Profile --- tbc/models.py | 3 +++ tbc/templates/tbc/books.html | 11 ++++++++++- tbc/templates/tbc/profile.html | 1 - tbc/views.py | 32 ++++++++++++++------------------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/tbc/models.py b/tbc/models.py index 0747882..7deb31c 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -80,6 +80,9 @@ class Profile(models.Model): gender = models.CharField(max_length=10, choices=GENDER) phone_no = models.CharField(max_length=15) about_proj = models.CharField(max_length=50, choices=ABOUT_PROJ) + city = models.CharField(max_length=50, default=None) + state = models.CharField(max_length=50, default=None) + pin_code = models.IntegerField(max_length=6, default=None) def __unicode__(self): name = self.user.first_name or 'Profile' return '%s'%(name) diff --git a/tbc/templates/tbc/books.html b/tbc/templates/tbc/books.html index b1d975f..80070f1 100644 --- a/tbc/templates/tbc/books.html +++ b/tbc/templates/tbc/books.html @@ -5,8 +5,17 @@
Books without start and end time +
+ Books without any log available
    - {% for book in books_incomplete %} + {% for book in manual %} +
  1. {{ book.title }}
  2. + {% endfor %} +
+
+ Books with log available, so can be automated +
    + {% for book in auto %}
  1. {{ book.title }}
  2. {% endfor %}
diff --git a/tbc/templates/tbc/profile.html b/tbc/templates/tbc/profile.html index e6f706a..1485849 100644 --- a/tbc/templates/tbc/profile.html +++ b/tbc/templates/tbc/profile.html @@ -15,7 +15,6 @@
{% csrf_token %} {{ form.as_p }} - {{ form.errors }}
diff --git a/tbc/views.py b/tbc/views.py index 647037d..358a606 100644 --- a/tbc/views.py +++ b/tbc/views.py @@ -228,12 +228,10 @@ def user_profile(request): context = {} user = request.user if user.is_authenticated(): + user_profile = Profile.objects.filter(user=user) + profile = user_profile[0] if user_profile.exists() else None if request.method == 'POST': - user_profile = Profile.objects.filter(user=user) - if user_profile.exists(): - form = UserProfileForm(request.POST, instance=user_profile[0]) - else: - form = UserProfileForm(request.POST) + form = UserProfileForm(request.POST, instance=profile) if form.is_valid(): data = form.save(commit=False) data.user = request.user @@ -244,8 +242,7 @@ def user_profile(request): context.update(csrf(request)) context['form'] = form return render_to_response('tbc/profile.html', context) - else: - form = UserProfileForm() + form = UserProfileForm(instance=profile) context.update(csrf(request)) context['form'] = form context['user'] = user @@ -267,7 +264,7 @@ def update_profile(request): context['user'] = user user_profile = Profile.objects.get(user=user) if request.method == "POST": - form = UserProfileForm(request.POST) + form = UserProfileForm(request.POST, instance=user_profile) if form.is_valid(): data = form.save(commit=False) data.user = request.user @@ -278,15 +275,7 @@ def update_profile(request): context['form'] = form return render_to_response('tbc/update-profile.html', context) else: - form = UserProfileForm() - form.initial['about'] = user_profile.about - form.initial['insti_org'] = user_profile.insti_org - form.initial['course'] = user_profile.course - form.initial['dept_desg'] = user_profile.dept_desg - form.initial['dob'] = user_profile.dob - form.initial['gender'] = user_profile.gender - form.initial['phone_no'] = user_profile.phone_no - form.initial['about_proj'] = user_profile.about_proj + form = UserProfileForm(instance=user_profile) context['form'] = form return render_to_response('tbc/update-profile.html', context) @@ -372,12 +361,19 @@ def books(request): books = Book.objects.all() books_incomplete = [] books_complete = [] + auto = [] + manual = [] for book in books: if book.start_time is None or book.end_time is None: books_incomplete.append(book) else: books_complete.append(book) - context = {'books_incomplete': books_incomplete, 'books_complete': books_complete} + for book in books_incomplete: + if book.approved_textbook.all(): + auto.append(book) + else: + manual.append(book) + context = {'auto': auto, 'manual': manual, 'books_complete': books_complete} return render_to_response('tbc/books.html', context) else: return HttpResponseRedirect("/login/?require_login=true") -- cgit