コード例 #1
0
ファイル: views.py プロジェクト: nick6918/ThingCloud
def complain(request):
    _user = request.user
    user = User.objects.filter(uid=user["uid"])
    user = user[0]
    oid = request.POST.get("oid", None)
    notes = request.POST.get("notes", None)
    if not oid or not notes:
        return Jsonify({"status":False, "error":"1101", "error_message":u"输入信息不足。"})
    oid = int(oid)
    _order = Order.objects.filter(oid=oid)
    if not _order:
        return Jsonify({"status":False, "error":"1302", "error_message":u"订单不存在。"})
    else:
        _order = _order[0]
        if _order.state!=5:
            return Jsonify({"status":False, "error":"1303", "error_message":u"用户无权进行此操作。"})
        else:
            comp = Complaint(order_id=oid, user_id=_user["uid"], notes=notes, state=0)
            comp.save()
            _order.state = 9
            itemList = _order.itemList
            thingList = getThingList(itemList)
            address = Address.objects.filter(adid=_order.addr_id)
            if address:
                address = address[0]
                address = address.toDict()
            else:
                address=""
            _order.save()
            return Jsonify({"status":True, "error":"", "error_message":"", "order":_order.toDict(), "thinglist":thingList, "address":address, "detail":u"同仓存取快递费: 6元。"})
コード例 #2
0
ファイル: management.py プロジェクト: lqs4188980/DOB_analyzer
 def getResolve(self, complaint_number):
     complaint_number = str(complaint_number)
     info = {}
     if exists(p for p in Complaint if p.complaint_number == complaint_number):
         obj = Complaint.get(complaint_number=complaint_number)
         info = self.__resolveDataPacker(obj)
     return info
コード例 #3
0
def image(request):
    '''
        This is the landing page for Municipalithree where all the complaints can be searched and browsed
    '''
    image = Complaint.get_by_id(int(request.GET.get('id',0))).photo
    response = HttpResponse(image,mimetype="image")
    return response
コード例 #4
0
    def post(self, c_id):
        args = request.get_json()

        if ('status' not in args):
            return {'success': False, 'error': "invalid input"}
        status = args['status']

        complaint = Complaint.get(c_id)
        if complaint is None:
            return {"success": False, "error": "404 Not found"}
        if (complaint.get_status() != 'waiting'):
            return {
                "success": False,
                "error": "The complaint status is already set"
            }

        try:
            complaint.set_status(status)
        except ValueError as e:
            return {"success": False, "error": "Invalid Status"}

        complainant = complaint.get_complainant()
        prev_comment = complaint.get_latest_comment()
        prev_post_id = complaint.id if prev_comment is None else prev_comment.id

        twitter_api.update_status(
            '@' + complainant.account_handle + '! Your complaint has been ' +
            status + '. Thanks for registering your complaint.', prev_post_id)

        return {"success": True, "error": False}
コード例 #5
0
    def get(self, c_id):
        complaint = Complaint.get(c_id)
        if complaint is None:
            return {"success": False, "error": "404 Not found"}

        complaint_json = {}
        complaint_json['id'] = complaint.id
        complaint_json['text'] = complaint.text
        complaint_json['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(
            complaint.timestamp)
        complaint_json['status'] = complaint.status

        result = {}
        result['complaint'] = complaint_json
        result['comments'] = []

        comments = complaint.get_comments()
        for comment in comments:
            comment_json = {}
            comment_json['id'] = comment.id
            comment_json['text'] = comment.text
            comment_json['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(
                comment.timestamp)
            comment_json['by'] = comment.by

            result['comments'].append(comment_json)

        result['success'] = True
        return result
コード例 #6
0
    def post(self, c_id):
        args = request.get_json()

        if ('text' not in args):
            return {'success': False, 'error': "invalid input"}

        complaint = Complaint.get(c_id)

        if (complaint is None):
            return {'success': False, 'error': "complaint not found"}

        complainant = complaint.get_complainant()
        prev_comment = complaint.get_latest_comment()
        comment_text = args['text']

        prev_post_id = complaint.id if prev_comment is None else prev_comment.id
        s = twitter_api.update_status(
            '@' + complainant.account_handle + '!\n' + comment_text,
            prev_post_id)
        comment_id = s.id

        comment = Comment.create_comment(complaint,
                                         prev_comment,
                                         id=str(comment_id),
                                         text=comment_text,
                                         timestamp=datetime.datetime.now(),
                                         by='admin')
        comment.save()

        complaint.latest_comment_id = comment.id
        complaint.save()

        return {'success': True}
コード例 #7
0
def browsers(request):
    if request.method == "POST":
      pass
    else:
      complaints = Complaint.all()
      data = [{"id":idx+1, "title":c.title, "desc":c.desc, "loc":c.add, "status":c.status, "remarks":c.remarks} for idx,c in enumerate(complaints)]
      response = {"id":-1,"fieldErrors":[],"sError":"","aaData":data}
    return HttpResponse(json.dumps(response),mimetype='application/json')
コード例 #8
0
def dashboard(request):
    user = users.get_current_user()
    if user:
      if user.email() == settings.SUPERUSER_EMAIL_ID:
        logout_url = users.create_logout_url(settings.SITE_URL)
        complaints = Complaint.all()
        return render_to_response("dashboard.html", locals(), context_instance=RequestContext(request))
    else:
      return redirect(settings.SITE_URL)
コード例 #9
0
ファイル: views.py プロジェクト: raman2805/pukar
def AddComplaint(request) : 
  context = RequestContext(request)
  c = Complaint()
  # <to-do-some-sanity-checking>
  if request.method == 'GET' :
    c = Complaint()
    # figure out the userid
    c.complainant = GetUserFromRequest(request)
    c.location = request.GET.get('location', 'unknown')
    c.complaint_time = datetime.datetime.now()
    c.status = 'OPEN'
    if 'informer' in request.GET :
      c.informer = request.GET.get('informer')
    c.save()
  return HttpResponseRedirect('/sos_action/update/%s' % (c.id))
コード例 #10
0
ファイル: app.py プロジェクト: hvorovk/flask-lab-example
def add_comp():
    if request.method == 'POST':
        db.session.add(
            Complaint(request.form["type"], request.form["flat"],
                      request.form["date"], request.form["comment"]))
        db.session.commit()
        return redirect("/comp")
    else:
        return render_template("add_comp.html",
                               flats=Flat.query.all(),
                               types=TypeComplaint.query.all())
コード例 #11
0
def stats(request):
    '''
      This view handles the Stats page for Municipalithree.
    '''
#    user = users.get_current_user()
    complaints = Complaint.all()
#    if user:
#        logout_url = users.create_logout_url(settings.SITE_URL)
#    else:
#        login_url = users.create_login_url(settings.SITE_URL)
    return render_to_response("stats.html", locals(), context_instance=RequestContext(request))
コード例 #12
0
def browse(request):
    '''
        This is the landing page for Municipalithree where all the complaints can be searched and browsed
    '''
#    user = users.get_current_user()
    complaints = Complaint.all()
#    if user:
#        logout_url = users.create_logout_url(settings.SITE_URL)
#    else:
#        login_url = users.create_login_url(settings.SITE_URL)
    return render_to_response("browse.html", locals(), context_instance=RequestContext(request))
コード例 #13
0
def home(request):
    '''
        This is the landing page for Municipalithree where all the complaints can be searched and browsed
    '''
    user = users.get_current_user()
    complaints = Complaint.all()
    if user:
      if user.email() == settings.SUPERUSER_EMAIL_ID:
        return redirect(settings.SITE_URL + 'dashboard/')      
    else:
      login_url = users.create_login_url(settings.SITE_URL)
    return render_to_response("index.html", locals(), context_instance=RequestContext(request))
コード例 #14
0
    def setUp(self):
        # Rinnegan.app.config['TESTING'] = True
        # Rinnegan.app.config['MAIL_SUPPRESS_SEND'] = True
        self.app = Rinnegan.app.test_client()
        self.mail = Rinnegan.mail

        self.complainant = Complainant(account_handle="goyal_arush",
                                       account_type="twitter")

        self.complainant.save()

        self.supervisor = Supervisor(email="*****@*****.**",
                                     password="******")

        self.supervisor.save()

        self.complaint = Complaint(text="random text",
                                   timestamp=datetime.datetime.now(),
                                   status="waiting",
                                   complainant_id=self.complainant.id)

        self.complaint.save()
コード例 #15
0
    def test_comment(self):
        comment_text = "Hey Bro!"
        rv = self.comment(self.complaint.id, comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        self.login(self.supervisor.email, self.supervisor.password)

        rv = self.comment("randomid", comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        rv = self.comment(self.complaint.id, comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)

        self.complaint = Complaint.get(self.complaint.id)
        latest_comment = self.complaint.get_latest_comment()
        self.assertEqual(comment_text, latest_comment.text)
コード例 #16
0
    def get(self, status, skip, limit):
        if ((status != "all" and status != "resolved" and status != "rejected"
             and status != "waiting")):
            return {"success": False, "error": "Invalid input"}

        if (status == "all"):
            status = None

        complaints = Complaint.get_by_timestamp(skip, limit, status)
        complaints_json = []
        for complaint in complaints:
            complaint_json = {}
            complaint_json['id'] = complaint.id
            complaint_json['text'] = complaint.text
            complaint_json['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(
                complaint.timestamp)
            complaint_json['status'] = complaint.status

            complaints_json.append(complaint_json)

        result = {}
        result['complaints'] = complaints_json
        result['success'] = True
        return result
コード例 #17
0
class ComplaintResourceTestCase(unittest.TestCase):
    def setUp(self):
        # Rinnegan.app.config['TESTING'] = True
        # Rinnegan.app.config['MAIL_SUPPRESS_SEND'] = True
        self.app = Rinnegan.app.test_client()
        self.mail = Rinnegan.mail

        self.complainant = Complainant(account_handle="goyal_arush",
                                       account_type="twitter")

        self.complainant.save()

        self.supervisor = Supervisor(email="*****@*****.**",
                                     password="******")

        self.supervisor.save()

        self.complaint = Complaint(text="random text",
                                   timestamp=datetime.datetime.now(),
                                   status="waiting",
                                   complainant_id=self.complainant.id)

        self.complaint.save()

    def get_complaints(self, skip, limit):
        return self.app.get('/v1/complaints/ofstatus/all/' + str(skip) + '/' +
                            str(limit))

    def get_complaint(self, c_id):
        return self.app.get('/v1/complaints/' + c_id)

    def set_complaint_status(self, c_id, status):
        posted_dict = {'status': status}
        return self.app.post('/v1/complaints/' + c_id + '/status',
                             data=json.dumps(posted_dict),
                             content_type='application/json')

    def login(self, email, password):
        posted_dict = {'email': email, 'password': password}
        return self.app.post('/v1/login',
                             data=json.dumps(posted_dict),
                             content_type='application/json')

    def logout(self):
        return self.app.post('/v1/logout', content_type='application/json')

    def comment(self, c_id, text):
        posted_dict = {'text': text}

        return self.app.post('/v1/complaints/' + c_id + '/comments',
                             data=json.dumps(posted_dict),
                             content_type='application/json')

    def dejsonify(self, string):
        obj = json.loads(string.decode('utf-8'))
        return obj

    def test_get_complaints(self):
        rv = self.get_complaints(0, 5)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        self.login(self.supervisor.email, self.supervisor.password)

        rv = self.get_complaints(0, 5)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)

        rv = self.get_complaints(100, 200)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)
        self.assertEqual(len(j['complaints']), 0)

    def test_get_complaint(self):
        rv = self.get_complaint(self.complaint.id)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        self.login(self.supervisor.email, self.supervisor.password)

        rv = self.get_complaint(self.complaint.id)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)

        rv = self.get_complaint("random_string")
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

    def test_set_complaint_status(self):
        rv = self.set_complaint_status(self.complaint.id, "rejected")
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        self.login(self.supervisor.email, self.supervisor.password)

        rv = self.set_complaint_status("randomid", "rejected")
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        rv = self.set_complaint_status(self.complaint.id, "somestatus")
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        rv = self.set_complaint_status(self.complaint.id, "rejected")
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)
        rv = self.get_complaint(self.complaint.id)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['complaint']['status'], "rejected")

    def test_comment(self):
        comment_text = "Hey Bro!"
        rv = self.comment(self.complaint.id, comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        self.login(self.supervisor.email, self.supervisor.password)

        rv = self.comment("randomid", comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], False)

        rv = self.comment(self.complaint.id, comment_text)
        j = self.dejsonify(rv.data)
        self.assertEqual(j['success'], True)

        self.complaint = Complaint.get(self.complaint.id)
        latest_comment = self.complaint.get_latest_comment()
        self.assertEqual(comment_text, latest_comment.text)

    def tearDown(self):
        self.logout()
        self.supervisor.delete()
        self.complaint.delete()
        self.complainant.delete()
