From d689e3042bb7aaba6cd6db153be0b9417f3b0520 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 10:11:55 +0200 Subject: [PATCH 1/6] Uprava pudlic_url --- seminar/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index e601b807..c5a7cf44 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -29,11 +29,14 @@ class SeminarModelBase(models.Model): def verejne(self): return False - def public_url(self): - if self.Meta.url_name: - return reverse(self.Meta.url_name, - kwargs={'id': self.id, 'pk': self.id}) - return None +# def public_url(self): +# if self.Meta.url_name: +# return reverse(self.Meta.url_name, +# kwargs={'id': self.id, 'pk': self.id}) +# return None + + def get_absolute_url(self): + return self.verejne_url() # TODO "absolute" def admin_url(self): model_name = self.__class__.__name__.lower() From 2b38042798477972284626f86a19fcededd9d844 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 10:20:42 +0200 Subject: [PATCH 2/6] Added full threaded comments (to Problem for now) --- mamweb/settings_common.py | 14 ++++++++++++++ mamweb/static/css/mamweb.css | 10 ++++++++++ mamweb/templates/base.html | 4 ++++ mamweb/urls.py | 11 ++++++++++- requirements.txt | 8 +++++++- seminar/templates/seminar/problem.html | 8 ++++++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 6214ce41..18949127 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -99,6 +99,11 @@ INSTALLED_APPS = ( 'taggit', 'autocomplete_light', + 'fluent_comments', + 'crispy_forms', + 'threadedcomments', + 'django_comments', + # MaMweb 'mamweb', 'seminar', @@ -159,6 +164,13 @@ CKEDITOR_CONFIGS = { } +# Comments + +COMMENTS_APP = 'fluent_comments' +#COMMENTS_APP = 'threadedcomments' +FLUENT_COMMENTS_EXCLUDE_FIELDS = ('name', 'email', 'url', 'title') + + # SECURITY WARNING: keep the secret key used in production secret! # Create file 'django.secret' in every install (it is not kept in git) @@ -168,6 +180,8 @@ try: except: SECRET_KEY = '12345zmr_k53a*@f4q_+ji^o@!pgpef*5&8c7zzdqwkdlkj' + + # MaM specific SEMINAR_RESENI_DIR = os.path.join(BASE_DIR, 'media', 'reseni') diff --git a/mamweb/static/css/mamweb.css b/mamweb/static/css/mamweb.css index 9f6b779a..1e6f003b 100644 --- a/mamweb/static/css/mamweb.css +++ b/mamweb/static/css/mamweb.css @@ -30,3 +30,13 @@ table .border-b { .vysledkovka { border: solid 2px; } + + +/* Comments */ + +#id_comment { + width: 100%; + height: 6em; +} + + diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index 864387e6..f9dcf422 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -12,6 +12,10 @@ {% include 'autocomplete_light/static.html' %} + + + + diff --git a/mamweb/urls.py b/mamweb/urls.py index eb564ebe..56b8ce6e 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -7,12 +7,21 @@ from django.views.generic.base import TemplateView urlpatterns = i18n_patterns('', + # Admin a nastroje url(r'^admin/', include(admin.site.urls)), # NOQA - url(r'^admin_tools/', include('admin_tools.urls')), url(r'^ckeditor/', include('ckeditor.urls')), url(r'^autocomplete/', include('autocomplete_light.urls')), + + # Seminarova aplikace (ma vlastni podadresare) url(r'^', include('seminar.urls')), + + # Comments (interni i verejne) + url(r'^comments_dj/', include('django_comments.urls')), + url(r'^comments_fl/', include('fluent_comments.urls')), + + # Obsah url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'), + ) # This is only needed when using runserver. diff --git a/requirements.txt b/requirements.txt index 6e398b41..14be2256 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,13 @@ django-ckeditor==4.4.7 django-flat-theme==0.9.3 django-taggit==0.14.0 django-autocomplete-light==2.1.1 -# django-admin-tools==0.5.2 +django-crispy-forms==1.4.0 + +# Comments +akismet==0.2.0 +django-fluent-comments==1.0.2 +django-threadedcomments==1.0b1 +django-contrib-comments==1.6.1 # debug tools/extensions diff --git a/seminar/templates/seminar/problem.html b/seminar/templates/seminar/problem.html index acb3d075..1b9b364c 100644 --- a/seminar/templates/seminar/problem.html +++ b/seminar/templates/seminar/problem.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load comments %} + {% block content %}

Problém {{ problem.kod_v_rocniku }} {{ problem.nazev }}

