diff options
-rw-r--r-- | forums/settings.py | 31 | ||||
-rw-r--r-- | forums/urls.py | 9 | ||||
-rw-r--r-- | static/website/js/custom.js | 8 | ||||
-rw-r--r-- | static/website/templates/filter.html | 18 | ||||
-rw-r--r-- | static/website/templates/get-question.html | 16 | ||||
-rw-r--r-- | static/website/templates/index.html | 18 | ||||
-rw-r--r-- | static/website/templates/new-question.html | 9 | ||||
-rw-r--r-- | static/website/templates/questions.html | 4 | ||||
-rw-r--r-- | website/forms.py | 39 | ||||
-rw-r--r-- | website/models.py | 29 | ||||
-rw-r--r-- | website/templatetags/helpers.py | 2 | ||||
-rw-r--r-- | website/templatetags/permission_tags.py | 2 | ||||
-rw-r--r-- | website/urls.py | 4 | ||||
-rw-r--r-- | website/views.py | 24 |
14 files changed, 53 insertions, 160 deletions
diff --git a/forums/settings.py b/forums/settings.py index 7b758e0..88133d2 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -19,31 +19,13 @@ MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'forums', # Or path to database file if using sqlite3. + 'NAME': 'forum', # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': db_user, 'PASSWORD': db_pass, 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '', # Set to empty string for default. - }, - 'spoken': { - 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'spoken', # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: - 'USER': db_user, - 'PASSWORD': db_pass, - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. - }, - 'cdeep': { - 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'CDEEP', # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: - 'USER': db_user, - 'PASSWORD': db_pass, - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. - }, + } } # Hosts/domain names that are valid for this site; required if DEBUG is False @@ -151,15 +133,15 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: - #'django.contrib.admin', + 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'website', 'widget_tweaks', - 'spoken_auth', + #'spoken_auth', 'compressor', 'debug_toolbar', - 'migrate_spoken', + #'migrate_spoken', ) # A sample logging configuration. The only tangible logging @@ -191,9 +173,6 @@ LOGGING = { } } -AUTH_USER_MODEL = 'spoken_auth.Users' -AUTHENTICATION_BACKENDS = ( 'spoken_auth.backends.DrupalAuthBackend', ) -DATABASE_ROUTERS = ['spoken_auth.routers.DrupalAuthRouter'] TEMPLATE_CONTEXT_PROCESSORS += ( 'django.core.context_processors.request', 'website.context_processors.admin_processor', diff --git a/forums/urls.py b/forums/urls.py index cb8b54e..90d61fb 100644 --- a/forums/urls.py +++ b/forums/urls.py @@ -1,21 +1,20 @@ from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: -#from django.contrib import admin -#admin.autodiscover() +from django.contrib import admin +admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'forums.views.home', name='home'), # url(r'^forums/', include('forums.foo.urls')), - url(r'^', include('website.urls', namespace='website')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: - #url(r'^admin/', include(admin.site.urls)), - + url(r'^admin/', include(admin.site.urls)), + url(r'^', include('website.urls', namespace='website')), # User account urls url(r'^accounts/login/', 'forums.views.user_login', name='user_login'), url(r'^accounts/logout/', 'forums.views.user_logout', name='user_logout'), diff --git a/static/website/js/custom.js b/static/website/js/custom.js index 5565683..90ebe9c 100644 --- a/static/website/js/custom.js +++ b/static/website/js/custom.js @@ -4,7 +4,7 @@ $(document).ready(function() { $minute_range = $("#id_minute_range"); $second_range = $("#id_second_range"); - function reset() { +/* function reset() { for (var i = 0, l = arguments.length; i < l; i ++) { switch(arguments[i]) { case "tutorial": @@ -25,16 +25,12 @@ $(document).ready(function() { } } } - $category.change(function() { $("#similar-link").hide(); - /* resetting dropdowns */ reset("tutorial", "minute_range", "second_range"); - /* see thread-user.js */ $("#question-details-ok").show(); var category = $(this).val(); if(category == "General") { - /* disabling all other fields */ $tutorial.html("<option value='None'>Not required</option>"); $tutorial.removeAttr("disabled"); $minute_range.html("<option value='None'>Not required</option>"); @@ -55,7 +51,7 @@ $(document).ready(function() { }); } }); - +*/ $tutorial.change(function() { /* resetting dropdowns */ reset("minute_range", "second_range"); diff --git a/static/website/templates/filter.html b/static/website/templates/filter.html index 85ff760..8a54c72 100644 --- a/static/website/templates/filter.html +++ b/static/website/templates/filter.html @@ -28,8 +28,6 @@ <table class="table table-bordered"> <th> FOSS </th> <th> Tutorial</th> - <th> Min </th> - <th> Sec </th> <th> Question</th> <th> Date</th> <th> Views</th> @@ -56,22 +54,6 @@ </td> <td> - <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}?qid={{ question.id }}"> - {{ question.minute_range }} - </a> - </span> - </td> - - <td> - <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}?qid={{ question.id }}"> - {{ question.second_range }} - </a> - </span> - </td> - - <td> <span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}"> <a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a> </span> diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html index 2983412..4b37652 100644 --- a/static/website/templates/get-question.html +++ b/static/website/templates/get-question.html @@ -47,22 +47,6 @@ </small> </span> - <span class="minute_range {% if question.minute_range == 'None' %}hideme{% endif %}"> - <small> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}"> - {{ question.minute_range }} min - </a> - </small> - </span> - - <span class="second_range {% if question.minute_range == 'None' %}hideme{% endif %}"> - <small> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}"> - {{ question.second_range }} sec - </a> - </small> - </span> - <a id="question-details-edit" data-toggle="modal" data-target="#detailsModal" href="#" class="hideme"> <span class="glyphicon glyphicon-edit"></span> </a> diff --git a/static/website/templates/index.html b/static/website/templates/index.html index 63890fd..95a5360 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -61,8 +61,6 @@ <table class="table table-bordered table-hover"> <th> FOSS </th> <th> Tutorial</th> - <th> Min </th> - <th> Sec </th> <th> Question <span class="glyphicon glyphicon-link"></span></th> <th> Date</th> <th> Views</th> @@ -89,22 +87,6 @@ </td> <td> - <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}?qid={{ question.id }}"> - {{ question.minute_range }} - </a> - </span> - </td> - - <td> - <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}?qid={{ question.id }}"> - {{ question.second_range }} - </a> - </span> - </td> - - <td> <span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}"> <a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a> </span> diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index 28fc707..aa135ca 100644 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -9,7 +9,6 @@ <hr> <form role="form" action="" method="POST">{% csrf_token %} {% with WIDGET_ERROR_CLASS='field_error' %} - <p> Please enter the tutorial details. <img id="ajax-loader" src="{% static 'website/images/ajax-loader.gif' %}" style="display:none;"> @@ -22,16 +21,10 @@ {% if category %} {% render_field form.tutorial class+="form-control" %} {% else %} - {% render_field form.tutorial class+="form-control" disabled="disabled" %} + {% render_field form.tutorial class+="form-control" %} {% endif %} </div> <div class="col-lg-2 col-md-2 col-sm-2"> - {% render_field form.minute_range class+="form-control" disabled="disabled" %} - </div> - <div class="col-lg-2 col-md-2 col-sm-2"> - {% render_field form.second_range class+="form-control" disabled="disabled" %} - </div> - <div class="col-lg-2 col-md-2 col-sm-2"> <small><strong> <a id="similar-link" data-toggle="modal" data-target="#similarModal" href="#"> 0 similar questions diff --git a/static/website/templates/questions.html b/static/website/templates/questions.html index 88c3dd3..7a259a9 100644 --- a/static/website/templates/questions.html +++ b/static/website/templates/questions.html @@ -40,7 +40,7 @@ <td> <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}?qid={{ question.id }}"> + <a href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}"> {{ question.minute_range }} </a> </span> @@ -48,7 +48,7 @@ <td> <span> - <a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}?qid={{ question.id }}"> + <a href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}"> {{ question.second_range }} </a> </span> diff --git a/website/forms.py b/website/forms.py index e2e6783..14f4d2d 100644 --- a/website/forms.py +++ b/website/forms.py @@ -1,42 +1,19 @@ from django import forms from website.models import * -from spoken_auth.models import TutorialDetails, TutorialResources, FossCategory +#from spoken_auth.models import TutorialDetails from django.db.models import Q -tutorials = ( - ("", "Select a Tutorial"), -) -minutes = ( - ("", "min"), -) -seconds= ( - ("", "sec"), -) +class NewQuestionForm(forms.ModelForm): + category = forms.ModelChoiceField(widget = forms.Select(attrs = {}), queryset = FossCategory.objects.order_by('name'), empty_label = "Select a category", error_messages = {'required':'Categoty field required.'}) + tutorial = forms.ModelChoiceField(widget = forms.Select(attrs = {}), queryset = Issue.objects.order_by('name'), empty_label = "Select a Issue", error_messages = {'required':'Issue field required.'}) + class Meta: + model = Question + fields = ['category', 'tutorial', 'title', 'body'] -class NewQuestionForm(forms.Form): - category = forms.ChoiceField(choices = [('', 'Select a Category'),] + list(TutorialResources.objects.filter(Q(status = 1) | Q(status = 2), language__name = 'English').values('tutorial_detail__foss__foss').order_by('tutorial_detail__foss__foss').values_list('tutorial_detail__foss__foss', 'tutorial_detail__foss__foss').distinct()), widget=forms.Select(attrs = {}), required = True, error_messages = {'required':'State field is required.'}) def __init__(self, *args, **kwargs): category = kwargs.pop('category', None) super(NewQuestionForm, self).__init__(*args, **kwargs) - tutorial_choices = ( - ("", "Select a Tutorial"), - ) - if not category and args and 'category' in args[0] and args[0]['category']: - category = args[0]['category'] - if FossCategory.objects.filter(foss=category).exists(): - self.fields['category'].initial = category - tutorials = TutorialDetails.objects.using('spoken').filter(foss__foss=category) - for tutorial in tutorials: - tutorial_choices += ((tutorial.tutorial, tutorial.tutorial),) - 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) - body = forms.CharField(widget=forms.Textarea()) - + class AnswerQuesitionForm(forms.Form): question = forms.IntegerField(widget=forms.HiddenInput()) body = forms.CharField(widget=forms.Textarea()) diff --git a/website/models.py b/website/models.py index 727edd1..e6816f3 100644 --- a/website/models.py +++ b/website/models.py @@ -5,12 +5,25 @@ from django.contrib.auth.models import User from django.contrib.auth import get_user_model User = get_user_model() +class FossCategory(models.Model): + name = models.CharField(max_length=100) + description = models.TextField() + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + def __unicode__(self): + return self.name + +class Issue(models.Model): + name = models.CharField(max_length=100) + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + def __unicode__(self): + return self.name + class Question(models.Model): - uid = models.IntegerField() - category = models.CharField(max_length=200) - tutorial = models.CharField(max_length=200) - minute_range = models.CharField(max_length=10) - second_range = models.CharField(max_length=10) + user = models.ForeignKey(User) + category = models.ForeignKey(FossCategory) + tutorial = models.ForeignKey(Issue) title = models.CharField(max_length=200) body = models.TextField() date_created = models.DateTimeField(auto_now_add=True) @@ -18,10 +31,6 @@ class Question(models.Model): views = models.IntegerField(default=1) # votes = models.IntegerField(default=0) - def user(self): - user = User.objects.get(id=self.uid) - return user.username - class Meta: get_latest_by = "date_created" @@ -74,5 +83,3 @@ class Notification(models.Model): def poster(self): user = User.objects.get(id=self.pid) return user.username - -# CDEEP database created using inspectdb arg of manage.py diff --git a/website/templatetags/helpers.py b/website/templatetags/helpers.py index e6afc51..47c1f9e 100644 --- a/website/templatetags/helpers.py +++ b/website/templatetags/helpers.py @@ -9,7 +9,7 @@ register = template.Library() def get_category_image(category): base_path = settings.PROJECT_DIR + '/static/website/images/' - file_name = category.replace(' ', '-') + '.jpg' + file_name = category.name.replace(' ', '-') + '.jpg' file_path = base_path + file_name if os.path.isfile(file_path): return 'website/images/' + file_name diff --git a/website/templatetags/permission_tags.py b/website/templatetags/permission_tags.py index b85d747..c4a0ac7 100644 --- a/website/templatetags/permission_tags.py +++ b/website/templatetags/permission_tags.py @@ -5,7 +5,7 @@ from website.views import admins register = template.Library() def can_edit(user, obj): - if user.id == obj.uid or user.id in admins: + if user.id == obj.user or user.id in admins: return True return False diff --git a/website/urls.py b/website/urls.py index d05a5f0..a61892a 100644 --- a/website/urls.py +++ b/website/urls.py @@ -9,8 +9,8 @@ urlpatterns = patterns('', url(r'^answer-comment/$', 'website.views.answer_comment', name='answer_comment'), url(r'^filter/(?P<category>[^/]+)/$', 'website.views.filter', name='filter'), url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/$', 'website.views.filter', name='filter'), - url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/$', 'website.views.filter', name='filter'), - url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/(?P<second_range>[^/]+)/$', 'website.views.filter', name='filter'), + #url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/$', 'website.views.filter', name='filter'), + #url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/(?P<second_range>[^/]+)/$', 'website.views.filter', name='filter'), url(r'^new-question/$', 'website.views.new_question', name='new_question'), url(r'^user/(?P<user_id>\d+)/notifications/$', 'website.views.user_notifications', name='user_notifications'), url(r'^user/(?P<user_id>\d+)/questions/$', 'website.views.user_questions', name='user_questions'), diff --git a/website/views.py b/website/views.py index df35fa7..d80835d 100644 --- a/website/views.py +++ b/website/views.py @@ -12,7 +12,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth import get_user_model User = get_user_model() -from website.models import Question, Answer, Notification, AnswerComment +from website.models import Question, Answer, Notification, AnswerComment, FossCategory from spoken_auth.models import TutorialDetails, TutorialResources from website.forms import NewQuestionForm, AnswerQuesitionForm from website.helpers import get_video_info, prettify @@ -21,12 +21,7 @@ from django.db.models import Count admins = ( 9, 4376, 4915, 14595, 12329, 22467, 5518, 30705 ) - -categories = [] -trs = TutorialResources.objects.filter(Q(status = 1) | Q(status = 2), language__name = 'English').values('tutorial_detail__foss__foss').order_by('tutorial_detail__foss__foss').values_list('tutorial_detail__foss__foss').distinct() -for tr in trs: - categories.append(tr[0]) - +categories = FossCategory.objects.order_by('name') def home(request): questions = Question.objects.all().order_by('date_created').reverse()[:10] context = { @@ -83,7 +78,7 @@ def question_answer(request): answer.question = question answer.body = body.encode('unicode_escape') answer.save() - if question.uid != request.user.id: + if question.user_id != request.user.id: notification = Notification() notification.uid = question.uid notification.pid = request.user.id @@ -194,7 +189,7 @@ def filter(request, category=None, tutorial=None, minute_range=None, second_ran if category and tutorial and minute_range and second_range: questions = Question.objects.filter(category=category).filter(tutorial=tutorial).filter(minute_range=minute_range).filter(second_range=second_range) elif tutorial is None: - questions = Question.objects.filter(category=category) + questions = Question.objects.filter(category__name=category) elif minute_range is None: questions = Question.objects.filter(category=category).filter(tutorial=tutorial) else: #second_range is None @@ -203,7 +198,7 @@ def filter(request, category=None, tutorial=None, minute_range=None, second_ran if 'qid' in request.GET: context['qid'] = int(request.GET['qid']) - context['questions'] = questions.order_by('category', 'tutorial', 'minute_range', 'second_range') + context['questions'] = questions return render(request, 'website/templates/filter.html', context) @login_required @@ -212,13 +207,12 @@ def new_question(request): if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): + print "EEEEEEEEEEEEEEEE" cleaned_data = form.cleaned_data question = Question() - question.uid = request.user.id - question.category = cleaned_data['category'].replace(' ', '-') - question.tutorial = cleaned_data['tutorial'].replace(' ', '-') - question.minute_range = cleaned_data['minute_range'] - question.second_range = cleaned_data['second_range'] + question.user = request.user + question.category = cleaned_data['category'] + question.tutorial = cleaned_data['tutorial'] question.title = cleaned_data['title'] question.body = cleaned_data['body'].encode('unicode_escape') question.views= 1 |