Skip to content

Commit

Permalink
#4 메인페이지 관심학과 추천코멘트 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
min authored and min committed May 27, 2016
1 parent 77037dd commit 837d238
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
24 changes: 16 additions & 8 deletions apps/review/management/commands/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from datetime import datetime, timedelta, time, date
from django.utils import timezone
from django.db.models import Q
from apps.subject.models import Department
class Command(BaseCommand):
help = 'BestComment Changer'
def handle(self, *args, **options):
print "BestComment changing start!"
last_date = timezone.now()
first_date = timezone.now() - timedelta(hours = 2 )
first_date = timezone.now() - timedelta(days = 1 )
last_date_all = timezone.now()
first_date_all = timezone.now() - timedelta(days = 600)
Comment_latest = Comment.objects.filter(written_datetime__range=(first_date, last_date))
Comment_liberal = list(Comment_latest.filter(Q(course__department__code="HSS")))
Comment_major = list(Comment_latest.filter(~Q(course__department__code="HSS")))
Expand All @@ -24,7 +27,7 @@ def cmp1(a,b):


try :
bComment_liberal=list(LiberalBestComment.objects.all())
bComment_liberal=list(LiberalBestComment.objects.filter(written_datetime__range=(first_date_all, last_date_all)))
except:
bComment_liberal=[]

Expand All @@ -41,7 +44,7 @@ def cmp1(a,b):


try :
bComment_major=list(MajorBestComment.objects.all())
bComment_major=list(MajorBestComment.objects.filter(written_datetime__range=(first_date_all, last_date_all)))
except:
bComment_major=[]

Expand All @@ -50,11 +53,16 @@ def cmp1(a,b):
bComment_major.sort(cmp1)
mbcl = MajorBestComment.objects.all()
mbcl.delete()
for i in range(50):
try :
bComment_major[i].save()
except:
continue
for department in Department.objects.all():
comment_d = []
for i in range(len(bComment_major)):
if bComment_major[i].comment.course.department.code == department.code:
comment_d.append(bComment_major[i])
for i in range(15):
try :
comment_d[i].save()
except:
continue


print "BestComment was changed"
8 changes: 5 additions & 3 deletions apps/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ def search_view(request):
auto_source = [i.title for i in course_source] + [i.title_en for i in course_source] + [i.professor_name for i in professor_source] + [i.professor_name_en for i in professor_source]
auto_source = ','.join(auto_source)


comment_liberal = list(LiberalBestComment.objects.all())
if request.user.is_authenticated():
user = request.user
user_profile = UserProfile.objects.get(user=user)

comment_liberal = list(LiberalBestComment.objects.all())
comment_major = list(MajorBestComment.objects.all())
comment_major = list(MajorBestComment.objects.filter(comment__course__department = user_profile.favorite_departments.all()))
else:
comment_major = list(MajorBestComment.objects.all())

liberal_comment = []
major_comment = []
Expand Down
10 changes: 5 additions & 5 deletions apps/session/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import subprocess

# TESTING #
#sso_client = Client(is_test=True)
sso_client = Client(is_test=True)

# PRODUCTION #
sso_client = Client(is_test=False,
app_name='otlplus',
secret_key=settings.SSO_KEY)
#sso_client = Client(is_test=False,
# app_name='otlplus',
# secret_key=settings.SSO_KEY)


def home(request):
Expand Down Expand Up @@ -116,7 +116,7 @@ def settings(request):
dpt = Department.objects.get(id=dpt_id)
user_profile.favorite_departments.add(dpt)
for dpt in user_profile.favorite_departments.all():
favorite_departments.append(dpt.id)
favorite_departments.append(dpt)
if str(dpt.id) not in request.POST.getlist('fav_department', []):
user_profile.favorite_departments.remove(dpt)

Expand Down
2 changes: 1 addition & 1 deletion otlplus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SSO_KEY = f.read().strip()

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True

ALLOWED_HOSTS = ['*']

Expand Down
2 changes: 1 addition & 1 deletion templates/session/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h3>관심 학과 </h3>
<div id="favorites">
{% for dpt in department %}
<div class="col-xs-12 col-lg-8">
<input type="checkbox" style="display:inline-block"name="fav_department" value="{{ dpt.id }}" {% if dpt.id in fav_department %} checked {% endif %}>
<input type="checkbox" style="display:inline-block"name="fav_department" value="{{ dpt.id }}" {% if dpt in fav_department %} checked {% endif %}>
<p style="display:inline-block;margin:1px">{{ dpt.name }} </p>
</div>
{% endfor %}
Expand Down

0 comments on commit 837d238

Please sign in to comment.