def inner_decorator(request,*args, **kwargs):
     system = args[0]
     childs = findChild(request.session["system"])
     if isChild(int(system),childs):
         return func(request, *args, **kwargs)
     else:
         return HttpResponseForbidden(u"Você não tem permissão para alterar esse sistema.")        
예제 #2
0
def delete(request,offset):
  if request.method == 'POST':
    
    user = User.objects.get(pk=int(offset))
    profile = UserProfile.objects.get(profile=int(offset))
    
    profile.delete()
    user.delete()
    
    system = request.session['system']
    
    #TO-DO pegar usarios pelo ID do sistema
    users = User.objects.filter(system=system)
    
    return render_to_response("accounts/templates/delete_finish.html",locals(),context_instance=RequestContext(request))
    
  else:
    user = User.objects.get(pk=int(offset))
    profile = UserProfile.objects.get(profile=int(offset))
    
    system = request.session['system']
    try:
        s = System.objects.get(users__id=user.id)
    except:
        s = System.objects.get(administrator__id = user.id)
        
    if isChild(s.id,[system,findChild(system)]): 
      return render_to_response("accounts/templates/delete.html",locals(),context_instance=RequestContext(request))
      
    else:
      return HttpResponseForbidden(u'Você não tem permissão para deletar este usuário.')      
예제 #3
0
    def __init__(self,current_system, system, *args, **kwargs):
        super(EquipmentsForm, self).__init__(*args, **kwargs)

        #searching the brothers of the system: the not_systems list is here to guarantee that only one subsystem
        #can have an equipment of the parent's equip list.
        childs = findChild(current_system)
        parent = System.objects.get(pk=system).parent

        not_systems =  findDirectChild(parent.id)
        
        not_systems.remove(system)
        if not_systems is None:
            not_systems = []
        
        #mounting the list of possible choices    
        queryset = Equipment.objects.filter(system=parent).exclude(system__in=not_systems).order_by('type').values_list('id','serial','type__name')
        initial = Equipment.objects.filter(system=system).values_list('id', flat=True)
        
        queryset = map(lambda x: (x[0],x[1]+' : '+x[2]), queryset)
        #initial = map(lambda x: (x[0],x[1]+' : '+x[2]), initial)
        
        self.fields["equipments"].choices = queryset
        self.fields["equipments"].initial = initial
        
        #cosmetic things
        self.fields["equipments"].label = ""
예제 #4
0
def index(request):
    system_id = request.session['system']
        
    childs = findChild(system_id)
    geofence_tree = mountGeofenceTree([system_id,childs],system_id)
    
    return render_to_response("geofence/templates/index.html",locals())
예제 #5
0
def index(request):
    system = request.session["system"]
    childs = findChild(system)
    vector_html = []

    rendered_list = render_equipment_html(childs)
    
    print childs
    
    return render_to_response("equipments/templates/home.html",locals())
예제 #6
0
def permissions(request,offset):
 
        childs = findChild(request.session['system'])
        parent = System.objects.get(pk=int(offset)).parent
        system_name = System.objects.get(pk=int(offset))

        equip_types = EquipmentType.objects.filter(equipment__system=int(offset)).distinct()

        AvailableFieldsFormset = formset_factory(AvailableFieldsForm, extra=len(equip_types))        
        if request.method == 'POST':
                formset = AvailableFieldsFormset(request.POST)
                
                if formset.is_valid() or not formset.is_valid():
                    for form in formset.cleaned_data:
                        try:
                            form["equip_type"] = EquipmentType.objects.get(name = form["equip_type"])
                            AvailableFields.objects.filter(Q(system=int(offset))&Q(equip_type=form["equip_type"])).delete()
                            
                            av = AvailableFields()
                            av.system = System.objects.get(pk=int(offset))
                            
                            av.equip_type = form["equip_type"]
                            av.save()
                            
                            for cf in form["custom_fields"]:
                                av.custom_fields.add(cf.custom_field)
                            av.save()
                        except KeyError:
                            pass
                    
                    if request.session["system_being_created"]:
                        return HttpResponseRedirect("/equipment/fieldnames/"+offset)
                    else:        
                        return HttpResponseRedirect("/equipment/finish/")
        else:
            
            formset = AvailableFieldsFormset()
            for form,equip in zip(formset,equip_types):
                
                form.fields["custom_fields"].queryset = CustomFieldName.objects.filter(Q(custom_field__availablefields__system = parent) & Q(custom_field__availablefields__equip_type = equip)& Q(system=int(offset)))
                
                form.fields["custom_fields"].initial = CustomFieldName.objects.filter(Q(custom_field__availablefields__system = int(offset)) & Q(custom_field__availablefields__equip_type = equip)&Q(system=int(offset)))
                
                form.fields["custom_fields"].label = ""
                form.fields["equip_type"].initial = EquipmentType.objects.get(pk=equip.id).name
                if not form.fields["custom_fields"].queryset:
                    form.fields["custom_fields"].widget = HiddenInput()
                    form.fields["equip_type"].widget = HiddenInput()
                    

            return render_to_response("equipments/templates/permissions.html",locals(),context_instance=RequestContext(request)) 
예제 #7
0
def index(request):
    c = {}
    c.update(csrf(request))
    system = request.session['system']
    
    #TO-DO pegar usarios pelo ID do sistema
    
    users = User.objects.filter(system=system)
    
    rendered_list = ""
    
    for item in users:
      
      rendered_list+=u"<tr style='width:5%;' ><td style='width:50%;'>"+item.username+": </td><td><a class='table-button' href=\"/accounts/edit/"+str(item.id)+"/\">Editar</a>  <a class='table-button' href=\"/accounts/delete/"+str(item.id)+"/\">Apagar</a></td></tr>"
    
    
    rendered_list = render_user_html([system,findChild(system)])
    return render_to_response("accounts/templates/home.html",locals(),context_instance=RequestContext(request))
