From: Radek Czajka Date: Mon, 4 Jul 2011 13:37:34 +0000 (+0200) Subject: no CAS, X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/577bb2b84d936d65bf072ef0a6b898db9d6e77ab?ds=sidebyside;hp=--cc no CAS, some fixes --- 577bb2b84d936d65bf072ef0a6b898db9d6e77ab diff --git a/apps/wiki/helpers.py b/apps/wiki/helpers.py index 253f1291..3e0267ed 100644 --- a/apps/wiki/helpers.py +++ b/apps/wiki/helpers.py @@ -152,7 +152,7 @@ class ChunksList(object): 'book', 'stage__name', 'user') - self.book_ids = [x['book_id'] for x in chunk_qs.values('book_id')] + self.book_qs = chunk_qs.values('book_id') def __getitem__(self, key): if isinstance(key, slice): @@ -163,10 +163,10 @@ class ChunksList(object): raise TypeError('Unsupported list index. Must be a slice or an int.') def __len__(self): - return len(self.book_ids) + return self.book_qs.count() def get_slice(self, slice_): - book_ids = self.book_ids[slice_] + book_ids = [x['book_id'] for x in self.book_qs[slice_]] chunk_qs = self.chunk_qs.filter(book__in=book_ids) chunks_list = [] diff --git a/apps/wiki/migrations/0003_add_dvcs.py b/apps/wiki/migrations/0003_add_dvcs.py index a301abf9..87ac321e 100644 --- a/apps/wiki/migrations/0003_add_dvcs.py +++ b/apps/wiki/migrations/0003_add_dvcs.py @@ -178,13 +178,12 @@ class Migration(SchemaMigration): # Adding model 'Book' db.create_table('wiki_book', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('title', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('title', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)), ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=128, db_index=True)), ('gallery', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)), ('parent', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='children', null=True, to=orm['wiki.Book'])), ('parent_number', self.gf('django.db.models.fields.IntegerField')(db_index=True, null=True, blank=True)), - ('last_published', self.gf('django.db.models.fields.DateTimeField')(null=True)), - ('_list_html', self.gf('django.db.models.fields.TextField')(null=True)), + ('last_published', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)), )) db.send_create_signal('wiki', ['Book']) @@ -230,7 +229,7 @@ class Migration(SchemaMigration): ('description', self.gf('django.db.models.fields.TextField')(default='', blank=True)), ('created_at', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, db_index=True)), ('publishable', self.gf('django.db.models.fields.BooleanField')(default=False)), - ('tree', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['wiki.Chunk'])), + ('tree', self.gf('django.db.models.fields.related.ForeignKey')(related_name='change_set', to=orm['wiki.Chunk'])), )) db.send_create_signal('wiki', ['ChunkChange']) @@ -317,14 +316,13 @@ class Migration(SchemaMigration): }, 'wiki.book': { 'Meta': {'ordering': "['parent_number', 'title']", 'object_name': 'Book'}, - '_list_html': ('django.db.models.fields.TextField', [], {'null': 'True'}), 'gallery': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'last_published': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'last_published': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}), 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['wiki.Book']"}), 'parent_number': ('django.db.models.fields.IntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '128', 'db_index': 'True'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}) }, 'wiki.chunk': { 'Meta': {'ordering': "['number']", 'unique_together': "[['book', 'number'], ['book', 'slug']]", 'object_name': 'Chunk'}, @@ -351,8 +349,8 @@ class Migration(SchemaMigration): 'patch': ('django.db.models.fields.TextField', [], {'blank': 'True'}), 'publishable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'revision': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), - 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['wiki.ChunkTag']", 'symmetrical': 'False'}), - 'tree': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['wiki.Chunk']"}) + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'change_set'", 'symmetrical': 'False', 'to': "orm['wiki.ChunkTag']"}), + 'tree': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'change_set'", 'to': "orm['wiki.Chunk']"}) }, 'wiki.chunktag': { 'Meta': {'ordering': "['ordering']", 'object_name': 'ChunkTag'}, diff --git a/apps/wiki/models.py b/apps/wiki/models.py index d35b3c40..20c8b869 100644 --- a/apps/wiki/models.py +++ b/apps/wiki/models.py @@ -22,15 +22,13 @@ logger = logging.getLogger("fnp.wiki") class Book(models.Model): """ A document edited on the wiki """ - title = models.CharField(_('title'), max_length=255) - slug = models.SlugField(_('slug'), max_length=128, unique=True) + title = models.CharField(_('title'), max_length=255, db_index=True) + slug = models.SlugField(_('slug'), max_length=128, unique=True, db_index=True) gallery = models.CharField(_('scan gallery name'), max_length=255, blank=True) parent = models.ForeignKey('self', null=True, blank=True, verbose_name=_('parent'), related_name="children") parent_number = models.IntegerField(_('parent number'), null=True, blank=True, db_index=True) - last_published = models.DateTimeField(null=True, editable=False) - - _list_html = models.TextField(editable=False, null=True) + last_published = models.DateTimeField(null=True, editable=False, db_index=True) class NoTextError(BaseException): pass @@ -46,11 +44,6 @@ class Book(models.Model): def get_absolute_url(self): return reverse("wiki_book", args=[self.slug]) - def save(self, reset_list_html=True, *args, **kwargs): - if reset_list_html: - self._list_html = None - return super(Book, self).save(*args, **kwargs) - @classmethod def create(cls, creator=None, text=u'', *args, **kwargs): """ @@ -68,17 +61,6 @@ class Book(models.Model): def __getitem__(self, chunk): return self.chunk_set.all()[chunk] - def __len__(self): - return self.chunk_set.count() - - def list_html(self): - if self._list_html is None: - print 'rendering', self.title - self._list_html = render_to_string('wiki/document_list_item.html', - {'book': self}) - self.save(reset_list_html=False) - return mark_safe(self._list_html) - def materialize(self, publishable=True): """ Get full text of the document compiled from chunks. diff --git a/apps/wiki/templates/wiki/base.html b/apps/wiki/templates/wiki/base.html index 5d20bbca..83cfb7c5 100644 --- a/apps/wiki/templates/wiki/base.html +++ b/apps/wiki/templates/wiki/base.html @@ -12,7 +12,9 @@
- + + +
{% main_tabs %} @@ -27,6 +29,7 @@
+{% block content %}
{% block leftcolumn %} {% endblock leftcolumn %} @@ -35,6 +38,7 @@ {% block rightcolumn %} {% endblock rightcolumn %}
+{% endblock content %}
diff --git a/apps/wiki/templates/wiki/document_list.html b/apps/wiki/templates/wiki/document_list.html index 434324ca..f68ba3eb 100644 --- a/apps/wiki/templates/wiki/document_list.html +++ b/apps/wiki/templates/wiki/document_list.html @@ -41,7 +41,7 @@ $(function() {
- {% autopaginate books 20 %} + {% autopaginate books 100 %} {% if not books %} {% endif %} diff --git a/apps/wiki/templatetags/wiki.py b/apps/wiki/templatetags/wiki.py index db2eca3e..3a1cc172 100644 --- a/apps/wiki/templatetags/wiki.py +++ b/apps/wiki/templatetags/wiki.py @@ -30,11 +30,10 @@ def main_tabs(context): tabs = [] user = context['user'] if user.is_authenticated(): - tabs.append(Tab('my', _('Assigned to me'), reverse("wiki_user"))) + tabs.append(Tab('my', _('My page'), reverse("wiki_user"))) tabs.append(Tab('unassigned', _('Unassigned'), reverse("wiki_unassigned"))) tabs.append(Tab('users', _('Users'), reverse("wiki_users"))) - tabs.append(Tab('all', _('All'), reverse("wiki_document_list"))) tabs.append(Tab('create', _('Add'), reverse("wiki_create_missing"))) tabs.append(Tab('upload', _('Upload'), reverse("wiki_upload"))) @@ -65,8 +64,7 @@ class WallItem(object): def changes_wall(max_len): qs = Chunk.change_model.objects.filter(revision__gt=-1).order_by('-created_at') qs = qs.defer('patch') - qs = qs.select_related('author', 'tree') - #qs = qs.annotate(book_length=Count('chunk__book__chunk')) + qs = qs.select_related('author', 'tree', 'tree__book__title') qs = qs[:max_len] for item in qs: tag = 'stage' if item.tags.count() else 'change' diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 59ba9846..424de244 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -7,9 +7,11 @@ from lxml import etree from django.conf import settings +from django.contrib import auth from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required from django.db.models import Count +from django.utils.http import urlquote_plus from django.views.generic.simple import direct_to_template from django.views.decorators.http import require_POST, require_GET from django.core.urlresolvers import reverse @@ -100,6 +102,12 @@ def users(request): }) +@never_cache +def logout_then_redirect(request): + auth.logout(request) + return http.HttpResponseRedirect(urlquote_plus(request.GET.get('next', '/'), safe='/?=')) + + @never_cache def editor(request, slug, chunk=None, template_name='wiki/document_details.html'): try: diff --git a/redakcja/settings/common.py b/redakcja/settings/common.py index 7c40abe5..eb6c9ba9 100644 --- a/redakcja/settings/common.py +++ b/redakcja/settings/common.py @@ -81,7 +81,6 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django_cas.middleware.CASMiddleware', 'django.middleware.doc.XViewMiddleware', 'pagination.middleware.PaginationMiddleware', @@ -90,7 +89,6 @@ MIDDLEWARE_CLASSES = ( AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', - 'django_cas.backends.CASBackend', ) ROOT_URLCONF = 'redakcja.urls' @@ -101,13 +99,6 @@ TEMPLATE_DIRS = ( FIREPYTHON_LOGGER_NAME = "fnp" -# -# Central Auth System -# -## Set this to where the CAS server lives -# CAS_SERVER_URL = "http://cas.fnp.pl/ -CAS_LOGOUT_COMPLETELY = True - INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', @@ -117,7 +108,6 @@ INSTALLED_APPS = ( 'django.contrib.admindocs', 'django.contrib.comments', - 'django_cas', 'compress', 'south', 'sorl.thumbnail', @@ -131,6 +121,9 @@ INSTALLED_APPS = ( 'apiclient', ) +LOGIN_REDIRECT_URL = '/documents/user' + + FILEBROWSER_URL_FILEBROWSER_MEDIA = STATIC_URL + 'filebrowser/' FILEBROWSER_DIRECTORY = 'images/' FILEBROWSER_ADMIN_VERSIONS = [] diff --git a/redakcja/templates/registration/login.html b/redakcja/templates/registration/login.html index e4b0897c..e2b0465f 100644 --- a/redakcja/templates/registration/login.html +++ b/redakcja/templates/registration/login.html @@ -1,15 +1,16 @@ -{% extends "base.html" %} +{% extends "wiki/base.html" %} {% block subtitle %} - Logowanie {% endblock subtitle %} -{% block maincontent %} +{% block content %}
- + +{% csrf_token %} {{ form.as_p }}

-{% endblock maincontent %} +{% endblock content %} diff --git a/redakcja/urls.py b/redakcja/urls.py index 3fd6ff52..edb5fc2e 100644 --- a/redakcja/urls.py +++ b/redakcja/urls.py @@ -10,8 +10,8 @@ admin.autodiscover() urlpatterns = patterns('', # Auth - url(r'^accounts/login/$', 'django_cas.views.login', name='login'), - url(r'^accounts/logout/$', 'django_cas.views.logout', name='logout'), + url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'), + url(r'^accounts/logout/$', 'wiki.views.logout_then_redirect', name='logout'), # Admin panel (r'^admin/filebrowser/', include('filebrowser.urls')),
{% trans "No books found." %}