diff --git a/colab/plugins/trac/__init__.py b/colab/plugins/trac/__init__.py deleted file mode 100644 index 9531fa6..0000000 --- a/colab/plugins/trac/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ - - -default_app_config = 'colab.plugins.trac.apps.ProxyTracAppConfig' diff --git a/colab/plugins/trac/admin.py b/colab/plugins/trac/admin.py deleted file mode 100644 index 6209b09..0000000 --- a/colab/plugins/trac/admin.py +++ /dev/null @@ -1 +0,0 @@ -# from . import signals diff --git a/colab/plugins/trac/apps.py b/colab/plugins/trac/apps.py deleted file mode 100644 index 60bbbe1..0000000 --- a/colab/plugins/trac/apps.py +++ /dev/null @@ -1,24 +0,0 @@ - -from django.utils.translation import ugettext_lazy as _ - -from ..utils.apps import ColabProxiedAppConfig - - -class ProxyTracAppConfig(ColabProxiedAppConfig): - name = 'colab.plugins.trac' - verbose_name = 'Trac Proxy' - - menu = { - 'title': _('Code'), - 'links': ( - (_('Timeline'), 'timeline'), - (_('Wiki'), 'wiki'), - (_('View Tickets'), 'report'), - (_('Roadmap'), 'roadmap'), - (_('Browse Source'), 'browser'), - ), - 'auth_links': ( - (_('New Ticket'), 'newticket'), - (_('New Wiki Page'), 'wiki/WikiNewPage'), - ), - } diff --git a/colab/plugins/trac/data_api.py b/colab/plugins/trac/data_api.py deleted file mode 100644 index 02f2562..0000000 --- a/colab/plugins/trac/data_api.py +++ /dev/null @@ -1,7 +0,0 @@ -from colab.plugins.utils.proxy_data_api import ProxyDataAPI - - -class TracDataAPI(ProxyDataAPI): - - def fetch_data(self): - pass diff --git a/colab/plugins/trac/diazo.xml b/colab/plugins/trac/diazo.xml deleted file mode 100644 index 03ab404..0000000 --- a/colab/plugins/trac/diazo.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - diff --git a/colab/plugins/trac/migrations/0001_initial.py b/colab/plugins/trac/migrations/0001_initial.py deleted file mode 100644 index 20f94eb..0000000 --- a/colab/plugins/trac/migrations/0001_initial.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations, connections - - -def create_views(apps, schema_editor): - connection = connections['trac'] - - cursor = connection.cursor() - - # revision_view - cursor.execute(''' - CREATE OR REPLACE VIEW revision_view AS SELECT - revision.rev, - revision.author, - revision.message, - repository.value AS repository_name, - TIMESTAMP WITH TIME ZONE 'epoch' + (revision.time/1000000) * INTERVAL '1s' AS created, - CONCAT(revision.repos, '-', revision.rev) AS key - FROM revision - INNER JOIN repository ON( - repository.id = revision.repos - AND repository.name = 'name' - AND repository.value != '' - ); - ''') - - # attachment_view - cursor.execute(''' - CREATE OR REPLACE VIEW attachment_view AS SELECT - CONCAT(attachment.type, '/' , attachment.id, '/', attachment.filename) AS url, - attachment.type AS used_by, - attachment.filename AS filename, - attachment.id as attach_id, - (SELECT LOWER(SUBSTRING(attachment.filename FROM '\.(\w+)$'))) AS mimetype, - attachment.author AS author, - attachment.description AS description, - attachment.size AS size, - TIMESTAMP WITH TIME ZONE 'epoch' + (attachment.time/1000000)* INTERVAL '1s' AS created - FROM attachment; - ''') - - # wiki_view - cursor.execute(''' - CREATE OR REPLACE VIEW wiki_view AS SELECT - wiki.name AS name, - (SELECT wiki2.text FROM wiki AS wiki2 WHERE wiki2.name = wiki.name - AND wiki2.version = MAX(wiki.version)) AS wiki_text, - (SELECT wiki3.author FROM wiki AS wiki3 WHERE wiki3.name = wiki.name - AND wiki3.version = 1) AS author, - string_agg(DISTINCT wiki.author, ', ') AS collaborators, - TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(wiki.time)/1000000) * INTERVAL '1s' AS created, - TIMESTAMP WITH TIME ZONE 'epoch' + (MAX(wiki.time)/1000000) * INTERVAL '1s' AS modified, - (SELECT wiki4.author FROM wiki AS wiki4 WHERE wiki4.name = wiki.name - AND wiki4.version = MAX(wiki.version)) AS modified_by - FROM wiki - GROUP BY wiki.name; - ''') - - # ticket_view - cursor.execute(''' - CREATE OR REPLACE VIEW ticket_view AS SELECT - ticket.id AS id, - ticket.summary as summary, - ticket.description as description, - ticket.milestone as milestone, - ticket.priority as priority, - ticket.component as component, - ticket.version as version, - ticket.severity as severity, - ticket.reporter as reporter, - ticket.reporter as author, - ticket.status as status, - ticket.keywords as keywords, - (SELECT - string_agg(DISTINCT ticket_change.author, ', ') - FROM ticket_change WHERE ticket_change.ticket = ticket.id - GROUP BY ticket_change.ticket) as collaborators, - TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000)* INTERVAL '1s' AS created, - TIMESTAMP WITH TIME ZONE 'epoch' + (changetime/1000000) * INTERVAL '1s' AS modified, - (SELECT - ticket_change.author - FROM ticket_change - WHERE ticket_change.ticket = ticket.id - AND ticket_change.time = ticket.changetime - LIMIT 1 - ) AS modified_by - FROM ticket; - ''') - - # ticket_collab_count_view - cursor.execute(''' - CREATE OR REPLACE VIEW ticket_collab_count_view AS - SELECT - COALESCE (t1.author, t2.author) as author, - (COALESCE(t1.count, 0) + COALESCE(t2.count, 0)) as count - FROM - (SELECT author, count(*) as count - FROM ticket_change - GROUP BY author - ORDER BY author - ) AS t1 - FULL OUTER JOIN - (SELECT reporter as author, count(*) as count - FROM ticket - GROUP BY reporter - ORDER BY reporter - ) AS t2 - ON t1.author = t2.author; - ''') - - # wiki_collab_count_view - cursor.execute(''' - CREATE OR REPLACE VIEW wiki_collab_count_view AS - SELECT author, count(*) from wiki GROUP BY author; - ''') - - -def drop_views(apps, schema_editor): - connection = connections['trac'] - - cursor = connection.cursor() - cursor.execute(''' - DROP VIEW IF EXISTS revision_view; - DROP VIEW IF EXISTS ticket_view; - DROP VIEW IF EXISTS wiki_view; - DROP VIEW IF EXISTS ticket_collab_count_view; - DROP VIEW IF EXISTS wiki_collab_count_view; - DROP VIEW IF EXISTS attachment_view; - ''') - - -class Migration(migrations.Migration): - - dependencies = [ - ] - - operations = [ - migrations.RunPython(code=create_views, reverse_code=drop_views) - ] diff --git a/colab/plugins/trac/migrations/__init__.py b/colab/plugins/trac/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/colab/plugins/trac/migrations/__init__.py +++ /dev/null diff --git a/colab/plugins/trac/models.py b/colab/plugins/trac/models.py deleted file mode 100644 index f1725a6..0000000 --- a/colab/plugins/trac/models.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- coding: utf-8 -*- -import os -import urllib2 - -from django.db import models -from django.conf import settings - -from hitcounter.models import HitCounterModelMixin - -from colab.accounts.models import User - - -class Attachment(models.Model, HitCounterModelMixin): - url = models.TextField(primary_key=True) - attach_id = models.TextField() - used_by = models.TextField() - filename = models.TextField() - author = models.TextField(blank=True) - description = models.TextField(blank=True) - created = models.DateTimeField(blank=True) - mimetype = models.TextField(blank=True) - size = models.IntegerField(blank=True) - - class Meta: - managed = False - db_table = 'attachment_view' - - @property - def filepath(self): - return os.path.join( - settings.ATTACHMENTS_FOLDER_PATH, - self.used_by, - self.attach_id, - urllib2.quote(self.filename.encode('utf8')) - ) - - def get_absolute_url(self): - return u'/raw-attachment/{}'.format(self.url) - - def get_author(self): - try: - return User.objects.get(username=self.author) - except User.DoesNotExist: - return None - - -class Revision(models.Model, HitCounterModelMixin): - key = models.TextField(blank=True, primary_key=True) - rev = models.TextField(blank=True) - author = models.TextField(blank=True) - message = models.TextField(blank=True) - repository_name = models.TextField(blank=True) - created = models.DateTimeField(blank=True, null=True) - - class Meta: - managed = False - db_table = 'revision_view' - - def get_absolute_url(self): - return u'/changeset/{}/{}'.format(self.rev, self.repository_name) - - def get_author(self): - try: - return User.objects.get(username=self.author) - except User.DoesNotExist: - return None - - -class Ticket(models.Model, HitCounterModelMixin): - id = models.IntegerField(primary_key=True) - summary = models.TextField(blank=True) - description = models.TextField(blank=True) - milestone = models.TextField(blank=True) - priority = models.TextField(blank=True) - component = models.TextField(blank=True) - version = models.TextField(blank=True) - severity = models.TextField(blank=True) - reporter = models.TextField(blank=True) - author = models.TextField(blank=True) - status = models.TextField(blank=True) - keywords = models.TextField(blank=True) - collaborators = models.TextField(blank=True) - created = models.DateTimeField(blank=True, null=True) - modified = models.DateTimeField(blank=True, null=True) - modified_by = models.TextField(blank=True) - - class Meta: - managed = False - db_table = 'ticket_view' - - def get_absolute_url(self): - return u'/ticket/{}'.format(self.id) - - def get_author(self): - try: - return User.objects.get(username=self.author) - except User.DoesNotExist: - return None - - def get_modified_by(self): - try: - return User.objects.get(username=self.modified_by) - except User.DoesNotExist: - return None - - -class Wiki(models.Model, HitCounterModelMixin): - name = models.TextField(primary_key=True) - wiki_text = models.TextField(blank=True) - author = models.TextField(blank=True) - collaborators = models.TextField(blank=True) - created = models.DateTimeField(blank=True, null=True) - modified = models.DateTimeField(blank=True, null=True) - modified_by = models.TextField(blank=True) - - class Meta: - managed = False - db_table = 'wiki_view' - - def get_absolute_url(self): - return u'/wiki/{}'.format(self.name) - - def get_author(self): - try: - return User.objects.get(username=self.author) - except User.DoesNotExist: - return None - - def get_modified_by(self): - try: - return User.objects.get(username=self.modified_by) - except User.DoesNotExist: - return None diff --git a/colab/plugins/trac/routers.py b/colab/plugins/trac/routers.py deleted file mode 100644 index 37a8ee9..0000000 --- a/colab/plugins/trac/routers.py +++ /dev/null @@ -1,23 +0,0 @@ -class TracRouter(object): - def db_for_read(self, model, **hints): - if model._meta.app_label == 'proxy': - return 'trac' - return None - - def db_for_write(self, model, **hints): - if model._meta.app_label == 'proxy': - return 'trac' - return None - - def allow_relation(self, obj1, obj2, **hints): - if obj1._meta.app_label == 'proxy' or \ - obj2._meta.app_label == 'proxy': - return True - return None - - def allow_migrate(self, db, model): - if db == 'trac': - return model._meta.app_label == 'proxy' - elif model._meta.app_label == 'proxy': - False - return None diff --git a/colab/plugins/trac/search_indexes.py b/colab/plugins/trac/search_indexes.py deleted file mode 100644 index 0e0923f..0000000 --- a/colab/plugins/trac/search_indexes.py +++ /dev/null @@ -1,155 +0,0 @@ -# -*- coding: utf-8 -*- - -import string - -from django.template import loader, Context -from haystack import indexes -from haystack.utils import log as logging - -from colab.search.base_indexes import BaseIndex -from .models import Attachment, Ticket, Wiki, Revision - - -logger = logging.getLogger('haystack') - -# the string maketrans always return a string encoded with latin1 -# http://stackoverflow.com/questions/1324067/how-do-i-get-str-translate-to-work-with-unicode-strings # noqa -table = string.maketrans( - string.punctuation, - '.' * len(string.punctuation) -).decode('latin1') - - -class AttachmentIndex(BaseIndex, indexes.Indexable): - title = indexes.CharField(model_attr='filename') - description = indexes.CharField(model_attr='description', null=True) - modified = indexes.DateTimeField(model_attr='created', null=True) - used_by = indexes.CharField(model_attr='used_by', null=True, stored=False) - mimetype = indexes.CharField( - model_attr='mimetype', - null=True, - stored=False - ) - size = indexes.IntegerField(model_attr='size', null=True, stored=False) - filename = indexes.CharField(stored=False) - - def get_model(self): - return Attachment - - def get_updated_field(self): - return 'created' - - def prepare(self, obj): - data = super(AttachmentIndex, self).prepare(obj) - - try: - file_obj = open(obj.filepath) - except IOError as e: - logger.warning(u'IOError: %s - %s', e.strerror, e.filename) - return data - backend = self._get_backend(None) - - extracted_data = backend.extract_file_contents(file_obj) - file_obj.close() - - if not extracted_data: - return data - - t = loader.select_template( - ('search/indexes/proxy/attachment_text.txt', ) - ) - data['text'] = t.render(Context({ - 'object': obj, - 'extracted': extracted_data, - })) - return data - - def prepare_filename(self, obj): - return obj.filename.translate(table).replace('.', ' ') - - def prepare_icon_name(self, obj): - return u'file' - - def prepare_type(self, obj): - return u'attachment' - - -class WikiIndex(BaseIndex, indexes.Indexable): - title = indexes.CharField(model_attr='name') - collaborators = indexes.CharField( - model_attr='collaborators', - null=True, - stored=False, - ) - - def get_model(self): - return Wiki - - def prepare_description(self, obj): - return u'{}\n{}'.format(obj.wiki_text, obj.collaborators) - - def prepare_icon_name(self, obj): - return u'book' - - def prepare_type(self, obj): - return u'wiki' - - -class TicketIndex(BaseIndex, indexes.Indexable): - tag = indexes.CharField(model_attr='status', null=True) - milestone = indexes.CharField(model_attr='milestone', null=True) - component = indexes.CharField(model_attr='component', null=True) - severity = indexes.CharField(model_attr='severity', null=True) - reporter = indexes.CharField(model_attr='reporter', null=True) - keywords = indexes.CharField(model_attr='keywords', null=True) - collaborators = indexes.CharField( - model_attr='collaborators', - null=True, - stored=False, - ) - - def get_model(self): - return Ticket - - def prepare_description(self, obj): - return u'{}\n{}\n{}\n{}\n{}\n{}\n{}'.format( - obj.description, obj.milestone, obj.component, obj.severity, - obj.reporter, obj.keywords, obj.collaborators - ) - - def prepare_icon_name(self, obj): - return u'tag' - - def prepare_title(self, obj): - return u'#{} - {}'.format(obj.pk, obj.summary) - - def prepare_type(self, obj): - return 'ticket' - - -class RevisionIndex(BaseIndex, indexes.Indexable): - description = indexes.CharField(model_attr='message', null=True) - modified = indexes.DateTimeField(model_attr='created', null=True) - repository_name = indexes.CharField( - model_attr='repository_name', - stored=False - ) - - def get_model(self): - return Revision - - def get_updated_field(self): - return 'created' - - def get_boost(self, obj): - boost = super(RevisionIndex, self).get_boost(obj) - return boost * 0.8 - - def prepare_icon_name(self, obj): - return u'align-right' - - def prepare_title(self, obj): - return u'{} [{}]'.format(obj.repository_name, obj.rev) - - def prepare_type(self, obj): - return 'changeset' diff --git a/colab/plugins/trac/signals.py b/colab/plugins/trac/signals.py deleted file mode 100644 index cb0d4d1..0000000 --- a/colab/plugins/trac/signals.py +++ /dev/null @@ -1,33 +0,0 @@ - -from django.db import connections -from django.dispatch import receiver -from django.db.models.signals import post_save - -from colab.accounts.models import User - - -@receiver(post_save, sender=User) -def change_session_attribute_email(sender, instance, **kwargs): - cursor = connections['trac'].cursor() - - cursor.execute(("UPDATE session_attribute SET value=%s " - "WHERE name='email' AND sid=%s"), - [instance.email, instance.username]) - cursor.execute(("UPDATE session_attribute SET value=%s " - "WHERE name='name' AND sid=%s"), - [instance.get_full_name(), instance.username]) - - cursor.execute(("INSERT INTO session_attribute " - "(sid, authenticated, name, value) " - "SELECT %s, '1', 'email', %s WHERE NOT EXISTS " - "(SELECT 1 FROM session_attribute WHERE sid=%s " - "AND name='email')"), - [instance.username, instance.email, instance.username]) - - cursor.execute(("INSERT INTO session_attribute " - "(sid, authenticated, name, value) " - "SELECT %s, '1', 'name', %s WHERE NOT EXISTS " - "(SELECT 1 FROM session_attribute WHERE sid=%s " - "AND name='name')"), - [instance.username, instance.get_full_name(), - instance.username]) diff --git a/colab/plugins/trac/templates/proxy/trac.html b/colab/plugins/trac/templates/proxy/trac.html deleted file mode 100644 index bae56e4..0000000 --- a/colab/plugins/trac/templates/proxy/trac.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "base.html" %} - -{% block head %} - - - {{ block.super }} -{% endblock %} diff --git a/colab/plugins/trac/templates/search/indexes/proxy/attachment_text.txt b/colab/plugins/trac/templates/search/indexes/proxy/attachment_text.txt deleted file mode 100644 index 9b22bae..0000000 --- a/colab/plugins/trac/templates/search/indexes/proxy/attachment_text.txt +++ /dev/null @@ -1,15 +0,0 @@ -{{ object.filename }} -{{ object.filename|slugify }} -{{ object.description }} -{{ object.description|slugify }} -{{ object.used_by }} -{{ object.mimetype }} -{{ object.get_author.get_full_name }} - -{% for k, v in extracted.metadata.items %} - {% for val in v %} - {{ k }}: {{ val|safe }} - {% endfor %} -{% endfor %} - -{{ extracted.contents|striptags|safe }} diff --git a/colab/plugins/trac/templates/search/indexes/proxy/revision_text.txt b/colab/plugins/trac/templates/search/indexes/proxy/revision_text.txt deleted file mode 100644 index 64cca83..0000000 --- a/colab/plugins/trac/templates/search/indexes/proxy/revision_text.txt +++ /dev/null @@ -1,8 +0,0 @@ -{{ object.repository_name }} -{{ object.repository_name|slugify }} -{{ object.rev }} -{{ object.rev|slugify }} -{% firstof object.get_author.get_full_name object.author %} -{% firstof object.get_author.get_full_name|slugify object.author|slugify %} -{{ object.message }} -{{ object.message|slugify }} diff --git a/colab/plugins/trac/templates/search/indexes/proxy/ticket_text.txt b/colab/plugins/trac/templates/search/indexes/proxy/ticket_text.txt deleted file mode 100644 index 93d199e..0000000 --- a/colab/plugins/trac/templates/search/indexes/proxy/ticket_text.txt +++ /dev/null @@ -1,20 +0,0 @@ -{{ object.summary }} -{{ object.summary|slugify }} -{{ object.description }} -{{ object.description|slugify }} -{{ object.milestone }} -{{ object.milestone|slugify }} -{{ object.component|slugify }} -{{ object.version }} -{{ object.severity }} -{{ object.severity|slugify }} -{{ object.reporter }} -{{ object.reporter|slugify }} -{% firstof object.get_author.get_fullname or object.author %} -{% firstof object.get_author.get_fullname|slugify or object.author|slugify %} -{{ object.status }} -{{ object.status|slugify }} -{{ object.keywords }} -{{ object.keywords|slugify }} -{{ object.collaborators }} -{{ object.collaborators|slugify }} diff --git a/colab/plugins/trac/templates/search/indexes/proxy/wiki_text.txt b/colab/plugins/trac/templates/search/indexes/proxy/wiki_text.txt deleted file mode 100644 index d1b51c4..0000000 --- a/colab/plugins/trac/templates/search/indexes/proxy/wiki_text.txt +++ /dev/null @@ -1,9 +0,0 @@ -{{ object.author }} -{{ object.get_author.get_full_name }} -{{ object.get_author.get_full_name|slugify }} -{{ object.name }} -{{ object.name|slugify }} -{{ object.collaborators }} -{{ object.collaborators|slugify }} -{{ object.wiki_text }} -{{ object.wiki_text|slugify }} diff --git a/colab/plugins/trac/urls.py b/colab/plugins/trac/urls.py deleted file mode 100644 index 4d78679..0000000 --- a/colab/plugins/trac/urls.py +++ /dev/null @@ -1,10 +0,0 @@ - -from django.conf.urls import patterns, url - -from .views import TracProxyView - - -urlpatterns = patterns('', - # Trac - url(r'^(?P.*)$', TracProxyView.as_view(), name='trac'), -) diff --git a/colab/plugins/trac/views.py b/colab/plugins/trac/views.py deleted file mode 100644 index c189e91..0000000 --- a/colab/plugins/trac/views.py +++ /dev/null @@ -1,40 +0,0 @@ - -from hitcounter.views import HitCounterViewMixin - -from ..utils.views import ColabProxyView -from .models import Wiki, Ticket, Revision - - -class TracProxyView(HitCounterViewMixin, ColabProxyView): - app_label = 'trac' - diazo_theme_template = 'proxy/trac.html' - - def get_object(self): - obj = None - - if self.request.path_info.startswith('/wiki'): - wiki_name = self.request.path_info.split('/', 2)[-1] - if not wiki_name: - wiki_name = 'WikiStart' - try: - obj = Wiki.objects.get(name=wiki_name) - except Wiki.DoesNotExist: - return None - elif self.request.path_info.startswith('/ticket'): - ticket_id = self.request.path_info.split('/')[2] - try: - obj = Ticket.objects.get(id=ticket_id) - except (Ticket.DoesNotExist, ValueError): - return None - elif self.request.path_info.startswith('/changeset'): - try: - changeset, repo = self.request.path_info.split('/')[2:4] - except ValueError: - return None - try: - obj = Revision.objects.get(rev=changeset, - repository_name=repo) - except Revision.DoesNotExist: - return None - - return obj diff --git a/colab/urls.py b/colab/urls.py index b230bc9..f80e525 100644 --- a/colab/urls.py +++ b/colab/urls.py @@ -35,7 +35,6 @@ urlpatterns = patterns('', # Uncomment the next line to enable the admin: url(r'^colab/admin/', include(admin.site.urls)), - url(r'^trac/', include('colab.plugins.trac.urls')), url(r'^gitlab/', include('colab.plugins.gitlab.urls')), url(r'^mezuro/', include('colab.plugins.mezuro.urls')), url(r'^social/', include('colab.plugins.noosfero.urls')), -- libgit2 0.21.2