示例#1
0
 def posted(*args, **kwargs):
     request = args[0]
     if request.method == 'POST':
         if 'query' in request.POST:
             return viewfunc(*args, **kwargs)
         else:
             return HttpResponseBadRequest(json_error('Query missing.'))
     else:
         return HttpResponseBadRequest(json_error('Post only.'))
示例#2
0
 def posted(*args, **kwargs):
     request = args[0]
     if request.method == 'POST':
         if 'query' in request.POST:
             return viewfunc(*args, **kwargs)
         else:
             return HttpResponseBadRequest(json_error('Query missing.'))
     else:
         return HttpResponseBadRequest(json_error('Post only.'))
示例#3
0
文件: views.py 项目: Bartelo/openjumo
def fetch_org_by_centroid(request):
    try:
        lat = float(request.POST.get('lat'))
        lon = float(request.POST.get('lon'))
        limit = float(request.POST.get('limit', 20))
    except AttributeError:
        json_error(INVALID_CENTROID_ERROR)

    orgs = Org.objects.filter(location__latitude__range = (lat - limit, lat + limit)).filter(location__longitude__range = (lon - limit, lon + limit))[0:limit]
    return json_response(json_encode(orgs))
示例#4
0
def fetch_org_by_centroid(request):
    try:
        lat = float(request.POST.get('lat'))
        lon = float(request.POST.get('lon'))
        limit = float(request.POST.get('limit', 20))
    except AttributeError:
        json_error(INVALID_CENTROID_ERROR)

    orgs = Org.objects.filter(
        location__latitude__range=(lat - limit, lat + limit)).filter(
            location__longitude__range=(lon - limit, lon + limit))[0:limit]
    return json_response(json_encode(orgs))
示例#5
0
def update_org(request):
    try:
        org = json.loads(request.POST.get('org', {}))
        org_id = int(org['id'])
    except AttributeError:
        json_error(INVALID_ORG_ID_ERROR)

    str_fields = [
        'name',
        'email',
        'phone_number',
        'url',
        'img_url',
        'revenue',
        'size',
        'vision_statement',
        'mission_statement',
        'blog_url',
        'twitter_id',
        'flickr_id',
        'vimeo_id',
        'youtube_id',
    ]

    int_fields = [
        'year_founded',
        'facebook_id',  # changed 'year' to 'year_founded' here -b
    ]

    bool_fields = [
        'fb_fetch_enabled',
        'twitter_fetch_enabled',
    ]

    original = Org.objects.get(id=org_id)

    if 'parent_orgs' in org:
        if org['parent_orgs']:
            original.parent_org = Org.objects.get(id=org['parent_orgs'][0])

    if 'ein' in org and org['ein'] != original.ein:
        original.donation_enabled = False
        if org['ein'] == '':
            original.ein = ''
        else:
            original.ein = org['ein']
            try:
                original.donation_enable = False
            #  if nfg_api.npo_is_donation_enabled(org['ein']):
            #      original.donation_enabled = True
            except Exception, inst:
                logging.exception("Error checking donation status with nfs")
示例#6
0
文件: views.py 项目: Bartelo/openjumo
def error_404(request):
    if request.is_ajax():
        exception = getattr(request, 'exception', None)
        return json_error(404, exception)

    return HttpResponseNotFound(render_string(request, 'errors/error.html', {
            }))
示例#7
0
文件: views.py 项目: Bartelo/openjumo
def error_500(request):
    if request.is_ajax():
        exception = getattr(request, 'exception', None)
        return json_error(500, exception)

    return HttpResponseServerError(render_string(request, 'errors/error.html', {
            }))
示例#8
0
def error_404(request):
    if request.is_ajax():
        exception = getattr(request, 'exception', None)
        return json_error(404, exception)

    return HttpResponseNotFound(render_string(request, 'errors/error.html',
                                              {}))
示例#9
0
def error_500(request):
    if request.is_ajax():
        exception = getattr(request, 'exception', None)
        return json_error(500, exception)

    return HttpResponseServerError(
        render_string(request, 'errors/error.html', {}))
示例#10
0
文件: views.py 项目: Bartelo/openjumo
def normalize_facebook_id(request):
    facebook_id = request.POST['fbid']

    if facebook_id:
        try:
            facebook_id = facebook_id_magic(facebook_id)
        except:
            return json_error(123, 'Sorry, your Facebook ID is invalid')

    return json_response({"facebook_id": facebook_id })
示例#11
0
def normalize_facebook_id(request):
    facebook_id = request.POST['fbid']

    if facebook_id:
        try:
            facebook_id = facebook_id_magic(facebook_id)
        except:
            return json_error(123, 'Sorry, your Facebook ID is invalid')

    return json_response({"facebook_id": facebook_id})