@@ -13,8 +15,14 @@ {% if True %}
+

Text - org

{{ problem.text_problemu_org |safe }} + +

Diskuse - org

+ {% render_comment_list for object %} + {% render_comment_form for object %} +
{% endif %} From 8bf8eb8b23ae5da045684b6803184f29668cb051 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 13:12:56 +0200 Subject: [PATCH 3/6] Import komentaru, unescape dat, uprava uzivatelu --- dakosdump/README.md | 44 +++++++++++++++++++++++--- seminar/admin.py | 4 +-- seminar/templates/seminar/problem.html | 14 +++++--- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/dakosdump/README.md b/dakosdump/README.md index 4583102b..13d103d6 100644 --- a/dakosdump/README.md +++ b/dakosdump/README.md @@ -27,13 +27,13 @@ Překlad ID je potom: MAMID_FOR_DAKOSID = {u'18313': 501, u'25075': 595, u'15162': 453, u'14673': 441, u'218': 549, u'20414': 525, u'27538': 617, u'18733': 504, u'13935': 427, u'12074': 409, u'23855': 580, u'12372': 412, u'14950': 448, u'428': 620, u'14989': 451, u'26574': 609, u'24791': 590, u'26628': 610, u'26705': 615, u'17273': 486, u'12172': 410, u'1377': 426, u'19859': 517, u'25597': 603, u'21176': 543, u'20453': 527, u'19278': 509, u'14107': 429, u'19274': 508, u'14842': 445, u'14667': 440, u'25176': 597, u'17713': 490, u'15753': 463, u'2': 518, u'17393': 489, u'22673': 568, u'1553': 459, u'13600': 423, u'1556': 460, u'1708': 480, u'18753': 506, u'13609': 424, u'415': 619, u'19653': 516, u'13499': 418, u'22637': 557, u'25608': 604, u'15744': 462, u'21102': 539, u'15740': 461, u'21107': 541, u'22633': 553, u'22793': 573, u'22711': 572, u'14323': 434, u'22643': 563, u'22013': 551, u'22641': 561, u'22640': 560, u'22646': 566, u'20113': 520, u'22644': 564, u'21993': 550, u'22833': 574, u'24022': 583, u'24375': 587, u'21183': 544, u'26693': 614, u'1359': 422, u'21184': 545, u'26555': 608, u'14290': 430, u'22635': 555, u'12313': 411, u'17253': 485, u'18734': 505, u'15522': 458, u'19219': 507, u'25535': 599, u'22653': 567, u'25538': 600, u'17234': 484, u'17233': 483, u'1135': 403, u'381': 618, u'21453': 546, u'20433': 526, u'17133': 481, u'101': 402, u'21056': 536, u'14522': 437, u'19282': 510, u'19285': 511, u'21513': 547, u'11515': 404, u'17974': 499, u'16813': 478, u'1648': 477, u'17973': 498, u'14689': 442, u'15833': 464, u'21094': 537, u'15836': 466, u'15837': 467, u'15834': 465, u'22974': 577, u'15838': 468, u'15839': 469, u'24930': 593, u'459': 623, u'16333': 475, u'11948': 408, u'15087': 452, u'19617': 514, u'23655': 579, u'14387': 435, u'457': 622, u'14307': 431, u'24126': 585, u'21105': 540, u'24081': 584, u'15324': 455, u'23193': 578, u'24004': 582, u'26661': 612, u'1730': 488, u'24825': 592, u'17960': 497, u'11620': 405, u'1469': 443, u'250': 594, u'19290': 512, u'24296': 586, u'17887': 494, u'26235': 606, u'14962': 450, u'14961': 449, u'1358': 421, u'22636': 556, u'17274': 487, u'22634': 554, u'13965': 428, u'19622': 515, u'22638': 558, u'1350': 419, u'1357': 420, u'24637': 589, u'14878': 446, u'25556': 602, u'25555': 601, u'20475': 530, u'14314': 432, u'14315': 433, u'221': 552, u'20413': 524, u'15313': 454, u'1188': 407, u'21733': 548, u'26684': 613, u'26455': 607, u'17955': 496, u'25916': 605, u'22863': 575, u'21098': 538, u'1453': 438, u'26642': 611, u'20154': 521, u'14625': 439, u'15874': 472, u'14879': 447, u'1169': 406, u'16053': 473, u'12546': 413, u'22685': 570, u'20014': 519, u'16353': 476, u'17829': 492, u'22642': 562, u'20393': 523, u'469': 624, u'17949': 495, u'16193': 474, u'20313': 522, u'13468': 417, u'27476': 616, u'24442': 588, u'22681': 569, u'21036': 535, u'25111': 596, u'19420': 513, u'18633': 503, u'22645': 565, u'1293': 414, u'25495': 598, u'18133': 500, u'17193': 482, u'22639': 559, u'15841': 471, u'15840': 470, u'450': 621, u'17838': 493, u'20478': 533, u'20479': 534, u'22694': 571, u'17793': 491, u'21159': 542, u'20473': 528, u'23981': 581, u'20476': 531, u'20477': 532, u'20474': 529, u'17073': 479, u'22865': 576, u'13072': 415, u'13073': 416, u'14404': 436, u'15375': 457, u'15374': 456, u'24815': 591, u'1365': 425, u'1474': 444, u'18453': 502} -#### Staří orgové [MAMOPER_MM_ULOHA] #### +#### Staří orgové `[MAMOPER_MM_ULOHA]` #### for i in set([i.OPRAVUJICI for i in sqget(db, "select * from MAMOPER_MM_ULOHA")]): if i and len(User.objects.filter(username=i))==0: User.objects.create_user(i) -#### Staré úlohy [MAMOPER_MM_ULOHA] #### +#### Staré úlohy `[MAMOPER_MM_ULOHA]` #### Temata (prořezávání opakujících se) @@ -86,7 +86,7 @@ A pak prořezání opakujících se témátek ... poznamka="Import z MAMOPER_MM_RESENI, MAMOPER_MM_RESENI_BODY\nVyzvedl: %s\nPuvodni poznamka: %s" % (i.VYZVEDL, i.POZNAMKA, )) -#### Novější problémy (znovu) [MM_ZADANIA] #### +#### Novější problémy (znovu) `[MM_ZADANIA]` #### Pozn.: CISLO udává vždy nejen číslo zadání, ale zároveň určuje číslo řešení i u témat (+2). Témata jsou též zadána vícekrát, jednou za každé číslo s výsledky (číslované (-2)). @@ -115,7 +115,7 @@ Témata: nazev=i.NAZOV, typ=Problem.TYP_TEMA, cislo_zadani__isnull=False) else None -#### Novější řešení (znovu) [MM_RIESENIA] #### +#### Novější řešení (znovu) `[MM_RIESENIA]` #### r=sqget(db, "select * from MAMOPER_MM_RIESENIA") for i in r: @@ -142,7 +142,43 @@ Témata: cislo_body=cbod) +#### Komentáře `[MAMOPER_MM_DOZ_DISKUSIA]` #### + from django.contrib.contenttypes.models import ContentType + from django.utils.encoding import force_text + from django.conf import settings + import HTMLParser + + r = sqget(db, 'SELECT * from MAMOPER_MM_DOZ_DISKUSIA') + r = sorted(r, key=lambda x:x.ID_REAK) + tab_ID_REAK_to_ThrComment_id = {} + html_parser = HTMLParser.HTMLParser() + + for i in r: + print i + prb = Problem.objects.get(import_dakos_id='DOZ:%s' % (i.ID, )) + print prb.id + un = i.ORG + if un == u'Al\u010da': un = 'alca' + if un == u'Anet': un = 'anet' + user = User.objects.get(username=un) + parent = None if not i.ID_PARENT else ThreadedComment.objects.get(id=tab_ID_REAK_to_ThrComment_id[i.ID_PARENT]) + text = html_parser.unescape(i.TEXT_PRISPEVKU).replace('
', '\n').replace('
', '\n') + text = html_parser.unescape(text) + d = dict( + content_type=ContentType.objects.get_for_model(Problem), + object_pk=force_text(prb._get_pk_val()), + comment=text, + submit_date=transdate(i.DATUM), + site_id=settings.SITE_ID, + is_public=True, + is_removed=False, + parent=parent, + title="", + user=user, + ) + c = ThreadedComment.objects.create(**d) + tab_ID_REAK_to_ThrComment_id[i.ID_REAK] = c.id diff --git a/seminar/admin.py b/seminar/admin.py index 31e6027b..d32fcc2b 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -236,11 +236,11 @@ class ProblemAdminForm(forms.ModelForm): class ProblemAdmin(reversion.VersionAdmin): form = ProblemAdminForm fieldsets = [ - (None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'zamereni', 'body', 'timestamp']}), + (None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'zamereni', 'body', 'timestamp', 'import_dakos_id']}), (u'Vydání', {'fields': ['cislo_zadani', 'kod', 'cislo_reseni', 'opravovatel', 'text_problemu']}), (None, {'fields': ['text_problemu_org']}), ] - readonly_fields = ['timestamp'] + readonly_fields = ['timestamp', 'import_dakos_id'] list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani', 'pocet_reseni'] list_select_related = True list_filter = ['typ', 'stav', 'timestamp'] diff --git a/seminar/templates/seminar/problem.html b/seminar/templates/seminar/problem.html index 1b9b364c..f7778281 100644 --- a/seminar/templates/seminar/problem.html +++ b/seminar/templates/seminar/problem.html @@ -4,11 +4,17 @@ {% block content %}
-