コード例 #18
0
ファイル: views.py プロジェクト: kedark3/clrms
def complaint_send(request):

    u=request.session['user']
    lab_name=request.session['lab']
    description=request.POST['describe']
    computer=request.session['computer']
    type_of_complaint=request.session['type_of_complaint']
    if type_of_complaint == "Hardware" or type_of_complaint=="Software":
        selected= request.POST['selection']
    else:
        selected="other"

    construct_complaint=[]
    conn = connect()
    cur = conn.cursor()
    cur.execute ("select dead_stock_no,ip_address,mac_address from account_computer where computer_name='%s'"%computer)
    for row in cur.fetchall ():
       construct_complaint.append (row[0])
       construct_complaint.append (row[1])
       construct_complaint.append (row[2])


    #Update Logic------------------------------

    comp=Computer.objects.get(computer_name=computer)
    l=Lab.objects.get(name=lab_name)
    l.complaints_made=l.complaints_made+1
    incharge=l.incharge
    assistant=l.assistant
    l.save()

    if type_of_complaint == "Software" or type_of_complaint== "Hardware":
        fatal=CommonComplaints.objects.get(complaint=selected)
        if 'Printer' in fatal.complaint:
            p=Printers.objects.get(computer=comp.id)
            p.complaints_made=p.complaints_made+1
            p.status='OFF'
            p.save()
        if 'Scanner' in fatal.complaint:
            s=Scanners.objects.get(computer=comp.id)
            s.complaints_made=s.complaints_made+1
            s.status='OFF'
            s.save()
        complaint_update=Complaint(lab=l,computer_name=comp,complaint=CommonComplaints.objects.get(complaint=selected),\
        date=time.strftime("%Y-%m-%d"),status='Pending')
        complaint_update.save()
        if fatal.critical == 1:
            comp.status='OFF'
    comp.complaints_made=comp.complaints_made+1
    comp.description=comp.description+':\nCompalint'+selected+'  '+description
    comp.save()




    mailContent= '\nlab:'+lab_name+ '\nComputer: ' + computer+'\nType:'+type_of_complaint+'\nComplaint:'+selected+ '\n'+ description +\
    '\nDeadStock No.:'+ str(construct_complaint[0])+'\nIP:'+ str(construct_complaint[1])+'\nMAC:'+ \
    str(construct_complaint[2]) + '\n' \
    + '\n\n\nThis is an auto-generated email from our website.'

    send_mail('Complaint from:' + u, mailContent, '*****@*****.**',[incharge,assistant], fail_silently=False)

    return HttpResponseRedirect('http://kedark7893.pythonanywhere.com/Thank-You')