コード例 #1
0
def create_wammu(request):
    '''
    Compatibility interface for Wammu.
    '''
    INVALID = 'Invalid values: %s'
    OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d'
    OKAY_V2 = 'Entry created, id=%d, url=%s'
    invalid = []
    version = 1
    response = HttpResponse(content_type='text/plain')

    if 'irobot' not in request.POST or request.POST['irobot'] != 'wammu':
        invalid.append('irobot')

    if 'version' in request.POST:
        version = int(request.POST['version'])

    phone = Phone()

    try:
        phone.vendor = Vendor.objects.get(pk=int(request.POST['manufacturer']))
    except:
        invalid.append('vendor')

    try:
        phone.name = request.POST['name']
        if len(phone.name) == 0:
            invalid.append('name')
    except:
        invalid.append('name')

    try:
        phone.connection = Connection.objects.get(
            name=request.POST['connection'])
    except:
        invalid.append('connection')

    try:
        phone.model = request.POST['model']
        if phone.model == 'auto':
            phone.model = ''
    except:
        invalid.append('model')

    try:
        phone.note = request.POST['note']
    except:
        invalid.append('note')

    try:
        phone.author_name = request.POST['author_name']
    except:
        invalid.append('author_name')

    try:
        phone.author_email = request.POST['author_email']
    except:
        invalid.append('author_email')

    try:
        phone.email_garble = request.POST['email_garble']
        if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]:
            invalid.append('email_garble')
    except:
        invalid.append('email_garble')

    try:
        phone.gammu_version = request.POST['gammu_version']
    except:
        invalid.append('gammu_version')

    try:
        phone.full_clean()
    except ValidationError as e:
        invalid.extend(e.message_dict.keys())
        invalid = list(set(invalid))

    if len(invalid) > 0:
        response.write(INVALID % ','.join(invalid))
        return response

    features = []
    for feature in Feature.objects.all():
        key = 'fts[%s]' % feature.name
        if key in request.POST and request.POST[key] == '1':
            features.append(feature)

    phone.save()

    for feature in features:
        phone.features.add(feature)

    if version == 2:
        response.write(OKAY_V2 % (phone.id, phone.get_absolute_url()))
    else:
        response.write(OKAY % (phone.id, phone.vendor.slug, phone.id))
    return response
コード例 #2
0
def create_wammu(request):
    '''
    Compatibility interface for Wammu.
    '''
    INVALID = 'Invalid values: %s'
    OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d'
    OKAY_V2 = 'Entry created, id=%d, url=%s'
    invalid = []
    version = 1
    response = HttpResponse(content_type='text/plain')

    if not request.POST.has_key('irobot') or request.POST['irobot'] != 'wammu':
        invalid.append('irobot')

    if request.POST.has_key('version'):
        version = int(request.POST['version'])

    phone = Phone()

    try:
        phone.vendor = Vendor.objects.get(pk=int(request.POST['manufacturer']))
    except:
        invalid.append('vendor')

    try:
        phone.name = request.POST['name']
        if len(phone.name) == 0:
            invalid.append('name')
    except:
        invalid.append('name')

    try:
        phone.connection = Connection.objects.get(
            name=request.POST['connection'])
    except:
        invalid.append('connection')

    try:
        phone.model = request.POST['model']
        if phone.model == 'auto':
            phone.model = ''
    except:
        invalid.append('model')

    try:
        phone.note = request.POST['note']
    except:
        invalid.append('note')

    try:
        phone.author_name = request.POST['author_name']
    except:
        invalid.append('author_name')

    try:
        phone.author_email = request.POST['author_email']
    except:
        invalid.append('author_email')

    try:
        phone.email_garble = request.POST['email_garble']
        if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]:
            invalid.append('email_garble')
    except:
        invalid.append('email_garble')

    try:
        phone.gammu_version = request.POST['gammu_version']
    except:
        invalid.append('gammu_version')

    try:
        phone.full_clean()
    except ValidationError, e:
        invalid.extend(e.message_dict.keys())
        invalid = list(set(invalid))
コード例 #3
0
ファイル: views.py プロジェクト: juanjosezg/website
def create_wammu(request):
    '''
    Compatibility interface for Wammu.
    '''
    INVALID = 'Invalid values: %s'
    OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d'
    OKAY_V2 = 'Entry created, id=%d, url=%s'
    invalid = []
    version = 1
    response = HttpResponse(mimetype='text/plain')

    if not request.POST.has_key('irobot') or request.POST['irobot'] != 'wammu':
        invalid.append('irobot')

    if request.POST.has_key('version'):
        version = int(request.POST['version'])

    phone = Phone()

    try:
        phone.vendor = Vendor.objects.get(pk = int(request.POST['manufacturer']))
    except:
        invalid.append('vendor')

    try:
        phone.name = request.POST['name']
        if len(phone.name) == 0:
            invalid.append('name')
    except:
        invalid.append('name')

    try:
        phone.connection = Connection.objects.get(name = request.POST['connection'])
    except:
        invalid.append('connection')

    try:
        phone.model = request.POST['model']
        if phone.model == 'auto':
            phone.model = ''
    except:
        invalid.append('model')

    try:
        phone.note = request.POST['note']
    except:
        invalid.append('note')

    try:
        phone.author_name = request.POST['author_name']
    except:
        invalid.append('author_name')

    try:
        phone.author_email = request.POST['author_email']
    except:
        invalid.append('author_email')

    try:
        phone.email_garble = request.POST['email_garble']
        if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]:
            invalid.append('email_garble')
    except:
        invalid.append('email_garble')

    try:
        phone.gammu_version = request.POST['gammu_version']
    except:
        invalid.append('gammu_version')

    try:
        phone.full_clean()
    except ValidationError, e:
        invalid.extend(e.message_dict.keys())
        invalid = list(set(invalid))