Problém {{ problem.kod_v_rocniku }} {{ problem.nazev }}

+ {% if problem.cislo_zadani %} +

Problém {{ problem.kod_v_rocniku }} {{ problem.nazev }}

+ +

Zadáno v čísle {{ problem.cislo_zadani.kod }}. + {% if problem.cislo_reseni %} +

Řešeno v čísle {{ problem.cislo_reseni.kod }}. + {% endif %} + {% else %} +

Problém {{ problem.nazev }}

+ {% endif %} -

Zadáno v čísle {{ problem.cislo_zadani.kod }}, -

řešeno v čísle {{ problem.cislo_reseni.kod }}, -

Text

{{ problem.text_problemu |safe }} From 7ad8a8f88b43e51398d28295ef8ae2a36b836e86 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 13:35:14 +0200 Subject: [PATCH 4/6] Update db nastaveni pro -test a -prod --- Makefile | 2 ++ mamweb/settings_prod.py | 11 ++++++----- mamweb/settings_test.py | 10 +++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 62bb504e..d42be96a 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ HEAD=`git log --color=never |head -1|sed 's/.*commit //'` push_test: @echo "Checking out commited HEAD (${HEAD}) state at ${TEST_SSH} ..." + git tag deploy-test-`date +%Y-%m-%d-%H-%M`-${USER} git push --all ssh ${TEST_USER}@${TEST_SERVER} -n -x "\ cd ${TEST_DIR} && \ @@ -89,6 +90,7 @@ push_test: push_prod: @echo "Checking out commited HEAD (${HEAD}) state at ${PROD_SSH} ..." + git tag deploy-prod-`date +%Y-%m-%d-%H-%M`-${USER} git push --all ssh ${PROD_USER}@${PROD_SERVER} -n -x "\ cd ${PROD_DIR} && \ diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index 9a93aa8a..0eede77c 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -22,11 +22,12 @@ ALLOWED_HOSTS = ['mam.mff.cuni.cz', 'www.mam.mff.cuni.cz', 'atrey.karlin.mff.cun DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db-prod-temp.sqlite3'), -# 'ENGINE': 'django.db.backends.postgresql_psycopg2', -# 'NAME': 'mam-prod', -# 'USER': 'mam', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'mam-prod', + 'USER': 'mam', + 'TEST': { + 'NAME': 'mam-prod-testdb', + }, }, } diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index 202cd2e7..50bff36e 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -25,9 +25,13 @@ ALLOWED_HOSTS = ['*.mam.mff.cuni.cz'] DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db-test.sqlite3'), - } + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'mam-test', + 'USER': 'mam', + 'TEST': { + 'NAME': 'mam-test-testdb', + }, + }, } From 57315766d058aaa3e0c389641f6b06e1e67eee06 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 14:14:52 +0200 Subject: [PATCH 5/6] Update nastaveni logu --- mamweb/settings_prod.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index 0eede77c..78c400ef 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -31,3 +31,21 @@ DATABASES = { }, } +import os + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + }, + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), + }, + }, +} + From 9cbbfeaa9560631d4edfdaf3e1cc2f13c35044d5 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 26 May 2015 17:04:34 +0200 Subject: [PATCH 6/6] Fix bug: poradi v exportu --- seminar/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/export.py b/seminar/export.py index a6ca7ff5..ce52220a 100644 --- a/seminar/export.py +++ b/seminar/export.py @@ -36,7 +36,7 @@ class ExportRocnikView(generic.DetailView): 'points', 'rank',] radky = [] - vysledky = VysledkyKCislu.objects.filter(cislo = cislo).select_related("resitel").all() + vysledky = VysledkyKCislu.objects.filter(cislo = cislo).select_related("resitel").order_by('-body_celkem').all() posledni_body = 100000 posledni_poradi = 0