示例#1
0
def _postdoc(request, is_image):
    docpath = u'{0}/{1}'.format(settings.MEDIA_ROOT, is_image and u'images'
                                or u'documents')

    if not os.path.exists(docpath):
        os.mkdir(docpath)

    f = request.FILES[u'file']

    fd = open(u'{0}/{1}'.format(docpath, f.name), u'wb+')
    for chunk in f.chunks():
        fd.write(chunk)
    fd.close()

    url = u'{0}/{1}/{2}'.format(settings.MEDIA_URL, is_image and u'images'
                                or u'documents', f.name)

    try:
        doc = Document.objects.get(path=url)

    except Document.DoesNotExist:
        doc = Document()

        doc.is_image = is_image
        doc.path = url

        doc.wikipath = request.POST[u'page']
        doc.save()

    return HttpResponse(doc.path)
示例#2
0
def document(**kwargs):
    """Return an empty document with enough stuff filled out that it can be
    saved."""
    defaults = {'category': CATEGORIES[0][0], 'title': str(datetime.now())}
    defaults.update(kwargs)
    if 'slug' not in kwargs:
        defaults['slug'] = slugify(defaults['title'])
    return Document(**defaults)
示例#3
0
def document(save=False, **kwargs):
    """Return an empty document with enough stuff filled out that it can be
    saved."""
    defaults = {'category': CATEGORIES[0][0], 'title': str(datetime.now()),
                'is_redirect': 0}
    defaults.update(kwargs)
    if 'slug' not in kwargs:
        defaults['slug'] = slugify(defaults['title'])
    d = Document(**defaults)
    if save:
        d.save()
    return d
示例#4
0
class UntranslatedReadout(Readout):
    title = _lazy(u'Untranslated')
    short_title = _lazy(u'Untranslated')
    details_link_text = _lazy(u'All untranslated articles...')
    slug = 'untranslated'
    column4_label = _lazy(u'Updated')

    def _query_and_params(self, max):
        # Incidentally, we tried this both as a left join and as a search
        # against an inner query returning translated docs, and the left join
        # yielded a faster-looking plan (on a production corpus).
        #
        # Find non-archived, localizable documents in categories 10,
        # 20 and 60 having at least one ready- for-localization
        # revision. Of those, show the ones that have no translation.
        return ('SELECT parent.slug, parent.title, '
                'wiki_revision.reviewed, dashboards_wikidocumentvisits.visits '
                'FROM wiki_document parent '
                'INNER JOIN wiki_revision ON '
                'parent.latest_localizable_revision_id=wiki_revision.id '
                'LEFT JOIN wiki_document translated ON '
                'parent.id=translated.parent_id AND translated.locale=%s '
                'LEFT JOIN dashboards_wikidocumentvisits ON '
                'parent.id=dashboards_wikidocumentvisits.document_id AND '
                'dashboards_wikidocumentvisits.period=%s '
                'WHERE '
                'translated.id IS NULL AND parent.is_localizable AND '
                'parent.category in (10, 20, 60) AND '
                'parent.locale=%s AND NOT parent.is_archived '
                'AND wiki_revision.content NOT LIKE "REDIRECT%%" ' +
                self._order_clause() + self._limit_clause(max),
                (self.locale, LAST_30_DAYS, settings.WIKI_DEFAULT_LANGUAGE))

    def _order_clause(self):
        return ('ORDER BY wiki_revision.reviewed DESC, parent.title ASC'
                if self.mode == MOST_RECENT else
                'ORDER BY dashboards_wikidocumentvisits.visits DESC, '
                'parent.title ASC')

    def _format_row(self, (slug, title, reviewed, visits)):
        # Run the data through the model to (potentially) format it and
        # take advantage of SPOTs (like for get_absolute_url()):
        d = Document(slug=slug,
                     title=title,
                     locale=settings.WIKI_DEFAULT_LANGUAGE)
        return dict(title=d.title,
                    url=d.get_absolute_url(),
                    visits=visits,
                    updated=reviewed)
