Commits

Julio Flores-Schwarzbeck committed d5bbe4c

50% into Q&A management, finally it'll be System roperties, then
writing a quick and dirty manual and *finally* the first
"release candidate"

Comments (0)

Files changed (5)

controllers/admin.py

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+# IDE "helper" not part of the framework
+if False:
+    from gluon.globals import *
+    from gluon.html import *
+    from gluon.http import *
+    #from gluon.sqlhtml import SQLFORM, SQLTABLE, form_factory
+    session = Session()
+    request = Request()
+    response = Response()
+    # The following three lines are application-specific and used just so
+    # komodo (edit) (or even other IDEs sich as Wing) "finds" the methods
+    # for my classes, this does not have anyhing to do with the web2py
+    # framework itself, as I am already instantiating "auth_user",
+    # "stackhelper" etc in one of my models...
+    from qastack.models import db
+    from qastack.modules.CustomAuthentication import CustomAuthentication \
+        as auth_user
+    from qastack.modules.QAStackHelper import QAStackHelper as stackhelper
+
+
 @auth_user.requires_role('SysAdmin')
 def index():
     req = request.vars # /admin/function?tag=value
 
 @auth_user.requires_role('SysAdmin')
 def qa_mgmt():
+    """ Main page to control question/answer/comment management, usually
+    to manage any of those that have been flagged for deletion.
+    
+    """
     q_cnt = db(db.questions.is_visible==False).count()
     qc_cnt = db((db.comments.c_type=='Q') & (
         db.comments.is_visible==False)).count()
 
 @auth_user.requires_role('SysAdmin')
 def qa_mgmt_hq():
+    """ Management of question that have been marked for possible deletion
+    by a sysadmin.
+    
+    """
     questions = db(db.questions.is_visible==False).select(
         db.questions.ALL, orderby=~db.questions.modified_on)
     return dict(questions=questions)
 
