summaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
authorSanmugasundaram K2015-02-19 14:26:04 +0530
committerSanmugasundaram K2015-02-19 14:26:04 +0530
commit130bb98ed8876aa48c94d98650729f6662024db1 (patch)
treeb4c77db1881d2bacde2eeb562da4390dd7122ecd /website
parent911fbd1637efcec8bfacec3d658213e910845a93 (diff)
downloadFOSSEE-Forum-130bb98ed8876aa48c94d98650729f6662024db1.tar.gz
FOSSEE-Forum-130bb98ed8876aa48c94d98650729f6662024db1.tar.bz2
FOSSEE-Forum-130bb98ed8876aa48c94d98650729f6662024db1.zip
base data for FOSSEE Forum
Diffstat (limited to 'website')
-rw-r--r--website/forms.py39
-rw-r--r--website/models.py29
-rw-r--r--website/templatetags/helpers.py2
-rw-r--r--website/templatetags/permission_tags.py2
-rw-r--r--website/urls.py4
-rw-r--r--website/views.py24
6 files changed, 39 insertions, 61 deletions
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