コード例 #4
0
ファイル: views.py プロジェクト: gammu/website
def create_wammu(request):
    '''
    Compatibility interface for Wammu.
    '''
    INVALID = 'Invalid values: %s'
    OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d'
    OKAY_V2 = 'Entry created, id=%d, url=%s'
    invalid = []
    version = 1
    response = HttpResponse(content_type='text/plain')

    if 'irobot' not in request.POST or request.POST['irobot'] != 'wammu':
        invalid.append('irobot')

    if 'version' in request.POST:
        version = int(request.POST['version'])

    phone = Phone()

    try:
        phone.vendor = Vendor.objects.get(pk = int(request.POST['manufacturer']))
    except:
        invalid.append('vendor')

    try:
        phone.name = request.POST['name']
        if len(phone.name) == 0:
            invalid.append('name')
    except:
        invalid.append('name')

    try:
        phone.connection = Connection.objects.get(name = request.POST['connection'])
    except:
        invalid.append('connection')

    try:
        phone.model = request.POST['model']
        if phone.model == 'auto':
            phone.model = ''
    except:
        invalid.append('model')

    try:
        phone.note = request.POST['note']
    except:
        invalid.append('note')

    try:
        phone.author_name = request.POST['author_name']
    except:
        invalid.append('author_name')

    try:
        phone.author_email = request.POST['author_email']
    except:
        invalid.append('author_email')

    try:
        phone.email_garble = request.POST['email_garble']
        if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]:
            invalid.append('email_garble')
    except:
        invalid.append('email_garble')

    try:
        phone.gammu_version = request.POST['gammu_version']
    except:
        invalid.append('gammu_version')

    try:
        phone.full_clean()
    except ValidationError as e:
        invalid.extend(e.message_dict.keys())
        invalid = list(set(invalid))

    if len(invalid) > 0:
        response.write(INVALID % ','.join(invalid))
        return response

    features = []
    for feature in Feature.objects.all():
        key = 'fts[%s]' % feature.name
        if key in request.POST and request.POST[key] == '1':
            features.append(feature)

    phone.save()

    for feature in features:
        phone.features.add(feature)

    if version == 2:
        response.write(OKAY_V2 % (phone.id, phone.get_absolute_url()))
    else:
        response.write(OKAY % (phone.id, phone.vendor.slug, phone.id))
    return response
コード例 #5
0
ファイル: views.py プロジェクト: yeputons/website
def create_wammu(request):  # noqa: C901
    """
    Compatibility interface for Wammu.
    """
    invalid = []
    version = 1
    response = HttpResponse(content_type="text/plain")

    if "irobot" not in request.POST or request.POST["irobot"] != "wammu":
        invalid.append("irobot")

    if "version" in request.POST:
        version = int(request.POST["version"])

    phone = Phone()

    try:
        phone.vendor = Vendor.objects.get(pk=int(request.POST["manufacturer"]))
    except Exception:
        invalid.append("vendor")

    try:
        phone.name = request.POST["name"]
        if len(phone.name) == 0:
            invalid.append("name")
    except Exception:
        invalid.append("name")

    try:
        phone.connection = Connection.objects.get(
            name=request.POST["connection"])
    except Exception:
        invalid.append("connection")

    try:
        phone.model = request.POST["model"]
        if phone.model == "auto":
            phone.model = ""
    except Exception:
        invalid.append("model")

    try:
        phone.note = request.POST["note"]
    except Exception:
        invalid.append("note")

    try:
        phone.author_name = request.POST["author_name"]
    except Exception:
        invalid.append("author_name")

    try:
        phone.author_email = request.POST["author_email"]
    except Exception:
        invalid.append("author_email")

    try:
        phone.email_garble = request.POST["email_garble"]
        if phone.email_garble not in (x[0] for x in GARBLE_CHOICES):
            invalid.append("email_garble")
    except Exception:
        invalid.append("email_garble")

    try:
        phone.gammu_version = request.POST["gammu_version"]
    except Exception:
        invalid.append("gammu_version")

    try:
        phone.full_clean()
    except ValidationError as e:
        invalid.extend(e.message_dict.keys())
        invalid = list(set(invalid))

    if len(invalid) > 0:
        response.write(INVALID % ",".join(invalid))
        return response

    features = []
    for feature in Feature.objects.all():
        key = "fts[%s]" % feature.name
        if key in request.POST and request.POST[key] == "1":
            features.append(feature)

    phone.save()

    for feature in features:
        phone.features.add(feature)

    if version == 2:
        response.write(OKAY_V2 % (phone.id, phone.get_absolute_url()))
    else:
        response.write(OKAY % (phone.id, phone.vendor.slug, phone.id))
    return response
コード例 #6
0
import sys
sys.path = ['../'] + sys.path

from phonedb.models import Phone, Connection, Vendor, Feature
import csv
import datetime

if len(sys.argv) < 2:
    print 'Usage: import_phonedb_phones.py file.csv'
    sys.exit(1)

input = file(sys.argv[1])
reader = csv.reader(input)
for (id, vendor, name, features, connection, model, comment, author, email, garble, deleted, created, address, hostname, gammuver) in reader:
    phone = Phone()
    phone.id = int(id)
    phone.vendor = Vendor.objects.get(pk = vendor)
    phone.name = name
    if connection != 'NULL' and connection != '':
        phone.connection = Connection.objects.get(name = connection)
    phone.model = model
    phone.note = unicode(comment, 'utf-8')
    phone.author_name = unicode(author, 'utf-8')
    phone.author_email = unicode(email, 'utf-8')
    phone.email_garble = garble
    if phone.id >= 3038:
        phone.state = 'draft'
    elif deleted == '1':
        phone.state = 'deleted'
    else: