Пример #1
0
def registerOffer(request, *args, **kwargs):
    """The function for create, update offer information."""
    offer = None
    initParam = {}
    form = offerForms.OfferForm()

    # Initial data
    if kwargs.get("pk"):
        offer = get_object_or_404(offerModels.Offer, pk=kwargs.get("pk"), publisher_id=request.user.id)
        form = offerForms.OfferForm(instance=offer)

    # Create or update offer.
    if request.method == "POST":
        form = offerForms.OfferForm(request.POST, instance=offer)
        if form.is_valid():
            offer = form.save(commit=False)
            offer.publisher = request.user
            offer.save()

            offer.position.clear()
            for position in form.cleaned_data["position"]:
                offer.position.add(position)

            company_icon = request.FILES.get("company_icon")
            if company_icon:
                if company_icon.content_type.startswith("image"):
                    if company_icon.size > 1000000:
                        initParam["error"] = _("The image size must be not larger than 1M.")
                    else:
                        path = "/".join([settings.MEDIA_ROOT, str(request.user.id)])
                        if os.path.exists(path) is False:
                            os.makedirs(path)
                        if offer.company_icon:
                            path = "/".join([settings.MEDIA_ROOT, str(offer.company_icon)])
                            if os.path.exists(path):
                                os.remove(path)
                        offer.company_icon = company_icon
                        offer.save()
                        if company_icon:
                            # Shrink image to (50*50) for offer company_icon.
                            path = "/".join([settings.MEDIA_ROOT, str(offer.company_icon)])
                            common.imageThumbnail(path=path, size=[100, 100])
                        initParam["msg"] = _("The offer has been created successful.")
                        return redirect(reverse("offer:offer_detail", kwargs={"pk": offer.id}))
                else:
                    initParam["error"] = _("The file type of %(param)s is not supported.") % {
                        "param": company_icon.name
                    }
            else:
                initParam["msg"] = _("The offer has been created successfully.")
                return redirect(reverse("offer:offer_detail", kwargs={"pk": offer.id}))
    initParam["form"] = form
    return render_to_response("offer/register_offer.html", initParam, context_instance=RequestContext(request))
Пример #2
0
def userPublicProfile(request, *args, **kwargs):
    """Save user public profile."""
    initParam = {}
    user = get_object_or_404(models.User, pk=request.user.id, username=request.user.username)
    userPublicProfiles = models.UserPublicProfile.objects.filter(user_id=user.id)
    if userPublicProfiles:
        userPublicProfile = userPublicProfiles[0]
    else:
        userPublicProfile = models.UserPublicProfile()
        userPublicProfile.user = user
        userPublicProfile.gender = 3
        userPublicProfile.save()
    userPublicProfileForm = forms.UserPublicProfileForm(instance=userPublicProfile)
    if request.method == "POST":
        userPublicProfileForm = forms.UserPublicProfileForm(request.POST, instance=userPublicProfile)
        if userPublicProfileForm.is_valid():
            userPublicProfile = userPublicProfileForm.save(commit=False)
            userPublicProfile.user_id = request.user.id
            thumbnail = request.FILES.get('thumbnail')
            if thumbnail:
                if thumbnail.content_type.startswith('image'):
                    if thumbnail.size > 1000000:
                        initParam['account_error'] = _('The image size must be not larger than 1M.')
                    else:
                        path = '/'.join([settings.MEDIA_ROOT, str(user.id)])
                        if os.path.exists(path) is False:
                            os.makedirs(path)
                        if userPublicProfile.thumbnail:
                            path = '/'.join([settings.MEDIA_ROOT, str(userPublicProfile.thumbnail)])
                            if os.path.exists(path):
                                os.remove(path)
                        userPublicProfile.thumbnail = thumbnail
                        userPublicProfileForm = forms.UserPublicProfileForm(instance=userPublicProfile)
                        userPublicProfile.save()
                        if thumbnail:
                            #Shrink image to (50*50) for user thumbnail.
                            path = '/'.join([settings.MEDIA_ROOT, str(userPublicProfile.thumbnail)])
                            common.imageThumbnail(path=path, size=[50, 50])
                        initParam['account_msg'] = _('The public profile has been updated successful.')
                else:
                    initParam['account_error'] = _('The file type of %(param)s is not supported.') % {'param': thumbnail.name}
            else:
                userPublicProfile.save()
                initParam['account_msg'] = _('The public profile has been updated successfully.')

    initParam['form'] = userPublicProfileForm
    return render_to_response("usersetting/publicprofile.html", initParam, context_instance=RequestContext(request))
