Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Aug 10, 2010
2 parents 8a12128 + dca544a commit b76cd10
Show file tree
Hide file tree
Showing 30 changed files with 435 additions and 390 deletions.
4 changes: 4 additions & 0 deletions apps/flagit/models.py
Expand Up @@ -51,3 +51,7 @@ class FlaggedObject(ModelBase):
class Meta:
unique_together = (('content_type', 'object_id', 'creator'),)
ordering = ['created']
permissions = (
('can_moderate',
'Can moderate flagged objects'),
)
4 changes: 2 additions & 2 deletions apps/flagit/templates/flagit/includes/flagged_question.html
Expand Up @@ -11,8 +11,8 @@ <h3>{{ _('Updated:') }}</h3>
<h3>{{ _('Take Action:') }}</h3>
<div class="actions">
<a href="{{ object.content_object.get_absolute_url() }}">View</a>
<a href="# {# TODO: depends on Erik's patch that adds edit question #}">Edit</a>
<a href="{{ url('questions.edit_question', object.content_object.id) }}">Edit</a>
{% if user.has_perm('questions.delete_question') %}
<a class="delete" href="{{ url('questions.delete', object.content_object.id) }}">{{ _('Delete') }}</a>
{% endif %}
</div>
</div>
44 changes: 24 additions & 20 deletions apps/flagit/templates/flagit/queue.html
Expand Up @@ -9,25 +9,29 @@ <h1>{{ _('Flagged Content Pending Moderation') }}</h1>
{% for object in objects %}
{% if loop.first %}<ul>{% endif %}
<li class="{{ object.content_type }}">
<hgroup>
<h2>{{ _('Flagged {t} (Reason: {r})')|f(t=object.content_type, r=object.get_reason_display()) }}</h2>
{% if object.notes %}
<h3 class="notes">{{ _('Other reason:') }} {{ object.notes }}</h3>
{% endif %}
</hgroup>
<div class="wrap">
{% include 'flagit/includes/flagged_%s.html' % object.content_type %}
<h3>{{ _('Update Status:') }}</h3>
<form class="update" action="{{ url('flagit.update', object.id) }}" method="post">
{{ csrf() }}
<select name="status">
<option value="">{{ _('Please select...') }}</option>
<option value="1">{{ _('The flag is valid and I fixed the issue.') }}</option>
<option value="2">{{ _('The flag is invalid.') }}</option>
</select>
<input type="submit" class="btn g-btn" value="Update" />
</form>
</div>
{% if object.content_object %}
<hgroup>
<h2>{{ _('Flagged {t} (Reason: {r})')|f(t=object.content_type, r=object.get_reason_display()) }}</h2>
{% if object.notes %}
<h3 class="notes">{{ _('Other reason:') }} {{ object.notes }}</h3>
{% endif %}
</hgroup>
<div class="wrap">
{% include 'flagit/includes/flagged_%s.html' % object.content_type %}
<h3>{{ _('Update Status:') }}</h3>
<form class="update" action="{{ url('flagit.update', object.id) }}" method="post">
{{ csrf() }}
<select name="status">
<option value="">{{ _('Please select...') }}</option>
<option value="1">{{ _('The flag is valid and I fixed the issue.') }}</option>
<option value="2">{{ _('The flag is invalid.') }}</option>
</select>
<input type="submit" class="btn g-btn" value="Update" />
</form>
</div>
{% else %}
{{ _('Oops! {t} {id} no longer exists.')|f(t=object.content_type, id=object.object_id) }}
{% endif %}
</li>
{% if loop.last %}</ul>{% endif %}
{% else %}
Expand All @@ -37,4 +41,4 @@ <h3>{{ _('Update Status:') }}</h3>
{% endblock %}

{% block side %}
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion apps/forums/tests/test_models.py
Expand Up @@ -135,7 +135,7 @@ class SaveDateTestCase(ForumTestCase):
and updated dates.
"""

delta = datetime.timedelta(milliseconds=50)
delta = datetime.timedelta(milliseconds=100)

def setUp(self):
super(SaveDateTestCase, self).setUp()
Expand Down
62 changes: 29 additions & 33 deletions apps/questions/management/commands/migrate_questions.py
Expand Up @@ -14,18 +14,31 @@
"""
from datetime import datetime
import re
import time

from django.core.management.base import BaseCommand, CommandError

from multidb.pinning import pin_this_thread

from questions.models import Question, Answer, CONFIRMED
from questions.question_config import products
from sumo.models import (Forum as TikiForum,
ForumThread as TikiThread,
ForumThreadMetaData as TikiThreadMetaData)
from sumo.converter import TikiMarkupConverter
from sumo.migration_utils import (get_django_user, fetch_threads, fetch_posts,
get_firefox_version, get_OS)
from sumo.migration_utils import get_django_user, fetch_threads, fetch_posts