示例#12
0
文件: views.py 项目: Bartelo/openjumo
def update_org(request):
    try:
        org = json.loads(request.POST.get('org', {}))
        org_id = int(org['id'])
    except AttributeError:
        json_error(INVALID_ORG_ID_ERROR)

    str_fields = [
                    'name', 'email', 'phone_number', 'url', 'img_url',
                    'revenue', 'size', 'vision_statement', 'mission_statement',
                    'blog_url', 'twitter_id', 'flickr_id', 'vimeo_id', 'youtube_id',
                 ]

    int_fields = [
                    'year_founded', 'facebook_id', # changed 'year' to 'year_founded' here -b
                 ]

    bool_fields = [
                    'fb_fetch_enabled', 'twitter_fetch_enabled',
                  ]

    original = Org.objects.get(id = org_id)


    if 'parent_orgs' in org:
        if org['parent_orgs']:
            original.parent_org = Org.objects.get(id = org['parent_orgs'][0])

    if 'ein' in org and org['ein'] != original.ein:
        original.donation_enabled = False
        if org['ein'] == '':
            original.ein = ''
        else:
            original.ein = org['ein']
            try:
                original.donation_enable = False
              #  if nfg_api.npo_is_donation_enabled(org['ein']):
              #      original.donation_enabled = True
            except Exception, inst:
                logging.exception("Error checking donation status with nfs")
示例#13
0
文件: views.py 项目: Bartelo/openjumo
def forgot_password(request):
    email = request.POST['email'].strip()
    try:
        u = User.objects.get(email = email, is_active=True)
    except:
        return json_error(INVALID_EMAIL_ERROR, 'No user at that email address.')
    pr = PasswordResetRequest()
    pr.user = u
    pr.uid = str(uuid4().hex)
    pr.save()
    p = PasswordResetRequest.objects.all()
    send_notification(type=EmailTypes.RESET_PASSWORD,
                                  user=u,
                                  entity=u,
                                  password_reset_id=pr.uid)
    return json_response({'response' : 1})
示例#14
0
def forgot_password(request):
    email = request.POST['email'].strip()
    try:
        u = User.objects.get(email=email, is_active=True)
    except:
        return json_error(INVALID_EMAIL_ERROR,
                          'No user at that email address.')
    pr = PasswordResetRequest()
    pr.user = u
    pr.uid = str(uuid4().hex)
    pr.save()
    p = PasswordResetRequest.objects.all()
    send_notification(type=EmailTypes.RESET_PASSWORD,
                      user=u,
                      entity=u,
                      password_reset_id=pr.uid)
    return json_response({'response': 1})
示例#15
0
def create(request):
    entity_id = request.POST['object_id']
    entity_type = request.POST['content_type']
    content_type = ContentType.objects.get(id=entity_type)
    entity = content_type.get_object_for_this_type(id=entity_id)
    commitment = Commitment(entity=entity, user=request.user)

    response = redirect(entity)
    try:
        commitment.full_clean()
        commitment.save()
        if request.is_ajax():
            button = render_inclusiontag(request, "commitment_button entity", "commitment_tags",
                                         {'entity': entity})
            actions = render_string(request, "action/includes/action_list.html", {
                'entity': entity,
                'actions': entity.actions.all(),
            })
            response = json_response({'button': button, 'actions': actions})
    except ValidationError:
        if request.is_ajax():
            response = json_error(400, "You have already committed to this issue/org.")
    return response
示例#16
0
def flag_org(request):
    try:
        org_id = getattr(request.POST, 'org_id')
        org = Org.objects.get(id=org_id)
    except AttributeError, ObjectDoesNotExist:
        return json_error(CANNOT_FLAG_ERROR)
示例#17
0
def remove_org(request):
    try:
        id = getattr(request.POST, 'id')
        org = Org.objects.get(id=id)
    except AttributeError, ObjectDoesNotExist:
        return json_error(INVALID_ORG_ID_ERROR)
示例#18
0
文件: views.py 项目: Bartelo/openjumo
def flag_org(request):
    try:
        org_id = getattr(request.POST, 'org_id')
        org = Org.objects.get(id = org_id)
    except AttributeError, ObjectDoesNotExist:
        return json_error(CANNOT_FLAG_ERROR)
示例#19
0
 def posted(*args, **kwargs):
     request = args[0]
     if request.method == 'POST':
         return viewfunc(*args, **kwargs)
     return HttpResponseBadRequest(json_error('Post only.'))
示例#20
0
文件: views.py 项目: Bartelo/openjumo
def remove_org(request):
    try:
        id = getattr(request.POST, 'id')
        org = Org.objects.get(id = id)
    except AttributeError, ObjectDoesNotExist:
        return json_error(INVALID_ORG_ID_ERROR)
示例#21
0
 def posted(*args, **kwargs):
     request = args[0]
     if request.method == 'POST':
         return viewfunc(*args, **kwargs)
     return HttpResponseBadRequest(json_error('Post only.'))