+
+@auth_user.requires_role('SysAdmin')
+def qa_mgmt_hqc():
+    """ Management of commments for a question that have been marked for
+    possible deletion by a sysadmin.
+    
+    """    
+    questions = db(
+        (db.questions.id==db.comments.qa_id) & (db.comments.c_type=='Q') & (
+            db.comments.is_visible==False)).select(
+        db.comments.qa_id, db.comments.description, db.comments.id,
+        db.questions.id, db.questions.title, db.comments.modified_on,
+        orderby=~db.comments.modified_on)
+    return dict(questions=questions)
+
+
 @auth_user.requires_role('SysAdmin')
 def qa_mgmt_actions():
     """ This really should be a "helper" method for a module instead
         # other question's siblings (comments, answers, and answers
         # to comments should become visible as well
         db(db.questions.id==question).update(is_visible=True)
-    redirect(URL(r=request, c='admin', f='qa_mgmt_hq'))
+    elif action == 'remove' and action_type == 'question':
+        # This is a little bit more "complex" so to speak, the following
+        # rules will apply:
+        # Question is deleted.
+        # Comments on the actual question, as well as answers and comments
+        # on these answers are also removed.
+        # Points awarded, etc remain.
+        
+        # 1. Remove all comments for this question
+        db((db.comments.c_type=='Q') & (db.comments.qa_id==question)).delete()
+        
+        # 2. Get all the possible answers for this question
+        answers = db(db.answers.question_id==question).select(db.answers.id)
+        
+        # 3. for each answer, remove all its comments and the answer itself
+        if answers:
+            # Store all of our answer_ids
+            a_ids = [answer.id for answer in answers]
+            # Remove any comments for any of the answer ids stored above
+            db((db.comments.c_type=='A') & (
+                db.comments.qa_id.belongs(tuple(a_ids)))).delete()
+            # Remove all the answers for this question
+            db(db.answers.question_id==question).delete()
+            
+        # 4. Remove the actual question.
+        db(db.questions.id==question).delete()
+        
+        # 5. Clean up stub tables:
+        # Remove the references of this question from the subscriptions
+        # table in case some members have this question marked
+        db(db.question_subscriptions.question_id==question).delete()
+        # Remove the tags associated with this question
+        db(db.question_tags.question_id==question).delete()
+    redirect(URL(r=request, c='admin', f='qa_mgmt_hq'))
+    

controllers/members.py

             
             # Hide the question
             db(db.questions.id==qid).update(is_visible=False)
-            # Hide the answers
-            db(db.answers.question_id==qid).update(is_visible=False)
-            # Hide the comments of the question
-            db((db.comments.c_type=='Q') &\
-               (db.comments.qa_id==qid)).update(is_visible=False)
-            # Get all the answers for this question, and for each one
-            # of them, invalidate their respective comments
-            answers = db(db.answers.question_id==qid).select(db.questions.id)
-            for answer in answers:
-                db((db.comments.c_type=='A') &\
-                   (db.comments.qa_id==answer.id)).update(is_visible=False)
+            # The following will be temporarily disabled, as removing the
+            # Question from public view will effectively hide the comments,
+            # answers and comments on answers for this question,
+            ## Hide the answers
+            #db(db.answers.question_id==qid).update(is_visible=False)
+            ## Hide the comments of the question
+            #db((db.comments.c_type=='Q') &\
+            #   (db.comments.qa_id==qid)).update(is_visible=False)
+            ## Get all the answers for this question, and for each one
+            ## of them, invalidate their respective comments
+            #answers = db(db.answers.question_id==qid).select(db.questions.id)
+            #for answer in answers:
+            #    db((db.comments.c_type=='A') &\
+            #       (db.comments.qa_id==answer.id)).update(is_visible=False)
             # The question is not "visible" anymore, redirect to home
             redirect(URL(r=request, c='default', f='index'))
         else:
 
 from gluon.tools import *
 
-# Control Migrations "automatically"
+# Control Migrations
 migrate = False
 
-# Allow auto completion work on Wing IDE
-if 0: 
-    from gluon.globals import * 
-    from gluon.html import * 
-    from gluon.http import * 
-    from gluon.sqlhtml import SQLFORM, SQLTABLE, form_factory 
-    session = Session() 
-    request = Request() 
-    response = Response()
-
 db = DAL('sqlite://qastack.sqlite')
 #db = DAL('mysql://web2py:py2web@ds9.virtual:3306/qastack')
 

views/admin/qa_mgmt_hq.html

                             style="vertical-align:middle;" /></a>
                         <a href="{{=URL(r=request, c='admin', f='qa_mgmt_actions', vars=dict(action='remove', action_type='question', question=q.id))}}"
                            title="Remove from the system"
-                           onclick="return confirm('This question and any dependancies (answers/comments) will be removed permanently from the system.\n\nPlease Confirm');"
+                           onclick="return confirm('This question and any dependancies (answers/comments) will be permanently removed from the system.\n\nPlease Confirm');"
                            class="nolink"
                         ><img src="{{=URL(r=request, c='static/images/small', f='x.png')}}"
                             alt="Remove Permanently"

views/admin/qa_mgmt_hqc.html

+{{extend 'qastack_layout.html'}}
+{{include 'admin_common.html'}}
+
+<script type="text/javascript">
+<!--
+     document.getElementById('aadmin').className = 'active';
+//-->
+
+</script>
+
+<h2 class="fancy">Administrative Messages - Q&amp;A Management - Hidden Comments for Questions</h2>
+
+<p><a href="{{=URL(r=request, c='admin', f='qa_mgmt')}}" title="">&lt;&lt; Back</a></p>
+
+{{if questions:}}
+    <table cellspacing="0" cellpadding="0" class="ftable">
+        <thead>
+            <tr class="shadedarker">
+                <th>&nbsp;</th>
+                <th>Question Title</th>
+                <th>Comment</th>
+                <th>Comment Date</th>
+                <th>Actions</th>
+            </tr>
+        </thead>
+        <tbody>
+            {{for idx,q in enumerate(questions):}}
+                <tr class="{{if idx%2:}}shadedark{{else:}}shadelight{{pass}}">
+                    <td style="text-align:center;">{{=idx+1}}</td>
+                    <td>
+                        <a href="{{=URL(r=request, c='default', f='view', args=[q.questions.id])}}"
+                        title="">{{=q.questions.title}}</a>
+                    </td>
+                    <td>
+                        <a href="{{=URL(r=request, c='default', f='view', args=[q.questions.id])}}"
+                        title="">{{=q.comments.description}}</a>
+                    </td>
+                    <td>{{=q.comments.modified_on.strftime('%c')}}</td>
+                    <td>
+                        <a href="{{=URL(r=request, c='admin', f='qa_mgmt_actions', vars=dict(action='release', action_type='question_comment', question=q.questions.id, comment=q.comments.id))}}"
+                           title="Make it publicly available"
+                           onclick="return confirm('This comment will become visible.\n\nPlease Confirm');"
+                           class="nolink"
+                        ><img src="{{=URL(r=request, c='static/images/small', f='checkmark.png')}}"
+                            alt="Restore"
+                            style="vertical-align:middle;" /></a>
+                        <a href="{{=URL(r=request, c='admin', f='qa_mgmt_actions', vars=dict(action='remove', action_type='question_comment', question=q.questions.id, comment=q.comments.id))}}"
+                           title="Remove from the system"
+                           onclick="return confirm('This comment will be permanently removed from the system.\n\nPlease Confirm');"
+                           class="nolink"
+                        ><img src="{{=URL(r=request, c='static/images/small', f='x.png')}}"
+                            alt="Remove Permanently"
+                            style="vertical-align:middle;" /></a>
+                    </td>
+                </tr>
+            {{pass}}
+        </tbody>
+    </table>
+{{else:}}
+    <p>No hidden comments found.</p>
+{{pass}}