CWW_REPLY_TITLE = 'Comment on thread %s'
CWW_REPLY_CONTENT = """We have migrated this forum thread to our new support\
system. The current system will no longer be accessible in a couple of months.
Please use and bookmark the link below to access and reply to this thread from\
now on.
__[/questions/%s|http://support.mozilla.com/questions/%s]__
Thank you!
"""


# Converts TikiWiki syntax to MediaWiki syntax
Expand Down Expand Up @@ -74,10 +87,6 @@ def clean_question_content(question):
"""

m = compiled_patterns_clean[0].search(question.content)
if m:
troubleshooting = m.group(1)

for p in compiled_patterns_clean:
question.content = p.sub('==', question.content)

Expand All @@ -86,9 +95,6 @@ def clean_question_content(question):
question.content = question.content.rstrip(' \t\r\n=')
question.save(no_update=True)

if m:
question.add_metadata(troubleshooting=troubleshooting)


def update_question_updated_date(question):
"""Update the question's updated date and set it to that of the most recent
Expand All @@ -100,6 +106,14 @@ def update_question_updated_date(question):
question.save(no_update=True)


def post_reply_in_old_thread(tiki_thread, question):
return TikiThread.objects.create(
type='n', object=6, objectType='forum', parentId=tiki_thread.threadId,
userName='Cww', commentDate=int(time.time()),
title=CWW_REPLY_TITLE % tiki_thread.threadId,
data=CWW_REPLY_CONTENT % (question.id, question.id))


def create_question(tiki_thread):
"""
Create a question from a Tiki thread.
Expand All @@ -113,7 +127,7 @@ def create_question(tiki_thread):
is_locked = (tiki_thread.type == 'l' or tiki_thread.type == 'a')

question = Question(
id=tiki_thread.threadId, title=tiki_thread.title, creator=creator,
title=tiki_thread.title, creator=creator,
is_locked=is_locked, status=CONFIRMED, confirmation_id='',
created=created, updated=created, content=content)

Expand All @@ -125,44 +139,25 @@ def create_question_metadata(question):
Look up metadata in the question and tiki_comments_metadata and create and
attach it to the QuestionMetaData model.
"""
dirty_content = question.content

clean_question_content(question)
metadata = TikiThreadMetaData.objects.filter(threadId=question.id)

for meta in metadata:
if meta.name == 'useragent':
question.add_metadata(useragent=meta.value)
# Look for OS and version
os_ = get_OS(meta.value)
if os_:
question.add_metadata(os=os_)
version = get_firefox_version(meta.value)
if version:
question.add_metadata(ff_version=version)

elif meta.name == 'plugins':
question.add_metadata(plugins=meta.value)

# Potential remaining metadata: sites_affected, troubleshooting

# Setting all questions to the desktop product
question.add_metadata(product='desktop')

# Set category based on the content
cats = products['desktop']['categories']
for c_name in cats:
if unicode(cats[c_name]['name']) in dirty_content:
question.add_metadata(category=c_name)
break
question.add_metadata(product='home')

# Auto-tag this question after the metadata is added
question.auto_tag()


class Command(BaseCommand):
forum_id = 1
help = 'Migrate data from forum 1.'
forum_id = 6
help = 'Migrate data from forum 6.'
max_threads = 100 # Max number of threads to store at any time
max_posts = 100 # Max number of posts to store at any time

Expand Down Expand Up @@ -234,6 +229,7 @@ def handle(self, *args, **options):
# Now that all answers have been migrated, update the question's
# updated date
update_question_updated_date(question)
post_reply_in_old_thread(tiki_thread, question)
thread_i = thread_i + 1

if options['verbosity'] > 0:
Expand Down
10 changes: 8 additions & 2 deletions apps/questions/models.py
Expand Up @@ -11,6 +11,7 @@
import product_details
from taggit.models import Tag

from flagit.models import FlaggedObject
from notifications import create_watch
from notifications.tasks import delete_watches
from sumo.models import ModelBase, TaggableMixin
Expand Down Expand Up @@ -54,6 +55,7 @@ class Question(ModelBase, TaggableMixin):
confirmation_id = models.CharField(max_length=40, db_index=True)

images = generic.GenericRelation(ImageAttachment)
flags = generic.GenericRelation(FlaggedObject)

class Meta:
ordering = ['-updated']
Expand Down Expand Up @@ -146,7 +148,7 @@ def category(self):
return {}

def auto_tag(self):
"""Apply tags to myself that are implied by my contents.
"""Apply tags to myself that are implied by my metadata.
You don't need to call save on the question after this.
Expand Down Expand Up @@ -252,6 +254,7 @@ class Answer(ModelBase):
upvotes = models.IntegerField(default=0, db_index=True)

images = generic.GenericRelation(ImageAttachment)
flags = generic.GenericRelation(FlaggedObject)

