コード例 #1
0
ファイル: forms.py プロジェクト: esauro/SingularMS
 def save(self, commit=True):
     instance = super(singleAdminCommandForm, self).save(commit=False)
     instance.type = ADMIN
     ans = Body(plainTxt = self.cleaned_data['answer'])
     ans.save()
     instance.defaultAnswer = ans
     # Getting a translation if available
     try:
         index = int(self.cleaned_data['action'])            
         actionName = getNameFromTuple(ADMIN_COMMAND_LIST_CHOICES, index)
         translatedCommandType = ADMIN_COMMAND_TRANSLATION[self.language][actionName]
     except KeyError:
         translatedCommandType = actionName
          
     channel = Channel.objects.get(pk=self.cleaned_data['channel'])
     instance.pattern = translatedCommandType + ASCII_SPACE + channel.name                
     if commit:
         # Already existing commands are deleted
         try:
             oldcommand = Command.objects.get(pattern=instance.pattern)
             oldcommand.delete()
         except Command.DoesNotExist:
             pass            
         instance.save()            
         adminInstance = AdminCommand()
         adminInstance.command = instance
         adminInstance.channel = channel
         adminInstance.action = self.cleaned_data['action']
         adminInstance.save()            
     return instance
コード例 #2
0
ファイル: views.py プロジェクト: esauro/SingularMS
def getRow(request, block, keyfield, obj, urlname=None):    
    # Special cases:    
    # Handling choicefields.
    if keyfield in CHOICE_FIELDS.keys():
        fullname = getNameFromTuple(CHOICE_FIELDS[keyfield], obj[keyfield])
        if fullname:
                block.append(fullname)
                return None
        else:
            warning (request, 'getRow', "Requested field: %s, which doesn't exist for %s. Fields are: %s"
                  % (keyfield, urlname, obj) )            
    if keyfield in 'action':        
        num = obj[keyfield]
        for item in ADMIN_COMMAND_LIST_CHOICES:
            if item[0] is num:
                block.append(item[1])
                return None
        else:
            warning (request, 'getRow', "Requested field: %s, which doesn't exist for %s. Fields are: %s"
                  % (keyfield, urlname, obj) )
    # Adding the field by default            
    try:    
        block.append(obj[keyfield])
        return None
    except KeyError:
        pass
    new_keyfield = keyfield + '_id'
    try:
        primaryKey = obj[new_keyfield]
    except KeyError:    
        warning (request, 'getRow', "Requested field: %s, which doesn't exist for %s. Fields are: %s"
                  % (keyfield, urlname, obj) )        
        raise Http404  
    # Lets get the unicode data  
    if new_keyfield in SPECIAL_KEYFIELDS.keys():
        model = SPECIAL_KEYFIELDS[new_keyfield]
        try:
            data = model.objects.get(pk=primaryKey)
        except model.DoesNotExist:
            data = None
        block.append(data)
        return None    
    return None