示例#5
0
 def reload_period_from_json(cls, period, json_data):
     """Replace the stats for the given period with the given JSON."""
     counts = cls._visit_counts(json_data)
     if counts:
         # Delete and remake the rows:
         # Horribly inefficient until
         # http://code.djangoproject.com/ticket/9519 is fixed.
         cls.objects.filter(period=period).delete()
         for doc_id, visits in counts.iteritems():
             cls.objects.create(document=Document(pk=doc_id), visits=visits,
                                period=period)
     else:
         # Don't erase interesting data if there's nothing to replace it:
         log.warning('WebTrends returned no interesting data, so I kept '
                     'what I had.')
示例#6
0
 def reload_period_from_analytics(cls, period):
     """Replace the stats for the given period from Google Analytics."""
     counts = googleanalytics.pageviews_by_document(*period_dates(period))
     if counts:
         # Delete and remake the rows:
         # Horribly inefficient until
         # http://code.djangoproject.com/ticket/9519 is fixed.
         cls.objects.filter(period=period).delete()
         for doc_id, visits in counts.iteritems():
             cls.objects.create(document=Document(pk=doc_id), visits=visits,
                                period=period)
     else:
         # Don't erase interesting data if there's nothing to replace it:
         log.warning('Google Analytics returned no interesting data,'
                     ' so I kept what I had.')
示例#7
0
class UntranslatedReadout(Readout):
    title = _lazy(u'Untranslated')
    description = _lazy(
        u'This indicates there are no approved translations of these articles. '
        'Some of the articles may have proposed translations waiting to be '
        'reviewed and will appear in the Unreviewed Changes section as well.')
    short_title = _lazy(u'Untranslated')
    details_link_text = _lazy(u'All untranslated articles...')
    slug = 'untranslated'
    column4_label = _lazy(u'Updated')

    def _query_and_params(self, max):
        # Filter by product if specified.
        if self.product:
            extra_joins = PRODUCT_FILTER
            params = (self.locale, LAST_30_DAYS, self.product.id,
                      settings.WIKI_DEFAULT_LANGUAGE)
        else:
            extra_joins = ''
            params = (self.locale, LAST_30_DAYS,
                      settings.WIKI_DEFAULT_LANGUAGE)

        # Incidentally, we tried this both as a left join and as a search
        # against an inner query returning translated docs, and the left join
        # yielded a faster-looking plan (on a production corpus).
        #
        # Find non-archived, localizable documents in categories 10,
        # 20 and 60 having at least one ready- for-localization
        # revision. Of those, show the ones that have no translation.
        query = (
            'SELECT engdoc.slug, engdoc.title, '
            'wiki_revision.reviewed, dashboards_wikidocumentvisits.visits '
            'FROM wiki_document engdoc '
            'INNER JOIN wiki_revision ON '
            'engdoc.latest_localizable_revision_id=wiki_revision.id '
            'LEFT JOIN wiki_document translated ON '
            'engdoc.id=translated.parent_id AND translated.locale=%s '
            'LEFT JOIN dashboards_wikidocumentvisits ON '
            'engdoc.id=dashboards_wikidocumentvisits.document_id AND '
            'dashboards_wikidocumentvisits.period=%s ' + extra_joins + 'WHERE '
            '(translated.id IS NULL OR translated.current_revision_id IS NULL) '
            'AND engdoc.is_localizable AND '
            'engdoc.category in (10, 20, 60) AND '
            'engdoc.locale=%s AND NOT engdoc.is_archived '
            'AND wiki_revision.content NOT LIKE "REDIRECT%%" ' +
            self._order_clause() + self._limit_clause(max))

        return query, params

    def _order_clause(self):
        return ('ORDER BY wiki_revision.reviewed DESC, engdoc.title ASC'
                if self.mode == MOST_RECENT else
                'ORDER BY dashboards_wikidocumentvisits.visits DESC, '
                'engdoc.title ASC')

    def _format_row(self, (slug, title, reviewed, visits)):
        # Run the data through the model to (potentially) format it and
        # take advantage of SPOTs (like for get_absolute_url()):
        d = Document(slug=slug,
                     title=title,
                     locale=settings.WIKI_DEFAULT_LANGUAGE)
        return dict(title=d.title,
                    url=d.get_absolute_url(),
                    visits=visits,
                    updated=reviewed)