class Meta:
ordering = ['created']
Expand Down Expand Up @@ -287,13 +290,16 @@ def save(self, no_update=False, no_notify=False, *args, **kwargs):
def delete(self, *args, **kwargs):
"""Override delete method to update parent question info."""
question = Question.uncached.get(pk=self.question.id)
if question.last_answer and question.last_answer == self:
if question.last_answer == self:
answers = question.answers.all().order_by('-created')
try:
question.last_answer = answers[1]
except IndexError:
# The question has only one answer
question.last_answer = None
if question.solution == self:
question.solution = None

question.num_answers = question.answers.count() - 1
question.save()

Expand Down
42 changes: 33 additions & 9 deletions apps/questions/question_config.py
Expand Up @@ -22,6 +22,18 @@
('d2', {
'name': _('Firefox is crashing or closing unexpectedly'),
'extra_fields': ['crash_id'],
'articles': [
{'title': 'Firefox crashes',
'url': '/en-US/kb/Firefox+Crashes'},
{'title': 'Firefox crashes when you open it',
'url': '/en-US/kb/Firefox+crashes+when+you+open+it'},
{'title': 'Firefox crashes when loading certain pages',
'url': '/en-US/kb/Firefox+crashes+when+loading+certain+pages'},
{'title': 'Firefox crashes when you exit it',
'url': '/en-US/kb/Firefox+crashes+when+you+exit+it'},
{'title': 'The Adobe Flash plugin has crashed',
'url': '/en-US/kb/The+Adobe+Flash+plugin+has+crashed'},
],
'tags': ['crash'],
}),
('d3', {
Expand Down Expand Up @@ -109,9 +121,10 @@
}),
('b6', {
'name': _('I have feedback/suggestions about the beta'),
'html': 'You can provide feedback and suggestions<br /> 1) at our quick'
' feedback form<br /> 2) by taking our feedback survey or<br /> 3) by'
' suggesting features in our feedback forums.',
'html': 'Firefox 4 beta versions have a feedback system built in.'
' For more details, see our '
'<a href="http://www.mozilla.com/en-US/firefox/beta/feedback/">'
'beta feedback page</a>.',
'deadend': True,
}),
])
Expand Down Expand Up @@ -157,8 +170,15 @@
'tags': ['addon'],
}),
('m5', {
'name': _('I have feedback/suggestions about Firefox for Mobile'),
'html': 'You can provide feedback and suggestions in our feedback forums.',
'name': _('I have suggestions for how to improve Firefox for Mobile'),
'html': '<p>You can provide suggestions for '
'<strong>Firefox on Maemo</strong> in the '
'<a href="http://firefoxformobile.uservoice.com/forums/70215-firefox-for-maemo-ideas">'
'Maemo feedback forum</a>.</p>'
'<p>You can provide suggestions for '
'<strong>Firefox on Android</strong> in the '
'<a href="http://firefoxformobile.uservoice.com/forums/70211-firefox-for-android-ideas">'
'Android feedback forum</a>.</p>',
'deadend': True,
}),
])
Expand Down Expand Up @@ -197,8 +217,10 @@
'tags': ['sync'],
}),
('i4', {
'name': _('I have feedback/suggestions about Firefox Home for iPhone'),
'html': 'You can provide feedback and suggestions in our feedback forums.',
'name': _('I have suggestions for how to improve Firefox Home for iPhone'),
'html': 'You can provide suggestions in our '
'<a href="http://firefoxformobile.uservoice.com/forums/67057-firefox-home-ideas">'
'Firefox Home feedback forum</a>.',
'deadend': True,
}),
])
Expand Down Expand Up @@ -246,8 +268,10 @@
'tags': ['sync'],
}),
('s5', {
'name': _('I have feedback/suggestions about Firefox Home for iPhone'),
'html': 'You can provide feedback and suggestions in our feedback forums.',
'name': _('I have suggestions for how to improve Firefox Sync'),
'html': 'You can provide suggestions in our '
'<a href="http://assets2.getsatisfaction.com/mozilla_labs/products/mozilla_labs_weave_sync">'
'Firefox Sync feedback forum</a>.',
'deadend': True,
}),
])
Expand Down
4 changes: 2 additions & 2 deletions apps/questions/templates/questions/answers.html
Expand Up @@ -160,15 +160,15 @@ <h5>{{ _('Crash ID') }}</h5>
{% endif %}
{% if question.metadata.frequency %}
<h5>{{ _('This happened') }}</h5>
<p>{{ question.metadata.frequency }}</p>
<p>{{ frequencies[question.metadata.frequency] }}</p>
{% endif %}
{% if question.metadata.started %}
<h5>{{ _('This started when...') }}</h5>
<p>{{ question.metadata.started }}</p>
{% endif %}
{% if question.metadata.troubleshooting %}
<h5>{{ _('More Information') }}</h5>
<p>{{ question.metadata.troubleshooting }}</p>
<p>{{ question.metadata.troubleshooting|trim|collapse_linebreaks|nl2br }}</p>
{% endif %}
{% if question.metadata.plugins %}
<h5>{{ _('Installed Plug-ins') }}</h5>
Expand Down

0 comments on commit b76cd10

Please sign in to comment.