Пример #3
0
def userPublicProfile(request, *args, **kwargs):
    """Save user public profile."""
    initParam = {}
    user = get_object_or_404(models.User,
                             pk=request.user.id,
                             username=request.user.username)
    userPublicProfiles = models.UserPublicProfile.objects.filter(
        user_id=user.id)
    if userPublicProfiles:
        userPublicProfile = userPublicProfiles[0]
    else:
        userPublicProfile = models.UserPublicProfile()
        userPublicProfile.user = user
        userPublicProfile.gender = 3
        userPublicProfile.save()
    userPublicProfileForm = forms.UserPublicProfileForm(
        instance=userPublicProfile)
    if request.method == "POST":
        userPublicProfileForm = forms.UserPublicProfileForm(
            request.POST, instance=userPublicProfile)
        if userPublicProfileForm.is_valid():
            userPublicProfile = userPublicProfileForm.save(commit=False)
            userPublicProfile.user_id = request.user.id
            thumbnail = request.FILES.get('thumbnail')
            if thumbnail:
                if thumbnail.content_type.startswith('image'):
                    if thumbnail.size > 1000000:
                        initParam['account_error'] = _(
                            'The image size must be not larger than 1M.')
                    else:
                        path = '/'.join([settings.MEDIA_ROOT, str(user.id)])
                        if os.path.exists(path) is False:
                            os.makedirs(path)
                        if userPublicProfile.thumbnail:
                            path = '/'.join([
                                settings.MEDIA_ROOT,
                                str(userPublicProfile.thumbnail)
                            ])
                            if os.path.exists(path):
                                os.remove(path)
                        userPublicProfile.thumbnail = thumbnail
                        userPublicProfileForm = forms.UserPublicProfileForm(
                            instance=userPublicProfile)
                        userPublicProfile.save()
                        if thumbnail:
                            #Shrink image to (50*50) for user thumbnail.
                            path = '/'.join([
                                settings.MEDIA_ROOT,
                                str(userPublicProfile.thumbnail)
                            ])
                            common.imageThumbnail(path=path, size=[50, 50])
                        initParam['account_msg'] = _(
                            'The public profile has been updated successful.')
                else:
                    initParam['account_error'] = _(
                        'The file type of %(param)s is not supported.') % {
                            'param': thumbnail.name
                        }
            else:
                userPublicProfile.save()
                initParam['account_msg'] = _(
                    'The public profile has been updated successfully.')

    initParam['form'] = userPublicProfileForm
    return render_to_response("usersetting/publicprofile.html",
                              initParam,
                              context_instance=RequestContext(request))