예제 #8
0
def edit(request,offset):
  
  user = User.objects.get(pk=int(offset))
  profile = UserProfile.objects.get(profile=int(offset))
  first_login = profile.is_first_login
  if request.method == 'POST':
    request.session["dont_check_first_login"] = True
    form = UserCompleteForm(request.POST,instance= user,profile=profile)
    form_user = UserForm(request.POST, instance = user)
    form_profile = UserProfileForm(request.POST, instance = profile)
    
    
    if form_user.is_valid() and form_profile.is_valid():
        new_user = form_user.save(commit=False)
        new_user.set_password(new_user.password)
        new_user.save()
        
        try:
            alert = request.POST["alert"]
        except:
            alert = None
            
        try:
          command = request.POST["command"]
        except:
          command = None

        try:
          adm = request.POST['Administrador']
        except:
          adm = None

        
        if adm is not None:
          user.groups.add(1)
          
        elif alert is not None and command is not None:
          user.groups.add(2)
          user.groups.add(3)
          
        elif command is not None:
          user.groups.add(3)
          
        elif alert is not None:
          user.groups.add(2)
        
        new_profile = form_profile.save()
        if (first_login == False):
            return HttpResponseRedirect ("/accounts/edit/finish")
        else:
            profile.is_first_login == False
            profile.save()
            return HttpResponseRedirect ("/accounts/edit/finish_firstlogin")

    return render_to_response("accounts/templates/edit.html",locals(),context_instance=RequestContext(request))
    
  else:
    request.session["dont_check_first_login"] = False
    system = request.session['system']
    users = User.objects.filter(system=system)
    profile = UserProfile.objects.get(profile=user)
    
    try:
        s = System.objects.get(users__id=user.id)
    except:
        s = System.objects.get(administrator__id = user.id)
    if isChild(s.id,[system,findChild(system)]):

        form = UserCompleteForm(instance = user,profile = profile)
      
        # ROOOTS BLOODY ROOTS
        if profile.is_first_login == False:
            form.fields["Administrador"] = forms.CharField(widget=forms.CheckboxInput(),help_text="Marque a caixa para atribuir privilégios administrativos ao usuário")
      
        else:
            title1 = "Primeiro acesso"
            
            title2 = "Para sua segurança solicitamos que mude sua senha antes de acessar o sistema."
            
        form.initial = dict( form.initial.items() + profile.__dict__.items())
        form.initial["password"] = ""
        return render_to_response("accounts/templates/edit.html",locals(),context_instance=RequestContext(request))
      
    else:
      return HttpResponseForbidden(u'Você não tem permissão para editar este usuário.')
예제 #9
0
def index(request):
    system = request.session['system']
    
    equipments = Command.objects.filter(system = system)
    rendered_list = ""
    
    display_list = []
    
    
    #conect to mt gateway to get status updates
    
    #host = settings.MXT_IP
    #port = settings.MXT_PORT
    #skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
    #skt.connect((host,port))
    
    hasmtcinlist = False
    for c in equipments:
        _equiptype = str(c.equipment.equipment.type).strip()
        if _equiptype == "MTC-400":
            if c.state!= u'2' and c.state!= u'3':
                eqX = c.equipment.equipment
                sent = False 
                cfX = CustomField.objects.get(tag="SendCmdState")
                t0 = TrackingData.objects.filter(type=cfX).filter(tracking__equipment=eqX).latest('tracking__eventdate')
                if t0.value=='1' or t0.value==1:
                    c.state = u'1'
                    t0.value = 201 # value 1, which is 'sending', is also being used now.
                    t0.save()
                cfX = CustomField.objects.get(tag="Output1")
                tX = TrackingData.objects.filter(type=cfX).filter(tracking__equipment=eqX).latest('tracking__eventdate')
                if str(tX.value)=="1" and c.action=='ON':
                    c.state = u'2'
                    c.time_executed = tX.tracking.eventdate
                elif str(tX.value)=="0" and c.action=='OFF':
                    c.state= u'2'
                    c.time_executed = tX.tracking.eventdate
                c.save()
        else: #old code (leandro|fabio)
            #checks the status of the command and update if matches the equipment tracking table
            tracking = Tracking.objects.filter(equipment=c.equipment.equipment).order_by('eventdate').reverse()[0]
            trackingdata = TrackingData.objects.filter(tracking=tracking).filter(type=c.type.custom_field)
            if c.action == 'ON' and len(trackingdata) > 0:
                c.state = u"2"
                c.time_executed = tracking.eventdate
                c.save()
            elif c.action == 'OFF' and len(trackingdata) == 0 :
                c.state = u"2"
                c.time_executed = tracking.eventdate
                c.save()
            
        sender = User.objects.get(pk=c.sender_id)
        
        display_list.append({
            'plate': c.equipment.license_plate,
            'type': c.type,
            'state': str(c.state),
            'time_sent': (c.time_sent),
            'time_received': str(c.time_received),
            'time_executed': (c.time_executed),
            'id': c.id,
            'action' : c.action,
            'sender': str(sender.username)
#            'test':str(c.type)
        })

    childs = findChild(system)
    command_tree = mountCommandTree([system,childs],system)    
    
    return render_to_response("command/templates/index.html",locals(),context_instance=RequestContext(request))