diff options
author | Jayaram Pai | 2014-04-23 17:18:27 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-04-23 17:18:27 +0530 |
commit | 99bbf8ec16fca5eeec9d0ddad5f0a5ae169e4218 (patch) | |
tree | effff301f9792e9b02c266bd5a2fac055674a2b3 | |
parent | 8dd84484c4afa20d65a8232aba5a0e9931e7a749 (diff) | |
download | spoken-tutorial-forums-99bbf8ec16fca5eeec9d0ddad5f0a5ae169e4218.tar.gz spoken-tutorial-forums-99bbf8ec16fca5eeec9d0ddad5f0a5ae169e4218.tar.bz2 spoken-tutorial-forums-99bbf8ec16fca5eeec9d0ddad5f0a5ae169e4218.zip |
changed slick in index page
changed login:next_url
modified the forms.py for initial value
-rw-r--r-- | forums/settings.py | 4 | ||||
-rw-r--r-- | forums/views.py | 7 | ||||
-rw-r--r-- | forums/wsgi.py | 4 | ||||
-rw-r--r-- | static/forums/templates/user-login.html | 4 | ||||
-rw-r--r-- | static/website/css/main.css | 48 | ||||
-rw-r--r-- | static/website/templates/filter.html | 3 | ||||
-rw-r--r-- | static/website/templates/index.html | 61 | ||||
-rw-r--r-- | static/website/templates/latest_question.html | 11 | ||||
-rw-r--r-- | static/website/templates/new-question.html | 8 | ||||
-rw-r--r-- | website/forms.py | 22 | ||||
-rw-r--r-- | website/models.py | 3 | ||||
-rw-r--r-- | website/templatetags/notify.py | 13 | ||||
-rw-r--r-- | website/views.py | 14 |
13 files changed, 129 insertions, 73 deletions
diff --git a/forums/settings.py b/forums/settings.py index be17520..c2811f4 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -188,5 +188,5 @@ DATABASE_ROUTERS = ['drupal_auth.routers.DrupalAuthRouter'] TEMPLATE_CONTEXT_PROCESSORS += ('website.context_processors.admin_processor', ) COMPRESS_ROOT = PROJECT_DIR + "/static/" -COMPRESS_ENABLED = True -HTML_MINIFY = True +COMPRESS_ENABLED = False +HTML_MINIFY = False diff --git a/forums/views.py b/forums/views.py index 6890d61..a38d6b7 100644 --- a/forums/views.py +++ b/forums/views.py @@ -14,6 +14,9 @@ def user_login(request): if user is not None: if user.is_active: login(request, user) + if 'next' in request.POST: + next_url = request.POST.get('next') + return HttpResponseRedirect(next_url) return HttpResponseRedirect('/') else: return HttpResponse('you are blocked') @@ -21,8 +24,10 @@ def user_login(request): return HttpResponse('Invalid username or password') else: form = UserLoginForm() + next_url = request.GET.get('next') context = { - 'form': form + 'form': form, + 'next': next_url } context.update(csrf(request)) return render_to_response('forums/templates/user-login.html', context) diff --git a/forums/wsgi.py b/forums/wsgi.py index 728eed4..3901802 100644 --- a/forums/wsgi.py +++ b/forums/wsgi.py @@ -24,8 +24,8 @@ sys.path.append('/Sites/venv/forums/') # os.environ["DJANGO_SETTINGS_MODULE"] = "forums.settings" os.environ["DJANGO_SETTINGS_MODULE"] = "forums.settings" -activate_this = '/Sites/venv/bin/activate_this.py' -execfile(activate_this, dict(__file__=activate_this)) +# activate_this = '/Sites/venv/bin/activate_this.py' +# execfile(activate_this, dict(__file__=activate_this)) # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION diff --git a/static/forums/templates/user-login.html b/static/forums/templates/user-login.html index a1951fe..21c4551 100644 --- a/static/forums/templates/user-login.html +++ b/static/forums/templates/user-login.html @@ -16,7 +16,9 @@ <label for="id_username">Password:</label> {% render_field form.password class+="form-control" %} </div> - + {% if next %} + <input type="hidden" name="next" value="{{ next }}"> + {% endif %} <input class="btn btn-sm btn-primary" type="submit" value="Login"> {% endwith %} </form> diff --git a/static/website/css/main.css b/static/website/css/main.css index ae785bc..4726635 100644 --- a/static/website/css/main.css +++ b/static/website/css/main.css @@ -12,23 +12,6 @@ hr { .navbar-default { margin-bottom: 0; } -.carousel, .slick-list { - height: 100px; - margin-right: -2px; -} -.carousel .item { - border: 1px solid #333333; - position: relative; -} -.carousel .thumb { - text-align: center; - height: 75px; -} -.carousel .descp { - position: absolute; - bottom: 0; - width: 100%; -} #filter-container { background: #f5f5f5; padding: 15px; @@ -340,3 +323,34 @@ table .title a { .slick-prev:after { color: #a26dc8; } +.carousel, .slick-list { + height: 245px; + margin-right: -2px; +} +.carousel .thumbnail { + width: 97%; + height: 245px; + border: 1px solid #cccccc; +} +.carousel .thumbnail img { + height: 100px; +} +.carousel .caption .category { + display: block; + width: 100%; + white-space: nowrap; + overflow: hidden; + text-align: center; +} +.carousel .caption .latest { + display: block; + padding: 5px 0 5px 0; + border-top: 1px solid #cccccc; + width: 100%; + white-space: nowrap; + overflow: hidden; + text-align: center; +} +.carousel .caption .btn { + margin-top: 7px; +} diff --git a/static/website/templates/filter.html b/static/website/templates/filter.html index dada403..7496c0c 100644 --- a/static/website/templates/filter.html +++ b/static/website/templates/filter.html @@ -70,7 +70,10 @@ <b> > </b> {{ second_range }} sec {% endif %} + <a class="btn btn-xs btn-success pull-right" href="{% url 'website:new_question' %}?category={{ category|urlencode }}">Ask a new question.</a> </h5> +<br> +<div class="clearfix"></div> <table class="table table-striped table-bordered"> <th> FOSS </th> diff --git a/static/website/templates/index.html b/static/website/templates/index.html index 95c8500..991c777 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -1,45 +1,33 @@ {% extends 'website/templates/base.html' %} {% load static %} {% load count_tags %} +{% load notify %} {% block content %} <div id="carousel-container"> - <div class="row"> - <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> - <div class="carousel"> - {% for category in categories %} - <div class="item"> - <div class="thumb"> - <img data-lazy="{% static "website/images/" %}{{ category }}.jpg" height="75px" width="99px"> - </div> - <div class="descp"> - <a class="btn btn-block btn-default btn-sm vs" href="{% url 'website:filter' category %}">{{ category }}</a> + <div class="carousel"> + {% for category in categories %} + <div> + <div class="thumbnail"> + <img src="{% static 'website/images/' %}{{ category }}.jpg"> + <div class="caption"> + <small class="category"> + {{ category }} + </small> + {% latest_question category %} + <a class="btn btn-xs btn-block btn-success" href="{% url 'website:new_question' %}?category={{ category|urlencode }}">Ask new question</a> </div> - </div> <!-- /.item --> - {% endfor %} - </div> <!-- /.carousel --> - </div> <!-- /.col --> - </div> <!-- /.row --> - </div> + </div> + </div> + {% endfor %} + </div> <!-- /.carousel --> + </div> <!-- /#carousel-container --> <div id="filter-container"> <div class="row"> <form class ="" id="filter-form" action="" role="form"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> - <h3>Filter questions . . .</h3> - <div class="row"> - <div class="form-group col-lg-10 col-md-10 col-sm-10 col-xs-10"> - <select id="filter-select" class="form-control"> - <option value="-1">Select a FOSS category</option> - {% for category in categories %} - <option value="{{ category }}">{{ category }}</option> - {% endfor %} - </select> - </div> <!-- /.form-group, .col --> - <div class="form-group col-lg-2 col-md-2 col-sm-2 col-xs-2"> - <input class="btn btn-primary btn-block" type="submit" value="Go"> - </div> <!-- /.form-group, .col --> - </div> + <a class="btn btn-block btn-primary" href="{% url 'website:questions' %}" style="margin-top: 30px;">View all previous questions.</a> </div> <!-- /.col --> </form> <div class="col-lg-6 col-md-6 col-sm-6"> @@ -57,15 +45,10 @@ </div> <!-- /.row --> </div> <!-- /#filter-container --> - <br> +<br> <div class="panel panel-default"> <div class="panel-heading"> Recent questions - <a class="pull-right" href="{% url 'website:questions' %}"> - <small> - View all questions - </small> - </a> </div> <div class="panel-body"> <table class="table table-bordered table-hover"> @@ -157,9 +140,9 @@ dots: false, touchMove: false, draggable: false, - slidesToShow: 8, - slidesToScroll: 3, - speed: 500, + slidesToShow: 4, + slidesToScroll: 1, + speed: 1000, autoplay: true, autoplaySpeed: 1000, }); diff --git a/static/website/templates/latest_question.html b/static/website/templates/latest_question.html new file mode 100644 index 0000000..5279f19 --- /dev/null +++ b/static/website/templates/latest_question.html @@ -0,0 +1,11 @@ +{% if question %} + <small class="latest"> + <a href="{% url 'website:get_question' question.id %}">{{ question.title }}</a> + </small> + <a class="btn btn-xs btn-block btn-primary" href="{% url 'website:filter' question.category %}">View previous questions</a> +{% else %} + <small class="latest"> + Be the first to ask question. + </small> + <a class="btn btn-xs btn-block btn-primary" disabled="disabled" href="#">View previous questions</a> +{% endif %} diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index d9576bb..16c6021 100644 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -11,7 +11,7 @@ {% with WIDGET_ERROR_CLASS='field_error' %} <p> - Please enter the tutorial details. + Please enter the tutorial details. {{ category }} <img id="ajax-loader" src="{% static 'website/images/ajax-loader.gif' %}" style="display:none;"> </p> <div class="row"> @@ -19,7 +19,11 @@ {% render_field form.category class+="form-control"%} </div> <div class="col-lg-3 col-md-3 col-sm-3"> - {% render_field form.tutorial class+="form-control" disabled="disabled" %} + {% if category %} + {% render_field form.tutorial class+="form-control" %} + {% else %} + {% render_field form.tutorial class+="form-control" disabled="disabled" %} + {% endif %} </div> <div class="col-lg-2 col-md-2 col-sm-2"> {% render_field form.minute_range class+="form-control" disabled="disabled" %} diff --git a/website/forms.py b/website/forms.py index f1e29be..7d60ffa 100644 --- a/website/forms.py +++ b/website/forms.py @@ -1,6 +1,6 @@ from django import forms -from website.models import Question +from website.models import * categories = ( ("None", "Select a Category"), @@ -64,8 +64,24 @@ seconds= ( ) class NewQuestionForm(forms.Form): - category = forms.CharField(widget=forms.Select(choices=categories)) - tutorial = forms.CharField(widget=forms.Select(choices=tutorials)) + #fix dirty code + def __init__(self, *args, **kwargs): + category = kwargs.pop('category') + super(NewQuestionForm, self).__init__(*args, **kwargs) + self.fields['category'] = forms.CharField(widget=forms.Select(choices=categories)) + self.fields['category'].initial = category + + tutorial_choices = ( + ("None", "Select a Tutorial"), + ) + if (category, category) in categories: + tutorials = TutorialDetails.objects.using('spoken').filter(foss_category=category) + for tutorial in tutorials: + tutorial_choices += ((tutorial.tutorial_name, tutorial.tutorial_name),) + self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices)) + else: + self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices)) + minute_range = forms.CharField(widget=forms.Select(choices=minutes)) second_range = forms.CharField(widget=forms.Select(choices=seconds)) title = forms.CharField(max_length=200) diff --git a/website/models.py b/website/models.py index c280d2d..7a845c5 100644 --- a/website/models.py +++ b/website/models.py @@ -22,6 +22,9 @@ class Question(models.Model): user = User.objects.get(id=self.uid) return user.username + class Meta: + get_latest_by = "date_created" + class QuestionVote(models.Model): uid = models.IntegerField() question = models.ForeignKey(Question) diff --git a/website/templatetags/notify.py b/website/templatetags/notify.py index 44465ea..c39e658 100644 --- a/website/templatetags/notify.py +++ b/website/templatetags/notify.py @@ -20,3 +20,16 @@ def notification_count(user_id): count = Notification.objects.filter(uid=user_id).count() return count register.simple_tag(notification_count) + +# retriving the latest post of a category +def latest_question(category): + question = None + try: + question = Question.objects.filter(category=category).order_by('-date_created')[0] + except: + pass + context = { + 'question': question + } + return context +register.inclusion_tag('website/templates/latest_question.html')(latest_question) diff --git a/website/views.py b/website/views.py index cd1665b..925fc2c 100644 --- a/website/views.py +++ b/website/views.py @@ -5,7 +5,7 @@ from django.shortcuts import render, get_object_or_404 from django.core.context_processors import csrf from django.views.decorators.csrf import csrf_exempt from django.contrib.auth.decorators import login_required -from django.db.models import Q +from django.db.models import Q, Max from django.core.mail import EmailMultiAlternatives from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib.auth import get_user_model @@ -217,6 +217,7 @@ def filter(request, category=None, tutorial=None, minute_range=None, second_ran @login_required def new_question(request): + context = {} if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): @@ -257,11 +258,12 @@ def new_question(request): return HttpResponseRedirect('/') else: - form = NewQuestionForm() - - context = { - 'form': form - } + #fix dirty code + category = request.GET.get('category') + form = NewQuestionForm(category=category) + context['category'] = category + + context['form'] = form context.update(csrf(request)) return render(request, 'website/templates/new-question.html', context) |