Пример #4
0
 try:
     path = '/'.join(
         [settings.MEDIA_ROOT,
          str(model.publisher.id),
          str(model.id)])
     if os.path.exists(path) is False:
         os.makedirs(path)
     path = '/'.join([path, 'Icon.jpg'])
     if os.path.exists(path):
         os.remove(path)
     if result.get('artworkUrl512', None):
         if os.path.exists(path):
             os.remove(path)
         urllib.urlretrieve(result.get('artworkUrl512', None), path)
         #Shrink image From (1024*1024) to (200*200)
         common.imageThumbnail(path=path, size=[200, 200])
     elif result.get('artworkUrl100', None):
         urllib.urlretrieve(result.get('artworkUrl100', None), path)
     elif result.get('artworkUrl60', None):
         urllib.urlretrieve(result.get('artworkUrl60', None), path)
 except Exception, e:
     initParam['error_msg'] = _('Link %(param)s is not correct.') % {
         'param': ''
     }
     log.error(
         _('The app store link %(param)s is not correct.') %
         {'param': match.group(1)})
     log.error(e.message)
     return None
 appInfo.icon = '/'.join(
     [str(model.publisher.id),
Пример #5
0
def registerOffer(request, *args, **kwargs):
    """The function for create, update offer information."""
    offer = None
    initParam = {}
    form = offerForms.OfferForm()

    #Initial data
    if kwargs.get('pk'):
        offer = get_object_or_404(offerModels.Offer,
                                  pk=kwargs.get('pk'),
                                  publisher_id=request.user.id)
        form = offerForms.OfferForm(instance=offer)

    #Create or update offer.
    if request.method == "POST":
        form = offerForms.OfferForm(request.POST, instance=offer)
        if form.is_valid():
            offer = form.save(commit=False)
            offer.publisher = request.user
            offer.save()

            offer.position.clear()
            for position in form.cleaned_data['position']:
                offer.position.add(position)

            company_icon = request.FILES.get('company_icon')
            if company_icon:
                if company_icon.content_type.startswith('image'):
                    if company_icon.size > 1000000:
                        initParam['error'] = _(
                            'The image size must be not larger than 1M.')
                    else:
                        path = '/'.join(
                            [settings.MEDIA_ROOT,
                             str(request.user.id)])
                        if os.path.exists(path) is False:
                            os.makedirs(path)
                        if offer.company_icon:
                            path = '/'.join(
                                [settings.MEDIA_ROOT,
                                 str(offer.company_icon)])
                            if os.path.exists(path):
                                os.remove(path)
                        offer.company_icon = company_icon
                        offer.save()
                        if company_icon:
                            #Shrink image to (50*50) for offer company_icon.
                            path = '/'.join(
                                [settings.MEDIA_ROOT,
                                 str(offer.company_icon)])
                            common.imageThumbnail(path=path, size=[100, 100])
                        initParam['msg'] = _(
                            'The offer has been created successful.')
                        return redirect(
                            reverse('offer:offer_detail',
                                    kwargs={'pk': offer.id}))
                else:
                    initParam['error'] = _(
                        'The file type of %(param)s is not supported.') % {
                            'param': company_icon.name
                        }
            else:
                initParam['msg'] = _(
                    'The offer has been created successfully.')
                return redirect(
                    reverse('offer:offer_detail', kwargs={'pk': offer.id}))
    initParam['form'] = form
    return render_to_response("offer/register_offer.html",
                              initParam,
                              context_instance=RequestContext(request))
Пример #6
0
        appInfo.app_id = model.id
    appInfo.price = result.get("price", 0)
    appInfo.release_date = datetime.datetime.strptime(result.get("releaseDate", None), "%Y-%m-%dT%H:%M:%SZ")
    try:
        path = "/".join([settings.MEDIA_ROOT, str(model.publisher.id), str(model.id)])
        if os.path.exists(path) is False:
            os.makedirs(path)
        path = "/".join([path, "Icon.jpg"])
        if os.path.exists(path):
            os.remove(path)
        if result.get("artworkUrl512", None):
            if os.path.exists(path):
                os.remove(path)
            urllib.urlretrieve(result.get("artworkUrl512", None), path)
            # Shrink image From (1024*1024) to (200*200)
            common.imageThumbnail(path=path, size=[200, 200])
        elif result.get("artworkUrl100", None):
            urllib.urlretrieve(result.get("artworkUrl100", None), path)
        elif result.get("artworkUrl60", None):
            urllib.urlretrieve(result.get("artworkUrl60", None), path)
    except Exception, e:
        initParam["error_msg"] = _("Link %(param)s is not correct.") % {"param": ""}
        log.error(_("The app store link %(param)s is not correct.") % {"param": match.group(1)})
        log.error(e.message)
        return None
    appInfo.icon = "/".join([str(model.publisher.id), str(model.id), "Icon.jpg"])

    # Make the image of two dimension code for app store link
    if appInfo.app_store_link_code is None:
        app_store_link_code = "/".join([str(model.publisher.id), str(model.id), "app_store_link_code.jpg"])
        path = "/".join([settings.MEDIA_ROOT, app_store_link_code])